mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Backport from xs.
This commit is contained in:
parent
db365bc20c
commit
9eb960ae8a
2 changed files with 9 additions and 7 deletions
14
xs.h
14
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
/* a04f6c8482d42d4d972f5190ecbad5c0509531b4 */
|
||||
/* 52f1885c0439e886094a9506e6b06f3d657fe8d9 */
|
||||
|
|
Loading…
Reference in a new issue