summaryrefslogtreecommitdiff
path: root/string-list.h
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-09-12 16:04:46 +0200
committerJunio C Hamano <gitster@pobox.com>2012-09-12 11:43:25 -0700
commitf103f95b11d087f07c0c48bf784cd9197e18f203 (patch)
tree97c404425b942675ffedece855f58b5132cd55e5 /string-list.h
parent31d5451eed2677531c80177ff9dc8f5285f5a187 (diff)
downloadgit-f103f95b11d087f07c0c48bf784cd9197e18f203.tar.gz
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>
Diffstat (limited to 'string-list.h')
-rw-r--r--string-list.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/string-list.h b/string-list.h
index 3a6a6dc392..5efd07b44e 100644
--- a/string-list.h
+++ b/string-list.h
@@ -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);