-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand Regex to allow querying for metacharacters #5962
Conversation
fe03410
to
e67a1d7
Compare
I hate to deal with special characters...especially manually. So, this gets a big 👍 from me. |
What exactly is a "need for such query from outside of Regex.escape"? A use case like
|
@straight-shoota When you'd want to validate strings in terms are they regex-like, without resorting to manual checks. Escaping them is another step which sometimes could even be omitted. |
e67a1d7
to
6081b62
Compare
But |
On second thought, how about |
@straight-shoota I misspoke, what I meant was checking whether a string needs to be escaped - for validation purposes only. |
@sdogruyol For me such name would imply non-raising version of |
@Sija yeah, you're right (looking at you Ruby) 👍 |
6081b62
to
0f7f5c1
Compare
Since previous, although cleaner, code results in ~60% performance penalty.
0f7f5c1
to
4324e05
Compare
Since this one incurs ~10% performance penalty due to optimizer heuristics (as per crystal-lang#5962 (comment))
* Add Regex.needs_escape? * Revert to using case statement with hard-coded character list Since previous, although cleaner, code results in ~60% performance penalty. * Use macro expansion instead of hard-coded list, props to @RX14 * Revert to the original implementation Since this one incurs ~10% performance penalty due to optimizer heuristics (as per crystal-lang#5962 (comment))
Would accommodate the need for such query from outside of
Regex.escape
.