diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-12-20 00:14:16 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-12-20 00:14:16 +1030 |
commit | fe25699a3ba84a35fac58bc7236ab6b3ff3e7ba3 (patch) | |
tree | a1ab65bc27651e6b7004e4e42494101ec7b881d1 | |
parent | 7bbb4bd8decb8239c78abe3c7f54dafb9fca8120 (diff) | |
download | lua-cjson-fe25699a3ba84a35fac58bc7236ab6b3ff3e7ba3.tar.gz lua-cjson-fe25699a3ba84a35fac58bc7236ab6b3ff3e7ba3.tar.bz2 lua-cjson-fe25699a3ba84a35fac58bc7236ab6b3ff3e7ba3.zip |
Add UTF-8 caution to manual (and misc changes)
-rw-r--r-- | manual.txt | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -1,6 +1,6 @@ | |||
1 | = Lua CJSON 1.0devel Manual = | 1 | = Lua CJSON 1.0devel Manual = |
2 | Mark Pulford <mark@kyne.com.au> | 2 | Mark Pulford <mark@kyne.com.au> |
3 | :revdate: 30th November 2011 | 3 | :revdate: November 30, 2011 |
4 | 4 | ||
5 | Overview | 5 | Overview |
6 | -------- | 6 | -------- |
@@ -8,7 +8,7 @@ Overview | |||
8 | Lua CJSON provides fast JSON parsing and encoding support for Lua. | 8 | Lua CJSON provides fast JSON parsing and encoding support for Lua. |
9 | 9 | ||
10 | .Features | 10 | .Features |
11 | - More than 10x to 20x faster than the efficient pure Lua JSON modules. | 11 | - More than 10x to 20x faster than efficient pure Lua JSON modules. |
12 | - Full support for JSON with UTF-8, including decoding surrogate | 12 | - Full support for JSON with UTF-8, including decoding surrogate |
13 | pairs. | 13 | pairs. |
14 | - Optional run-time support for common exceptions to the JSON | 14 | - Optional run-time support for common exceptions to the JSON |
@@ -48,10 +48,9 @@ Build options (#define) | |||
48 | ~~~~~~~~~~~~~~~~~~~~~~~ | 48 | ~~~~~~~~~~~~~~~~~~~~~~~ |
49 | 49 | ||
50 | Lua CJSON uses +strtod+(3) and +snprintf+(3) to perform numeric | 50 | Lua CJSON uses +strtod+(3) and +snprintf+(3) to perform numeric |
51 | conversion as they are usually well supported, fast and bug free. To | 51 | conversion as they are usually well supported, fast and bug free. Lua |
52 | ensure JSON encoding/decoding works correctly under locales using | 52 | CJSON may optionally be compiled with (only) one of the following |
53 | comma decimal separators, Lua CJSON may optionally be compiled with | 53 | preprocessor macros to support locales with comma decimal separators: |
54 | one of the following preprocessor macros: | ||
55 | 54 | ||
56 | [horizontal] | 55 | [horizontal] |
57 | USE_POSIX_USELOCALE:: Thread safe. Supported by Linux and Mac OSX. | 56 | USE_POSIX_USELOCALE:: Thread safe. Supported by Linux and Mac OSX. |
@@ -222,9 +221,10 @@ The remaining Lua types will generate an error: | |||
222 | - +userdata+ | 221 | - +userdata+ |
223 | 222 | ||
224 | By default, numbers are encoded using the standard Lua number | 223 | By default, numbers are encoded using the standard Lua number |
225 | +printf+(3) format ("%.14g"). | 224 | +printf+(3) format (+%.14g+). |
226 | 225 | ||
227 | Lua CJSON will escape the following characters within each string: | 226 | Lua CJSON will escape the following characters within each UTF-8 |
227 | string: | ||
228 | 228 | ||
229 | - Control characters (ASCII 0 - 31) | 229 | - Control characters (ASCII 0 - 31) |
230 | - Double quote (ASCII 34) | 230 | - Double quote (ASCII 34) |
@@ -232,8 +232,20 @@ Lua CJSON will escape the following characters within each string: | |||
232 | - Blackslash (ASCII 92) | 232 | - Blackslash (ASCII 92) |
233 | - Delete (ASCII 127) | 233 | - Delete (ASCII 127) |
234 | 234 | ||
235 | All other characters are passed transparently. Any UTF-8 error | 235 | All other characters are passed transparently. |
236 | checking must be done by the application. | 236 | |
237 | [CAUTION] | ||
238 | ========= | ||
239 | Lua CJSON will successfully encode/decode binary strings, but this is | ||
240 | technically not supported by JSON and may not be compatible with other | ||
241 | JSON libraries. Applications should ensure all Lua strings passed to | ||
242 | +cjson.encode+ are valid UTF-8 to ensure the output is valid JSON. | ||
243 | |||
244 | Base64 is a common way to transport binary data through JSON. Lua | ||
245 | Base64 routines can be found in the | ||
246 | http://w3.impa.br/~diego/software/luasocket/[LuaSocket] and | ||
247 | http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lbase64[lbase64] packages. | ||
248 | ========= | ||
237 | 249 | ||
238 | Lua CJSON uses a heuristic to determine whether to encode a Lua table | 250 | Lua CJSON uses a heuristic to determine whether to encode a Lua table |
239 | as a JSON array or an object. A Lua table with only positive integers | 251 | as a JSON array or an object. A Lua table with only positive integers |
@@ -256,6 +268,7 @@ generate an error. | |||
256 | Standards compliant JSON must be encapsulated in either an object | 268 | Standards compliant JSON must be encapsulated in either an object |
257 | (+{}+) or an array (+[]+). Hence a table must be passed to | 269 | (+{}+) or an array (+[]+). Hence a table must be passed to |
258 | +cjson.encode+ to generate standards compliant JSON output. | 270 | +cjson.encode+ to generate standards compliant JSON output. |
271 | This may not be required by some applications. | ||
259 | 272 | ||
260 | By default, the following Lua values will generate errors: | 273 | By default, the following Lua values will generate errors: |
261 | 274 | ||
@@ -430,4 +443,5 @@ References | |||
430 | - http://tools.ietf.org/html/rfc4627[RFC 4627] | 443 | - http://tools.ietf.org/html/rfc4627[RFC 4627] |
431 | - http://www.json.org/[JSON website] | 444 | - http://www.json.org/[JSON website] |
432 | 445 | ||
446 | |||
433 | // vi:tw=70: | 447 | // vi:tw=70: |