]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
string-util: modernize string_contains_word_strv a bit
authorMike Yuan <me@yhndnzj.com>
Tue, 26 Mar 2024 16:15:40 +0000 (00:15 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 28 Mar 2024 09:16:25 +0000 (17:16 +0800)
Also correct the comment on flags.

src/basic/string-util.c
src/basic/string-util.h

index 7f6c87b4613fde9c2d04aeffe4a15a1a6f20905d..b50f45f7f4a5407a9ed1c9dfa93db1a17fd542e3 100644 (file)
@@ -1268,18 +1268,16 @@ int string_extract_line(const char *s, size_t i, char **ret) {
         }
 }
 
-int string_contains_word_strv(const char *string, const char *separators, char **words, const char **ret_word) {
-        /* In the default mode with no separators specified, we split on whitespace and
-         * don't coalesce separators. */
+int string_contains_word_strv(const char *string, const char *separators, char * const *words, const char **ret_word) {
+        /* In the default mode with no separators specified, we split on whitespace and coalesce separators. */
         const ExtractFlags flags = separators ? EXTRACT_DONT_COALESCE_SEPARATORS : 0;
-
         const char *found = NULL;
+        int r;
 
-        for (const char *p = string;;) {
+        for (;;) {
                 _cleanup_free_ char *w = NULL;
-                int r;
 
-                r = extract_first_word(&p, &w, separators, flags);
+                r = extract_first_word(&string, &w, separators, flags);
                 if (r < 0)
                         return r;
                 if (r == 0)
index a68f3c94abc4180601c885a8a28c43fc31f4217a..055ab66668b84d2009c238f4082d95d70d6d7139 100644 (file)
@@ -271,7 +271,7 @@ char* string_erase(char *x);
 int string_truncate_lines(const char *s, size_t n_lines, char **ret);
 int string_extract_line(const char *s, size_t i, char **ret);
 
-int string_contains_word_strv(const char *string, const char *separators, char **words, const char **ret_word);
+int string_contains_word_strv(const char *string, const char *separators, char * const *words, const char **ret_word);
 static inline int string_contains_word(const char *string, const char *separators, const char *word) {
         return string_contains_word_strv(string, separators, STRV_MAKE(word), NULL);
 }