diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-07 03:00:42 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-07 03:00:42 -0400 |
| commit | 6bacf34211e144a321c7a6c7955201a4eff6cf25 (patch) | |
| tree | 5576d77c9ad23ba673cc0fd31230dd0baea9e18b | |
| parent | cbf0bc9207b71e67d43f73b6e6474fd839ce3fbd (diff) | |
Fix captures for {..} optimization
| -rw-r--r-- | builtins/text.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/builtins/text.c b/builtins/text.c index fb71d8d0..768e6a5d 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -1630,14 +1630,16 @@ int64_t match(Text_t text, int64_t text_index, Pattern_t pattern, int64_t patter } } + 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; - return remaining >= pat.min ? MIN(remaining, pat.max) : -1; + capture_len = remaining >= pat.min ? MIN(remaining, pat.max) : -1; + text_index += capture_len; + goto success; } - int64_t capture_start = text_index; - int64_t count = 0, capture_len = 0, next_match_len = 0; - 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) { |
