From b5f93e02d0e28b694fe452ef868620fffbd7872b Mon Sep 17 00:00:00 2001 From: Saikari Date: Sat, 17 Jan 2026 04:00:16 +0300 Subject: try use setlocale --- core/src/xmake/string/case.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/string/case.c b/core/src/xmake/string/case.c index 858d4be08..ee20b4a9b 100644 --- a/core/src/xmake/string/case.c +++ b/core/src/xmake/string/case.c @@ -34,6 +34,9 @@ #if defined(TB_CONFIG_OS_WINDOWS) # include #endif +#if defined(TB_CONFIG_LIBC_HAVE_SETLOCALE) +# include +#endif /* ////////////////////////////////////////////////////////////////////////////////////// * helper @@ -43,6 +46,11 @@ static tb_int_t xm_string_case(lua_State* lua, tb_bool_t lower) { // check tb_assert_and_check_return_val(lua, 0); +#if defined(TB_CONFIG_LIBC_HAVE_SETLOCALE) + // set locale to utf8 + setlocale(LC_ALL, ""); +#endif + // get the string size_t size = 0; tb_char_t const* str = luaL_checklstring(lua, 1, &size); @@ -79,12 +87,14 @@ static tb_int_t xm_string_case(lua_State* lua, tb_bool_t lower) { tb_uint32_t* p = (tb_uint32_t*)dst_data; tb_size_t n = (tb_size_t)dst_size / 4; while (n--) { - if (lower) { - if (iswupper((wint_t)*p)) - *p = towlower((wint_t)*p); - } else { - if (iswlower((wint_t)*p)) - *p = towupper((wint_t)*p); + if (*p < 0x10000) { + if (lower) { + if (iswupper((wint_t)*p)) + *p = towlower((wint_t)*p); + } else { + if (iswlower((wint_t)*p)) + *p = towupper((wint_t)*p); + } } p++; } -- cgit v1.3.1