commit 9eb960a
default
·
2023-01-08 17:50:37 +0000 UTC
parent db365bc
Backport from xs.
2 files changed,
+9,
-7
M
xs.h
M
xs.h
+8,
-6
1@@ -61,7 +61,8 @@ int xs_str_in(const char *haystack, const char *needle);
2 int xs_startswith(const char *str, const char *prefix);
3 int xs_endswith(const char *str, const char *postfix);
4 d_char *xs_crop(d_char *str, int start, int end);
5-d_char *xs_strip(d_char *str);
6+d_char *xs_strip_chars(d_char *str, const char *chars);
7+#define xs_strip(str) xs_strip_chars(str, " \r\n\t\v\f")
8 d_char *xs_tolower(d_char *str);
9 d_char *xs_list_new(void);
10 d_char *xs_list_append_m(d_char *list, const char *mem, int dsz);
11@@ -455,15 +456,16 @@ d_char *xs_crop(d_char *str, int start, int end)
12 }
13
14
15-d_char *xs_strip(d_char *str)
16-/* strips the string of blanks from the start and the end */
17+d_char *xs_strip_chars(d_char *str, const char *chars)
18+/* strips the string of chars from the start and the end */
19 {
20 int s, e;
21
22- for (s = 0; isspace(str[s]); s++);
23- for (e = strlen(str); e > 0 && isspace(str[e - 1]); e--);
24+ for (s = 0; strchr(chars, str[s]); s++);
25+ for (e = strlen(str); e > 0 && strchr(chars, str[e - 1]); e--);
26
27- return xs_crop(str, s, e);
28+ str[e] = '\0';
29+ return xs_collapse(str, 0, s);
30 }
31
32
+1,
-1
1@@ -1 +1 @@
2-/* a04f6c8482d42d4d972f5190ecbad5c0509531b4 */
3+/* 52f1885c0439e886094a9506e6b06f3d657fe8d9 */