commit f58642b
default
·
2025-02-11 17:50:14 +0000 UTC
parent 5c27885
Added some checks to xs_regex_split_n().
1 files changed,
+4,
-2
+4,
-2
1@@ -43,11 +43,13 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
2 while (count > 0 && !regexec(&re, (p = str + offset), 1, &rm, offset > 0 ? REG_NOTBOL : 0)) {
3 /* add first the leading part of the string */
4 xs *s1 = xs_str_new_sz(p, rm.rm_so);
5- list = xs_list_append(list, s1);
6+
7+ list = xs_list_append(list, xs_is_string(s1) ? s1 : "");
8
9 /* add now the matched text as the separator */
10 xs *s2 = xs_str_new_sz(p + rm.rm_so, rm.rm_eo - rm.rm_so);
11- list = xs_list_append(list, s2);
12+
13+ list = xs_list_append(list, xs_is_string(s2) ? s2 : "");
14
15 /* move forward */
16 offset += rm.rm_eo;