1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-16 23:38:08 +11:00
Zorya-NEO/utils/mkluastring.lua

41 lines
845 B
Lua
Raw Normal View History

2020-01-09 15:01:35 +11:00
local f = io.stdin:read("*a")
--[[io.stdout:write("\"")
for i=1, #f do
if (f:byte(i) < 32 or f:byte(i) > 126) then
io.stdout:write(string.format("\\x%.2x",f:byte(i)))
elseif (f:sub(i,i) == "\\") then
io.stdout:write("\\\\")
elseif (f:sub(i,i) == "\"") then
io.stdout:write("\\\"")
elseif (f:sub(i,i) == "\n") then
io.stdout:write("\\n")
elseif (f:sub(i,i) == "\r") then
io.stdout:write("\\r")
else
io.stdout:write(f:sub(i,i))
end
end
io.stdout:write("\"\n")]]
2020-01-15 12:07:27 +11:00
local rep = {
["\0"] = "\\0",
["\\"] = "\\\\",
["\""] = "\\\"",
["\n"] = "\\n",
["\r"] = "\\r",
["\t"] = "\\t",
[" "] = "\x20"
}
2020-01-09 15:01:35 +11:00
local function mkstr(d)
local dat = "\""
for i=1, #f do
2020-01-15 12:07:27 +11:00
if (rep[d:sub(i, i)]) then
dat = dat .. rep[d:sub(i, i)]
2020-01-09 15:01:35 +11:00
else
dat = dat .. (d:sub(i,i))
end
end
dat = dat .. ("\"")
return dat
end
io.stdout:write(mkstr(f))