From be2eb02d7a9bba97aeb022174e4abe2cc132d6a3 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Mon, 9 Oct 2006 10:23:35 +0000 Subject: FS#6137: add "oneof" operator to tagnavi.conf syntax. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11157 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagcache.c | 19 +++++++++++++++++++ apps/tagcache.h | 2 +- apps/tagtree.c | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/tagcache.c b/apps/tagcache.c index 1c180b7f43..ca2421171b 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -592,6 +592,23 @@ inline static bool str_ends_with(const char *str1, const char *str2) return !strcasecmp(&str1[str_len - clause_len], str2); } +inline static bool str_oneof(const char *str, const char *list) +{ + const char *sep; + int l, len = strlen(str); + + while (*list) + { + sep = strchr(list, '|'); + l = sep ? (long)sep - (long)list : (int)strlen(list); + if ((l==len) && !strncasecmp(str, list, len)) + return true; + list += sep ? l + 1 : l; + } + + return false; +} + static bool check_against_clause(long numeric, const char *str, const struct tagcache_search_clause *clause) { @@ -643,6 +660,8 @@ static bool check_against_clause(long numeric, const char *str, return str_ends_with(str, clause->str); case clause_not_ends_with: return !str_ends_with(str, clause->str); + case clause_oneof: + return str_oneof(str, clause->str); default: logf("Incorrect tag: %d", clause->type); diff --git a/apps/tagcache.h b/apps/tagcache.h index 23525f8ea8..1a3afcac16 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -77,7 +77,7 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq, clause_lt, clause_lteq, clause_contains, clause_not_contains, clause_begins_with, clause_not_begins_with, clause_ends_with, - clause_not_ends_with }; + clause_not_ends_with, clause_oneof }; struct tagcache_stat { bool initialized; /* Is tagcache currently busy? */ diff --git a/apps/tagtree.c b/apps/tagtree.c index f9542821d8..90fa617aad 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -244,6 +244,7 @@ static int get_clause(int *condition) MATCH(condition, buf, "!^", clause_not_begins_with); MATCH(condition, buf, "$", clause_ends_with); MATCH(condition, buf, "!$", clause_not_ends_with); + MATCH(condition, buf, "@", clause_oneof); return 0; } -- cgit v1.2.3