From 82fb77ca52d097ebf399924e3b8b6231362885af Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Thu, 1 Jan 2026 17:50:03 -0500 Subject: fix taking regex offset from the wrong chunk --- main.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index d511084..6879999 100644 --- a/main.c +++ b/main.c @@ -637,25 +637,24 @@ int search_next_regex(TxtLoc l, Str src, TxtLoc *out) { e.msg = str_printf(&e.scratch, "Regex error: %s", re_comp_strerror(err)); return 0; } - TxtLoc t = l; int match_found = 0; search_from_start: + TxtLoc t = l; re_search_start(&s, &re, &e.scratch); while (!at_end(t)) { - TxtLoc p = t; Str chnk = txt_next_chunk(&t); re_search_chunk(&s, chnk.s, chnk.n); if (at_end(t)) re_search_last_chunk(&s); ReMatch m; if (re_search_match(&s, &m)) { - while (m.extent.start--) p = bnext(p); - *out = p; + while (m.extent.start--) l = bnext(l); + *out = l; return 1; } } if (match_found == 0) { match_found = -1; - t = txt_start(t.t); + l = txt_start(l.t); goto search_from_start; } return 0; -- cgit v1.2.3