From a8387de735ee929fe66a4bdb7e3514004b580618 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sat, 6 Feb 2021 23:54:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96json=E5=BA=93=E7=9A=84utf8?= =?UTF-8?q?=E8=BD=AC=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/toolfunc.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index 581e8582..b41a25c3 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -332,17 +332,15 @@ do--json local function codepoint_to_utf8(n) -- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa - local f = math.floor + local f = bit.rshift if n <= 0x7f then return char(n) elseif n <= 0x7ff then - return char(f(n / 64) + 192, n % 64 + 128) + return char(f(n, 6) + 192, n % 64 + 128) elseif n <= 0xffff then - return char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, - n % 64 + 128) + return char(f(n, 12) + 224, f(n % 4096, 6) + 128, n % 64 + 128) elseif n <= 0x10ffff then - return char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128, - f(n % 4096 / 64) + 128, n % 64 + 128) + return char(f(n, 18) + 240, f(n % 262144, 12) + 128, f(n % 4096, 6) + 128, n % 64 + 128) end error(string.format("invalid unicode codepoint '%x'", n)) end