forked from Dependencies/lua-json
Fixed codepoint_to_utf8()'s string.char usage for Lua5.3
Lua5.3 requires that string.char's arguments are integers (<=5.2 and JIT do not)master
parent
b51b7a53f7
commit
3cfffd299e
9
json.lua
9
json.lua
|
@ -163,15 +163,16 @@ end
|
||||||
|
|
||||||
local function codepoint_to_utf8(n)
|
local function codepoint_to_utf8(n)
|
||||||
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
||||||
|
local f = math.floor
|
||||||
if n <= 0x7f then
|
if n <= 0x7f then
|
||||||
return string.char(n)
|
return string.char(n)
|
||||||
elseif n <= 0x7ff then
|
elseif n <= 0x7ff then
|
||||||
return string.char(n / 64 + 192, n % 64 + 128)
|
return string.char(f(n / 64) + 192, n % 64 + 128)
|
||||||
elseif n <= 0xffff then
|
elseif n <= 0xffff then
|
||||||
return string.char(n / 4096 + 224, n % 4096 / 64 + 128, n % 64 + 128)
|
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
|
||||||
elseif n <= 0x10ffff then
|
elseif n <= 0x10ffff then
|
||||||
return string.char(n / 262144 + 240, n % 262144 / 4096 + 128,
|
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
|
||||||
n % 4096 / 64 + 128, n % 64 + 128)
|
f(n % 4096 / 64) + 128, n % 64 + 128)
|
||||||
end
|
end
|
||||||
error( string.format("invalid unicode codepoint '%x'", n) )
|
error( string.format("invalid unicode codepoint '%x'", n) )
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue