Skip to content

Commit 93de9eb

Browse files
committed
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.
1 parent 8372da4 commit 93de9eb

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/basic/extract-word.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
4242
/* Bail early if called after last value or with no input */
4343
if (!*p)
4444
goto finish_force_terminate;
45+
c = **p;
4546

4647
if (!separators)
4748
separators = WHITESPACE;
@@ -55,14 +56,14 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
5556
if (!GREEDY_REALLOC(s, allocated, sz+1))
5657
return -ENOMEM;
5758

58-
for (;;) {
59-
c = **p;
59+
for (;; (*p) ++, c = **p) {
6060
if (c == 0)
6161
goto finish_force_terminate;
6262
else if (strchr(separators, c)) {
63-
(*p) ++;
64-
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
63+
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
64+
(*p) ++;
6565
goto finish_force_next;
66+
}
6667
} else {
6768
/* We found a non-blank character, so we will always
6869
* 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
7374
}
7475
}
7576

76-
for (;;) {
77-
c = **p;
78-
77+
for (;; (*p) ++, c = **p) {
7978
if (backslash) {
8079
if (!GREEDY_REALLOC(s, allocated, sz+7))
8180
return -ENOMEM;
@@ -163,8 +162,6 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
163162
s[sz++] = c;
164163
}
165164
}
166-
167-
(*p) ++;
168165
}
169166

170167
finish_force_terminate:

0 commit comments

Comments
 (0)