You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
406 B
Lua
16 lines
406 B
Lua
local byte, format = string.byte, string.format
|
|
|
|
local builtins = {
|
|
["\a"] = "\\a", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r",
|
|
["\t"] = "\\t", ["\v"] = "\\v", ["\\"] = "\\\\", ['"'] = '\\"',
|
|
}
|
|
|
|
function string:escape()
|
|
local repl = self:gsub("[\"%\\%c\x80-\xff]", function(m)
|
|
return builtins[m] or format("\\x%02x", byte(m))
|
|
end)
|
|
return '"'..repl..'"'
|
|
end
|
|
|
|
return string
|