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 | |
parent | be1543d301ecd6933b87c90ec527d235af49377c (diff) |
stringop.c: refactor a few functions
Diffstat (limited to 'common')
-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) { list_t *split_string(const char *str, const char *delims) { list_t *res = create_list(); char *copy = strdup(str); - char *token; - token = strtok(copy, delims); - while(token) { - token = strdup(token); - list_add(res, token); + char *token = strtok(copy, delims); + while (token) { + list_add(res, strdup(token)); token = strtok(NULL, delims); } free(copy); @@ -268,13 +266,13 @@ char *argsep(char **stringp, const char *delim) { escaped = !escaped; } else if (*end == '\0') { *stringp = NULL; - goto found; + break; } else if (!in_string && !in_char && !escaped && strchr(delim, *end)) { if (end - start) { *(end++) = 0; *stringp = end + strspn(end, delim);; if (!**stringp) *stringp = NULL; - goto found; + break; } else { ++start; end = start; @@ -285,6 +283,5 @@ char *argsep(char **stringp, const char *delim) { } ++end; } - found: return start; } |