string-util: modernize string_contains_word_strv a bit

Also correct the comment on flags.
This commit is contained in:
Mike Yuan
2024-03-28 17:16:25 +08:00
parent a6fe020ab8
commit f8c700791e
2 changed files with 6 additions and 8 deletions
+5 -7
View 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)