diff options
| author | Saikari <[email protected]> | 2026-01-17 04:20:37 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-01-17 04:20:37 +0300 |
| commit | 4fcbf73e87bfd1910ed87a43ad000ef1d128a395 (patch) | |
| tree | b4a44d6314d59ab85c89429398964890538e1d99 /core/src/xmake/string | |
| parent | e7ab18bef196961d784d0e98746bd41c3453a3ad (diff) | |
test macos
Diffstat (limited to 'core/src/xmake/string')
| -rw-r--r-- | core/src/xmake/string/case.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/src/xmake/string/case.c b/core/src/xmake/string/case.c index 1c2341cb1..81cdeae1c 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_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) +# include <CoreFoundation/CoreFoundation.h> +#endif #include "tbox/libc/stdlib/setlocale.h" /* ////////////////////////////////////////////////////////////////////////////////////// @@ -58,6 +61,34 @@ static tb_int_t xm_string_case(lua_State* lua, tb_bool_t lower) { return 1; } +#if defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) + CFStringRef cf_str = CFStringCreateWithBytes(kCFAllocatorDefault, (tb_byte_t const*)str, size, kCFStringEncodingUTF8, false); + if (cf_str) { + CFMutableStringRef cf_mutable = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, cf_str); + CFRelease(cf_str); + if (cf_mutable) { + if (lower) CFStringLowercase(cf_mutable, NULL); + else CFStringUppercase(cf_mutable, NULL); + + CFIndex len = CFStringGetLength(cf_mutable); + CFIndex max_size = CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1; + tb_char_t* buffer = tb_malloc_bytes(max_size); + if (buffer) { + if (CFStringGetCString(cf_mutable, buffer, max_size, kCFStringEncodingUTF8)) { + lua_pushstring(lua, buffer); + } else { + lua_pushnil(lua); + } + tb_free(buffer); + } else { + lua_pushnil(lua); + } + CFRelease(cf_mutable); + return 1; + } + } +#endif + // find charsets xm_charset_entry_ref_t fcharset = xm_charset_find_by_name("utf8"); #if defined(TB_CONFIG_OS_WINDOWS) |
