format: implement generic format parser and printer
This commit is contained in:
@@ -331,95 +331,6 @@ template <typename Iterator> std::string getSharedDirectory(Iterator first, Iter
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void stringToBuffer(Iterator first, Iterator last, NC::BasicBuffer<typename Iterator::value_type> &buf)
|
||||
{
|
||||
for (auto it = first; it != last; ++it)
|
||||
{
|
||||
if (*it == '$')
|
||||
{
|
||||
if (++it == last)
|
||||
{
|
||||
buf << '$';
|
||||
break;
|
||||
}
|
||||
else if (isdigit(*it))
|
||||
{
|
||||
buf << charToColor(*it);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
case 'b':
|
||||
buf << NC::Format::Bold;
|
||||
break;
|
||||
case 'u':
|
||||
buf << NC::Format::Underline;
|
||||
break;
|
||||
case 'a':
|
||||
buf << NC::Format::AltCharset;
|
||||
break;
|
||||
case 'r':
|
||||
buf << NC::Format::Reverse;
|
||||
break;
|
||||
case '/':
|
||||
if (++it == last)
|
||||
{
|
||||
buf << '$' << '/';
|
||||
break;
|
||||
}
|
||||
switch (*it)
|
||||
{
|
||||
case 'b':
|
||||
buf << NC::Format::NoBold;
|
||||
break;
|
||||
case 'u':
|
||||
buf << NC::Format::NoUnderline;
|
||||
break;
|
||||
case 'a':
|
||||
buf << NC::Format::NoAltCharset;
|
||||
break;
|
||||
case 'r':
|
||||
buf << NC::Format::NoReverse;
|
||||
break;
|
||||
default:
|
||||
buf << '$' << *--it;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
buf << *--it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*it == MPD::Song::FormatEscapeCharacter)
|
||||
{
|
||||
// treat '$' as a normal character if song format escape char is prepended to it
|
||||
if (++it == last || *it != '$')
|
||||
--it;
|
||||
buf << *it;
|
||||
}
|
||||
else
|
||||
buf << *it;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
void stringToBuffer(const std::basic_string<CharT> &s, NC::BasicBuffer<CharT> &buf)
|
||||
{
|
||||
stringToBuffer(s.begin(), s.end(), buf);
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
NC::BasicBuffer<CharT> stringToBuffer(const std::basic_string<CharT> &s)
|
||||
{
|
||||
NC::BasicBuffer<CharT> result;
|
||||
stringToBuffer(s, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
|
||||
{
|
||||
const unsigned MINUTE = 60;
|
||||
|
||||
Reference in New Issue
Block a user