summaryrefslogtreecommitdiff
path: root/src/basic/hashmap.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-06-15 22:36:58 +0200
committerLennart Poettering <lennart@poettering.net>2016-06-21 13:20:48 +0200
commitd97c5aeab8b9c6d871cad292c17c9b9c94736e25 (patch)
tree5cc3dd338be2ef6b969a124801df3cb6fade60fd /src/basic/hashmap.c
parentb6274a0e9e3dd592826411940a71a67dbf05bcef (diff)
set: add new set_put_strsplit() call
It's like set_put_strdup(), but splits up a string via an extract_first_word() loop.
Diffstat (limited to 'src/basic/hashmap.c')
-rw-r--r--src/basic/hashmap.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 49a0479592..50fefb0b54 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -1764,6 +1764,9 @@ void *ordered_hashmap_next(OrderedHashmap *h, const void *key) {
int set_consume(Set *s, void *value) {
int r;
+ assert(s);
+ assert(value);
+
r = set_put(s, value);
if (r <= 0)
free(value);
@@ -1791,6 +1794,8 @@ int set_put_strdupv(Set *s, char **l) {
int n = 0, r;
char **i;
+ assert(s);
+
STRV_FOREACH(i, l) {
r = set_put_strdup(s, *i);
if (r < 0)
@@ -1801,3 +1806,23 @@ int set_put_strdupv(Set *s, char **l) {
return n;
}
+
+int set_put_strsplit(Set *s, const char *v, const char *separators, ExtractFlags flags) {
+ const char *p = v;
+ int r;
+
+ assert(s);
+ assert(v);
+
+ for (;;) {
+ char *word;
+
+ r = extract_first_word(&p, &word, separators, flags);
+ if (r <= 0)
+ return r;
+
+ r = set_consume(s, word);
+ if (r < 0)
+ return r;
+ }
+}