From 30dc02a6aec640e966bb8f2008c2214b63ceeedc Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 4 May 2026 19:20:09 +0300 Subject: [PATCH] update stringutil locale choice --- src/util/stringutil.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/util/stringutil.cpp b/src/util/stringutil.cpp index f97eed83e..55529a398 100644 --- a/src/util/stringutil.cpp +++ b/src/util/stringutil.cpp @@ -7,7 +7,25 @@ #include #include -static std::locale locale("en_US.UTF-8"); +static std::locale get_utf8_locale() { + std::vector candidates = { + "C.UTF-8", + "en_US.UTF-8", + "en_US.utf8", + ".UTF8", + }; + + for (const auto& name : candidates) { + try { + return std::locale(name); + } catch (const std::runtime_error&) { + continue; + } + } + return std::locale::classic(); +} + +static std::locale locale = get_utf8_locale(); std::string util::escape(std::string_view s, bool escapeUnicode) { std::stringstream ss;