From 7abbf279c5d1e3b564128584d8dd6a4cdf165c8a Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 29 Sep 2014 12:16:36 +0200 Subject: [PATCH] wide char: remove assert in wideLength and count length all chars separately --- src/utility/wide_string.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utility/wide_string.cpp b/src/utility/wide_string.cpp index 3370256..4453ec5 100644 --- a/src/utility/wide_string.cpp +++ b/src/utility/wide_string.cpp @@ -34,9 +34,16 @@ std::wstring ToWString(std::string s) size_t wideLength(const std::wstring &ws) { - int len = wcswidth(ws.c_str(), -1); - assert(len >= 0); - return len; + size_t result = 0; + for (const auto &wc : ws) + { + int len = wcwidth(wc); + if (len < 0) + ++result; + else + result += len; + } + return result; } void wideCut(std::wstring &ws, size_t max_length) -- 2.11.4.GIT