src/json.c

changeset 1139
7dfa5bcf39ee
parent 1132
b7fea9b2874c
equal deleted inserted replaced
1138:29672c777a28 1139:7dfa5bcf39ee
261 261
262 // current token type and start index 262 // current token type and start index
263 CxJsonTokenType ttype = json->uncompleted.tokentype; 263 CxJsonTokenType ttype = json->uncompleted.tokentype;
264 size_t token_part_start = json->buffer.pos; 264 size_t token_part_start = json->buffer.pos;
265 265
266 bool escape_end_of_string = ttype == CX_JSON_TOKEN_STRING
267 && json->uncompleted.content.ptr[json->uncompleted.content.length-1] == '\\';
268
266 for (size_t i = json->buffer.pos; i < json->buffer.size; i++) { 269 for (size_t i = json->buffer.pos; i < json->buffer.size; i++) {
267 char c = json->buffer.space[i]; 270 char c = json->buffer.space[i];
268 if (ttype != CX_JSON_TOKEN_STRING) { 271 if (ttype != CX_JSON_TOKEN_STRING) {
269 // currently non-string token 272 // currently non-string token
270 CxJsonTokenType ctype = char2ttype(c); // start of new token? 273 CxJsonTokenType ctype = char2ttype(c); // start of new token?
299 return CX_JSON_NO_ERROR; 302 return CX_JSON_NO_ERROR;
300 } 303 }
301 } 304 }
302 } else { 305 } else {
303 // currently inside a string 306 // currently inside a string
304 if (json->tokenizer_escape) { 307 if (escape_end_of_string) {
305 json->tokenizer_escape = false; 308 escape_end_of_string = false;
306 } else { 309 } else {
307 if (c == '"') { 310 if (c == '"') {
308 *result = token_create(json, true, token_part_start, i + 1); 311 *result = token_create(json, true, token_part_start, i + 1);
309 if (result->tokentype == CX_JSON_NO_TOKEN) { 312 if (result->tokentype == CX_JSON_NO_TOKEN) {
310 return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE 313 return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
311 } 314 }
312 json->buffer.pos = i + 1; 315 json->buffer.pos = i + 1;
313 return CX_JSON_NO_ERROR; 316 return CX_JSON_NO_ERROR;
314 } else if (c == '\\') { 317 } else if (c == '\\') {
315 json->tokenizer_escape = true; 318 escape_end_of_string = true;
316 } 319 }
317 } 320 }
318 } 321 }
319 } 322 }
320 323

mercurial