Skip to content

Commit 8b1df23

Browse files
authored
Merge pull request #4 from miscbill/master
Making hjson work with Lua 5.1
2 parents be5f82b + b863cd7 commit 8b1df23

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

hjson/encoderH.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ local escape_char_map = {
99
["\t"] = "\\t"
1010
}
1111

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

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

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

2323
local function needsQuotes(s)
2424
local sequences = {
2525
"^%s", '^"', "^'", "^#", "^/%*", "^//", "^{", "^}", "^%[", "^%]", "^:",
26-
"^,", "%s$", "[\x00-\x1f" .. COMMONRANGE .. "]"
26+
"^,", "%s$", "%z", "[\001-\031" .. COMMONRANGE .. "]"
2727
}
2828
return containsSequences(s, sequences)
2929
end
3030

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

0 commit comments

Comments
 (0)