diff options
Diffstat (limited to 'common/stringop.c')
-rw-r--r-- | common/stringop.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/common/stringop.c b/common/stringop.c index 4b8c9a38..f8b7aaec 100644 --- a/common/stringop.c +++ b/common/stringop.c | |||
@@ -9,24 +9,17 @@ | |||
9 | #include "string.h" | 9 | #include "string.h" |
10 | #include "list.h" | 10 | #include "list.h" |
11 | 11 | ||
12 | const char whitespace[] = " \f\n\r\t\v"; | 12 | static const char whitespace[] = " \f\n\r\t\v"; |
13 | 13 | ||
14 | char *strip_whitespace(char *_str) { | 14 | void strip_whitespace(char *str) { |
15 | if (*_str == '\0') | 15 | size_t len = strlen(str); |
16 | return _str; | 16 | size_t start = strspn(str, whitespace); |
17 | char *strold = _str; | 17 | memmove(str, &str[start], len + 1 - start); |
18 | while (*_str == ' ' || *_str == '\t') { | 18 | |
19 | _str++; | 19 | if (!*str) return; |
20 | } | 20 | |
21 | char *str = strdup(_str); | 21 | for (len -= start + 1; isspace(str[len]); --len) {} |
22 | free(strold); | 22 | str[len + 1] = '\0'; |
23 | int i; | ||
24 | for (i = 0; str[i] != '\0'; ++i); | ||
25 | do { | ||
26 | i--; | ||
27 | } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); | ||
28 | str[i + 1] = '\0'; | ||
29 | return str; | ||
30 | } | 23 | } |
31 | 24 | ||
32 | void strip_quotes(char *str) { | 25 | void strip_quotes(char *str) { |