Drop FOREACH_WORD_QUOTED
This commit is contained in:
parent
ceed8f0c8b
commit
bc8ec170d2
3
TODO
3
TODO
|
@ -23,9 +23,6 @@ External:
|
|||
|
||||
Janitorial Clean-ups:
|
||||
|
||||
* code cleanup: retire FOREACH_WORD_QUOTED, port to extract_first_word() loops instead.
|
||||
For example, most conf parsing callbacks should use it.
|
||||
|
||||
* replace manual readdir() loops with FOREACH_DIRENT or FOREACH_DIRENT_ALL
|
||||
|
||||
* Rearrange tests so that the various test-xyz.c match a specific src/basic/xyz.c again
|
||||
|
|
|
@ -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)))
|
||||
|
||||
|
|
|
@ -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;
|
||||
for (;;) {
|
||||
_cleanup_free_ char *word = NULL;
|
||||
|
||||
assert_se(t = strndup(word, l));
|
||||
assert_se(strneq(expected[i++], word, l));
|
||||
printf("<%s>\n", t);
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue