diff --git a/libsaria/library/list.cpp b/libsaria/library/list.cpp index 7e769b72..ce6b4fde 100644 --- a/libsaria/library/list.cpp +++ b/libsaria/library/list.cpp @@ -9,10 +9,54 @@ using namespace std; static list play_list; static list::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; }