mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-01-05 21:49:04 +01:00
Add array_contains0() and array_count0() function to tools module
This commit is contained in:
parent
b51724f3b1
commit
aab643acbc
29
src/tools.c
29
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: */
|
||||
|
14
src/tools.h
14
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user