diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2014-11-11 00:16:58 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2014-11-11 00:16:58 +0100 |
commit | 61d841d29af086b9f7cbc9b1fd5786ea7644587d (patch) | |
tree | fe14c314a6429a266b592fe9f97777cac93c4267 | |
parent | 8d24c42261c17d18ce723df5a65cc9d1e8dc3a9d (diff) |
wide string: a few adjustments
-rw-r--r-- | src/lyrics.cpp | 2 | ||||
-rw-r--r-- | src/utility/wide_string.cpp | 10 | ||||
-rw-r--r-- | src/utility/wide_string.h | 7 |
3 files changed, 9 insertions, 10 deletions
diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 2d0450ff..3677a72e 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -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()) ); diff --git a/src/utility/wide_string.cpp b/src/utility/wide_string.cpp index ee1193ca..3f214558 100644 --- a/src/utility/wide_string.cpp +++ b/src/utility/wide_string.cpp @@ -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); diff --git a/src/utility/wide_string.h b/src/utility/wide_string.h index 774aeb15..076dfe95 100644 --- a/src/utility/wide_string.h +++ b/src/utility/wide_string.h @@ -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)); |