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

Function json_next_string_token

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

Source from the content-addressed store, hash-verified

911}
912
913static void json_next_string_token(json_parse_t *json, json_token_t *token)
914{
915 char *escape2char = json->cfg->escape2char;
916 char ch;
917
918 /* Caller must ensure a string is next */
919 assert(*json->ptr == '"');
920
921 /* Skip " */
922 json->ptr++;
923
924 /* json->tmp is the temporary strbuf used to accumulate the
925 * decoded string value.
926 * json->tmp is sized to handle JSON containing only a string value.
927 */
928 strbuf_reset(json->tmp);
929
930 while ((ch = *json->ptr) != '"') {
931 if (!ch) {
932 /* Premature end of the string */
933 json_set_token_error(token, json, "unexpected end of string");
934 return;
935 }
936
937 /* Handle escapes */
938 if (ch == '\\') {
939 /* Fetch escape character */
940 ch = *(json->ptr + 1);
941
942 /* Translate escape code and append to tmp string */
943 ch = escape2char[(unsigned char)ch];
944 if (ch == 'u') {
945 if (json_append_unicode_escape(json) == 0)
946 continue;
947
948 json_set_token_error(token, json,
949 "invalid unicode escape code");
950 return;
951 }
952 if (!ch) {
953 json_set_token_error(token, json, "invalid escape code");
954 return;
955 }
956
957 /* Skip '\' */
958 json->ptr++;
959 }
960 /* Append normal character or translated single character
961 * Unicode escapes are handled above */
962 strbuf_append_char_unsafe(json->tmp, ch);
963 json->ptr++;
964 }
965 json->ptr++; /* Eat final quote (") */
966
967 strbuf_ensure_null(json->tmp);
968
969 token->type = T_STRING;
970 token->value.string = strbuf_string(json->tmp, &token->string_len);

Callers 1

json_next_tokenFunction · 0.85

Calls 6

strbuf_resetFunction · 0.85
json_set_token_errorFunction · 0.85
strbuf_ensure_nullFunction · 0.85
strbuf_stringFunction · 0.85

Tested by

no test coverage detected