Prepend '0' to 'disc' tag if it's a single digit number

This commit is contained in:
Andrzej Rybczak
2017-03-12 19:52:36 +01:00
parent 86ec51624e
commit 468d13aac5

View File

@@ -33,6 +33,15 @@
namespace {
// Prepend '0' if the tag is a single digit number so that we get "expected"
// sort order with regular string comparison.
void format_numeric_tag(std::string &s)
{
if ((s.length() == 1 && s[0] != '0')
|| (s.length() > 3 && s[1] == '/'))
s = "0"+s;
}
size_t calc_hash(const char *s, size_t seed = 0)
{
for (; *s != '\0'; ++s)
@@ -131,9 +140,7 @@ std::string Song::getTrack(unsigned idx) const
{
assert(m_song);
std::string track = get(MPD_TAG_TRACK, idx);
if ((track.length() == 1 && track[0] != '0')
|| (track.length() > 3 && track[1] == '/'))
track = "0"+track;
format_numeric_tag(track);
return track;
}
@@ -174,7 +181,9 @@ std::string Song::getPerformer(unsigned idx) const
std::string Song::getDisc(unsigned idx) const
{
assert(m_song);
return get(MPD_TAG_DISC, idx);
std::string disc = get(MPD_TAG_DISC, idx);
format_numeric_tag(disc);
return disc;
}
std::string Song::getComment(unsigned idx) const