Fix captures for {..} optimization

This commit is contained in:
Bruce Hill 2024-09-07 03:00:42 -04:00
parent cbf0bc9207
commit 6bacf34211

View File

@ -1630,14 +1630,16 @@ int64_t match(Text_t text, int64_t text_index, Pattern_t pattern, int64_t patter
}
}
if (pat.tag == PAT_ANY && !pat.negated && pattern_index >= pattern.length) {
int64_t remaining = text.length - text_index;
return remaining >= pat.min ? MIN(remaining, pat.max) : -1;
}
int64_t capture_start = text_index;
int64_t count = 0, capture_len = 0, next_match_len = 0;
if (pat.tag == PAT_ANY && !pat.negated && pattern_index >= pattern.length) {
int64_t remaining = text.length - text_index;
capture_len = remaining >= pat.min ? MIN(remaining, pat.max) : -1;
text_index += capture_len;
goto success;
}
if (pat.min == 0 && pattern_index < pattern.length) {
next_match_len = match(text, text_index, pattern, pattern_index, captures, capture_index + (pat.non_capturing ? 0 : 1));
if (next_match_len >= 0) {