소스 검색

Backport from xs.

default 3 년 전
부모
커밋
9eb960ae8a
2개의 변경된 파일9개의 추가작업 그리고 7개의 파일을 삭제
  1. 8 6
      xs.h
  2. 1 1
      xs_version.h

+ 8 - 6
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
xs_version.h

@@ -1 +1 @@
-/* a04f6c8482d42d4d972f5190ecbad5c0509531b4 */
+/* 52f1885c0439e886094a9506e6b06f3d657fe8d9 */