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 support for Regexp
needles to String#index
and String#rindex
#2362
Comments
Is this still useful/actual? |
yup these cases are still hardcoded to |
I looked into https://github.com/artichoke/artichoke/blob/trunk/artichoke-backend/src/extn/core/regexp/backend/mod.rs#L83 and it appears that the only functions that expose positions are for capture groups and not for matches. I just wanted to confirm the right approach is to extend the trait, its implementations and the wrapper to expose similar functions for matches and not capture groups before moving forward LMK what you think |
dumping some raw notes here from DM with @edmondop: all capture group APIs have to go through artichoke/artichoke-backend/src/extn/core/string/trampoline.rs Lines 346 to 353 in 7454564
|
Not sure I fully understod, can you provide some additional context? In my original question I was trying to explain that it seems to me that it is not possible to implement this feature by using underlying methods that already exists in fn pos(&self, haystack: &[u8], at: usize) -> Result<Option<(usize, usize)>, Error> {
let haystack = str::from_utf8(haystack).map_err(|_| {
ArgumentError::with_message("regex crate utf8 backend for Regexp only supports UTF-8 haystacks")
})?;
let pos = self
.regex
.captures(haystack)
.and_then(|captures| captures.get(at))
.map(|match_pos| (match_pos.start(), match_pos.end()));
Ok(pos)
} but that provides start and ending position of the capture group, not of the full match. So I was seeking confirmation that somehow we need to create a method that returns either Matches by position, or a collection/iterator of matches. Maybe what I should have understood from your comment is that in reality it is possible to implement support for Regexp needless in |
@edmondop you seem to be hung up on using the You've found Generally when implementing APIs like this I've found it useful to play around in the REPL to see how they behave:
All of this behavior for offset and such is already implemented in the methods on I hope this additional context is enough to steer you in the right direction. |
I do have something that works for index, but not for rindex.
I think the problem might be that the match_data is the first match probably, and so my end function return the end of the first match rather than the last match. I have tried in |
String#index
andString#rindex
both support being called with aRegexp
pattern, like this:Don't worry about semantics of negative lookbehind and negative lookahead; Artichoke's Regexp engine does not support these features.
The implicated code is here:
artichoke/artichoke-backend/src/extn/core/string/trampoline.rs
Lines 1149 to 1152 in 8460b3f
artichoke/artichoke-backend/src/extn/core/string/trampoline.rs
Lines 1309 to 1312 in 8460b3f
See also:
Regexp
needles toString#byteindex
#2359The text was updated successfully, but these errors were encountered: