core/tags/track: Convert lowercased string into tokens

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-19 11:31:49 -04:00 committed by Anna Schumaker
parent 2e1c27294b
commit 6ad4325f22
3 changed files with 29 additions and 15 deletions

View File

@ -80,9 +80,10 @@ struct db_entry *track_alloc(const gchar *key)
track->tr_track = taglib_tag_track(tag);
date_set(&track->tr_date, 0, 0, 0);
track->tr_path = g_strdup(key);
track->tr_title = g_strdup(taglib_tag_title(tag));
track->tr_lower = string_lowercase(track->tr_title);
track->tr_path = g_strdup(key);
track->tr_title = g_strdup(taglib_tag_title(tag));
track->tr_tokens = g_str_tokenize_and_fold(track->tr_title, NULL,
&track->tr_alts);
taglib_tag_free_strings();
taglib_file_free(file);
@ -103,7 +104,10 @@ static void track_free(struct db_entry *dbe)
if (track->tr_library)
track->tr_library->li_size--;
filter_remove(track->tr_lower, track);
for (i = 0; track->tr_tokens[i]; i++)
filter_remove(track->tr_tokens[i], track);
for (i = 0; track->tr_alts[i]; i++)
filter_remove(track->tr_alts[i], track);
for (i = 0; track->tr_artist->ar_tokens[i]; i++)
filter_remove(track->tr_artist->ar_tokens[i], track);
@ -115,8 +119,9 @@ static void track_free(struct db_entry *dbe)
for (i = 0; track->tr_album->al_alts[i]; i++)
filter_remove(track->tr_album->al_alts[i], track);
g_strfreev(track->tr_tokens);
g_strfreev(track->tr_alts);
g_free(track->tr_title);
g_free(track->tr_lower);
g_free(track);
}
@ -125,7 +130,10 @@ static void track_setup(struct db_entry *dbe)
struct track *track = TRACK(dbe);
unsigned int i;
filter_add(track->tr_lower, track);
for (i = 0; track->tr_tokens[i]; i++)
filter_add(track->tr_tokens[i], track);
for (i = 0; track->tr_alts[i]; i++)
filter_add(track->tr_alts[i], track);
for (i = 0; track->tr_artist->ar_tokens[i]; i++)
filter_add(track->tr_artist->ar_tokens[i], track);
@ -167,8 +175,9 @@ static struct db_entry *track_read(struct file *file)
if (track->tr_album->al_artist == NULL)
track->tr_album->al_artist = track->tr_artist;
track->tr_title = file_readl(file);
track->tr_lower = string_lowercase(track->tr_title);
track->tr_title = file_readl(file);
track->tr_tokens = g_str_tokenize_and_fold(track->tr_title, NULL,
&track->tr_alts);
track->tr_path = __track_key(track->tr_library, file_readl(file));
return &track->tr_dbe;
}
@ -291,7 +300,7 @@ int track_compare(struct track *lhs, struct track *rhs, enum compare_t compare)
case COMPARE_PLAYED:
return date_compare(&lhs->tr_date, &rhs->tr_date);
case COMPARE_TITLE:
return string_compare(lhs->tr_lower, rhs->tr_lower);
return string_compare_tokens(lhs->tr_tokens, rhs->tr_tokens);
case COMPARE_TRACK:
return lhs->tr_track - rhs->tr_track;
case COMPARE_YEAR:

View File

@ -51,10 +51,11 @@ struct track {
unsigned int tr_length; /* This track's length, in seconds. */
unsigned int tr_track; /* This track's track number. */
struct date tr_date; /* This track's last-played date. */
gchar *tr_path; /* This track's path, relative to the library. */
gchar *tr_title; /* This track's title. */
gchar *tr_lower; /* This track's title (lowercased). */
struct date tr_date; /* This track's last-played date. */
gchar *tr_path; /* This track's path, relative to the library. */
gchar *tr_title; /* This track's title. */
gchar **tr_tokens; /* This track's tokenized strings. */
gchar **tr_alts; /* This track's alternate ascii tokens. */
struct db_entry tr_dbe;
};

View File

@ -31,7 +31,10 @@ static void test_verify_track(struct track *track)
test_verify_tags(track);
test_equal(track->tr_title, "Title Theme");
test_equal(track->tr_lower, "title theme");
test_equal(track->tr_tokens[0], "title");
test_equal(track->tr_tokens[1], "theme");
test_equal((void *)track->tr_tokens[2], NULL);
test_equal((void *)track->tr_alts[0], NULL);
test_equal(track_ops->dbe_key(&track->tr_dbe),
"0/Hyrule Symphony/01 - Title Theme.ogg");
test_str_equal(track_path(track),
@ -49,7 +52,8 @@ static void test_verify_notrack(struct track *track)
test_verify_tags(track);
test_equal(track->tr_title, "");
test_equal(track->tr_lower, "");
test_equal((void *)track->tr_tokens[0], NULL);
test_equal((void *)track->tr_alts[0], NULL);
test_equal(track_ops->dbe_key(&track->tr_dbe),
"0/Hyrule Symphony/00 - No Track.ogg");
test_str_equal(track_path(track),