diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-08-23 12:42:37 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-08-23 12:42:37 +0900 |
| commit | 07d294425a98ee5d1e22d03e2b24ae2c76e487c0 (patch) | |
| tree | a6818f0d64438c5fdb88b00a35d944f80c056213 /mac/.config/mpv/script-modules/utf8/primitives/native.lua | |
| parent | 6fc28cdb3529ca8ee864cb5c41674cb0a4af72a1 (diff) | |
updates
Diffstat (limited to 'mac/.config/mpv/script-modules/utf8/primitives/native.lua')
| -rw-r--r-- | mac/.config/mpv/script-modules/utf8/primitives/native.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/mac/.config/mpv/script-modules/utf8/primitives/native.lua b/mac/.config/mpv/script-modules/utf8/primitives/native.lua new file mode 100644 index 0000000..c9aca54 --- /dev/null +++ b/mac/.config/mpv/script-modules/utf8/primitives/native.lua @@ -0,0 +1,57 @@ +return function(utf8) + +local ffi = require("ffi") +if ffi.os == "Windows" then + os.setlocale(utf8.config.locale or "english_us.65001", "ctype") + ffi.cdef[[ + short towupper(short c); + short towlower(short c); + ]] +else + os.setlocale(utf8.config.locale or "C.UTF-8", "ctype") + ffi.cdef[[ + int towupper(int c); + int towlower(int c); + ]] +end + +utf8:require "primitives.dummy" + +if not utf8.config.conversion.uc_lc then + function utf8.lower(str) + local bs = 1 + local nbs + local bytes = utf8.raw.len(str) + local res = {} + + while bs <= bytes do + nbs = utf8.next(str, bs) + local cp = utf8.unicode(str, bs, nbs) + res[#res + 1] = ffi.C.towlower(cp) + bs = nbs + end + + return utf8.char(utf8.config.unpack(res)) + end +end + +if not utf8.config.conversion.lc_uc then + function utf8.upper(str) + local bs = 1 + local nbs + local bytes = utf8.raw.len(str) + local res = {} + + while bs <= bytes do + nbs = utf8.next(str, bs) + local cp = utf8.unicode(str, bs, nbs) + res[#res + 1] = ffi.C.towupper(cp) + bs = nbs + end + + return utf8.char(utf8.config.unpack(res)) + end +end + +return utf8 +end |
