display: improve showSongs a bit

This commit is contained in:
Andrzej Rybczak
2012-09-12 19:36:16 +02:00
parent fd6a5889d0
commit 8e7bcd219b
5 changed files with 39 additions and 30 deletions

View File

@@ -327,15 +327,14 @@ template <> struct StringConverter<NC::Scrollpad> {
std::wstring operator()(const char *s) { return ToWString(s); }
};
template <typename CharT>
void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &buf)
template <typename Iterator>
void stringToBuffer(Iterator first, Iterator last, NC::basic_buffer<typename Iterator::value_type> &buf)
{
StringConverter< NC::basic_buffer<CharT> > cnv;
for (auto it = s.begin(); it != s.end(); ++it)
for (auto it = first; it != last; ++it)
{
if (*it == '$')
{
if (++it == s.end())
if (++it == last)
{
buf << '$';
break;
@@ -361,9 +360,9 @@ void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &b
buf << NC::fmtReverse;
break;
case '/':
if (++it == s.end())
if (++it == last)
{
buf << cnv("$/");
buf << '$' << '/';
break;
}
switch (*it)
@@ -394,7 +393,7 @@ void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &b
else if (*it == MPD::Song::FormatEscapeCharacter)
{
// treat '$' as a normal character if song format escape char is prepended to it
if (++it == s.end() || *it != '$')
if (++it == last || *it != '$')
--it;
buf << *it;
}
@@ -403,6 +402,12 @@ void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &b
}
}
template <typename CharT>
void stringToBuffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &buf)
{
stringToBuffer(s.begin(), s.end(), buf);
}
template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
{
StringConverter<T> cnv;