commit a4bbb84
grunfink
·
2026-06-07 06:17:18 +0000 UTC
parent 22574d2
Fixed minor bug in xs_regex_split_n().
3 files changed,
+14,
-6
M
xs.h
+10,
-3
1@@ -141,6 +141,7 @@ const char *xs_number_str(const xs_number *v);
2
3 xs_data *xs_data_new(const void *data, int size);
4 int xs_data_size(const xs_data *value);
5+const void *xs_data_ptr(const xs_data *value);
6 void xs_data_get(void *data, const xs_data *value);
7
8 void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
9@@ -965,10 +966,9 @@ int xs_list_in(const xs_list *list, const xs_val *val)
10
11 int n = 0;
12 const xs_val *v;
13- int sz = xs_size(val);
14
15 xs_list_foreach(list, v) {
16- if (sz == xs_size(v) && memcmp(val, v, sz) == 0)
17+ if (xs_cmp(val, v) == 0)
18 return n;
19
20 n++;
21@@ -1524,10 +1524,17 @@ int xs_data_size(const xs_data *value)
22 }
23
24
25+const void *xs_data_ptr(const xs_data *value)
26+/* return an internal pointer to the stored data */
27+{
28+ return &value[1 + _XS_TYPE_SIZE];
29+}
30+
31+
32 void xs_data_get(void *data, const xs_data *value)
33 /* copies the raw data stored inside value into data */
34 {
35- memcpy(data, &value[1 + _XS_TYPE_SIZE], xs_data_size(value));
36+ memcpy(data, xs_data_ptr(value), xs_data_size(value));
37 }
38
39
+3,
-2
1@@ -35,12 +35,12 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
2 regmatch_t rm;
3 int offset = 0;
4 xs_list *list = xs_list_new();
5- const char *p;
6+ const char *p = str;
7
8 if (regcomp(&re, rx, REG_EXTENDED))
9 return list;
10
11- while (count > 0 && !regexec(&re, (p = str + offset), 1, &rm, offset > 0 ? REG_NOTBOL : 0)) {
12+ while (count > 0 && !regexec(&re, p, 1, &rm, offset > 0 ? REG_NOTBOL : 0)) {
13 /* add first the leading part of the string */
14 xs *s1 = xs_str_new_sz(p, rm.rm_so);
15
16@@ -55,6 +55,7 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
17 offset += rm.rm_eo;
18
19 count--;
20+ p = str + offset;
21 }
22
23 /* add the rest of the string */
+1,
-1
1@@ -1 +1 @@
2-/* 8c7b288a0e0eac3a61f7c465633499b2fd44ca61 2026-04-05T10:14:27+02:00 */
3+/* 2e209276f3f598dbee88350a33291198ab792eb2 2026-06-03T19:54:14+02:00 */