From 6bacf34211e144a321c7a6c7955201a4eff6cf25 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 7 Sep 2024 03:00:42 -0400 Subject: Fix captures for {..} optimization --- builtins/text.c | 10 ++++++---- 1 file 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) { -- cgit v1.2.3