diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2026-06-29 17:43:03 +0000 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2026-06-29 17:43:03 +0000 |
| commit | 25ccc2599aa722b0552193961d4cda15928112d8 (patch) | |
| tree | d562abe7d1539665aaa9861d0615f039d3ff7bfa /xs_regex.h | |
| parent | 6fc748933ad263ba0e8c78eb9ae1e085a2b0dfb2 (diff) | |
| parent | 795355acb496a8a8f015a80edf48f38786894f86 (diff) | |
Merge branch 'master' of https://codeberg.org/grunfink/snac2
Diffstat (limited to 'xs_regex.h')
| -rw-r--r-- | xs_regex.h | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -35,12 +35,12 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count) regmatch_t rm; int offset = 0; xs_list *list = xs_list_new(); - const char *p; + const char *p = str; if (regcomp(&re, rx, REG_EXTENDED)) return list; - while (count > 0 && !regexec(&re, (p = str + offset), 1, &rm, offset > 0 ? REG_NOTBOL : 0)) { + while (count > 0 && !regexec(&re, p, 1, &rm, offset > 0 ? REG_NOTBOL : 0)) { /* add first the leading part of the string */ xs *s1 = xs_str_new_sz(p, rm.rm_so); @@ -55,6 +55,7 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count) offset += rm.rm_eo; count--; + p = str + offset; } /* add the rest of the string */ |