diff options
author | Ian Fan <ianfan0@gmail.com> | 2019-01-17 16:56:04 +0000 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-03-11 14:42:58 +0100 |
commit | 00570c139e037d5d88f1683bb71b42a7f34139b8 (patch) | |
tree | eef5cc786aa9fee2b8b5bd52e616470d72d522b8 /common/stringop.c | |
parent | stringop.c: clean up headers (diff) | |
download | sway-00570c139e037d5d88f1683bb71b42a7f34139b8.tar.gz sway-00570c139e037d5d88f1683bb71b42a7f34139b8.tar.zst sway-00570c139e037d5d88f1683bb71b42a7f34139b8.zip |
stringop.c: refactor a few functions
Diffstat (limited to 'common/stringop.c')
-rw-r--r-- | common/stringop.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/common/stringop.c b/common/stringop.c index b42604c1..dea152cc 100644 --- a/common/stringop.c +++ b/common/stringop.c | |||
@@ -78,12 +78,10 @@ int lenient_strcmp(char *a, char *b) { | |||
78 | list_t *split_string(const char *str, const char *delims) { | 78 | list_t *split_string(const char *str, const char *delims) { |
79 | list_t *res = create_list(); | 79 | list_t *res = create_list(); |
80 | char *copy = strdup(str); | 80 | char *copy = strdup(str); |
81 | char *token; | ||
82 | 81 | ||
83 | token = strtok(copy, delims); | 82 | char *token = strtok(copy, delims); |
84 | while(token) { | 83 | while (token) { |
85 | token = strdup(token); | 84 | list_add(res, strdup(token)); |
86 | list_add(res, token); | ||
87 | token = strtok(NULL, delims); | 85 | token = strtok(NULL, delims); |
88 | } | 86 | } |
89 | free(copy); | 87 | free(copy); |
@@ -268,13 +266,13 @@ char *argsep(char **stringp, const char *delim) { | |||
268 | escaped = !escaped; | 266 | escaped = !escaped; |
269 | } else if (*end == '\0') { | 267 | } else if (*end == '\0') { |
270 | *stringp = NULL; | 268 | *stringp = NULL; |
271 | goto found; | 269 | break; |
272 | } else if (!in_string && !in_char && !escaped && strchr(delim, *end)) { | 270 | } else if (!in_string && !in_char && !escaped && strchr(delim, *end)) { |
273 | if (end - start) { | 271 | if (end - start) { |
274 | *(end++) = 0; | 272 | *(end++) = 0; |
275 | *stringp = end + strspn(end, delim);; | 273 | *stringp = end + strspn(end, delim);; |
276 | if (!**stringp) *stringp = NULL; | 274 | if (!**stringp) *stringp = NULL; |
277 | goto found; | 275 | break; |
278 | } else { | 276 | } else { |
279 | ++start; | 277 | ++start; |
280 | end = start; | 278 | end = start; |
@@ -285,6 +283,5 @@ char *argsep(char **stringp, const char *delim) { | |||
285 | } | 283 | } |
286 | ++end; | 284 | ++end; |
287 | } | 285 | } |
288 | found: | ||
289 | return start; | 286 | return start; |
290 | } | 287 | } |