X7UOHDX4QI4PCXIAVAKCRSLZLEEWT7QU6U6RCBOX2IZKGTBXYFAQC local floor, huge = math.floor, math.hugelocal strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat =string.rep, string.gsub, string.sub, string.byte, string.char,string.find, string.len, string.format
local floor = math.floorlocal gsub, strsub, strbyte, strchar, strfind, strformat =string.gsub, string.sub, string.byte, string.char,string.find, string.format
local function unichar (value)if value < 0 thenreturn nilelseif value <= 0x007f thenreturn strchar (value)elseif value <= 0x07ff thenreturn strchar (0xc0 + floor(value/0x40),0x80 + (floor(value) % 0x40))elseif value <= 0xffff thenreturn strchar (0xe0 + floor(value/0x1000),0x80 + (floor(value/0x40) % 0x40),0x80 + (floor(value) % 0x40))elseif value <= 0x10ffff thenreturn strchar (0xf0 + floor(value/0x40000),0x80 + (floor(value/0x1000) % 0x40),0x80 + (floor(value/0x40) % 0x40),0x80 + (floor(value) % 0x40))elsereturn nilend
local function unichar(value)if value < 0 thenreturn nilelseif value <= 0x007f thenreturn strchar(value)elseif value <= 0x07ff thenreturn strchar(0xc0 + floor(value / 0x40),0x80 + (floor(value) % 0x40))elseif value <= 0xffff thenreturn strchar(0xe0 + floor(value / 0x1000),0x80 + (floor(value / 0x40) % 0x40),0x80 + (floor(value) % 0x40))elseif value <= 0x10ffff thenreturn strchar(0xf0 + floor(value / 0x40000),0x80 + (floor(value / 0x1000) % 0x40),0x80 + (floor(value / 0x40) % 0x40),0x80 + (floor(value) % 0x40))elsereturn nilend
local function escapeutf8 (uchar)local value = escapecodes[uchar]if value thenreturn valueendlocal a, b, c, d = strbyte (uchar, 1, 4)a, b, c, d = a or 0, b or 0, c or 0, d or 0if a <= 0x7f thenvalue = aelseif 0xc0 <= a and a <= 0xdf and b >= 0x80 thenvalue = (a - 0xc0) * 0x40 + b - 0x80elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 thenvalue = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 thenvalue = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80elsereturn ""endif value <= 0xffff thenreturn strformat ("\\u%.4x", value)elseif value <= 0x10ffff then-- encode as UTF-16 surrogate pairvalue = value - 0x10000local highsur, lowsur = 0xD800 + floor (value/0x400), 0xDC00 + (value % 0x400)return strformat ("\\u%.4x\\u%.4x", highsur, lowsur)elsereturn ""endendlocal function fsub (str, pattern, repl)-- gsub always builds a new string in a buffer, even when no match-- exists. First using find should be more efficient when most strings-- don't contain the pattern.if strfind (str, pattern) thenreturn gsub (str, pattern, repl)elsereturn strendendlocal function scanstring (str, pos)local lastpos = pos + 1local buffer, n = {}, 0while true dolocal nextpos = strfind (str, "[\"\\]", lastpos)if not nextpos thenreturn nil, pos
local function escapeutf8(uchar)local value = escapecodes[uchar]if value thenreturn value
if nextpos > lastpos thenn = n + 1buffer[n] = strsub (str, lastpos, nextpos - 1)
local a, b, c, d = strbyte(uchar, 1, 4)a, b, c, d = a or 0, b or 0, c or 0, d or 0local charif a <= 0x7f thenchar = aelseif 0xc0 <= a and a <= 0xdf and b >= 0x80 thenchar = (a - 0xc0) * 0x40 + b - 0x80elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 thenchar = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 thenchar = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80elsereturn ""
if strsub (str, nextpos, nextpos) == "\"" thenlastpos = nextpos + 1break
if char <= 0xffff thenreturn strformat("\\u%.4x", char)elseif char <= 0x10ffff then-- encode as UTF-16 surrogate pairchar = char - 0x10000local highsur, lowsur = 0xD800 + floor(char / 0x400), 0xDC00 + (char % 0x400)return strformat("\\u%.4x\\u%.4x", highsur, lowsur)
local escchar = strsub (str, nextpos + 1, nextpos + 1)local valueif escchar == "u" thenvalue = tonumber (strsub (str, nextpos + 2, nextpos + 5), 16)if value thenlocal value2if 0xD800 <= value and value <= 0xDBff then-- we have the high surrogate of UTF-16. Check if there is a-- low surrogate escaped nearby to combine them.if strsub (str, nextpos + 6, nextpos + 7) == "\\u" thenvalue2 = tonumber (strsub (str, nextpos + 8, nextpos + 11), 16)if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF thenvalue = (value - 0xD800) * 0x400 + (value2 - 0xDC00) + 0x10000elsevalue2 = nil -- in case it was out of range for a low surrogateend
return ""endendlocal function fsub(str, pattern, repl)-- gsub always builds a new string in a buffer, even when no match-- exists. First using find should be more efficient when most strings-- don't contain the pattern.if strfind(str, pattern) thenreturn gsub(str, pattern, repl)elsereturn strendendlocal function scanstring(str, pos)local lastpos = pos + 1local buffer, n = {}, 0while true dolocal nextpos = strfind(str, "[\"\\]", lastpos)if not nextpos thenreturn nil, posendif nextpos > lastpos thenn = n + 1buffer[n] = strsub(str, lastpos, nextpos - 1)endif strsub(str, nextpos, nextpos) == "\"" thenlastpos = nextpos + 1breakelselocal escchar = strsub(str, nextpos + 1, nextpos + 1)local valueif escchar == "u" thenvalue = tonumber(strsub(str, nextpos + 2, nextpos + 5), 16)if value thenlocal value2if 0xD800 <= value and value <= 0xDBff then-- we have the high surrogate of UTF-16. Check if there is a-- low surrogate escaped nearby to combine them.if strsub(str, nextpos + 6, nextpos + 7) == "\\u" thenvalue2 = tonumber(strsub(str, nextpos + 8, nextpos + 11), 16)if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF thenvalue = (value - 0xD800) * 0x400 + (value2 - 0xDC00) + 0x10000elsevalue2 = nil -- in case it was out of range for a low surrogateendendendvalue = value and unichar(value)if value thenif value2 thenlastpos = nextpos + 12elselastpos = nextpos + 6endendend
endif n == 1 thenreturn buffer[1], lastposelseif n > 1 thenreturn concat (buffer), lastposelsereturn "", lastposend
if n == 1 thenreturn buffer[1], lastposelseif n > 1 thenreturn concat(buffer), lastposelsereturn "", lastposend
local function quotestring (value)-- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-jsvalue = fsub (value, "[%z\1-\31\"\\\127]", escapeutf8)if strfind (value, "[\194\216\220\225\226\239]") thenvalue = fsub (value, "\194[\128-\159\173]", escapeutf8)value = fsub (value, "\216[\128-\132]", escapeutf8)value = fsub (value, "\220\143", escapeutf8)value = fsub (value, "\225\158[\180\181]", escapeutf8)value = fsub (value, "\226\128[\140-\143\168\175]", escapeutf8)value = fsub (value, "\226\129[\160-\175]", escapeutf8)value = fsub (value, "\239\187\191", escapeutf8)value = fsub (value, "\239\191[\176\191]", escapeutf8)endreturn "\"" .. value .. "\""
local function quotestring(value)-- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-jsvalue = fsub(value, "[%z\1-\31\"\\\127]", escapeutf8)if strfind(value, "[\194\216\220\225\226\239]") thenvalue = fsub(value, "\194[\128-\159\173]", escapeutf8)value = fsub(value, "\216[\128-\132]", escapeutf8)value = fsub(value, "\220\143", escapeutf8)value = fsub(value, "\225\158[\180\181]", escapeutf8)value = fsub(value, "\226\128[\140-\143\168\175]", escapeutf8)value = fsub(value, "\226\129[\160-\175]", escapeutf8)value = fsub(value, "\239\187\191", escapeutf8)value = fsub(value, "\239\191[\176\191]", escapeutf8)endreturn "\"" .. value .. "\""
local function json_decode(self, brat_string, pos)local result, new_pos = scanstring(brat_string._lua_string, pos)if result and result ~= "" thenreturn array:new(base_string:new(result), new_pos - 1)elsereturn object.__nullend
local function json_decode(_, brat_string, pos)local result, new_pos = scanstring(brat_string._lua_string, pos)if result and result ~= "" thenreturn array:new(base_string:new(result), new_pos - 1)elsereturn object.__nullend