summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-03-19 02:15:35 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2022-03-19 02:24:14 -0400
commitddbca125a61ae25ffd0acb782d585b9318f4d072 (patch)
treea60330931cb555bd01230815dfcb210d31d30b0d
parent0f2d62321663d3f8942bf4cfba31c8dfa17efb61 (diff)
downloadrockbox-ddbca125a61ae25ffd0acb782d585b9318f4d072.tar.gz
rockbox-ddbca125a61ae25ffd0acb782d585b9318f4d072.zip
tagtree/tagcache add new clause operators begins/ends _oneof
new operators @^, @$ begins_oneof and ends_oneof albumartist @^ "L|The L" Led Zeppelin, The look albumartist @$ "girls|Boys" spice girls, beasty boys Change-Id: I26ce3d8155d970a55e003f74e2f9478db76204f1
-rw-r--r--apps/tagcache.c27
-rw-r--r--apps/tagcache.h4
-rw-r--r--apps/tagtree.c2
3 files changed, 31 insertions, 2 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index cf0d73f0fb..5a80885819 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -56,7 +56,7 @@
56 */ 56 */
57 57
58/*#define LOGF_ENABLE*/ 58/*#define LOGF_ENABLE*/
59/*#define LOGF_CLAUSES define to enable logf clause matching (LOGF_ENABLE req'd) */ 59/*#define LOGF_CLAUSES define to enable logf clause matching (LOGF_ENABLE req'd) */
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include <stdlib.h> 62#include <stdlib.h>
@@ -162,6 +162,8 @@ static const char *tag_type_str[] = {
162 [clause_ends_with] = "clause_ends_with", 162 [clause_ends_with] = "clause_ends_with",
163 [clause_not_ends_with] = "clause_not_ends_with", 163 [clause_not_ends_with] = "clause_not_ends_with",
164 [clause_oneof] = "clause_oneof", 164 [clause_oneof] = "clause_oneof",
165 [clause_begins_oneof] = "clause_begins_oneof",
166 [clause_ends_oneof] = "clause_ends_oneof",
165 [clause_logical_or] = "clause_logical_or" 167 [clause_logical_or] = "clause_logical_or"
166 }; 168 };
167#define logf_clauses logf 169#define logf_clauses logf
@@ -1052,6 +1054,25 @@ inline static bool str_oneof(const char *str, const char *list)
1052 return false; 1054 return false;
1053} 1055}
1054 1056
1057inline static bool str_begins_ends_oneof(const char *str, const char *list, bool begins)
1058{
1059 logf_clauses("%s %s (%s) %s", str, __func__, begins ? "begins" : "ends", list);
1060 const char *sep;
1061 int l, p, len = strlen(str);
1062
1063 while (*list)
1064 {
1065 sep = strchr(list, '|');
1066 l = sep ? (intptr_t)sep - (intptr_t)list : (int)strlen(list);
1067 p = begins ? 0 : len - l;
1068 if (l <= len && !strncasecmp(&str[p], list, l))
1069 return true;
1070 list += sep ? l + 1 : l;
1071 }
1072
1073 return false;
1074}
1075
1055static bool check_against_clause(long numeric, const char *str, 1076static bool check_against_clause(long numeric, const char *str,
1056 const struct tagcache_search_clause *clause) 1077 const struct tagcache_search_clause *clause)
1057{ 1078{
@@ -1105,6 +1126,10 @@ static bool check_against_clause(long numeric, const char *str,
1105 return !str_ends_with(str, clause->str); 1126 return !str_ends_with(str, clause->str);
1106 case clause_oneof: 1127 case clause_oneof:
1107 return str_oneof(str, clause->str); 1128 return str_oneof(str, clause->str);
1129 case clause_begins_oneof:
1130 return str_begins_ends_oneof(str, clause->str, true);
1131 case clause_ends_oneof:
1132 return str_begins_ends_oneof(str, clause->str, false);
1108 default: 1133 default:
1109 logf("Incorrect tag: %d", clause->type); 1134 logf("Incorrect tag: %d", clause->type);
1110 } 1135 }
diff --git a/apps/tagcache.h b/apps/tagcache.h
index b7c4aadbb1..1218e42b42 100644
--- a/apps/tagcache.h
+++ b/apps/tagcache.h
@@ -127,7 +127,9 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
127enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq, 127enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
128 clause_lt, clause_lteq, clause_contains, clause_not_contains, 128 clause_lt, clause_lteq, clause_contains, clause_not_contains,
129 clause_begins_with, clause_not_begins_with, clause_ends_with, 129 clause_begins_with, clause_not_begins_with, clause_ends_with,
130 clause_not_ends_with, clause_oneof, clause_logical_or }; 130 clause_not_ends_with, clause_oneof,
131 clause_begins_oneof, clause_ends_oneof,
132 clause_logical_or };
131 133
132struct tagcache_stat { 134struct tagcache_stat {
133 bool initialized; /* Is tagcache currently busy? */ 135 bool initialized; /* Is tagcache currently busy? */
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 48ef1e28ce..9fb2172e57 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -418,6 +418,8 @@ static int get_clause(int *condition)
418 CLAUSE('!', '^', clause_not_begins_with), 418 CLAUSE('!', '^', clause_not_begins_with),
419 CLAUSE('$', ' ', clause_ends_with), 419 CLAUSE('$', ' ', clause_ends_with),
420 CLAUSE('!', '$', clause_not_ends_with), 420 CLAUSE('!', '$', clause_not_ends_with),
421 CLAUSE('@', '^', clause_begins_oneof),
422 CLAUSE('@', '$', clause_ends_oneof),
421 CLAUSE('@', ' ', clause_oneof) 423 CLAUSE('@', ' ', clause_oneof)
422 }; 424 };
423 425