summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-18 05:00:52 +0300
committerSaikari <[email protected]>2026-01-18 05:00:52 +0300
commit3946b4ea50870d19e66df992520808eb74d1b1f7 (patch)
tree6febf569a2d6cf87152a7714aa65f04ea6948efb
parentb11183e1222db0026c70d85e3582c4b216a49962 (diff)
test commit
m---------core/src/tbox/tbox0
-rw-r--r--core/src/xmake/string/case.c98
2 files changed, 4 insertions, 94 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject dbe1674a47dbf15e6f7b493acc848841d4f8d2b
+Subproject 73028bf9165aece5ec9863124fda67500a005e2
diff --git a/core/src/xmake/string/case.c b/core/src/xmake/string/case.c
index ea6917b50..6dd372d16 100644
--- a/core/src/xmake/string/case.c
+++ b/core/src/xmake/string/case.c
@@ -29,55 +29,13 @@
* includes
*/
#include "prefix.h"
-#include <ctype.h>
-#include <wctype.h>
-#include <locale.h>
-#include "tbox/platform/spinlock.h"
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
-# include <xlocale.h>
-#endif
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * macros
- */
-
-/* Platforms that lack thread-safe uselocale() and must use setlocale() */
-#if defined(TB_CONFIG_OS_WINDOWS) || defined(__NetBSD__)
-# include "tbox/libc/stdlib/setlocale.h"
-# define XM_USE_SETLOCALE
-#endif
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * globals
- */
-
-#ifdef XM_USE_SETLOCALE
-/*
- * setlocale() is not thread-safe, so we protect it with a spinlock.
- */
-static tb_spinlock_t g_locale_lock = TB_SPINLOCK_INIT;
-#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/
-/* Perform wide character case conversion in-place
- */
-static tb_void_t xm_wchar_convert_case(tb_wchar_t* wb, tb_size_t wn, tb_bool_t lower) {
- tb_size_t i;
- for (i = 0; i < wn; i++) {
- tb_wchar_t wc = wb[i];
- if (lower) {
- if (!iswlower(wc)) wb[i] = towlower(wc);
- } else {
- if (!iswupper(wc)) wb[i] = towupper(wc);
- }
- }
-}
-
/* Unicode case conversion using wide characters
* Returns tb_true on success, tb_false on failure
*/
@@ -98,56 +56,8 @@ static tb_bool_t xm_string_case_unicode(lua_State* lua, tb_char_t const* str, tb
}
// Perform Case Conversion
-#ifdef XM_USE_SETLOCALE
- // Windows and NetBSD: Use setlocale (protected by spinlock)
- tb_spinlock_enter(&g_locale_lock);
-
- // Save current locale
- char* saved_locale = tb_null;
- char const* current_locale = setlocale(LC_CTYPE, tb_null);
-
- if (current_locale) {
- tb_size_t len = tb_strlen(current_locale);
- saved_locale = (char*)tb_malloc_bytes(len + 1);
- if (saved_locale) {
- tb_memcpy(saved_locale, current_locale, len + 1);
- }
- }
-
- // Force UTF-8 locale
- tb_setlocale();
-
- // Convert case
- xm_wchar_convert_case(wb, wn, lower);
-
- // Restore original locale
- if (saved_locale) {
- setlocale(LC_CTYPE, saved_locale);
- tb_free(saved_locale);
- }
-
- tb_spinlock_leave(&g_locale_lock);
-
-#else
- // POSIX Thread-Safe Implementation (Linux/macOS/FreeBSD/DragonFly)
- locale_t new_loc = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", (locale_t)0);
- if (!new_loc) {
- new_loc = newlocale(LC_CTYPE_MASK, "C.UTF-8", (locale_t)0);
- }
- if (!new_loc) {
- new_loc = newlocale(LC_CTYPE_MASK, "UTF-8", (locale_t)0);
- }
-
- if (new_loc) {
- locale_t old_loc = uselocale(new_loc);
- xm_wchar_convert_case(wb, wn, lower);
- uselocale(old_loc);
- freelocale(new_loc);
- } else {
- // Fallback: try without locale change
- xm_wchar_convert_case(wb, wn, lower);
- }
-#endif
+ if (lower) tb_wcslwr(wb);
+ else tb_wcsupr(wb);
// Convert Wide Char back to UTF-8
tb_size_t un = (wn + 1) * 4;
@@ -196,9 +106,9 @@ static tb_int_t xm_string_case(lua_State* lua, tb_bool_t lower) {
// convert ascii
tb_byte_t c = (tb_byte_t)str[i];
if (lower) {
- buf[i] = (tb_char_t)(isupper(c) ? tolower(c) : c);
+ buf[i] = (tb_char_t)tb_tolower(c);
} else {
- buf[i] = (tb_char_t)(islower(c) ? toupper(c) : c);
+ buf[i] = (tb_char_t)tb_toupper(c);
}
}