Turn string_is_equal_noncase into self-contained function
This commit is contained in:
parent
76788d3890
commit
607ae71259
|
@ -745,13 +745,13 @@ bool config_get_bool(config_file_t *conf, const char *key, bool *in)
|
||||||
|
|
||||||
if (entry)
|
if (entry)
|
||||||
{
|
{
|
||||||
if (strcasecmp(entry->value, "true") == 0)
|
if (string_is_equal_noncase(entry->value, "true"))
|
||||||
*in = true;
|
*in = true;
|
||||||
else if (strcasecmp(entry->value, "1") == 0)
|
else if (string_is_equal_noncase(entry->value, "1"))
|
||||||
*in = true;
|
*in = true;
|
||||||
else if (strcasecmp(entry->value, "false") == 0)
|
else if (string_is_equal_noncase(entry->value, "false"))
|
||||||
*in = false;
|
*in = false;
|
||||||
else if (strcasecmp(entry->value, "0") == 0)
|
else if (string_is_equal_noncase(entry->value, "0"))
|
||||||
*in = false;
|
*in = false;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
|
@ -49,7 +50,27 @@ static INLINE bool string_is_equal(const char *a, const char *b)
|
||||||
|
|
||||||
static INLINE bool string_is_equal_noncase(const char *a, const char *b)
|
static INLINE bool string_is_equal_noncase(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
return (a && b) ? (strcasecmp(a, b) == 0) : false;
|
bool ret;
|
||||||
|
int i;
|
||||||
|
char *cp1, *cp2;
|
||||||
|
|
||||||
|
if (!a || !b)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cp1 = (char*)malloc(strlen(a) + 1);
|
||||||
|
cp2 = (char*)malloc(strlen(b) + 1);
|
||||||
|
|
||||||
|
for (i = 0; i < strlen(a) + 1; i++)
|
||||||
|
cp1[i] = tolower((int) (unsigned char) a[i]);
|
||||||
|
for (i = 0; i < strlen(b) + 1; i++)
|
||||||
|
cp2[i] = tolower((int) (unsigned char) b[i]);
|
||||||
|
|
||||||
|
ret = string_is_equal(cp1, cp2);
|
||||||
|
|
||||||
|
free(cp1);
|
||||||
|
free(cp2);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *string_to_upper(char *s);
|
char *string_to_upper(char *s);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <retro_assert.h>
|
#include <retro_assert.h>
|
||||||
#include <retro_common.h>
|
#include <retro_common.h>
|
||||||
#include <lists/file_list.h>
|
#include <lists/file_list.h>
|
||||||
|
#include <string/stdstring.h>
|
||||||
#include <compat/strcasestr.h>
|
#include <compat/strcasestr.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <retro_assert.h>
|
#include <retro_assert.h>
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <compat/posix_string.h>
|
#include <compat/posix_string.h>
|
||||||
|
#include <string/stdstring.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_free
|
* string_list_free
|
||||||
|
@ -268,7 +269,7 @@ int string_list_find_elem(const struct string_list *list, const char *elem)
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(list->elems[i].data, elem) == 0)
|
if (string_is_equal_noncase(list->elems[i].data, elem))
|
||||||
return (int)(i + 1);
|
return (int)(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,8 +303,8 @@ bool string_list_find_elem_prefix(const struct string_list *list,
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(list->elems[i].data, elem) == 0 ||
|
if (string_is_equal_noncase(list->elems[i].data, elem) ||
|
||||||
strcasecmp(list->elems[i].data, prefixed) == 0)
|
string_is_equal_noncase(list->elems[i].data, prefixed) == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue