MCPcopy Create free account
hub / github.com/defold/defold / json_decode

Function json_decode

engine/script/src/luacjson/lua_cjson.c:1563–1601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1561
1562#if 0 // DEFOLD
1563static int json_decode(lua_State *l)
1564{
1565 json_parse_t json;
1566 json_token_t token;
1567 size_t json_len;
1568
1569 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
1570
1571 json.cfg = json_fetch_config(l);
1572 json.data = luaL_checklstring(l, 1, &json_len);
1573 json.current_depth = 0;
1574 json.ptr = json.data;
1575
1576 /* Detect Unicode other than UTF-8 (see RFC 4627, Sec 3)
1577 *
1578 * CJSON can support any simple data type, hence only the first
1579 * character is guaranteed to be ASCII (at worst: '"'). This is
1580 * still enough to detect whether the wrong encoding is in use. */
1581 if (json_len >= 2 && (!json.data[0] || !json.data[1]))
1582 luaL_error(l, "JSON parser does not support UTF-16 or UTF-32");
1583
1584 /* Ensure the temporary buffer can hold the entire string.
1585 * This means we no longer need to do length checks since the decoded
1586 * string must be smaller than the entire json string */
1587 json.tmp = strbuf_new(json_len);
1588
1589 json_next_token(&json, &token);
1590 json_process_value(l, &json, &token);
1591
1592 /* Ensure there is no more input left */
1593 json_next_token(&json, &token);
1594
1595 if (token.type != T_END)
1596 json_throw_parse_error(l, &json, "the end", &token);
1597
1598 strbuf_free(json.tmp);
1599
1600 return 1;
1601}
1602
1603#endif // DEFOLD
1604

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