wide string: a few adjustments

This commit is contained in:
Andrzej Rybczak
2014-11-11 00:16:58 +01:00
parent 8d24c42261
commit 61d841d29a
3 changed files with 9 additions and 10 deletions

View File

@@ -129,7 +129,7 @@ std::wstring Lyrics::title()
std::wstring result = L"Lyrics: ";
result += Scroller(
Format::stringify<wchar_t>(Format::wparse(L"{%a - %t}"), &itsSong),
Format::stringify<wchar_t>(Format::wparse(L"%a - %t"), &itsSong),
itsScrollBegin,
COLS-result.length()-(Config.design == Design::Alternative ? 2 : Global::VolumeState.length())
);

View File

@@ -22,14 +22,14 @@
#include <cassert>
#include "utility/wide_string.h"
std::string ToString(std::wstring ws)
std::string ToString(const std::wstring &ws)
{
return boost::locale::conv::utf_to_utf<char>(std::move(ws));
return boost::locale::conv::utf_to_utf<char>(ws);
}
std::wstring ToWString(std::string s)
std::wstring ToWString(const std::string &s)
{
return boost::locale::conv::utf_to_utf<wchar_t>(std::move(s));
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
size_t wideLength(const std::wstring &ws)
@@ -52,7 +52,7 @@ void wideCut(std::wstring &ws, size_t max_length)
int remained_len = max_length;
for (; i < ws.length(); ++i)
{
remained_len -= wcwidth(ws[i]);
remained_len -= std::max(wcwidth(ws[i]), 1);
if (remained_len < 0)
{
ws.resize(i);

View File

@@ -23,14 +23,13 @@
#include <string>
std::string ToString(std::wstring ws);
std::wstring ToWString(std::string s);
std::string ToString(const std::wstring &ws);
std::wstring ToWString(const std::string &s);
size_t wideLength(const std::wstring &ws);
void wideCut(std::wstring &ws, size_t max_length);
std::wstring wideShorten(const std::wstring &ws, size_t max_length);
std::wstring wideShorten(const std::wstring &ws, size_t max_length);
inline std::string wideShorten(const std::string &s, size_t max_length)
{
return ToString(wideShorten(ToWString(s), max_length));