Browse Source

Fix error that produces broken character at end of UTF8 string

pull/4930/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
56d7091f6e
  1. 7
      Source/utils/utf8.cpp

7
Source/utils/utf8.cpp

@ -13,9 +13,10 @@ namespace {
string_view TruncateUtf8(string_view str, std::size_t len)
{
if (str.size() > len) {
str.remove_suffix(str.size() - len);
while (!str.empty() && !IsTrailUtf8CodeUnit(str.back()))
str.remove_suffix(1);
std::size_t truncIndex = len;
while (truncIndex > 0 && IsTrailUtf8CodeUnit(str[truncIndex]))
truncIndex--;
str.remove_suffix(str.size() - truncIndex);
}
return str;
}

Loading…
Cancel
Save