summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-01-08 18:50:37 +0100
committerdefault <nobody@localhost>2023-01-08 18:50:37 +0100
commit9eb960ae8a94241643ad3a5d2477a417ec120e4a (patch)
tree8fbdb3761d628d4437e4caa6f75d6f1745f5b682
parentdb365bc20cec4735093de66f8a6d8152194846e0 (diff)
Backport from xs.
-rw-r--r--xs.h14
-rw-r--r--xs_version.h2
2 files changed, 9 insertions, 7 deletions
diff --git a/xs.h b/xs.h
index 38d3050..666f536 100644
--- a/xs.h
+++ b/xs.h
@@ -61,7 +61,8 @@ int xs_str_in(const char *haystack, const char *needle);
int xs_startswith(const char *str, const char *prefix);
int xs_endswith(const char *str, const char *postfix);
d_char *xs_crop(d_char *str, int start, int end);
-d_char *xs_strip(d_char *str);
+d_char *xs_strip_chars(d_char *str, const char *chars);
+#define xs_strip(str) xs_strip_chars(str, " \r\n\t\v\f")
d_char *xs_tolower(d_char *str);
d_char *xs_list_new(void);
d_char *xs_list_append_m(d_char *list, const char *mem, int dsz);
@@ -455,15 +456,16 @@ d_char *xs_crop(d_char *str, int start, int end)
}
-d_char *xs_strip(d_char *str)
-/* strips the string of blanks from the start and the end */
+d_char *xs_strip_chars(d_char *str, const char *chars)
+/* strips the string of chars from the start and the end */
{
int s, e;
- for (s = 0; isspace(str[s]); s++);
- for (e = strlen(str); e > 0 && isspace(str[e - 1]); e--);
+ for (s = 0; strchr(chars, str[s]); s++);
+ for (e = strlen(str); e > 0 && strchr(chars, str[e - 1]); e--);
- return xs_crop(str, s, e);
+ str[e] = '\0';
+ return xs_collapse(str, 0, s);
}
diff --git a/xs_version.h b/xs_version.h
index 682964a..c58ea4e 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
-/* a04f6c8482d42d4d972f5190ecbad5c0509531b4 */
+/* 52f1885c0439e886094a9506e6b06f3d657fe8d9 */