From 77704232b2044ec3af61d825c4237d33fc09c14f Mon Sep 17 00:00:00 2001 From: goerch Date: Mon, 18 Sep 2023 20:55:07 +0200 Subject: [PATCH] Fix debug assertion failure --- unicode.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unicode.h b/unicode.h index 23d1cb869..33488a690 100644 --- a/unicode.h +++ b/unicode.h @@ -250,7 +250,6 @@ static std::string codepoint_to_utf8(uint32_t cp) { static std::string codepoints_to_utf8(const std::vector& cps) { std::string result; - size_t offset = 0; for (auto i = 0; i < cps.size(); ++i) { result.append(codepoint_to_utf8(cps[i])); } @@ -316,7 +315,6 @@ static std::vector codepoint_to_utf16(uint32_t cp) { static std::vector codepoints_to_utf16(const std::vector& cps) { std::vector result; - size_t offset = 0; for (auto i = 0; i < cps.size(); ++i) { auto temp = codepoint_to_utf16(cps[i]); result.insert(result.end(), temp.begin(), temp.end()); @@ -349,6 +347,7 @@ static std::vector codepoints_from_utf16(const std::vector& return result; } +#define CODEPOINT_TYPE_UNIDENTIFIED 0 #define CODEPOINT_TYPE_DIGIT 1 #define CODEPOINT_TYPE_LETTER 2 #define CODEPOINT_TYPE_WHITESPACE 3 @@ -393,6 +392,8 @@ static int codepoint_type(uint32_t cp) { } static int codepoint_type(std::string utf8) { + if (utf8.length() == 0) + return CODEPOINT_TYPE_UNIDENTIFIED; size_t offset = 0; return codepoint_type(codepoint_from_utf8(utf8, offset)); }