diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-26 12:17:51 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-26 12:17:51 +0200 |
commit | af0b60b37c8bc5e5206d41e00f31f2682a51f21e (patch) | |
tree | 503776b6ae57c09935036e6c145acf25b43b2bad | |
parent | libsystemd: add missing 'global' specifier in libsystemd.sym (diff) | |
download | systemd-af0b60b37c8bc5e5206d41e00f31f2682a51f21e.tar.xz systemd-af0b60b37c8bc5e5206d41e00f31f2682a51f21e.zip |
strv: introduce strv_split_full() which optionally handle quotes
-rw-r--r-- | src/basic/strv.c | 6 | ||||
-rw-r--r-- | src/basic/strv.h | 5 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c index dc72f036ac..ffc7b98d70 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 34a660cb92..03fb5cc2b2 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); |