diff options
| author | WormHeamer | 2025-12-31 05:43:46 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-12-31 05:43:46 -0500 |
| commit | 83df7c5a4bed79c53357fd91c393071de1eb60a2 (patch) | |
| tree | bdbeffd79f60743cae260c4c78d509474d54ce1e /regex.c | |
| parent | d723f8a5d54f098f0cf378e5dcf3a7d4ec049822 (diff) | |
add (hacky and slow) reverse regex search
Diffstat (limited to 'regex.c')
| -rw-r--r-- | regex.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -846,18 +846,13 @@ void re_search_last_chunk(ReSearch *s) { * check s->flags to find if the match is done yet */ -int re_search_match(ReSearch *s, ReMatch *m) { +int re_search_match_at_start(ReSearch *s, ReMatch *m) { size_t i = s->buf_idx; size_t n = s->buf_len; while (i < n) { - if (s->re->first_byte && (~s->flags & RE_SEARCH_MID_MATCH)) { - const char *p = memchr(s->buf + i, s->re->first_byte, n - i); - if (!p) break; - i = p - s->buf; - } isize r = re_search_try_match(s, i, n); if (r < 0) { - i++; + return 0; } else { if (i == (usize)r) r++; if (s->flags & RE_SEARCH_MID_MATCH) { @@ -877,6 +872,22 @@ int re_search_match(ReSearch *s, ReMatch *m) { return 0; } +int re_search_match(ReSearch *s, ReMatch *m) { + u32 i = s->buf_idx; + u32 n = s->buf_len; + while (i < n) { + if (s->re->first_byte && (~s->flags & RE_SEARCH_MID_MATCH)) { + const char *p = memchr(s->buf + i, s->re->first_byte, n - i); + if (!p) break; + i = p - s->buf; + } + s->buf_idx = i++; + if (re_search_match_at_start(s, m)) return 1; + } + s->buf_idx = n; + return 0; +} + /* convenience wrappers */ ReMatchList re_match_all(RegEx *re, Str s, Arena *a) { |
