Accepted FS#6098 as the first patch from Robert Kukla and implemented using two switches.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11124 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-10-05 09:49:18 +00:00
parent ac39354b9e
commit 3eb9e70b64
2 changed files with 50 additions and 31 deletions

View file

@ -595,40 +595,58 @@ inline static bool str_ends_with(const char *str1, const char *str2)
static bool check_against_clause(long numeric, const char *str, static bool check_against_clause(long numeric, const char *str,
const struct tagcache_search_clause *clause) const struct tagcache_search_clause *clause)
{ {
switch (clause->type) if (clause->numeric)
{ {
case clause_is: switch (clause->type)
if (clause->numeric) {
case clause_is:
return numeric == clause->numeric_data; return numeric == clause->numeric_data;
else case clause_is_not:
return numeric != clause->numeric_data;
case clause_gt:
return numeric > clause->numeric_data;
case clause_gteq:
return numeric >= clause->numeric_data;
case clause_lt:
return numeric < clause->numeric_data;
case clause_lteq:
return numeric <= clause->numeric_data;
default:
logf("Incorrect numeric tag: %d", clause->type);
}
}
else
{
switch (clause->type)
{
case clause_is:
return !strcasecmp(clause->str, str); return !strcasecmp(clause->str, str);
case clause_is_not: case clause_is_not:
if (clause->numeric) return strcasecmp(clause->str, str);
return numeric != clause->numeric_data; case clause_gt:
else return 0>strcasecmp(clause->str, str);
return strcasecmp(clause->str, str); case clause_gteq:
return 0>=strcasecmp(clause->str, str);
case clause_lt:
return 0<strcasecmp(clause->str, str);
case clause_lteq:
return 0<=strcasecmp(clause->str, str);
case clause_contains:
return (strcasestr(str, clause->str) != NULL);
case clause_not_contains:
return (strcasestr(str, clause->str) == NULL);
case clause_begins_with:
return (strcasestr(str, clause->str) == str);
case clause_not_begins_with:
return (strcasestr(str, clause->str) != str);
case clause_ends_with:
return str_ends_with(str, clause->str);
case clause_not_ends_with:
return !str_ends_with(str, clause->str);
case clause_gt: default:
return numeric > clause->numeric_data; logf("Incorrect tag: %d", clause->type);
case clause_gteq: }
return numeric >= clause->numeric_data;
case clause_lt:
return numeric < clause->numeric_data;
case clause_lteq:
return numeric <= clause->numeric_data;
case clause_contains:
return (strcasestr(str, clause->str) != NULL);
case clause_not_contains:
return (strcasestr(str, clause->str) == NULL);
case clause_begins_with:
return (strcasestr(str, clause->str) == str);
case clause_not_begins_with:
return (strcasestr(str, clause->str) != str);
case clause_ends_with:
return str_ends_with(str, clause->str);
case clause_not_ends_with:
return !str_ends_with(str, clause->str);
} }
return false; return false;

View file

@ -239,3 +239,4 @@ Pengxuan Liu
Andrew Cupper Andrew Cupper
Thilo-Alexander Ginkel Thilo-Alexander Ginkel
Adam Gashlin Adam Gashlin
Robert Kukla