From 3eb9e70b6467becb2aa88cc8d24a82a7c288f1fd Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Thu, 5 Oct 2006 09:49:18 +0000 Subject: [PATCH] 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 --- apps/tagcache.c | 80 ++++++++++++++++++++++++++++++------------------- docs/CREDITS | 1 + 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/apps/tagcache.c b/apps/tagcache.c index 042d27cc84..70934b4f36 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -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, const struct tagcache_search_clause *clause) { - switch (clause->type) + if (clause->numeric) { - case clause_is: - if (clause->numeric) + switch (clause->type) + { + case clause_is: 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); - case clause_is_not: - if (clause->numeric) - return numeric != clause->numeric_data; - else - return strcasecmp(clause->str, str); - - 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; - - 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_is_not: + return strcasecmp(clause->str, str); + case clause_gt: + return 0>strcasecmp(clause->str, str); + case clause_gteq: + return 0>=strcasecmp(clause->str, str); + case clause_lt: + return 0str, 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); + + default: + logf("Incorrect tag: %d", clause->type); + } } return false; diff --git a/docs/CREDITS b/docs/CREDITS index 3fc97187c7..7a5c2e832b 100644 --- a/docs/CREDITS +++ b/docs/CREDITS @@ -239,3 +239,4 @@ Pengxuan Liu Andrew Cupper Thilo-Alexander Ginkel Adam Gashlin +Robert Kukla