From bb4c0a9d4c5fa21e7d8cf767556b9bb28192e132 Mon Sep 17 00:00:00 2001 From: jgr Date: Tue, 24 Mar 2015 02:39:59 +1000 Subject: [PATCH] tag editor: fix leading separator issue (#32) --- NEWS | 1 + src/tag_editor.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 97decf6..4433a56 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ncmpcpp-0.6.4 (????-??-??) * Fix title of a pop-up which shows during adding selected items to the current playlist. +* Correctly deal with leading separator while parsing filenames in tag editor. ncmpcpp-0.6.3 (2015-03-02) diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 0f01823..2532d64 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -1148,7 +1148,12 @@ std::string ParseFilename(MPD::MutableSong &s, std::string mask, bool preview) std::vector< std::pair > tags; std::string file = s.getName().substr(0, s.getName().rfind(".")); - for (size_t i = mask.find("%"); i != std::string::npos; i = mask.find("%")) + size_t i = mask.find("%"); + + if (!mask.substr(0, i).empty()) + file = file.substr(i); + + for (; i != std::string::npos; i = mask.find("%")) { tags.push_back(std::make_pair(mask.at(i+1), "")); mask = mask.substr(i+2); @@ -1156,7 +1161,7 @@ std::string ParseFilename(MPD::MutableSong &s, std::string mask, bool preview) if (!mask.empty()) separators.push_back(mask.substr(0, i)); } - size_t i = 0; + i = 0; for (auto it = separators.begin(); it != separators.end(); ++it, ++i) { size_t j = file.find(*it); -- 2.11.4.GIT