string_list: add a function string_list_longest_prefix()
Add a function that finds the longest string from a string_list that is a prefix of a given string. 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
31d5451eed
commit
f103f95b11
@ -38,6 +38,14 @@ int for_each_string_list(struct string_list *list,
|
||||
void filter_string_list(struct string_list *list, int free_util,
|
||||
string_list_each_func_t want, void *cb_data);
|
||||
|
||||
/*
|
||||
* Return the longest string in prefixes that is a prefix (in the
|
||||
* sense of prefixcmp()) of string, or NULL if no such prefix exists.
|
||||
* This function does not require the string_list to be sorted (it
|
||||
* does a linear search).
|
||||
*/
|
||||
char *string_list_longest_prefix(const struct string_list *prefixes, const char *string);
|
||||
|
||||
|
||||
/* Use these functions only on sorted lists: */
|
||||
int string_list_has_string(const struct string_list *list, const char *string);
|
||||
|
Reference in New Issue
Block a user