mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
removed use of string.quote("%q", str)
This commit is contained in:
parent
0303fec453
commit
fbb524a813
@ -31,10 +31,10 @@ local inspect ={
|
|||||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
||||||
-- Otherwise, it returns a regular quoted string
|
-- Otherwise, it returns a regular quoted string
|
||||||
local function smartQuote(str)
|
local function smartQuote(str)
|
||||||
if string.match( string.gsub(str,"[^'\"]",""), '^"+$' ) then
|
if str:match('"') and not str:match("'") then
|
||||||
return "'" .. str .. "'"
|
return "'" .. str .. "'"
|
||||||
end
|
end
|
||||||
return string.format("%q", str ):gsub("\\\n", "\n")
|
return '"' .. str:gsub('"', '\\"') .. '"'
|
||||||
end
|
end
|
||||||
|
|
||||||
local controlCharsTranslation = {
|
local controlCharsTranslation = {
|
||||||
@ -45,7 +45,7 @@ local controlCharsTranslation = {
|
|||||||
local function escapeChar(c) return controlCharsTranslation[c] end
|
local function escapeChar(c) return controlCharsTranslation[c] end
|
||||||
|
|
||||||
local function escape(str)
|
local function escape(str)
|
||||||
local result = string.gsub(str, "(%c)", escapeChar)
|
local result = str:gsub("\\", "\\\\"):gsub("(%c)", escapeChar)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ function inspect.inspect(rootObject, options)
|
|||||||
local tv = type(v)
|
local tv = type(v)
|
||||||
|
|
||||||
if tv == 'string' then
|
if tv == 'string' then
|
||||||
puts(escape(smartQuote(v)))
|
puts(smartQuote(escape(v)))
|
||||||
elseif tv == 'number' or tv == 'boolean' or tv == 'nil' then
|
elseif tv == 'number' or tv == 'boolean' or tv == 'nil' then
|
||||||
puts(tostring(v))
|
puts(tostring(v))
|
||||||
elseif tv == 'table' then
|
elseif tv == 'table' then
|
||||||
|
Loading…
Reference in New Issue
Block a user