Lines Matching +full:null +full:- +full:delimited
10 * See the COPYING.LIB file in the top-level directory.
25 #include "json-parser-int.h"
63 if (ctxt->err) { in parse_error()
69 error_setg(&ctxt->err, "JSON parse error, %s", message); in parse_error()
79 return -1; in cvt4hex()
83 cp |= s[i] - '0'; in cvt4hex()
85 cp |= 10 + s[i] - 'a'; in cvt4hex()
87 cp |= 10 + s[i] - 'A'; in cvt4hex()
89 return -1; in cvt4hex()
113 * quotation-mark = %x22 ; "
114 * unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
117 * - Extra escape sequence in strings:
119 * - Single-quoted strings:
120 * Like double-quoted strings, except they're delimited by %x27
125 * - Encoding is modified UTF-8.
126 * - Invalid Unicode characters are rejected.
127 * - Control characters \x00..\x1F are rejected by the lexer.
131 const char *ptr = token->str; in parse_string()
142 str = g_string_new(NULL); in parse_string()
192 cp = -1; /* invalid */ in parse_string()
199 (int)(ptr - beg), beg); in parse_string()
210 if (ctxt->ap) { in parse_string()
221 parse_error(ctxt, token, "invalid UTF-8 sequence in string"); in parse_string()
235 return NULL; in parse_string()
244 g_free(ctxt->current); in parser_context_pop_token()
245 ctxt->current = g_queue_pop_head(ctxt->buf); in parser_context_pop_token()
246 return ctxt->current; in parser_context_pop_token()
251 return g_queue_peek_head(ctxt->buf); in parser_context_peek_token()
259 QObject *key_obj = NULL; in parse_pair()
265 if (peek == NULL) { in parse_pair()
266 parse_error(ctxt, NULL, "premature EOI"); in parse_pair()
278 if (token == NULL) { in parse_pair()
279 parse_error(ctxt, NULL, "premature EOI"); in parse_pair()
283 if (token->type != JSON_COLON) { in parse_pair()
289 if (value == NULL) { in parse_pair()
306 return -1; in parse_pair()
311 QDict *dict = NULL; in parse_object()
315 assert(token && token->type == JSON_LCURLY); in parse_object()
320 if (peek == NULL) { in parse_object()
321 parse_error(ctxt, NULL, "premature EOI"); in parse_object()
325 if (peek->type != JSON_RCURLY) { in parse_object()
326 if (parse_pair(ctxt, dict) == -1) { in parse_object()
331 if (token == NULL) { in parse_object()
332 parse_error(ctxt, NULL, "premature EOI"); in parse_object()
336 while (token->type != JSON_RCURLY) { in parse_object()
337 if (token->type != JSON_COMMA) { in parse_object()
342 if (parse_pair(ctxt, dict) == -1) { in parse_object()
347 if (token == NULL) { in parse_object()
348 parse_error(ctxt, NULL, "premature EOI"); in parse_object()
360 return NULL; in parse_object()
365 QList *list = NULL; in parse_array()
369 assert(token && token->type == JSON_LSQUARE); in parse_array()
374 if (peek == NULL) { in parse_array()
375 parse_error(ctxt, NULL, "premature EOI"); in parse_array()
379 if (peek->type != JSON_RSQUARE) { in parse_array()
383 if (obj == NULL) { in parse_array()
391 if (token == NULL) { in parse_array()
392 parse_error(ctxt, NULL, "premature EOI"); in parse_array()
396 while (token->type != JSON_RSQUARE) { in parse_array()
397 if (token->type != JSON_COMMA) { in parse_array()
403 if (obj == NULL) { in parse_array()
411 if (token == NULL) { in parse_array()
412 parse_error(ctxt, NULL, "premature EOI"); in parse_array()
424 return NULL; in parse_array()
432 assert(token && token->type == JSON_KEYWORD); in parse_keyword()
434 if (!strcmp(token->str, "true")) { in parse_keyword()
436 } else if (!strcmp(token->str, "false")) { in parse_keyword()
438 } else if (!strcmp(token->str, "null")) { in parse_keyword()
441 parse_error(ctxt, token, "invalid keyword '%s'", token->str); in parse_keyword()
442 return NULL; in parse_keyword()
450 assert(token && token->type == JSON_INTERP); in parse_interpolation()
452 if (!strcmp(token->str, "%p")) { in parse_interpolation()
453 return va_arg(*ctxt->ap, QObject *); in parse_interpolation()
454 } else if (!strcmp(token->str, "%i")) { in parse_interpolation()
455 return QOBJECT(qbool_from_bool(va_arg(*ctxt->ap, int))); in parse_interpolation()
456 } else if (!strcmp(token->str, "%d")) { in parse_interpolation()
457 return QOBJECT(qnum_from_int(va_arg(*ctxt->ap, int))); in parse_interpolation()
458 } else if (!strcmp(token->str, "%ld")) { in parse_interpolation()
459 return QOBJECT(qnum_from_int(va_arg(*ctxt->ap, long))); in parse_interpolation()
460 } else if (!strcmp(token->str, "%lld")) { in parse_interpolation()
461 return QOBJECT(qnum_from_int(va_arg(*ctxt->ap, long long))); in parse_interpolation()
462 } else if (!strcmp(token->str, "%" PRId64)) { in parse_interpolation()
463 return QOBJECT(qnum_from_int(va_arg(*ctxt->ap, int64_t))); in parse_interpolation()
464 } else if (!strcmp(token->str, "%u")) { in parse_interpolation()
465 return QOBJECT(qnum_from_uint(va_arg(*ctxt->ap, unsigned int))); in parse_interpolation()
466 } else if (!strcmp(token->str, "%lu")) { in parse_interpolation()
467 return QOBJECT(qnum_from_uint(va_arg(*ctxt->ap, unsigned long))); in parse_interpolation()
468 } else if (!strcmp(token->str, "%llu")) { in parse_interpolation()
469 return QOBJECT(qnum_from_uint(va_arg(*ctxt->ap, unsigned long long))); in parse_interpolation()
470 } else if (!strcmp(token->str, "%" PRIu64)) { in parse_interpolation()
471 return QOBJECT(qnum_from_uint(va_arg(*ctxt->ap, uint64_t))); in parse_interpolation()
472 } else if (!strcmp(token->str, "%s")) { in parse_interpolation()
473 return QOBJECT(qstring_from_str(va_arg(*ctxt->ap, const char *))); in parse_interpolation()
474 } else if (!strcmp(token->str, "%f")) { in parse_interpolation()
475 return QOBJECT(qnum_from_double(va_arg(*ctxt->ap, double))); in parse_interpolation()
477 parse_error(ctxt, token, "invalid interpolation '%s'", token->str); in parse_interpolation()
478 return NULL; in parse_interpolation()
488 switch (token->type) { in parse_literal()
498 * qnum_get_int() will then work for any signed 64-bit in parse_literal()
499 * JSON_INTEGER, qnum_get_uint() for any unsigned 64-bit in parse_literal()
508 ret = qemu_strtoi64(token->str, NULL, 10, &value); in parse_literal()
512 assert(ret == -ERANGE); in parse_literal()
514 if (token->str[0] != '-') { in parse_literal()
515 ret = qemu_strtou64(token->str, NULL, 10, &uvalue); in parse_literal()
519 assert(ret == -ERANGE); in parse_literal()
527 return QOBJECT(qnum_from_double(strtod(token->str, NULL))); in parse_literal()
538 if (token == NULL) { in parse_value()
539 parse_error(ctxt, NULL, "premature EOI"); in parse_value()
540 return NULL; in parse_value()
543 switch (token->type) { in parse_value()
558 return NULL; in parse_value()
564 JSONToken *token = g_malloc(sizeof(JSONToken) + tokstr->len + 1); in json_token()
566 token->type = type; in json_token()
567 memcpy(token->str, tokstr->str, tokstr->len); in json_token()
568 token->str[tokstr->len] = 0; in json_token()
569 token->x = x; in json_token()
570 token->y = y; in json_token()