From bc8ec170d2bc3e294f24ff8bb255436a685ac14a Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 27 Oct 2016 22:44:50 -0400 Subject: Drop FOREACH_WORD_QUOTED --- src/basic/string-util.h | 3 --- src/test/test-string-util.c | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 0175803302..e99f7964be 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -107,9 +107,6 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo #define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \ _FOREACH_WORD(word, length, s, separator, false, state) -#define FOREACH_WORD_QUOTED(word, length, s, state) \ - _FOREACH_WORD(word, length, s, WHITESPACE, true, state) - #define _FOREACH_WORD(word, length, s, separator, quoted, state) \ for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted))) diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index d0f84d70bc..e43373b0f5 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -232,21 +232,25 @@ static void test_foreach_word(void) { } static void check(const char *test, char** expected, bool trailing) { - const char *word, *state; - size_t l; - int i = 0; + int i = 0, r; printf("<<<%s>>>\n", test); - FOREACH_WORD_QUOTED(word, l, test, state) { - _cleanup_free_ char *t = NULL; - - assert_se(t = strndup(word, l)); - assert_se(strneq(expected[i++], word, l)); - printf("<%s>\n", t); + for (;;) { + _cleanup_free_ char *word = NULL; + + r = extract_first_word(&test, &word, NULL, EXTRACT_QUOTES); + if (r == 0) { + assert_se(!trailing); + break; + } else if (r < 0) { + assert_se(trailing); + break; + } + + assert_se(streq(word, expected[i++])); + printf("<%s>\n", word); } - printf("<<<%s>>>\n", state); assert_se(expected[i] == NULL); - assert_se(isempty(state) == !trailing); } static void test_foreach_word_quoted(void) { -- cgit v1.2.3-54-g00ecf