Skip to content

Commit

Permalink
Serializer now has better , placements
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruor committed May 24, 2020
1 parent f45fae2 commit 3e24966
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/serialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ local function isMetaKey(key, useMetaKeys)
return useMetaKeys and type(key) == "string" and key:match(ignoredKeysPattern)
end

local function insertIfNotEmpty(t, s)
if s and s ~= "" then
table.insert(t, s)
end
end

function serialize.countKeys(t, useMetaKeys)
local numerical = 0
local total = 0
Expand Down Expand Up @@ -249,14 +255,19 @@ function serialize.serialize(t, pretty, sortKeys, useMetaKeys, seen, depth, succ
local entryValues = serialize.getEntries(entries, sortKeys)
local bracketedNumberValues = serialize.getEntries(bracketedNumerEntries, sortKeys)

local noKeyConent = table.concat(noKeyEntries, lineSep)
local noKeyContent = table.concat(noKeyEntries, lineSep)
local bracketNumberContent = table.concat(bracketedNumberValues, lineSep)
local keyValueContent = table.concat(entryValues, lineSep)

local noKeyToBracketedSep = #noKeyConent > 0 and lineSep or ""
local bracketToKeySep = #bracketNumberContent > 0 and lineSep or ""
local parts = {}

insertIfNotEmpty(parts, noKeyContent)
insertIfNotEmpty(parts, bracketNumberContent)
insertIfNotEmpty(parts, keyValueContent)

local content = table.concat(parts, lineSep)

return success, "{" .. newline .. noKeyConent .. noKeyToBracketedSep .. bracketNumberContent .. bracketToKeySep .. keyValueContent .. newline .. closingPadding .. "}"
return success, "{" .. newline .. content.. newline .. closingPadding .. "}"
end

function serialize.unserialize(s)
Expand Down

0 comments on commit 3e24966

Please sign in to comment.