diff --git a/src/tools.c b/src/tools.c index 9e971bb..53b950c 100644 --- a/src/tools.c +++ b/src/tools.c @@ -653,4 +653,33 @@ int array_contains(char **array, const size_t array_len, const char *s) } + +int array_contains0(char **array, const char *s) +{ + int result = 0; + if (array != NULL) { + for (size_t i = 0; array[i] != NULL; ++i) { + if (strcasecmp(array[i], s) == 0) { + result = 1; + break; + } + } + } + return result; +} + + + +size_t array_count0(char **array) +{ + size_t num_elems = 0; + if (array != NULL) { + while (array[num_elems] != NULL) { + ++num_elems; + } + } + return num_elems; +} + + /*EOF*/ /* vim: set sw=4: */ diff --git a/src/tools.h b/src/tools.h index eba6493..b65d1a0 100644 --- a/src/tools.h +++ b/src/tools.h @@ -82,6 +82,20 @@ void analyze_line_ascii(line_t *line); int array_contains(char **array, const size_t array_len, const char *s); +/** + * Determine if the given `array` contains the given string (case-insensitive!). + * @param array an array of strings to search + * @param s the string to search + * @returns != 0 if found, 0 if not found + */ +int array_contains0(char **array, const char *s); + +/** + * Count the number of elements in a zero-terminated array. + * @param array a zero-terminated array of strings (can be NULL) + * @returns the number of elements, excluding the zero terminator + */ +size_t array_count0(char **array); #endif