From 28589c4b3b8bf2a59be5a0047b7bad67b6dcdfc0 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 23 Nov 2025 19:56:12 +0300 Subject: [PATCH] fix utf8 support --- src/logic/scripting/lua/libs/libutf8.cpp | 4 ++-- src/util/stringutil.cpp | 22 +++++++++++----------- src/util/stringutil.hpp | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/logic/scripting/lua/libs/libutf8.cpp b/src/logic/scripting/lua/libs/libutf8.cpp index eb4c1065..15fc54e9 100644 --- a/src/logic/scripting/lua/libs/libutf8.cpp +++ b/src/logic/scripting/lua/libs/libutf8.cpp @@ -89,8 +89,8 @@ static int l_escape(lua::State* L) { } static int l_escape_xml(lua::State* L) { - auto string = lua::require_lstring(L, 1); - return lua::pushstring(L, util::escape_xml(string)); + auto string = lua::require_wstring(L, 1); + return lua::pushwstring(L, util::escape_xml(string)); } const luaL_Reg utf8lib[] = { diff --git a/src/util/stringutil.cpp b/src/util/stringutil.cpp index 01a32c9d..e1a99f9e 100644 --- a/src/util/stringutil.cpp +++ b/src/util/stringutil.cpp @@ -60,24 +60,24 @@ std::string util::escape(std::string_view s, bool escapeUnicode) { return ss.str(); } -std::string util::escape_xml(std::string_view s) { - std::stringstream ss; - for (char c : s) { +std::wstring util::escape_xml(std::wstring_view s) { + std::wstringstream ss; + for (wchar_t c : s) { switch (c) { - case '&': - ss << "&"; + case L'&': + ss << L"&"; break; - case '<': - ss << "<"; + case L'<': + ss << L"<"; break; - case '>': - ss << ">"; + case L'>': + ss << L">"; break; case '"': - ss << """; + ss << L"""; break; case '\'': - ss << "'"; + ss << L"'"; break; default: ss << c; diff --git a/src/util/stringutil.hpp b/src/util/stringutil.hpp index b005380a..c26f0274 100644 --- a/src/util/stringutil.hpp +++ b/src/util/stringutil.hpp @@ -11,7 +11,7 @@ namespace util { std::string escape(std::string_view s, bool escapeUnicode=true); /// @brief Escape all special XML characters - std::string escape_xml(std::string_view s); + std::wstring escape_xml(std::wstring_view s); /// @brief Function used for error messages std::string quote(const std::string& s);