mirror of
https://github.com/systemd/systemd
synced 2024-09-19 08:03:31 +00:00
string-util: modernize string_contains_word_strv a bit
Also correct the comment on flags.
This commit is contained in:
parent
a6fe020ab8
commit
f8c700791e
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue