1 local string_char
= string.char
3 module("json.encode.strings")
16 -- Pre-encode the control characters to speed up encoding...
17 -- NOTE: UTF-8 may not work out right w/ JavaScript
18 -- JavaScript uses 2 bytes after a \u... yet UTF-8 is a
19 -- byte-stream encoding, not pairs of bytes (it does encode
20 -- some letters > 1 byte, but base case is 1)
22 local c
= string_char(i
)
23 if c
:match('%c') and not encodingMap
[c
] then
24 encodingMap
[c
] = ('\\u%.4X'):format(i
)
28 function encode(s
, options
)
29 local stringPreprocess
= options
and options
.strings
and options
.strings
.preProcess
30 if stringPreprocess
then
31 s
= stringPreprocess(s
)
33 return '"' .. s
:gsub('[\\"/%c%z]', encodingMap
) .. '"'