summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Brandenburger <filbranden@google.com>2015-11-05 21:41:04 -0800
committerFilipe Brandenburger <filbranden@google.com>2015-11-05 21:41:04 -0800
commit93de9eb76d628cf731120d97332e03600c167271 (patch)
treece7e6e0831848996f50dd1060b1c5cc4fd9bb50a
parent8372da448f3c738e0154d988538d497f7e2e1f83 (diff)
extract-word: increment pointer p and keep c in sync in for loop
This will make it easier to use inner loops to keep looping in the same state, by just updating p and c in the same way in the inner loops. Tested that no regressions were created in test-extract-word.
-rw-r--r--src/basic/extract-word.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c
index b08851b89b..b0056a8485 100644
--- a/src/basic/extract-word.c
+++ b/src/basic/extract-word.c
@@ -42,6 +42,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
/* Bail early if called after last value or with no input */
if (!*p)
goto finish_force_terminate;
+ c = **p;
if (!separators)
separators = WHITESPACE;
@@ -55,14 +56,14 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
if (!GREEDY_REALLOC(s, allocated, sz+1))
return -ENOMEM;
- for (;;) {
- c = **p;
+ for (;; (*p) ++, c = **p) {
if (c == 0)
goto finish_force_terminate;
else if (strchr(separators, c)) {
- (*p) ++;
- if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
+ if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
+ (*p) ++;
goto finish_force_next;
+ }
} else {
/* We found a non-blank character, so we will always
* want to return a string (even if it is empty),
@@ -73,9 +74,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
}
}
- for (;;) {
- c = **p;
-
+ for (;; (*p) ++, c = **p) {
if (backslash) {
if (!GREEDY_REALLOC(s, allocated, sz+7))
return -ENOMEM;
@@ -163,8 +162,6 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
s[sz++] = c;
}
}
-
- (*p) ++;
}
finish_force_terminate: