lua-parser
lua-parser copied to clipboard
add non-UTF-8 escaping to toLua
add a config for toLua for non-UTF-8 escape to hex.
-- lua-parser internal function
function escape(s)
if checkutf8 and utf8.len(s) == nil then
local r = ""
for i=1, #s do
r = r .. string.format("\\x%02X", string.byte(s, i))
end
return r
else
return defaultEscape(s)
end
end
--
toLua()
or allow custom escape
function escape(s, default)
if utf8.len(s) == nil then
local r = ""
for i=1, #s do
r = r .. string.format("\\x%02X", string.byte(s, i))
end
return r
else
return default(s)
end
end
toLua({escape=escape})
or custom function return nil for default
function escape(s)
if utf8.len(s) == nil then
local r = ""
for i=1, #s do
r = r .. string.format("\\x%02X", string.byte(s, i))
end
return r
else
return nil
end
end
toLua({escape=escape})