song format: add support for limiting maximal length of a tag

This commit is contained in:
Andrzej Rybczak
2010-08-22 20:56:38 +02:00
parent e4b3d6aea2
commit f09f7c396f
3 changed files with 26 additions and 5 deletions

View File

@@ -22,6 +22,7 @@
#include <config.h>
#endif
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
@@ -370,13 +371,21 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *
if (*it == '%')
{
switch (*++it)
size_t delimiter = 0;
if (isdigit(*++it))
{
case '%':
result += *it; // no break here
default:
get = toGetFunction(*it);
delimiter = atol(&*it);
while (isdigit(*++it)) { }
}
if (*it == '%')
{
result += *it;
get = 0;
}
else
get = toGetFunction(*it);
if (get)
{
std::string tag = GetTags(get);
@@ -386,6 +395,12 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *
tag.replace(i, 1, std::string(1, FormatEscapeCharacter) + *ch);
if (!tag.empty() && (get != &MPD::Song::GetLength || GetTotalLength()))
{
if (delimiter)
{
const std::basic_string<my_char_t> &s = TO_WSTRING(tag);
if (NCurses::Window::Length(s) > delimiter)
tag = Shorten(s, delimiter);
}
has_some_tags = 1;
result += tag;
}