tagtree/tagcache add new clause operator contains_oneof

new operators @~, *~
contains_oneof and not_contains_oneof

genre @~ "metal|core"
black metal, death metal, grindcore, mathcore

genre ~ "jazz" & genre *~ "rock|pop|fusion"
included: jazz, free jazz, cool jazz, etc.
excluded: jazz rock, jazz pop, jazz fusion

Change-Id: If9590c8607b58373a98f5c9ea537f54df78d5a2f
This commit is contained in:
Nyx Guan 2025-12-27 23:43:42 +00:00 committed by Solomon Peachy
parent b31becd4bc
commit 012245c51f
3 changed files with 33 additions and 4 deletions

View file

@ -239,9 +239,11 @@ static const char * const tag_type_str[] = {
[clause_ends_with] = "clause_ends_with",
[clause_not_ends_with] = "clause_not_ends_with",
[clause_oneof] = "clause_oneof",
[clause_contains_oneof] = "clause_contains_oneof",
[clause_begins_oneof] = "clause_begins_oneof",
[clause_ends_oneof] = "clause_ends_oneof",
[clause_not_oneof] = "clause_not_oneof",
[clause_not_contains_oneof] = "clause_not_contains_oneof",
[clause_not_begins_oneof] = "clause_not_begins_oneof",
[clause_not_ends_oneof] = "clause_not_ends_oneof",
[clause_logical_or] = "clause_logical_or"
@ -1397,6 +1399,28 @@ inline static bool str_begins_ends_oneof(const char *str, const char *list, bool
return false;
}
inline static bool str_contains_oneof(const char *str, char *list)
{
logf_clauses("%s %s %s", str, __func__, list);
const char *sep;
int l, len = strlen(str);
while (*list)
{
sep = strchr(list, '|');
l = sep ? (intptr_t)sep - (intptr_t)list : (int)strlen(list);
list[l] = '\0';
if (l <= len && strcasestr(str, list) != NULL) {
if (sep) list[l] = '|';
return true;
}
if (sep) list[l] = '|';
list += sep ? l + 1 : l;
}
return false;
}
static bool check_against_clause(long numeric, const char *str,
const struct tagcache_search_clause *clause)
{
@ -1462,6 +1486,10 @@ static bool check_against_clause(long numeric, const char *str,
case clause_not_begins_oneof:
return !str_begins_ends_oneof(str, clause->str,
clause->type == clause_not_begins_oneof);
case clause_contains_oneof:
return str_contains_oneof(str, clause->str);
case clause_not_contains_oneof:
return !str_contains_oneof(str, clause->str);
default:
logf("Incorrect tag: %d", clause->type);
}

View file

@ -72,10 +72,9 @@ 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_oneof,
clause_begins_oneof, clause_ends_oneof, clause_not_oneof,
clause_not_begins_oneof, clause_not_ends_oneof,
clause_begins_with, clause_not_begins_with, clause_ends_with, clause_not_ends_with,
clause_oneof, clause_begins_oneof, clause_ends_oneof, clause_contains_oneof,
clause_not_oneof, clause_not_begins_oneof, clause_not_ends_oneof, clause_not_contains_oneof,
clause_logical_or };
struct tagcache_stat {

View file

@ -481,9 +481,11 @@ static int get_clause(int *condition)
CLAUSE('!', '^', clause_not_begins_with),
CLAUSE('$', ' ', clause_ends_with),
CLAUSE('!', '$', clause_not_ends_with),
CLAUSE('@', '~', clause_contains_oneof),
CLAUSE('@', '^', clause_begins_oneof),
CLAUSE('@', '$', clause_ends_oneof),
CLAUSE('@', ' ', clause_oneof),
CLAUSE('*', '~', clause_not_contains_oneof),
CLAUSE('*', '^', clause_not_begins_oneof),
CLAUSE('*', '$', clause_not_ends_oneof),
CLAUSE('!', '@', clause_not_oneof),