From 3c1ea127c553ba28904aa15816a2d9bd115ed9dd Mon Sep 17 00:00:00 2001 From: Stefan Erben Date: Tue, 4 Aug 2009 11:47:42 +0200 Subject: utils:: strwidth() returned npos, if a char in the string is non-printable (see wcswidth(3)). --- src/utils.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/utils.cpp') diff --git a/src/utils.cpp b/src/utils.cpp index c72a3fbd..6c85d5d1 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -602,7 +602,10 @@ std::vector > utils::partition_indexes(uns size_t utils::strwidth(const std::string& str) { std::wstring wstr = str2wstr(str); - return wcswidth(wstr.c_str(), wstr.length()); + int width = wcswidth(wstr.c_str(), wstr.length()); + if (width < 1) // a non-printable character found? + return wstr.length(); // return a sane width (which might be larger than necessary) + return width; // exact width } std::string utils::join(const std::vector& strings, const std::string& separator) { -- cgit v1.2.3