MCPcopy Create free account
hub / github.com/axmolengine/axmol / json_decode

Function json_decode

3rdparty/lua/lua-cjson/lua_cjson.c:1289–1327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1287}
1288
1289static int json_decode(lua_State *l)
1290{
1291 json_parse_t json;
1292 json_token_t token;
1293 size_t json_len;
1294
1295 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
1296
1297 json.cfg = json_fetch_config(l);
1298 json.data = luaL_checklstring(l, 1, &json_len);
1299 json.current_depth = 0;
1300 json.ptr = json.data;
1301
1302 /* Detect Unicode other than UTF-8 (see RFC 4627, Sec 3)
1303 *
1304 * CJSON can support any simple data type, hence only the first
1305 * character is guaranteed to be ASCII (at worst: '"'). This is
1306 * still enough to detect whether the wrong encoding is in use. */
1307 if (json_len >= 2 && (!json.data[0] || !json.data[1]))
1308 luaL_error(l, "JSON parser does not support UTF-16 or UTF-32");
1309
1310 /* Ensure the temporary buffer can hold the entire string.
1311 * This means we no longer need to do length checks since the decoded
1312 * string must be smaller than the entire json string */
1313 json.tmp = strbuf_new(json_len);
1314
1315 json_next_token(&json, &token);
1316 json_process_value(l, &json, &token);
1317
1318 /* Ensure there is no more input left */
1319 json_next_token(&json, &token);
1320
1321 if (token.type != T_END)
1322 json_throw_parse_error(l, &json, "the end", &token);
1323
1324 strbuf_free(json.tmp);
1325
1326 return 1;
1327}
1328
1329/* ===== INITIALISATION ===== */
1330

Callers

nothing calls this directly

Calls 9

lua_gettopFunction · 0.85
json_fetch_configFunction · 0.85
luaL_checklstringFunction · 0.85
luaL_errorFunction · 0.85
strbuf_newFunction · 0.85
json_next_tokenFunction · 0.85
json_process_valueFunction · 0.85
json_throw_parse_errorFunction · 0.85
strbuf_freeFunction · 0.85

Tested by

no test coverage detected