basic: add STRCASE_IN_SET() which is to STR_IN_SET() what strcaseeq() is to streq()

This commit is contained in:
Lennart Poettering
2020-05-04 10:11:19 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 2d4f8cf467
commit ddd6a22a0f
5 changed files with 60 additions and 19 deletions
+11 -2
View File
@@ -14,9 +14,13 @@
#include "string-util.h"
char *strv_find(char * const *l, const char *name) _pure_;
char *strv_find_case(char * const *l, const char *name) _pure_;
char *strv_find_prefix(char * const *l, const char *name) _pure_;
char *strv_find_startswith(char * const *l, const char *name) _pure_;
#define strv_contains(l, s) (!!strv_find((l), (s)))
#define strv_contains_case(l, s) (!!strv_find_case((l), (s)))
char **strv_free(char **l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
#define _cleanup_strv_free_ _cleanup_(strv_freep)
@@ -54,8 +58,6 @@ static inline bool strv_equal(char * const *a, char * const *b) {
return strv_compare(a, b) == 0;
}
#define strv_contains(l, s) (!!strv_find((l), (s)))
char **strv_new_internal(const char *x, ...) _sentinel_;
char **strv_new_ap(const char *x, va_list ap);
#define strv_new(...) strv_new_internal(__VA_ARGS__, NULL)
@@ -156,6 +158,13 @@ void strv_print(char * const *l);
_x && strv_contains(STRV_MAKE(__VA_ARGS__), _x); \
})
#define STRCASE_IN_SET(x, ...) strv_contains_case(STRV_MAKE(__VA_ARGS__), x)
#define STRCASEPTR_IN_SET(x, ...) \
({ \
const char* _x = (x); \
_x && strv_contains_case(STRV_MAKE(__VA_ARGS__), _x); \
})
#define STARTSWITH_SET(p, ...) \
({ \
const char *_p = (p); \