From 3ed3b5a076975e3886f027f88b23342faee64f90 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 25 Aug 2024 13:56:01 +1000 Subject: [PATCH] StringUtil: Use unicode replacement character in DecodeUTF8() --- src/common/string_util.cpp | 2 +- src/common/string_util.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 7b8440053..9f307b5ae 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -388,7 +388,7 @@ size_t StringUtil::DecodeUTF8(const void* bytes, size_t length, char32_t* ch) } invalid: - *ch = 0xFFFFFFFFu; + *ch = UNICODE_REPLACEMENT_CHARACTER; // unicode replacement character return 1; } diff --git a/src/common/string_util.h b/src/common/string_util.h index 388bd70df..6656ed9ed 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -263,6 +263,9 @@ void ReplaceAll(std::string* subject, const char search, const char replacement) /// Parses an assignment string (Key = Value) into its two components. bool ParseAssignmentString(const std::string_view str, std::string_view* key, std::string_view* value); +/// Unicode replacement character. +static constexpr char32_t UNICODE_REPLACEMENT_CHARACTER = 0xFFFD; + /// Appends a UTF-16/UTF-32 codepoint to a UTF-8 string. void EncodeAndAppendUTF8(std::string& s, char32_t ch);