text
stringlengths 0
14.1k
|
---|
if (*tokend != 0 || errno)
|
goto failed;
|
} else {
|
v_int = strtoll(buf, &tokend, 10);
|
if (*tokend != 0 || errno || v_int < JSON_MININT || v_int > JSON_MAXINT)
|
goto failed;
|
}
|
/* create value struct */
|
jv = mk_value(ctx, type, 0, true);
|
if (!jv)
|
return false;
|
if (type == JSON_FLOAT) {
|
jv->u.v_float = v_float;
|
} else {
|
jv->u.v_int = v_int;
|
}
|
*src_p = src;
|
return true;
|
failed:
|
if (!errno)
|
errno = EINVAL;
|
return err_false(ctx, ""Number parse failed"");
|
}
|
/*
|
* String parsing
|
*/
|
static int parse_hex(const char *s, const char *end)
|
{
|
int v = 0, c, i, x;
|
if (s + 4 > end)
|
return -1;
|
for (i = 0; i < 4; i++) {
|
c = s[i];
|
if (c >= '0' && c <= '9') {
|
x = c - '0';
|
} else if (c >= 'a' && c <= 'f') {
|
x = c - 'a' + 10;
|
} else if (c >= 'A' && c <= 'F') {
|
x = c - 'A' + 10;
|
} else {
|
return -1;
|
}
|
v = (v << 4) | x;
|
}
|
return v;
|
}
|
/* process \uXXXX escapes, merge surrogates */
|
static bool parse_uescape(struct JsonContext *ctx, char **dst_p, char *dstend,
|
const char **src_p, const char *end)
|
{
|
int c, c2;
|
const char *src = *src_p;
|
c = parse_hex(src, end);
|
if (c <= 0)
|
return err_false(ctx, ""Invalid hex escape"");
|
src += 4;
|
if (c >= 0xD800 && c <= 0xDFFF) {
|
/* first surrogate */
|
if (c >= 0xDC00)
|
return err_false(ctx, ""Invalid UTF16 escape"");
|
if (src + 6 > end)
|
return err_false(ctx, ""Invalid UTF16 escape"");
|
/* second surrogate */
|
if (src[0] != '\\' || src[1] != 'u')
|
return err_false(ctx, ""Invalid UTF16 escape"");
|
c2 = parse_hex(src + 2, end);
|
if (c2 < 0xDC00 || c2 > 0xDFFF)
|
return err_false(ctx, ""Invalid UTF16 escape"");
|
c = 0x10000 + ((c & 0x3FF) << 10) + (c2 & 0x3FF);
|
src += 6;
|
}
|
/* now write char */
|
if (!utf8_put_char(c, dst_p, dstend))
|
return err_false(ctx, ""Invalid UTF16 escape"");
|
*src_p = src;
|
return true;
|
}
|
#define meta_string(c) (((c) == '""' || (c) == '\\' || (c) == '\0' || \
|
(c) == '\n' || ((c) & 0x80) != 0) ? 1 : 0)
|
static const uint8_t string_examine_chars[] = INTMAP256_CONST(meta_string);
|
/* look for string end, validate contents */
|
static bool scan_string(struct JsonContext *ctx, const char *src, const char *end,
|
const char **str_end_p, bool *hasesc_p, int64_t *nlines_p)
|
{
|
bool hasesc = false;
|
int64_t lines = 0;
|
unsigned int n;
|
bool check_utf8 = true;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.