aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2019-01-17 16:56:04 +0000
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-03-11 10:57:16 -0400
commitab1b1dab1f8a1ddb4a8b7b1e81c7506cece6a5f2 (patch)
treed5de8a1227529a34414a3c98dd66e6785d76a3b7
parentstringop.c: clean up headers (diff)
downloadsway-ab1b1dab1f8a1ddb4a8b7b1e81c7506cece6a5f2.tar.gz
sway-ab1b1dab1f8a1ddb4a8b7b1e81c7506cece6a5f2.tar.zst
sway-ab1b1dab1f8a1ddb4a8b7b1e81c7506cece6a5f2.zip
stringop.c: refactor a few functions
-rw-r--r--common/stringop.c13
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) {
78list_t *split_string(const char *str, const char *delims) { 78list_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}