src/json.c

changeset 1567
f60f23b362e9
parent 1565
fb314eeca7a4
equal deleted inserted replaced
1566:2ebbcb38986d 1567:f60f23b362e9
226 } 226 }
227 } 227 }
228 } 228 }
229 } 229 }
230 230
231 if (ttype != CX_JSON_NO_TOKEN) { 231 if (ttype == CX_JSON_NO_TOKEN) {
232 return CX_JSON_NO_DATA;
233 } else {
232 // uncompleted token 234 // uncompleted token
233 size_t uncompleted_len = json->buffer.size - token_part_start; 235 size_t uncompleted_len = json->buffer.size - token_part_start;
234 if (json->uncompleted.tokentype == CX_JSON_NO_TOKEN) { 236 if (json->uncompleted.tokentype == CX_JSON_NO_TOKEN) {
235 // current token is uncompleted 237 // current token is uncompleted
236 // save current token content 238 // save current token content
253 } 255 }
254 json->uncompleted.content = str; 256 json->uncompleted.content = str;
255 } 257 }
256 // advance the buffer position - we saved the stuff in the uncompleted token 258 // advance the buffer position - we saved the stuff in the uncompleted token
257 json->buffer.pos += uncompleted_len; 259 json->buffer.pos += uncompleted_len;
258 } 260 return CX_JSON_INCOMPLETE_DATA;
259 261 }
260 return CX_JSON_INCOMPLETE_DATA;
261 } 262 }
262 263
263 // converts a Unicode codepoint to utf8 264 // converts a Unicode codepoint to utf8
264 static unsigned codepoint_to_utf8(uint32_t codepoint, char *output_buf) { 265 static unsigned codepoint_to_utf8(uint32_t codepoint, char *output_buf) {
265 if (codepoint <= 0x7F) { 266 if (codepoint <= 0x7F) {
802 cxJsonDestroy(&parser); 803 cxJsonDestroy(&parser);
803 return CX_JSON_BUFFER_ALLOC_FAILED; 804 return CX_JSON_BUFFER_ALLOC_FAILED;
804 // LCOV_EXCL_STOP 805 // LCOV_EXCL_STOP
805 } 806 }
806 CxJsonStatus status = cxJsonNext(&parser, value); 807 CxJsonStatus status = cxJsonNext(&parser, value);
808 // check if we consume the total string
809 CxJsonValue *chk_value = NULL;
810 CxJsonStatus chk_status = CX_JSON_NO_DATA;
811 if (status == CX_JSON_NO_ERROR) {
812 chk_status = cxJsonNext(&parser, &chk_value);
813 }
807 cxJsonDestroy(&parser); 814 cxJsonDestroy(&parser);
808 return status; 815 if (chk_status == CX_JSON_NO_DATA) {
816 return status;
817 } else {
818 cxJsonValueFree(*value);
819 // if chk_value is nothing, the free is harmless
820 cxJsonValueFree(chk_value);
821 *value = &cx_json_value_nothing;
822 return CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN;
823 }
824
809 } 825 }
810 826
811 void cxJsonValueFree(CxJsonValue *value) { 827 void cxJsonValueFree(CxJsonValue *value) {
812 if (value == NULL || value->type == CX_JSON_NOTHING) return; 828 if (value == NULL || value->type == CX_JSON_NOTHING) return;
813 switch (value->type) { 829 switch (value->type) {

mercurial