Better implementation of string_is_equal_noncase and fix bug

in string_list
This commit is contained in:
twinaphex 2017-04-21 14:53:01 +02:00
parent 271edb4ca1
commit dd1da5154f
2 changed files with 10 additions and 17 deletions

View File

@ -50,27 +50,20 @@ 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)
{
bool ret;
int i;
char *cp1, *cp2;
int result;
const unsigned char *p1 = (const unsigned char*)a;
const unsigned char *p2 = (const unsigned char*)b;
if (!a || !b)
return false;
if (p1 == p2)
return false;
cp1 = (char*)malloc(strlen(a) + 1);
cp2 = (char*)malloc(strlen(b) + 1);
while ((result = tolower (*p1) - tolower (*p2++)) == 0)
if (*p1++ == '\0')
break;
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;
return (result == 0);
}
char *string_to_upper(char *s);

View File

@ -304,7 +304,7 @@ bool string_list_find_elem_prefix(const struct string_list *list,
for (i = 0; i < list->size; i++)
{
if (string_is_equal_noncase(list->elems[i].data, elem) ||
string_is_equal_noncase(list->elems[i].data, prefixed) == 0)
string_is_equal_noncase(list->elems[i].data, prefixed))
return true;
}