summaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authorGravatar default2023-01-10 08:45:36 +0100
committerGravatar default2023-01-10 08:45:36 +0100
commit061291cabfe23b5c7742ac5bc4dc7e968278ad00 (patch)
tree15debb64bf1893106a9919d0f1d7b5f6cda59527 /xs.h
parentUpdated RELEASE_NOTES. (diff)
downloadsnac2-061291cabfe23b5c7742ac5bc4dc7e968278ad00.tar.gz
snac2-061291cabfe23b5c7742ac5bc4dc7e968278ad00.tar.xz
snac2-061291cabfe23b5c7742ac5bc4dc7e968278ad00.zip
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/xs.h b/xs.h
index 666f536..68236a1 100644
--- a/xs.h
+++ b/xs.h
@@ -459,13 +459,21 @@ d_char *xs_crop(d_char *str, int start, int end)
459d_char *xs_strip_chars(d_char *str, const char *chars) 459d_char *xs_strip_chars(d_char *str, const char *chars)
460/* strips the string of chars from the start and the end */ 460/* strips the string of chars from the start and the end */
461{ 461{
462 int s, e; 462 int n;
463
464 /* strip first from the end */
465 for (n = strlen(str); n > 0 && strchr(chars, str[n - 1]); n--);
466 str[n] = '\0';
463 467
464 for (s = 0; strchr(chars, str[s]); s++); 468 if (str[0]) {
465 for (e = strlen(str); e > 0 && strchr(chars, str[e - 1]); e--); 469 /* now strip from the beginning */
470 for (n = 0; str[n] && strchr(chars, str[n]); n++);
466 471
467 str[e] = '\0'; 472 if (n)
468 return xs_collapse(str, 0, s); 473 str = xs_collapse(str, 0, n);
474 }
475
476 return str;
469} 477}
470 478
471 479