From 56d7091f6eab8a4fd6c6d4b57ee600ba0c63f962 Mon Sep 17 00:00:00 2001 From: staphen Date: Tue, 31 May 2022 12:53:58 -0400 Subject: [PATCH] Fix error that produces broken character at end of UTF8 string --- Source/utils/utf8.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/utils/utf8.cpp b/Source/utils/utf8.cpp index 66f98e5e1..3e08158bd 100644 --- a/Source/utils/utf8.cpp +++ b/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; }