removed use of string.quote("%q", str)

This commit is contained in:
Kodi Arfer 2014-01-07 10:57:42 -05:00
parent 0303fec453
commit fbb524a813

View File

@ -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