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

Function json_next_token

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

Fills in the token struct. * T_STRING will return a pointer to the json_parse_t temporary string * T_ERROR will leave the json->ptr pointer at the error. */

Source from the content-addressed store, hash-verified

1045 * T_ERROR will leave the json->ptr pointer at the error.
1046 */
1047static void json_next_token(json_parse_t *json, json_token_t *token)
1048{
1049 const json_token_type_t *ch2token = json->cfg->ch2token;
1050 int ch;
1051
1052 /* Eat whitespace. */
1053 while (1) {
1054 ch = (unsigned char)*(json->ptr);
1055 token->type = ch2token[ch];
1056 if (token->type != T_WHITESPACE)
1057 break;
1058 json->ptr++;
1059 }
1060
1061 /* Store location of new token. Required when throwing errors
1062 * for unexpected tokens (syntax errors). */
1063 token->index = json->ptr - json->data;
1064
1065 /* Don't advance the pointer for an error or the end */
1066 if (token->type == T_ERROR) {
1067 json_set_token_error(token, json, "invalid token");
1068 return;
1069 }
1070
1071 if (token->type == T_END) {
1072 return;
1073 }
1074
1075 /* Found a known single character token, advance index and return */
1076 if (token->type != T_UNKNOWN) {
1077 json->ptr++;
1078 return;
1079 }
1080
1081 /* Process characters which triggered T_UNKNOWN
1082 *
1083 * Must use strncmp() to match the front of the JSON string.
1084 * JSON identifier must be lowercase.
1085 * When strict_numbers if disabled, either case is allowed for
1086 * Infinity/NaN (since we are no longer following the spec..) */
1087 if (ch == '"') {
1088 json_next_string_token(json, token);
1089 return;
1090 } else if (ch == '-' || ('0' <= ch && ch <= '9')) {
1091 if (!json->cfg->decode_invalid_numbers && json_is_invalid_number(json)) {
1092 json_set_token_error(token, json, "invalid number");
1093 return;
1094 }
1095 json_next_number_token(json, token);
1096 return;
1097 } else if (!strncmp(json->ptr, "true", 4)) {
1098 token->type = T_BOOLEAN;
1099 token->value.boolean = 1;
1100 json->ptr += 4;
1101 return;
1102 } else if (!strncmp(json->ptr, "false", 5)) {
1103 token->type = T_BOOLEAN;
1104 token->value.boolean = 0;

Callers 3

json_parse_array_contextFunction · 0.85
json_decodeFunction · 0.85

Calls 4

json_set_token_errorFunction · 0.85
json_next_string_tokenFunction · 0.85
json_is_invalid_numberFunction · 0.85
json_next_number_tokenFunction · 0.85

Tested by

no test coverage detected