-
-
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
Add Regex#matches?
and String#matches?
#8989
Conversation
Fixed crystal-lang#8950 It is another version of `match` method, which does not allocate `MatchData` when matched, instead it returns `true` or `false`. Avoiding allocation, it is efficient in fact. crystal-lang#8950 (comment)
# Calls `pcre_exec` C function, and handles returning value. | ||
private def internal_matches?(str, byte_index, options, ovector, ovector_size) | ||
ret = LibPCRE.exec(@re, @extra, str, str.bytesize, byte_index, (options | Options::NO_UTF8_CHECK), ovector, ovector_size) | ||
# TODO: when `ret < -1`, it means PCRE error. It should handle correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep TODO in this PR. Because, fixing this needs bigger diff than adding new feature IMO.
It is not ideal to have both |
There should probably be a discussion about naming though. Ruby defines a similar |
@yxhuvud ... but only when you have a non-nilable method version, like |
On the other hand, As the above reason, I consider |
Documents of I think it is ready to merge. Please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wording suggestions.
Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl>
Thanks @Sija ❤️ |
Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl>
* Add `Regex#matches?` and `String#matches?` Fixed crystal-lang#8950 It is another version of `match` method, which does not allocate `MatchData` when matched, instead it returns `true` or `false`. Avoiding allocation, it is efficient in fact. crystal-lang#8950 (comment) * Update documents of `{Regex, String}#matches?` and `#match` * Improve document words in `#match` and `#matches?` Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl> * Apply suggestions from code review Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl> Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
Fixed #8950
It is another version of
match
method, which does not allocateMatchData
when matched, instead it returnstrue
orfalse
. Avoiding allocation, it is efficient in fact.#8950 (comment)