mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
Backport from xs.
This commit is contained in:
parent
c37dd39da2
commit
061291cabf
2 changed files with 14 additions and 6 deletions
18
xs.h
18
xs.h
|
@ -459,13 +459,21 @@ d_char *xs_crop(d_char *str, int start, int 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;
|
||||
int n;
|
||||
|
||||
for (s = 0; strchr(chars, str[s]); s++);
|
||||
for (e = strlen(str); e > 0 && strchr(chars, str[e - 1]); e--);
|
||||
/* strip first from the end */
|
||||
for (n = strlen(str); n > 0 && strchr(chars, str[n - 1]); n--);
|
||||
str[n] = '\0';
|
||||
|
||||
str[e] = '\0';
|
||||
return xs_collapse(str, 0, s);
|
||||
if (str[0]) {
|
||||
/* now strip from the beginning */
|
||||
for (n = 0; str[n] && strchr(chars, str[n]); n++);
|
||||
|
||||
if (n)
|
||||
str = xs_collapse(str, 0, n);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
/* 52f1885c0439e886094a9506e6b06f3d657fe8d9 */
|
||||
/* e8f087f6b185939256227ea21b69f5f16f25a2dd */
|
||||
|
|
Loading…
Reference in a new issue