core/tags/genre: Add genre_match_token() function
This is called to check if any string in a genre's token list is prefixed by the given string. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1ca9bb36c1
commit
2e1c27294b
|
@ -82,6 +82,12 @@ int genre_compare(struct genre *lhs, struct genre *rhs)
|
|||
return string_compare_tokens(lhs->ge_tokens, rhs->ge_tokens);
|
||||
}
|
||||
|
||||
bool genre_match_token(struct genre *genre, const gchar *string)
|
||||
{
|
||||
return string_match_token(string, genre->ge_tokens) ||
|
||||
string_match_token(string, genre->ge_alts);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
const struct db_ops *test_genre_ops() { return &genre_ops; }
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -40,6 +40,9 @@ struct genre *genre_get(const unsigned int);
|
|||
/* Called to compare two genre tags. */
|
||||
int genre_compare(struct genre *, struct genre *);
|
||||
|
||||
/* Called to check if a genre has a token that matches the given string. */
|
||||
bool genre_match_token(struct genre *, const gchar *);
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
const struct db_ops *test_genre_ops();
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -34,6 +34,9 @@ static void test_genre()
|
|||
|
||||
genre = GENRE(genre_ops->dbe_alloc("Video Game Music"));
|
||||
test_verify_vg(genre);
|
||||
test_equal(genre_match_token(genre, "video"), (bool)true);
|
||||
test_equal(genre_match_token(genre, "music"), (bool)true);
|
||||
test_equal(genre_match_token(genre, "rock"), (bool)false);
|
||||
|
||||
file_init(&f, "genre_tag", 0, 0);
|
||||
file_open(&f, OPEN_WRITE);
|
||||
|
|
Loading…
Reference in New Issue