X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fstrv.h;h=3034073d3288e5a28871769b4561b4d53d70837c;hp=737728a3c6bde296b262a9d0a09177b4227a9eed;hb=623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbf;hpb=250a918dc4c8a15d927deecc3b3f6a0604657ae4 diff --git a/src/shared/strv.h b/src/shared/strv.h index 737728a3c..3034073d3 100644 --- a/src/shared/strv.h +++ b/src/shared/strv.h @@ -36,14 +36,16 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free); char **strv_copy(char * const *l); unsigned strv_length(char * const *l) _pure_; -char **strv_merge(char **a, char **b); -char **strv_merge_concat(char **a, char **b, const char *suffix); -char **strv_append(char **l, const char *s); +int strv_extend_strv(char ***a, char **b); +int strv_extend_strv_concat(char ***a, char **b, const char *suffix); int strv_extend(char ***l, const char *value); +int strv_extendf(char ***l, const char *format, ...) _printf_(2,0); int strv_push(char ***l, char *value); +int strv_push_prepend(char ***l, char *value); +int strv_consume(char ***l, char *value); +int strv_consume_prepend(char ***l, char *value); char **strv_remove(char **l, const char *s); -char **strv_remove_prefix(char **l, const char *s); char **strv_uniq(char **l); #define strv_contains(l, s) (!!strv_find((l), (s))) @@ -82,16 +84,19 @@ bool strv_overlap(char **a, char **b) _pure_; #define STRV_FOREACH_PAIR(x, y, l) \ for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1)) - char **strv_sort(char **l); void strv_print(char **l); +#define STRV_MAKE(...) ((char**) ((const char*[]) { __VA_ARGS__, NULL })) + +#define STRV_MAKE_EMPTY ((char*[1]) { NULL }) + #define strv_from_stdarg_alloca(first) \ ({ \ char **_l; \ \ if (!first) \ - _l = ((char*[1]) { NULL }); \ + _l = (char**) &first; \ else { \ unsigned _n; \ va_list _ap; \ @@ -114,3 +119,17 @@ void strv_print(char **l); } \ _l; \ }) + +#define STR_IN_SET(x, ...) strv_contains(STRV_MAKE(__VA_ARGS__), x) + +#define FOREACH_STRING(x, ...) \ + for (char **_l = ({ \ + char **_ll = STRV_MAKE(__VA_ARGS__); \ + x = _ll ? _ll[0] : NULL; \ + _ll; \ + }); \ + _l && *_l; \ + x = ({ \ + _l ++; \ + _l[0]; \ + }))