diff options
| author | 2023-01-08 18:50:37 +0100 | |
|---|---|---|
| committer | 2023-01-08 18:50:37 +0100 | |
| commit | 9eb960ae8a94241643ad3a5d2477a417ec120e4a (patch) | |
| tree | 8fbdb3761d628d4437e4caa6f75d6f1745f5b682 | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-9eb960ae8a94241643ad3a5d2477a417ec120e4a.tar.gz snac2-9eb960ae8a94241643ad3a5d2477a417ec120e4a.tar.xz snac2-9eb960ae8a94241643ad3a5d2477a417ec120e4a.zip | |
Backport from xs.
| -rw-r--r-- | xs.h | 14 | ||||
| -rw-r--r-- | xs_version.h | 2 |
2 files changed, 9 insertions, 7 deletions
| @@ -61,7 +61,8 @@ int xs_str_in(const char *haystack, const char *needle); | |||
| 61 | int xs_startswith(const char *str, const char *prefix); | 61 | int xs_startswith(const char *str, const char *prefix); |
| 62 | int xs_endswith(const char *str, const char *postfix); | 62 | int xs_endswith(const char *str, const char *postfix); |
| 63 | d_char *xs_crop(d_char *str, int start, int end); | 63 | d_char *xs_crop(d_char *str, int start, int end); |
| 64 | d_char *xs_strip(d_char *str); | 64 | d_char *xs_strip_chars(d_char *str, const char *chars); |
| 65 | #define xs_strip(str) xs_strip_chars(str, " \r\n\t\v\f") | ||
| 65 | d_char *xs_tolower(d_char *str); | 66 | d_char *xs_tolower(d_char *str); |
| 66 | d_char *xs_list_new(void); | 67 | d_char *xs_list_new(void); |
| 67 | d_char *xs_list_append_m(d_char *list, const char *mem, int dsz); | 68 | 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) | |||
| 455 | } | 456 | } |
| 456 | 457 | ||
| 457 | 458 | ||
| 458 | d_char *xs_strip(d_char *str) | 459 | d_char *xs_strip_chars(d_char *str, const char *chars) |
| 459 | /* strips the string of blanks from the start and the end */ | 460 | /* strips the string of chars from the start and the end */ |
| 460 | { | 461 | { |
| 461 | int s, e; | 462 | int s, e; |
| 462 | 463 | ||
| 463 | for (s = 0; isspace(str[s]); s++); | 464 | for (s = 0; strchr(chars, str[s]); s++); |
| 464 | for (e = strlen(str); e > 0 && isspace(str[e - 1]); e--); | 465 | for (e = strlen(str); e > 0 && strchr(chars, str[e - 1]); e--); |
| 465 | 466 | ||
| 466 | return xs_crop(str, s, e); | 467 | str[e] = '\0'; |
| 468 | return xs_collapse(str, 0, s); | ||
| 467 | } | 469 | } |
| 468 | 470 | ||
| 469 | 471 | ||
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 */ | ||