Fix handling of empty matches in iterators, using PCRE2_NOTEMPTY_ATSTART #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
find_iterandcaptures_iterfunctions iterate over the distinct, non-overlapping matches within the subject string.Previously, this required tricky logic to ensure that the iterator would make forward progress. In particular, if the previous match was an empty match at byte position J, the next search would start at position J+1.
That didn't work correctly if the regex was in UTF or UCP mode. For example, if the pattern was
(?<=á)and the subject string wasáá:In "match-invalid-UTF" mode, trying to search at position 3 would fail to find the match at position 4 (because the byte at position 3 was regarded as invalid).
In "non-match-invalid-UTF" mode, trying to search at position 3 would give an error ("bad offset into UTF string").
PCRE2 has a mechanism to do what we really want: search for the next match that has
start >= Jand does not havestart == end == J. This is done by setting the PCRE2_NOTEMPTY_ATSTART flag.This PR is, I think, a better solution to the problem than my original PR #36. It avoids making assumptions about what the acceptable matching positions are, by deferring to PCRE2.