From 93de9eb76d628cf731120d97332e03600c167271 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Thu, 5 Nov 2015 21:41:04 -0800 Subject: [PATCH] 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. --- src/basic/extract-word.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index b08851b89bc..b0056a84857 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: -- 2.39.2