pipewire: utils: pw_split_walk(): skip leading runs of chars in delimiter

Previously, if the string started with any of the characters in
delimiter, the first returned string would've been an empty string.
This is in contrast with the fact that otherwise `pw_split_walk()`
skips empty fields.

E.g.

  "::field1::field2" with ":" as `delimiter`

would have resulted in
 *  ""
 *  "field1"
 *  "field2".

Adjust the function to skip leading runs of characters in `delimiter`
by calling `strspn()` first.
This commit is contained in:
Barnabás Pőcze 2021-06-03 16:18:17 +02:00
parent 576513583b
commit 3b681f2138

View file

@ -44,13 +44,12 @@ const char *pw_split_walk(const char *str, const char *delimiter, size_t * len,
{ {
const char *s = *state ? *state : str; const char *s = *state ? *state : str;
s += strspn(s, delimiter);
if (*s == '\0') if (*s == '\0')
return NULL; return NULL;
*len = strcspn(s, delimiter); *len = strcspn(s, delimiter);
*state = s + *len; *state = s + *len;
*state += strspn(*state, delimiter);
return s; return s;
} }