commit 061291c
default
·
2023-01-10 07:45:36 +0000 UTC
parent c37dd39
Backport from xs.
2 files changed,
+14,
-6
M
xs.h
M
xs.h
+13,
-5
1@@ -459,13 +459,21 @@ d_char *xs_crop(d_char *str, int start, int end)
2 d_char *xs_strip_chars(d_char *str, const char *chars)
3 /* strips the string of chars from the start and the end */
4 {
5- int s, e;
6+ int n;
7+
8+ /* strip first from the end */
9+ for (n = strlen(str); n > 0 && strchr(chars, str[n - 1]); n--);
10+ str[n] = '\0';
11
12- for (s = 0; strchr(chars, str[s]); s++);
13- for (e = strlen(str); e > 0 && strchr(chars, str[e - 1]); e--);
14+ if (str[0]) {
15+ /* now strip from the beginning */
16+ for (n = 0; str[n] && strchr(chars, str[n]); n++);
17
18- str[e] = '\0';
19- return xs_collapse(str, 0, s);
20+ if (n)
21+ str = xs_collapse(str, 0, n);
22+ }
23+
24+ return str;
25 }
26
27
+1,
-1
1@@ -1 +1 @@
2-/* 52f1885c0439e886094a9506e6b06f3d657fe8d9 */
3+/* e8f087f6b185939256227ea21b69f5f16f25a2dd */