mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
alternative implementation to fix problem with Lua 5.1
This commit is contained in:
parent
2a5205e53c
commit
ef3ae6b2d7
21
inspect.lua
21
inspect.lua
@ -41,17 +41,22 @@ local function smartQuote(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local controlCharsTranslation = {
|
local controlCharsTranslation = {
|
||||||
["\\7"] = "\\a", ["\\007"] = "\\a",
|
["\a"] = "\\a", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n",
|
||||||
["\\8"] = "\\b", ["\\008"] = "\\b",
|
["\r"] = "\\r", ["\t"] = "\\t", ["\v"] = "\\v"
|
||||||
["\\12"] = "\\f", ["\\012"] = "\\f",
|
|
||||||
["\\13"] = "\\r", ["\\013"] = "\\r",
|
|
||||||
["\\9"] = "\\t", ["\\009"] = "\\t",
|
|
||||||
["\\11"] = "\\v", ["\\011"] = "\\v",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local controlCharsTranslationBeforeDigit = {}
|
||||||
|
|
||||||
|
for i=0, 31 do
|
||||||
|
local ch = string.char(i)
|
||||||
|
if not controlCharsTranslation[ch] then
|
||||||
|
controlCharsTranslation[ch] = "\\"..i
|
||||||
|
controlCharsTranslationBeforeDigit[ch] = string.format("\\%03d",i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function escape(str)
|
local function escape(str)
|
||||||
local f = string.format("%q", str)
|
local result = str:gsub("\\", "\\\\"):gsub("(%c)%f[0-9]", controlCharsTranslationBeforeDigit):gsub("(%c)", controlCharsTranslation)
|
||||||
local result = f:gsub("\\%d%d?%d?", controlCharsTranslation):gsub("\\\n", "\\n"):gsub('\\"', '"'):sub(2,-2)
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user