GenericTag: Add a function for comparing tag names
I was only ever comparing the lowercase version of the name, so this should be done in a single place (the GenericTag) to make maintenance easier. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
f433ced9cb
commit
cbcd9c594d
|
@ -179,13 +179,13 @@ int Track :: less_than(Track *rhs, sort_t field)
|
|||
int ret;
|
||||
switch (field) {
|
||||
case SORT_ARTIST:
|
||||
return compare_string(artist->lowercase(), rhs->artist->lowercase());
|
||||
return artist->compare(rhs->artist);
|
||||
case SORT_ALBUM:
|
||||
return compare_string(album->lowercase(), rhs->album->lowercase());
|
||||
return album->compare(rhs->album);
|
||||
case SORT_COUNT:
|
||||
return compare_uint(play_count, rhs->play_count);
|
||||
case SORT_GENRE:
|
||||
return compare_string(genre->lowercase(), rhs->genre->lowercase());
|
||||
return genre->compare(rhs->genre);
|
||||
case SORT_LENGTH:
|
||||
return compare_uint(length, rhs->length);
|
||||
case SORT_PLAYED:
|
||||
|
|
|
@ -37,3 +37,12 @@ const std::string &GenericTag :: lowercase()
|
|||
{
|
||||
return _lower;
|
||||
}
|
||||
|
||||
int GenericTag :: compare(const GenericTag *rhs)
|
||||
{
|
||||
if (_lower.size() == 0)
|
||||
return 1;
|
||||
if (rhs->_lower.size() == 0)
|
||||
return -1;
|
||||
return _lower.compare(rhs->_lower);
|
||||
}
|
||||
|
|
|
@ -69,6 +69,16 @@ public:
|
|||
* @return GenericTag::_lower.
|
||||
*/
|
||||
const std::string &lowercase();
|
||||
|
||||
/**
|
||||
* Called to compare the names of two GenericTags
|
||||
*
|
||||
* @param rhs The other tag that we are comparing with.
|
||||
* @return < 0: lhs < rhs, or rhs is empty.
|
||||
* @return 0: lhs == rhs.
|
||||
* @return > 0: rhs > lhs, or lhs is empty.
|
||||
*/
|
||||
int compare(const GenericTag *);
|
||||
};
|
||||
|
||||
#endif /* OCARINA_CORE_TAGS_GENERIC_H */
|
||||
|
|
|
@ -32,8 +32,22 @@ static void test_generic_tag()
|
|||
test_equal(tag.primary_key(), (std::string)"Generic Tag");
|
||||
}
|
||||
|
||||
static void test_generic_tag_comparison()
|
||||
{
|
||||
GenericTag A("A"), a("a"), B("B"), empty("");
|
||||
|
||||
test_equal(A.compare(&A), 0);
|
||||
test_equal(a.compare(&a), 0);
|
||||
test_equal(A.compare(&B), -1);
|
||||
test_equal(B.compare(&A), 1);
|
||||
|
||||
test_equal(empty.compare(&A), 1);
|
||||
test_equal(A.compare(&empty), -1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
run_test("Generic Tag Test", test_generic_tag);
|
||||
run_test("Generic Tag Compare Test", test_generic_tag_comparison);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue