diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-01-04 09:44:15 +0100 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-01-04 09:49:05 +0100 |
commit | eba8b54130e15e3cd6626fdc1d93a643d6bfbea2 (patch) | |
tree | 84f2bfa75cb806e92b476d7466dc40f3814bab3d | |
parent | string-util: use strneq (diff) | |
download | systemd-eba8b54130e15e3cd6626fdc1d93a643d6bfbea2.tar.xz systemd-eba8b54130e15e3cd6626fdc1d93a643d6bfbea2.zip |
string-util: move startswith_strv to strv
-rw-r--r-- | src/basic/string-util.c | 12 | ||||
-rw-r--r-- | src/basic/string-util.h | 5 | ||||
-rw-r--r-- | src/basic/strv.c | 10 | ||||
-rw-r--r-- | src/basic/strv.h | 5 |
4 files changed, 15 insertions, 17 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 3c34d6b455..8b039ebd98 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -1420,18 +1420,6 @@ char *find_line_startswith(const char *haystack, const char *needle) { return p + strlen(needle); } -char *startswith_strv(const char *string, char **strv) { - char *found = NULL; - - STRV_FOREACH(i, strv) { - found = startswith(string, *i); - if (found) - break; - } - - return found; -} - bool version_is_valid(const char *s) { if (isempty(s)) return false; diff --git a/src/basic/string-util.h b/src/basic/string-util.h index bf427cd7f7..e162765aa7 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -291,11 +291,6 @@ char *strdupcspn(const char *a, const char *reject); char *find_line_startswith(const char *haystack, const char *needle); -char *startswith_strv(const char *string, char **strv); - -#define STARTSWITH_SET(p, ...) \ - startswith_strv(p, STRV_MAKE(__VA_ARGS__)) - bool version_is_valid(const char *s); bool version_is_valid_versionspec(const char *s); diff --git a/src/basic/strv.c b/src/basic/strv.c index 43a4f569bd..ff2f672c10 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -706,6 +706,16 @@ int strv_extendf(char ***l, const char *format, ...) { return strv_consume(l, x); } +char* startswith_strv(const char *s, char * const *l) { + STRV_FOREACH(i, l) { + char *found = startswith(s, *i); + if (found) + return found; + } + + return NULL; +} + char** strv_reverse(char **l) { size_t n; diff --git a/src/basic/strv.h b/src/basic/strv.h index 18df0f23f2..66fa0cd2e4 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -159,6 +159,11 @@ static inline void strv_print(char * const *l) { strv_print_full(l, NULL); } +char* startswith_strv(const char *s, char * const *l); + +#define STARTSWITH_SET(p, ...) \ + startswith_strv(p, STRV_MAKE(__VA_ARGS__)) + #define strv_from_stdarg_alloca(first) \ ({ \ char **_l; \ |