MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_parse_array_context

Function json_parse_array_context

deps/lua/src/lua_cjson.c:1186–1221  ·  view source on GitHub ↗

Handle the array context */

Source from the content-addressed store, hash-verified

1184
1185/* Handle the array context */
1186static void json_parse_array_context(lua_State *l, json_parse_t *json)
1187{
1188 json_token_t token;
1189 int i;
1190
1191 /* 2 slots required:
1192 * .., table, value */
1193 json_decode_descend(l, json, 2);
1194
1195 lua_newtable(l);
1196
1197 json_next_token(json, &token);
1198
1199 /* Handle empty arrays */
1200 if (token.type == T_ARR_END) {
1201 json_decode_ascend(json);
1202 return;
1203 }
1204
1205 for (i = 1; ; i++) {
1206 json_process_value(l, json, &token);
1207 lua_rawseti(l, -2, i); /* arr[i] = value */
1208
1209 json_next_token(json, &token);
1210
1211 if (token.type == T_ARR_END) {
1212 json_decode_ascend(json);
1213 return;
1214 }
1215
1216 if (token.type != T_COMMA)
1217 json_throw_parse_error(l, json, "comma or array end", &token);
1218
1219 json_next_token(json, &token);
1220 }
1221}
1222
1223/* Handle the "value" context */
1224static void json_process_value(lua_State *l, json_parse_t *json,

Callers 1

json_process_valueFunction · 0.85

Calls 6

json_decode_descendFunction · 0.85
json_next_tokenFunction · 0.85
json_decode_ascendFunction · 0.85
json_process_valueFunction · 0.85
lua_rawsetiFunction · 0.85
json_throw_parse_errorFunction · 0.85

Tested by

no test coverage detected