diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2016-10-30 19:01:11 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2016-10-30 19:01:11 +0100 |
commit | 6ebf00eb5d3e6a66ad567aa09ca575f5e0c9a982 (patch) | |
tree | fb55ef1238b1a5040fc1f68343178d9b42ba3fe3 /src/song.cpp | |
parent | 126e954528133765ef7fde84af08301f2ed73eb1 (diff) |
Song: add support for hiding duplicate tags
Diffstat (limited to 'src/song.cpp')
-rw-r--r-- | src/song.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/song.cpp b/src/song.cpp index e8ea294d..87bcde5d 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -46,6 +46,8 @@ namespace MPD { std::string Song::TagsSeparator = " | "; +bool Song::ShowDuplicateTags = true; + std::string Song::get(mpd_tag_type type, unsigned idx) const { std::string result; @@ -206,11 +208,38 @@ std::string MPD::Song::getTags(GetFunction f) const assert(m_song); unsigned idx = 0; std::string result; - for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) + if (ShowDuplicateTags) + { + for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) + { + if (!result.empty()) + result += TagsSeparator; + result += tag; + } + } + else { - if (!result.empty()) - result += TagsSeparator; - result += tag; + bool already_present; + // This is O(n^2), but it doesn't really matter as a list of tags will have + // at most 2 or 3 items the vast majority of time. + for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) + { + already_present = false; + for (unsigned i = 0; i < idx; ++i) + { + if ((this->*f)(i) == tag) + { + already_present = true; + break; + } + } + if (!already_present) + { + if (idx > 0) + result += TagsSeparator; + result += tag; + } + } } return result; } |