From cfa1ee6b340172a415049704cd848593392b9064 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Sun, 8 Feb 2009 15:34:28 +0100 Subject: Add find_insert_index, insert_at_index and clear_func functions to string_list string_list_find_insert_index() and string_list_insert_at_index() enables you to see if an item is in the string_list, and to insert at the appropriate index in the list, if not there. This is usefull if you need to manipulate an existing item, if present, and insert a new item if not. Future mailmap code will use this construct to enable complex (old_name, old_email) -> (new_name, new_email) lookups. The string_list_clear_func() allows to call a custom cleanup function on each item in a string_list, which is useful is the util member points to a complex structure. Signed-off-by: Marius Storm-Olsen Signed-off-by: Junio C Hamano --- string-list.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'string-list.h') diff --git a/string-list.h b/string-list.h index 4d6a7051f..d32ba0520 100644 --- a/string-list.h +++ b/string-list.h @@ -15,9 +15,18 @@ struct string_list void print_string_list(const char *text, const struct string_list *p); void string_list_clear(struct string_list *list, int free_util); +/* Use this function to call a custom clear function on each util pointer */ +/* The string associated with the util pointer is passed as the second argument */ +typedef void (*string_list_clear_func_t)(void *p, const char *str); +void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc); + /* Use these functions only on sorted lists: */ int string_list_has_string(const struct string_list *list, const char *string); +int string_list_find_insert_index(const struct string_list *list, const char *string, + int negative_existing_index); struct string_list_item *string_list_insert(const char *string, struct string_list *list); +struct string_list_item *string_list_insert_at_index(int insert_at, + const char *string, struct string_list *list); struct string_list_item *string_list_lookup(const char *string, struct string_list *list); /* Use these functions only on unsorted lists: */ -- cgit v1.2.1