From: Yu Watanabe Date: Wed, 26 Sep 2018 10:17:51 +0000 (+0900) Subject: strv: introduce strv_split_full() which optionally handle quotes X-Git-Tag: v240~630^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=af0b60b37c8bc5e5206d41e00f31f2682a51f21e;p=thirdparty%2Fsystemd.git strv: introduce strv_split_full() which optionally handle quotes --- diff --git a/src/basic/strv.c b/src/basic/strv.c index dc72f036ac9..ffc7b98d702 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -245,7 +245,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) { return 0; } -char **strv_split(const char *s, const char *separator) { +char **strv_split_full(const char *s, const char *separator, bool quoted) { const char *word, *state; size_t l; size_t n, i; @@ -258,7 +258,7 @@ char **strv_split(const char *s, const char *separator) { return new0(char*, 1); n = 0; - FOREACH_WORD_SEPARATOR(word, l, s, separator, state) + _FOREACH_WORD(word, l, s, separator, quoted, state) n++; r = new(char*, n+1); @@ -266,7 +266,7 @@ char **strv_split(const char *s, const char *separator) { return NULL; i = 0; - FOREACH_WORD_SEPARATOR(word, l, s, separator, state) { + _FOREACH_WORD(word, l, s, separator, quoted, state) { r[i] = strndup(word, l); if (!r[i]) { strv_free(r); diff --git a/src/basic/strv.h b/src/basic/strv.h index 34a660cb920..03fb5cc2b24 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -66,7 +66,10 @@ static inline bool strv_isempty(char * const *l) { return !l || !*l; } -char **strv_split(const char *s, const char *separator); +char **strv_split_full(const char *s, const char *separator, bool quoted); +static inline char **strv_split(const char *s, const char *separator) { + return strv_split_full(s, separator, false); +} char **strv_split_newlines(const char *s); int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);