From f58642b4396f1433f270f15a2a19e50e08179be4 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 11 Feb 2025 18:50:14 +0100 Subject: Added some checks to xs_regex_split_n(). --- xs_regex.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'xs_regex.h') diff --git a/xs_regex.h b/xs_regex.h index a4db447..1e157d2 100644 --- a/xs_regex.h +++ b/xs_regex.h @@ -43,11 +43,13 @@ 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 */ xs *s1 = xs_str_new_sz(p, rm.rm_so); - list = xs_list_append(list, s1); + + list = xs_list_append(list, xs_is_string(s1) ? s1 : ""); /* add now the matched text as the separator */ xs *s2 = xs_str_new_sz(p + rm.rm_so, rm.rm_eo - rm.rm_so); - list = xs_list_append(list, s2); + + list = xs_list_append(list, xs_is_string(s2) ? s2 : ""); /* move forward */ offset += rm.rm_eo; -- cgit v1.2.3