consider "ignore leading 'the' word" function while sorting playlist

This commit is contained in:
Andrzej Rybczak
2009-03-06 18:14:01 +01:00
parent e209a86e8e
commit 93fd687ec1
3 changed files with 17 additions and 14 deletions

View File

@@ -34,16 +34,6 @@ using Global::Mpd;
using Global::wFooter; using Global::wFooter;
using std::string; using std::string;
namespace
{
inline void remove_the_word(string &s)
{
size_t the_pos = s.find("the ");
if (the_pos == 0 && the_pos != string::npos)
s = s.substr(4);
}
}
bool ConnectToMPD() bool ConnectToMPD()
{ {
if (!Mpd->Connect()) if (!Mpd->Connect())
@@ -175,8 +165,8 @@ bool CaseInsensitiveSorting::operator()(string a, string b)
ToLower(b); ToLower(b);
if (Config.ignore_leading_the) if (Config.ignore_leading_the)
{ {
remove_the_word(a); RemoveTheWord(a);
remove_the_word(b); RemoveTheWord(b);
} }
return a < b; return a < b;
} }
@@ -189,8 +179,8 @@ bool CaseInsensitiveSorting::operator()(Song *sa, Song *sb)
ToLower(b); ToLower(b);
if (Config.ignore_leading_the) if (Config.ignore_leading_the)
{ {
remove_the_word(a); RemoveTheWord(a);
remove_the_word(b); RemoveTheWord(b);
} }
return a < b; return a < b;
} }
@@ -303,6 +293,13 @@ string GetLineValue(string &line, char a, char b, bool once)
return ""; return "";
} }
void RemoveTheWord(string &s)
{
size_t the_pos = s.find("the ");
if (the_pos == 0 && the_pos != string::npos)
s = s.substr(4);
}
std::string ExtractTopDirectory(const std::string &s) std::string ExtractTopDirectory(const std::string &s)
{ {
size_t slash = s.rfind("/"); size_t slash = s.rfind("/");

View File

@@ -63,6 +63,7 @@ std::string FindSharedDir(const std::string &, const std::string &);
std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0); std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0);
void RemoveTheWord(std::string &s);
std::string ExtractTopDirectory(const std::string &); std::string ExtractTopDirectory(const std::string &);
const Buffer &ShowTag(const std::string &); const Buffer &ShowTag(const std::string &);

View File

@@ -275,6 +275,11 @@ bool Playlist::Sorting(MPD::Song *a, MPD::Song *b)
std::string sb = (b->*(*SortDialog)[i].second)(); std::string sb = (b->*(*SortDialog)[i].second)();
ToLower(sa); ToLower(sa);
ToLower(sb); ToLower(sb);
if (Config.ignore_leading_the)
{
RemoveTheWord(sa);
RemoveTheWord(sb);
}
if (sa != sb) if (sa != sb)
return sa < sb; return sa < sb;
} }