Skip to content

Commit

Permalink
Merge pull request #4 from miscbill/master
Browse files Browse the repository at this point in the history
Making hjson work with Lua 5.1
  • Loading branch information
cryi authored Aug 29, 2024
2 parents be5f82b + b863cd7 commit 8b1df23
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hjson/encoderH.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ local escape_char_map = {
["\t"] = "\\t"
}

local COMMONRANGE = "\x7f-\x9f" -- // TODO: add unicode escape sequences
local COMMONRANGE = "\127-\159" -- // TODO: add unicode escape sequences

local function containsSequences(s, sequences)
for _, v in ipairs(sequences) do if s:find(v) then return true end end
return false
end

local function needsEscape(s)
return containsSequences(s, {'[\\"\x00-\x1f' .. COMMONRANGE .. "]"})
return containsSequences(s, {"%z", '[\\"\001-\031' .. COMMONRANGE .. "]"})
end

local function needsQuotes(s)
local sequences = {
"^%s", '^"', "^'", "^#", "^/%*", "^//", "^{", "^}", "^%[", "^%]", "^:",
"^,", "%s$", "[\x00-\x1f" .. COMMONRANGE .. "]"
"^,", "%s$", "%z", "[\001-\031" .. COMMONRANGE .. "]"
}
return containsSequences(s, sequences)
end

local function needsEscapeML(s)
local sequences = {
"'''", "^[\\s]+$", "[\x00-\x08\x0b\x0c\x0e-\x1f" .. COMMONRANGE .. "]"
"'''", "^[\\s]+$", "%z", "[\01-\08\011\012\014-\031" .. COMMONRANGE .. "]"
}
return containsSequences(s, sequences)
end
Expand Down

0 comments on commit 8b1df23

Please sign in to comment.