From 2ee21af12eaf85d32d36570c8189c581f59fb3c9 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sat, 17 Jan 2026 09:07:23 +0300 Subject: add locale handling for string case conversion on non-Windows platforms --- core/src/xmake/string/case.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/xmake/string/case.c b/core/src/xmake/string/case.c index 762110bd9..777148623 100644 --- a/core/src/xmake/string/case.c +++ b/core/src/xmake/string/case.c @@ -30,6 +30,7 @@ */ #include "prefix.h" #include +#include "tbox/libc/stdlib/setlocale.h" #ifdef TB_CONFIG_OS_WINDOWS # include #endif @@ -65,10 +66,23 @@ static tb_int_t xm_string_case(lua_State* lua, tb_bool_t lower) { if (lower) CharLowerBuffW((LPWSTR)wb, (DWORD)wn); else CharUpperBuffW((LPWSTR)wb, (DWORD)wn); #else + // attempt to set utf-8 locale for towlower/towupper + // we need this on some platforms like DragonFly BSD, because towlower/towupper depends on the current locale +#ifdef TB_CONFIG_LIBC_HAVE_SETLOCALE + tb_char_t* old_locale = tb_strdup(setlocale(LC_ALL, tb_null)); + tb_setlocale(); +#endif tb_size_t i = 0; for (i = 0; i < wn; i++) { wb[i] = lower? towlower(wb[i]) : towupper(wb[i]); } + +#ifdef TB_CONFIG_LIBC_HAVE_SETLOCALE + if (old_locale) { + setlocale(LC_ALL, old_locale); + tb_free(old_locale); + } +#endif #endif // convert to utf8 -- cgit v1.3.1