string-list: split-then-remove-empty can be done while splitting
Thanks to the new STRING_LIST_SPLIT_NONEMPTY flag, a common pattern to split a string into a string list and then remove empty items in the resulting list is no longer needed. Instead, just tell the string_list_split*() to omit empty ones while splitting. Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
27531efa41
commit
2ab2aac73d
4
notes.c
4
notes.c
|
|
@ -970,8 +970,8 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
|
|||
char *globs_copy = xstrdup(globs);
|
||||
int i;
|
||||
|
||||
string_list_split_in_place(&split, globs_copy, ":", -1);
|
||||
string_list_remove_empty_items(&split, 0);
|
||||
string_list_split_in_place_f(&split, globs_copy, ":", -1,
|
||||
STRING_LIST_SPLIT_NONEMPTY);
|
||||
|
||||
for (i = 0; i < split.nr; i++)
|
||||
string_list_add_refs_by_glob(list, split.items[i].string);
|
||||
|
|
|
|||
|
|
@ -201,8 +201,7 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *va
|
|||
if (!value || !*value)
|
||||
die(_("attr spec must not be empty"));
|
||||
|
||||
string_list_split(&list, value, " ", -1);
|
||||
string_list_remove_empty_items(&list, 0);
|
||||
string_list_split_f(&list, value, " ", -1, STRING_LIST_SPLIT_NONEMPTY);
|
||||
|
||||
item->attr_check = attr_check_alloc();
|
||||
CALLOC_ARRAY(item->attr_match, list.nr);
|
||||
|
|
|
|||
|
|
@ -149,8 +149,8 @@ int cmd__hashmap(int argc UNUSED, const char **argv UNUSED)
|
|||
|
||||
/* break line into command and up to two parameters */
|
||||
string_list_setlen(&parts, 0);
|
||||
string_list_split_in_place(&parts, line.buf, DELIM, 2);
|
||||
string_list_remove_empty_items(&parts, 0);
|
||||
string_list_split_in_place_f(&parts, line.buf, DELIM, 2,
|
||||
STRING_LIST_SPLIT_NONEMPTY);
|
||||
|
||||
/* ignore empty lines */
|
||||
if (!parts.nr)
|
||||
|
|
|
|||
|
|
@ -492,8 +492,8 @@ static int scripted(void)
|
|||
|
||||
/* break line into command and zero or more tokens */
|
||||
string_list_setlen(&parts, 0);
|
||||
string_list_split_in_place(&parts, line, " ", -1);
|
||||
string_list_remove_empty_items(&parts, 0);
|
||||
string_list_split_in_place_f(&parts, line, " ", -1,
|
||||
STRING_LIST_SPLIT_NONEMPTY);
|
||||
|
||||
/* ignore empty lines */
|
||||
if (!parts.nr || !*parts.items[0].string)
|
||||
|
|
|
|||
Loading…
Reference in New Issue