string-list: allow case-insensitive string list

Some string list needs to be searched case insensitively, and for
that to work correctly, the string needs to be sorted case
insensitively from the beginning.

Allow a custom comparison function to be defined on a string list
instance and use it throughout in place of strcmp().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2013-01-07 12:24:55 -08:00
parent 7e0651a630
commit 8dd5afc926
2 changed files with 17 additions and 4 deletions

View File

@@ -5,10 +5,14 @@ struct string_list_item {
char *string;
void *util;
};
typedef int (*compare_strings_fn)(const char *, const char *);
struct string_list {
struct string_list_item *items;
unsigned int nr, alloc;
unsigned int strdup_strings:1;
compare_strings_fn cmp; /* NULL uses strcmp() */
};
#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }