From ab5f4c4dfad3880f60c8555437aeb0c9ba85cd1e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 17 Jun 2014 15:58:07 +0200 Subject: BLI: Add two helpers to search a given string in an array of strings. --- source/blender/blenlib/intern/string.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'source/blender/blenlib/intern/string.c') diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index ab81c8fdd40..4ab568ece42 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -639,3 +639,45 @@ int BLI_str_rstrip_float_zero(char *str, const char pad) return totstrip; } + +/** + * Return index of a string in a string array. + * + * \param str The string to find. + * \param str_array Array of strings. + * \param str_array_len The length of the array, or -1 for a NULL-terminated array. + * \return The index of str in str_array or -1. + */ +int BLI_str_index_in_array_n(const char *str, const char **str_array, const int str_array_len) +{ + int index; + const char **str_iter = str_array; + + for (index = 0; index < str_array_len; str_iter++, index++) { + if (STREQ(str, *str_iter)) { + return index; + } + } + return -1; +} + +/** + * Return index of a string in a string array. + * + * \param str The string to find. + * \param str_array Array of strings, (must be NULL-terminated). + * \return The index of str in str_array or -1. + */ +int BLI_str_index_in_array(const char *str, const char **str_array) +{ + int index; + const char **str_iter = str_array; + + for (index = 0; *str_iter; str_iter++, index++) { + if (STREQ(str, *str_iter)) { + return index; + } + } + return -1; +} + -- cgit v1.2.3