summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-17 07:37:08 +0300
committerSaikari <[email protected]>2026-01-17 07:37:08 +0300
commit5f03e0684c22482c361586d64ca0e044a2f14f2b (patch)
tree84636330f2c2e62be453279a3bc9bf1a4bfa6318 /core/src
parent5e34b6a2e2f5f98b80481d864e84d5c016d6a7ab (diff)
cls
Diffstat (limited to 'core/src')
-rw-r--r--core/src/utf8proc/xmake.lua5
-rw-r--r--core/src/utf8proc/xmake.sh9
-rw-r--r--core/src/xmake/string/case.c49
-rw-r--r--core/src/xmake/xmake.lua2
-rwxr-xr-xcore/src/xmake/xmake.sh2
5 files changed, 30 insertions, 37 deletions
diff --git a/core/src/utf8proc/xmake.lua b/core/src/utf8proc/xmake.lua
deleted file mode 100644
index 2c57f0004..000000000
--- a/core/src/utf8proc/xmake.lua
+++ /dev/null
@@ -1,5 +0,0 @@
-target("utf8proc")
- set_kind("static")
- add_defines("UTF8PROC_STATIC", {public = true})
- add_includedirs("utf8proc", {public = true})
- add_files("utf8proc/utf8proc.c")
diff --git a/core/src/utf8proc/xmake.sh b/core/src/utf8proc/xmake.sh
deleted file mode 100644
index 0002eafab..000000000
--- a/core/src/utf8proc/xmake.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-target "utf8proc"
- set_kind "static"
- set_default false
- add_defines "UTF8PROC_STATIC" "{public}"
- add_includedirs "utf8proc" "{public}"
- add_files "utf8proc/utf8proc.c"
-
diff --git a/core/src/xmake/string/case.c b/core/src/xmake/string/case.c
index eeb459959..5fa4c5786 100644
--- a/core/src/xmake/string/case.c
+++ b/core/src/xmake/string/case.c
@@ -29,7 +29,7 @@
* includes
*/
#include "prefix.h"
-#include <utf8proc.h>
+#include <wctype.h>
/* //////////////////////////////////////////////////////////////////////////////////////
* helper
@@ -50,28 +50,37 @@ static tb_int_t xm_string_case(lua_State* lua, tb_bool_t lower) {
return 1;
}
- // convert string
- tb_size_t dst_maxn = (tb_size_t)(size + 1) * 4;
- tb_byte_t* dst_data = tb_malloc_bytes(dst_maxn);
- if (dst_data) {
- tb_byte_t* p = dst_data;
- tb_byte_t const* s = (tb_byte_t const*)str;
- tb_byte_t const* e = s + size;
- while (s < e) {
- utf8proc_int32_t codepoint;
- utf8proc_ssize_t len = utf8proc_iterate((utf8proc_uint8_t const*)s, e - s, &codepoint);
- if (len > 0) {
- if (lower) codepoint = utf8proc_tolower(codepoint);
- else codepoint = utf8proc_toupper(codepoint);
- utf8proc_ssize_t wlen = utf8proc_encode_char(codepoint, (utf8proc_uint8_t*)p);
- if (wlen > 0) p += wlen;
- s += len;
+ // convert to wchar
+ tb_size_t wn = size + 1;
+ tb_wchar_t* wb = tb_nalloc_type(wn, tb_wchar_t);
+ if (wb) {
+ wn = tb_mbstowcs(wb, str, wn);
+ if (wn != -1) {
+
+ // to case
+ tb_size_t i = 0;
+ for (i = 0; i < wn; i++) {
+ wb[i] = lower? towlower(wb[i]) : towupper(wb[i]);
+ }
+
+ // convert to utf8
+ tb_size_t un = (wn + 1) * 4;
+ tb_char_t* ub = (tb_char_t*)tb_malloc_bytes(un);
+ if (ub) {
+ tb_size_t n = tb_wcstombs(ub, wb, un);
+ if (n != -1) {
+ lua_pushlstring(lua, ub, n);
+ } else {
+ lua_pushnil(lua);
+ }
+ tb_free(ub);
} else {
- *p++ = *s++;
+ lua_pushnil(lua);
}
+ } else {
+ lua_pushnil(lua);
}
- lua_pushlstring(lua, (tb_char_t const*)dst_data, p - dst_data);
- tb_free(dst_data);
+ tb_free(wb);
} else {
lua_pushnil(lua);
}
diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua
index eb3b3eeb6..90f761b30 100644
--- a/core/src/xmake/xmake.lua
+++ b/core/src/xmake/xmake.lua
@@ -20,8 +20,6 @@ target("xmake")
add_deps("pdcurses")
end
- add_deps("utf8proc")
-
-- add definitions
add_defines("__tb_prefix__=\"xmake\"")
if is_mode("debug") then
diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh
index 11f33ab25..291001306 100755
--- a/core/src/xmake/xmake.sh
+++ b/core/src/xmake/xmake.sh
@@ -22,7 +22,7 @@ target "xmake"
fi
fi
else
- local libs="lua_cjson lz4 sv tbox utf8proc"
+ local libs="lua_cjson lz4 sv tbox"
for lib in $libs; do
add_deps "$lib"
done