summaryrefslogtreecommitdiff
path: root/core/src/xmake/string
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-17 04:00:16 +0300
committerSaikari <[email protected]>2026-01-17 04:00:16 +0300
commitb5f93e02d0e28b694fe452ef868620fffbd7872b (patch)
treedbbfd75399ac3f97ffe05835e29bed2cb2527d23 /core/src/xmake/string
parentd83c306af108ef93fc08b9db1c42469c7f14372f (diff)
try use setlocale
Diffstat (limited to 'core/src/xmake/string')
-rw-r--r--core/src/xmake/string/case.c22
1 files changed, 16 insertions, 6 deletions
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 <windows.h>
#endif
+#if defined(TB_CONFIG_LIBC_HAVE_SETLOCALE)
+# include <locale.h>
+#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++;
}