1
0
Fork 0
forked from len0rd/rockbox

add function string_option to misc.c use in skin_parser.c

function string_option allows a string to be found in a
supplied list of options

Change-Id: If9134090406b74ab11f4ef9ed6517a4b99b9d73e
This commit is contained in:
William Wilgus 2022-03-13 03:35:18 -04:00
parent a9c62f2c39
commit 74df3ba2d8
3 changed files with 97 additions and 29 deletions

View file

@ -1384,6 +1384,41 @@ int split_string(char *str, const char split_char, char *vector[], const int vec
return i;
}
/* returns match index from option list
* returns -1 if option was not found
* option list is array of char pointers with the final item set to null
* ex - const char *option[] = { "op_a", "op_b", "op_c", NULL}
*/
int string_option(const char *option, const char *const oplist[], bool ignore_case)
{
int i;
int ifound = -1;
const char *op;
if (ignore_case)
{
for (i=0; (op=oplist[i]) != NULL; i++)
{
if (strcasecmp(op, option) == 0)
{
ifound = i;
break;
}
}
}
else
{
for (i=0; (op=oplist[i]) != NULL; i++)
{
if (strcmp(op, option) == 0)
{
ifound = i;
break;
}
}
}
return ifound;
}
/** Open a UTF-8 file and set file descriptor to first byte after BOM.
* If no BOM is present this behaves like open().