mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
set: add new set_put_strsplit() call
It's like set_put_strdup(), but splits up a string via an extract_first_word() loop.
This commit is contained in:
parent
b6274a0e9e
commit
d97c5aeab8
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "extract-word.h"
|
||||
#include "hashmap.h"
|
||||
#include "macro.h"
|
||||
|
||||
@ -122,6 +123,7 @@ static inline char **set_get_strv(Set *s) {
|
||||
int set_consume(Set *s, void *value);
|
||||
int set_put_strdup(Set *s, const char *p);
|
||||
int set_put_strdupv(Set *s, char **l);
|
||||
int set_put_strsplit(Set *s, const char *v, const char *separators, ExtractFlags flags);
|
||||
|
||||
#define SET_FOREACH(e, s, i) \
|
||||
for ((i) = ITERATOR_FIRST; set_iterate((s), &(i), (void**)&(e)); )
|
||||
|
Loading…
Reference in New Issue
Block a user