diff --git a/src/core/misc.c b/src/core/misc.c index 1cfa15b6..c75f54db 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -168,6 +168,23 @@ int strarray_find(char **array, const char *item) return -1; } +int strarray_find_prefix(char **array, const char *item) +{ + char **tmp; + int index; + + g_return_val_if_fail(array != NULL, -1); + g_return_val_if_fail(item != NULL, -1); + + index = 0; + for (tmp = array; *tmp != NULL; tmp++, index++) { + if (g_str_has_prefix(*tmp, item)) + return index; + } + + return -1; +} + GSList *gslist_find_string(GSList *list, const char *key) { for (; list != NULL; list = list->next) diff --git a/src/core/misc.h b/src/core/misc.h index 00637da0..1c510c58 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -100,6 +100,9 @@ char *replace_chars(char *str, char from, char to); /* return index of `item' in `array' or -1 if not found */ int strarray_find(char **array, const char *item); +/* return index of element in `array' starting with `item' or -1 if not found */ +gboolean strarray_find_prefix(char **array, const char *item); + /* string -> uoff_t */ uoff_t str_to_uofft(const char *str);