From be29f53eaaa2c7a670d6eb518e363bc3921f3491 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 19 May 2016 14:47:58 -0400 Subject: [PATCH] core/tags/album: Add album_match_token() function This is called to check if any string in an album's token list is prefixed by the given string. Signed-off-by: Anna Schumaker --- core/tags/album.c | 6 ++++++ include/core/tags/album.h | 3 +++ tests/core/tags/album.c | 3 +++ 3 files changed, 12 insertions(+) diff --git a/core/tags/album.c b/core/tags/album.c index 7d6a4265..620af3d1 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -266,6 +266,12 @@ int album_compare_year(struct album *lhs, struct album *rhs) return lhs->al_year - rhs->al_year; } +bool album_match_token(struct album *album, const gchar *string) +{ + return string_match_token(string, album->al_tokens) || + string_match_token(string, album->al_alts); +} + bool album_artwork_exists(struct album *album) { struct cache_file file; diff --git a/include/core/tags/album.h b/include/core/tags/album.h index 43029e11..f41d6d4d 100644 --- a/include/core/tags/album.h +++ b/include/core/tags/album.h @@ -47,6 +47,9 @@ int album_compare(struct album *, struct album *); /* Called to compare two album tags by year. */ int album_compare_year(struct album *, struct album *); +/* Called to check if an artist has a token that matches the given string. */ +bool album_match_token(struct album *album, const gchar *); + /* Called to check if album artwork has been downloaded. */ bool album_artwork_exists(struct album *); diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index 9bae1d2c..ec22667e 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -37,6 +37,9 @@ static void test_album() album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony")); test_verify_hyrule(album); + test_equal(album_match_token(album, "hyrule"), (bool)true); + test_equal(album_match_token(album, "symphony"), (bool)true); + test_equal(album_match_token(album, "skyward"), (bool)false); file_init(&f, "album_tag", 0, 0); file_open(&f, OPEN_WRITE);