libsaria: Better track comparision function

I sort by artist / album / track, so I need to check each of these
fields in order.  It would be nice if I could expand numbers into words
for some tags (3 Doors Down, Matchbox 20 and so on), but I'm happy with
what I have right now.
This commit is contained in:
Bryan Schumaker 2011-11-06 15:44:45 -05:00
parent 858fa1821f
commit 9379a2cf33
1 changed files with 46 additions and 2 deletions

View File

@ -9,10 +9,54 @@ using namespace std;
static list<TrackTag *> play_list;
static list<TrackTag *>::iterator cur_track = play_list.end();
bool compare_tracktags(TrackTag *one, TrackTag *two)
static string format(string s)
{
if (one->get_artist() < two->get_artist())
string res;
char c, diff = 'a' - 'A';
/*
* TODO: Break into words based on spaces and format each word
* before joining. Turn numbers into their word form (3 -> three,
* 20 -> twenty)
*/
for (unsigned int i = 0; i < s.size(); i++) {
c = s[i];
if ( (c >= 'a') && (c <= 'z') )
res += c;
else if ( (c >= 'A') && (c <= 'Z') )
res += (c + diff);
if ( (c >= '0') && (c <= '9') )
res += c;
}
return res;
}
static inline bool compare_tracks(TrackTag *one, TrackTag *two)
{
return one->get_track() < two->get_track();
}
static inline bool compare_albums(TrackTag *one, TrackTag *two)
{
string s_one = format(one->get_album());
string s_two = format(two->get_album());
if (s_one < s_two)
return true;
else if (s_one == s_two)
return compare_tracks(one, two);
return false;
}
static bool compare_tracktags(TrackTag *one, TrackTag *two)
{
string s_one = format(one->get_artist());
string s_two = format(two->get_artist());
if (s_one == "")
return false;
if ( (s_one < s_two) || (s_two == "") )
return true;
else if (s_one == s_two)
return compare_albums(one, two);
return false;
}