string_list: add a new function, filter_string_list()
This function allows entries that don't match a specified criterion to be discarded from a string_list while preserving the order of the remaining entries. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
ff919f965d
commit
eb5f0c7a61
@ -102,6 +102,23 @@ int for_each_string_list(struct string_list *list,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void filter_string_list(struct string_list *list, int free_util,
|
||||
string_list_each_func_t want, void *cb_data)
|
||||
{
|
||||
int src, dst = 0;
|
||||
for (src = 0; src < list->nr; src++) {
|
||||
if (want(&list->items[src], cb_data)) {
|
||||
list->items[dst++] = list->items[src];
|
||||
} else {
|
||||
if (list->strdup_strings)
|
||||
free(list->items[src].string);
|
||||
if (free_util)
|
||||
free(list->items[src].util);
|
||||
}
|
||||
}
|
||||
list->nr = dst;
|
||||
}
|
||||
|
||||
void string_list_clear(struct string_list *list, int free_util)
|
||||
{
|
||||
if (list->items) {
|
||||
|
||||
Reference in New Issue
Block a user