From 468d13aac50edba2cd1e46cb0387700c95802377 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 12 Mar 2017 19:52:36 +0100 Subject: [PATCH] Prepend '0' to 'disc' tag if it's a single digit number --- src/song.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/song.cpp b/src/song.cpp index e9dbaa13..d18ba9df 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -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