diff --git a/src/utf8.cpp b/src/utf8.cpp index 129232e50..881b77ce0 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -188,10 +188,21 @@ unsigned int utf8_length (const std::string& str) unsigned int utf8_width (const std::string& str) { unsigned int length = 0; + int l; std::string::size_type i = 0; unsigned int c; while ((c = utf8_next_char (str, i))) - length += mk_wcwidth (c); + { + l = mk_wcwidth (c); + // Control characters, and more especially newline characters, make + // mk_wcwidth() return -1. Ignore that, thereby "adding zero" to length. + // Since control characters are not displayed in reports, this is a valid + // choice. + if (l != -1) + { + length += l; + } + } return length; }