small refactor

This commit is contained in:
kikito 2012-10-29 20:49:20 +01:00
parent 54ef1b0711
commit 282800b478

View File

@ -27,7 +27,7 @@ local function unescape(str)
end end
local function isIdentifier(str) local function isIdentifier(str)
return string.match( str, "^[_%a][_%a%d]*$" ) return type(str) == 'string' and str:match( "^[_%a][_%a%d]*$" )
end end
local function isArrayKey(k, length) local function isArrayKey(k, length)
@ -98,14 +98,6 @@ function Inspector:new(v, depth)
return inspector:putValue(v) return inspector:putValue(v)
end end
function Inspector:puts(...)
local args = {...}
for i=1, #args do
table.insert(self.buffer, tostring(args[i]))
end
return self
end
function Inspector:tabify() function Inspector:tabify()
self:puts("\n", string.rep(" ", self.level)) self:puts("\n", string.rep(" ", self.level))
return self return self
@ -119,6 +111,14 @@ function Inspector:down()
self.level = self.level + 1 self.level = self.level + 1
end end
function Inspector:puts(...)
local args = {...}
for i=1, #args do
table.insert(self.buffer, tostring(args[i]))
end
return self
end
function Inspector:putComma(comma) function Inspector:putComma(comma)
if comma then self:puts(',') end if comma then self:puts(',') end
return true return true
@ -202,10 +202,9 @@ function Inspector:putValue(v)
return self return self
end end
function Inspector:putKey(k) function Inspector:putKey(k)
if type(k) == "string" and isIdentifier(k) then if isIdentifier(k) then return self:puts(k) end
return self:puts(k)
end
return self:puts( "[" ):putValue(k):puts("]") return self:puts( "[" ):putValue(k):puts("]")
end end