summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2026-01-01 17:50:03 -0500
committerWormHeamer2026-01-01 17:50:03 -0500
commit82fb77ca52d097ebf399924e3b8b6231362885af (patch)
tree21fe88777e6017f68d747c8e4f6cd84531027a23 /main.c
parentf06633322a5eb5985b02c71deb409e529908d5b0 (diff)
fix taking regex offset from the wrong chunk
Diffstat (limited to 'main.c')
-rw-r--r--main.c9
1 files changed, 4 insertions, 5 deletions
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;