diff options
Diffstat (limited to 'string-list.c')
-rw-r--r-- | string-list.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/string-list.c b/string-list.c index 549fc416d6..0f8ac117fd 100644 --- a/string-list.c +++ b/string-list.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "string-list.h" +#include "alloc.h" void string_list_init_nodup(struct string_list *list) { @@ -156,7 +157,7 @@ void filter_string_list(struct string_list *list, int free_util, list->nr = dst; } -static int item_is_not_empty(struct string_list_item *item, void *unused) +static int item_is_not_empty(struct string_list_item *item, void *data UNUSED) { return *item->string != '\0'; } @@ -202,6 +203,15 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c list->nr = list->alloc = 0; } +void string_list_setlen(struct string_list *list, size_t nr) +{ + if (list->strdup_strings) + BUG("cannot setlen a string_list which owns its entries"); + if (nr > list->nr) + BUG("cannot grow a string_list with setlen"); + list->nr = nr; +} + struct string_list_item *string_list_append_nodup(struct string_list *list, char *string) { @@ -300,7 +310,7 @@ int string_list_split(struct string_list *list, const char *string, } int string_list_split_in_place(struct string_list *list, char *string, - int delim, int maxsplit) + const char *delim, int maxsplit) { int count = 0; char *p = string, *end; @@ -314,7 +324,7 @@ int string_list_split_in_place(struct string_list *list, char *string, string_list_append(list, p); return count; } - end = strchr(p, delim); + end = strpbrk(p, delim); if (end) { *end = '\0'; string_list_append(list, p); |