summaryrefslogtreecommitdiff
path: root/xs_regex.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-09-13 18:19:19 +0200
committerdefault <nobody@localhost>2023-09-13 18:19:19 +0200
commit4105e737e6ec9b9d8aca508ac5bedb69947b202d (patch)
treef90686ed12ef4ea2b50e65ddeee42bf3650144eb /xs_regex.h
parent53a906b3bdcadb477a0681b65a90cb5e450ec639 (diff)
Backport from xs.
Diffstat (limited to 'xs_regex.h')
-rw-r--r--xs_regex.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/xs_regex.h b/xs_regex.h
index 7e1c80f..3425661 100644
--- a/xs_regex.h
+++ b/xs_regex.h
@@ -33,12 +33,12 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
while (count > 0 && !regexec(&re, (p = str + offset), 1, &rm, offset > 0 ? REG_NOTBOL : 0)) {
/* add first the leading part of the string */
- list = xs_list_append_m(list, p, rm.rm_so);
- list = xs_insert_m(list, xs_size(list) - 1, "", 1);
+ xs *s1 = xs_str_new_sz(p, rm.rm_so);
+ list = xs_list_append(list, s1);
/* add now the matched text as the separator */
- list = xs_list_append_m(list, p + rm.rm_so, rm.rm_eo - rm.rm_so);
- list = xs_insert_m(list, xs_size(list) - 1, "", 1);
+ xs *s2 = xs_str_new_sz(p + rm.rm_so, rm.rm_eo - rm.rm_so);
+ list = xs_list_append(list, s2);
/* move forward */
offset += rm.rm_eo;