Skip to content

Commit

Permalink
Changed library construction to use iequals instead of imatch for art…
Browse files Browse the repository at this point in the history
…ist and album comparisons
  • Loading branch information
boysetsfrog committed Dec 18, 2013
1 parent 59ca061 commit b0d2bdc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ bool Algorithm::iequals(std::string const & s1, std::string const & s2)
return (strcasecmp(s1.c_str(), s2.c_str()) == 0);
}

bool Algorithm::iequals(std::string const & s1, std::string const & s2, bool ignoreLeadingThe, bool caseInsensitive)
{
std::string lower1(PrepString(s1, ignoreLeadingThe));
std::string lower2(PrepString(s2, ignoreLeadingThe));

if (caseInsensitive == true)
{
return (strcasecmp(lower1.c_str(), lower2.c_str()) == 0);
}

return (lower1 == lower2);
}

bool Algorithm::isNumeric(std::string const & s1)
{
for (unsigned int i = 0; i < s1.size(); ++i)
Expand Down
1 change: 1 addition & 0 deletions src/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Algorithm
bool icompare(std::string const & s1, std::string const & s2, bool ignoreLeadingThe = false, bool caseInsensitive = true);
bool imatch(std::string const & s1, std::string const & s2, bool ignoreLeadingThe, bool caseInsensitive);
bool iequals(std::string const & s1, std::string const & s2);
bool iequals(std::string const & s1, std::string const & s2, bool ignoreLeadingThe, bool caseInsensitive);

bool isNumeric(std::string const & s1);
}
Expand Down
12 changes: 6 additions & 6 deletions src/buffer/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Library::Library() :
AddCallback(Main::Buffer_Remove, [this] (LibraryEntry * const entry) { CheckIfVariousRemoved(entry); });

Main::Vimpc::EventHandler(Event::AllMetaDataReady, [this] (EventData const & Data) { Sort(); });
settings_.RegisterCallback(Setting::AlbumArtist, [this] (bool Value)
{

settings_.RegisterCallback(Setting::AlbumArtist, [this] (bool Value)
{
// Clear the cached format prints for every song
for (auto song : uriMap_)
{
Expand Down Expand Up @@ -133,7 +133,7 @@ void Library::Add(Mpc::Song * song)
CreateVariousArtist();

if ((lastAlbumEntry_ == NULL) ||
(Algorithm::imatch(lastAlbumEntry_->album_, album,
(Algorithm::iequals(lastAlbumEntry_->album_, album,
settings_.Get(Setting::IgnoreTheGroup), true) == false))
{
lastAlbumEntry_ = NULL;
Expand All @@ -148,7 +148,7 @@ void Library::Add(Mpc::Song * song)
for (i = 0;
((i < Size()) &&
((Get(i)->type_ != Mpc::ArtistType) ||
(Algorithm::imatch(Get(i)->artist_, artist,
(Algorithm::iequals(Get(i)->artist_, artist,
settings_.Get(Setting::IgnoreTheGroup), true) == false)));
++i);

Expand Down Expand Up @@ -184,7 +184,7 @@ void Library::Add(Mpc::Song * song)
(lastArtistEntry_ != variousArtist_) &&
(lastArtistEntry_->children_.back() == lastAlbumEntry_) &&
(Algorithm::iequals(lastAlbumEntry_->album_, album) == true) &&
(Algorithm::imatch(lastArtistEntry_->artist_, artist,
(Algorithm::iequals(lastArtistEntry_->artist_, artist,
settings_.Get(Setting::IgnoreTheGroup), true) == false))
{
lastArtistEntry_->children_.pop_back();
Expand Down

0 comments on commit b0d2bdc

Please # to comment.