summaryrefslogtreecommitdiff
path: root/src/basic/strv.h
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2020-07-07 17:12:48 +0100
committerLuca Boccassi <luca.boccassi@microsoft.com>2020-08-05 21:29:13 +0100
commita082edd53ac9da4a8e06281360754eb15bd1389f (patch)
tree071b655c2338f2055ca6b3b646c6728d10849f83 /src/basic/strv.h
parent1e198efcdb1423847642e141c8b296e544707a18 (diff)
downloadsystemd-a082edd53ac9da4a8e06281360754eb15bd1389f.tar.gz
strv: add strv_split_colon_pairs function
Given a string in the format 'one:two three four:five', returns a string vector with each word. If the second element of the tuple is not present, an empty string is returned in its place, so that the vector can be processed in pairs. [zjs: use EXTRACT_UNESCAPE_SEPARATORS instead of EXTRACT_CUNESCAPE_RELAX. This way we do escaping exactly once and in normal strict mode.]
Diffstat (limited to 'src/basic/strv.h')
-rw-r--r--src/basic/strv.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/basic/strv.h b/src/basic/strv.h
index 2ad927bce5..e57dfff69b 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -80,6 +80,11 @@ char **strv_split_newlines(const char *s);
int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);
+/* Given a string containing white-space separated tuples of words themselves separated by ':',
+ * returns a vector of strings. If the second element in a tuple is missing, the corresponding
+ * string in the vector is an empty string. */
+int strv_split_colon_pairs(char ***t, const char *s);
+
char *strv_join_prefix(char * const *l, const char *separator, const char *prefix);
static inline char *strv_join(char * const *l, const char *separator) {
return strv_join_prefix(l, separator, NULL);