mirror of
https://github.com/git/git.git
synced 2024-05-10 03:46:08 +02:00
string-list: add string_list_remove function
Teach string-list to be able to remove a string from a sorted 'struct string_list'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e3a434468f
commit
3a30033327
|
@ -67,6 +67,24 @@ struct string_list_item *string_list_insert(struct string_list *list, const char
|
||||||
return list->items + index;
|
return list->items + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void string_list_remove(struct string_list *list, const char *string,
|
||||||
|
int free_util)
|
||||||
|
{
|
||||||
|
int exact_match;
|
||||||
|
int i = get_entry_index(list, string, &exact_match);
|
||||||
|
|
||||||
|
if (exact_match) {
|
||||||
|
if (list->strdup_strings)
|
||||||
|
free(list->items[i].string);
|
||||||
|
if (free_util)
|
||||||
|
free(list->items[i].util);
|
||||||
|
|
||||||
|
list->nr--;
|
||||||
|
memmove(list->items + i, list->items + i + 1,
|
||||||
|
(list->nr - i) * sizeof(struct string_list_item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int string_list_has_string(const struct string_list *list, const char *string)
|
int string_list_has_string(const struct string_list *list, const char *string)
|
||||||
{
|
{
|
||||||
int exact_match;
|
int exact_match;
|
||||||
|
|
|
@ -62,6 +62,13 @@ int string_list_find_insert_index(const struct string_list *list, const char *st
|
||||||
*/
|
*/
|
||||||
struct string_list_item *string_list_insert(struct string_list *list, const char *string);
|
struct string_list_item *string_list_insert(struct string_list *list, const char *string);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Removes the given string from the sorted list.
|
||||||
|
* If the string doesn't exist, the list is not altered.
|
||||||
|
*/
|
||||||
|
extern void string_list_remove(struct string_list *list, const char *string,
|
||||||
|
int free_util);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks if the given string is part of a sorted list. If it is part of the list,
|
* Checks if the given string is part of a sorted list. If it is part of the list,
|
||||||
* return the coresponding string_list_item, NULL otherwise.
|
* return the coresponding string_list_item, NULL otherwise.
|
||||||
|
|
Loading…
Reference in New Issue