ignore special chars that occurs in tag values

ncmpcpp shouldn't treat '$' characters that
are part of a tag as special format chars.
This commit is contained in:
Andrzej Rybczak
2009-09-26 18:29:52 +02:00
parent 3e75ff6455
commit 4efaa18927
4 changed files with 90 additions and 48 deletions

View File

@@ -305,7 +305,7 @@ void MPD::Song::SetPosition(int pos)
itsSong->pos = pos;
}
std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *escape_chars) const
{
std::string result;
bool has_some_tags = 0;
@@ -314,7 +314,7 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
{
while (*it == '{')
{
std::string tags = ParseFormat(it);
std::string tags = ParseFormat(it, escape_chars);
if (!tags.empty())
{
has_some_tags = 1;
@@ -379,6 +379,10 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
if (get)
{
std::string tag = (this->*get)();
if (escape_chars) // prepend format escape character to all given chars to escape
for (const char *ch = escape_chars; *ch; ++ch)
for (size_t i = tag.find(*ch); i != std::string::npos; i = tag.find(*ch, i += 2))
tag.replace(i, 1, std::string(1, FormatEscapeCharacter) + ch);
if (!tag.empty() && (get != &MPD::Song::GetLength || GetTotalLength()))
{
has_some_tags = 1;
@@ -402,7 +406,7 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
--brace_counter;
}
if (*++it == '|')
return ParseFormat(++it);
return ParseFormat(++it, escape_chars);
else
return "";
}
@@ -423,10 +427,10 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
}
}
std::string MPD::Song::toString(const std::string &format) const
std::string MPD::Song::toString(const std::string &format, const char *escape_chars) const
{
std::string::const_iterator it = format.begin();
return ParseFormat(it);
return ParseFormat(it, escape_chars);
}
MPD::Song &MPD::Song::operator=(const MPD::Song &s)