core/tags/artist: Add artist_match_token() function

This is called to check if any string in an artist's token list is
prefixed by the given string.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-19 14:31:50 -04:00 committed by Anna Schumaker
parent b643b532d7
commit a70b27779f
3 changed files with 12 additions and 0 deletions

View File

@ -94,6 +94,11 @@ int artist_compare(struct artist *lhs, struct artist *rhs)
return string_compare_tokens(lhs->ar_tokens, rhs->ar_tokens);
}
bool artist_match_token(struct artist *artist, const gchar *string)
{
return string_match_token(string, artist->ar_tokens) ||
string_match_token(string, artist->ar_alts);
}
#ifdef CONFIG_TESTING
const struct db_ops *test_artist_ops() { return &artist_ops; }
#endif /* CONFIG_TESTING */

View File

@ -49,6 +49,9 @@ struct artist *artist_get(const unsigned int);
/* Called to compare two artist tags. */
int artist_compare(struct artist *, struct artist *);
/* Called to check if an artist has a token that matches the given string. */
bool artist_match_token(struct artist *artist, const gchar *);
#ifdef CONFIG_TESTING
const struct db_ops *test_artist_ops();
#endif /* CONFIG_TESTING */

View File

@ -34,7 +34,11 @@ static void test_artist()
struct file f;
artist = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
test_verify_koji(artist);
test_equal(artist_match_token(artist, "koji"), (bool)true);
test_equal(artist_match_token(artist, "kondo"), (bool)true);
test_equal(artist_match_token(artist, "hajime"), (bool)false);
file_init(&f, "artist_tag", 0, 0);
file_open(&f, OPEN_WRITE);