mirror of
https://github.com/systemd/systemd
synced 2024-09-16 06:43:18 +00:00
strv: rename strv_endswith to endswith_strv and dedup ENDSWITH_SET
This commit is contained in:
parent
eba8b54130
commit
2e6f012bf0
|
@ -716,6 +716,16 @@ char* startswith_strv(const char *s, char * const *l) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* endswith_strv(const char *s, char * const *l) {
|
||||
STRV_FOREACH(i, l) {
|
||||
char *found = endswith(s, *i);
|
||||
if (found)
|
||||
return found;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char** strv_reverse(char **l) {
|
||||
size_t n;
|
||||
|
||||
|
@ -915,13 +925,3 @@ int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const
|
|||
}
|
||||
|
||||
DEFINE_HASH_OPS_FULL(string_strv_hash_ops, char, string_hash_func, string_compare_func, free, char*, strv_free);
|
||||
|
||||
char* strv_endswith(const char *s, char **l) {
|
||||
STRV_FOREACH(i, l) {
|
||||
char *e = endswith(s, *i);
|
||||
if (e)
|
||||
return (char*) e;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -164,6 +164,11 @@ char* startswith_strv(const char *s, char * const *l);
|
|||
#define STARTSWITH_SET(p, ...) \
|
||||
startswith_strv(p, STRV_MAKE(__VA_ARGS__))
|
||||
|
||||
char* endswith_strv(const char *s, char * const *l);
|
||||
|
||||
#define ENDSWITH_SET(p, ...) \
|
||||
endswith_strv(p, STRV_MAKE(__VA_ARGS__))
|
||||
|
||||
#define strv_from_stdarg_alloca(first) \
|
||||
({ \
|
||||
char **_l; \
|
||||
|
@ -207,18 +212,6 @@ char* startswith_strv(const char *s, char * const *l);
|
|||
_x && strv_contains_case(STRV_MAKE(__VA_ARGS__), _x); \
|
||||
})
|
||||
|
||||
#define ENDSWITH_SET(p, ...) \
|
||||
({ \
|
||||
const char *_p = (p); \
|
||||
char *_found = NULL; \
|
||||
STRV_FOREACH(_i, STRV_MAKE(__VA_ARGS__)) { \
|
||||
_found = endswith(_p, *_i); \
|
||||
if (_found) \
|
||||
break; \
|
||||
} \
|
||||
_found; \
|
||||
})
|
||||
|
||||
#define _FOREACH_STRING(uniq, x, y, ...) \
|
||||
for (const char *x, * const*UNIQ_T(l, uniq) = STRV_MAKE_CONST(({ x = y; }), ##__VA_ARGS__); \
|
||||
x; \
|
||||
|
@ -257,5 +250,3 @@ int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value HA
|
|||
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS);
|
||||
#define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS)
|
||||
|
||||
char* strv_endswith(const char *s, char **l);
|
||||
|
|
|
@ -233,7 +233,7 @@ static int extract_image_basename(
|
|||
return r;
|
||||
|
||||
if (format_suffixes) {
|
||||
char *e = strv_endswith(name, format_suffixes);
|
||||
char *e = endswith_strv(name, format_suffixes);
|
||||
if (!e) /* Format suffix is required */
|
||||
return -EINVAL;
|
||||
|
||||
|
|
|
@ -1006,12 +1006,12 @@ TEST(strv_find_first_field) {
|
|||
assert_se(streq_ptr(strv_find_first_field(STRV_MAKE("i", "k", "l", "m", "d", "c", "a", "b"), haystack), "j"));
|
||||
}
|
||||
|
||||
TEST(strv_endswith) {
|
||||
assert_se(streq_ptr(strv_endswith("waldo", STRV_MAKE("xxx", "yyy", "ldo", "zzz")), "ldo"));
|
||||
assert_se(streq_ptr(strv_endswith("waldo", STRV_MAKE("xxx", "yyy", "zzz")), NULL));
|
||||
assert_se(streq_ptr(strv_endswith("waldo", STRV_MAKE("waldo")), "waldo"));
|
||||
assert_se(streq_ptr(strv_endswith("waldo", STRV_MAKE("w", "o", "ldo")), "o"));
|
||||
assert_se(streq_ptr(strv_endswith("waldo", STRV_MAKE("knurz", "", "waldo")), ""));
|
||||
TEST(endswith_strv) {
|
||||
assert_se(streq_ptr(endswith_strv("waldo", STRV_MAKE("xxx", "yyy", "ldo", "zzz")), "ldo"));
|
||||
assert_se(streq_ptr(endswith_strv("waldo", STRV_MAKE("xxx", "yyy", "zzz")), NULL));
|
||||
assert_se(streq_ptr(endswith_strv("waldo", STRV_MAKE("waldo")), "waldo"));
|
||||
assert_se(streq_ptr(endswith_strv("waldo", STRV_MAKE("w", "o", "ldo")), "o"));
|
||||
assert_se(streq_ptr(endswith_strv("waldo", STRV_MAKE("knurz", "", "waldo")), ""));
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
|
Loading…
Reference in a new issue