github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/native/value.c (about) 1 #include "scanning.h" 2 #include "vstring.h" 3 4 long value(const char *s, size_t n, long p, JsonState *ret, uint64_t flags) { 5 long q = p; 6 GoString m = {.buf = s, .len = n}; 7 bool allow_control = (flags & MASK_ALLOW_CONTROL) != 0; 8 /* parse the next identifier, q is UNSAFE, may cause out-of-bounds accessing */ 9 switch (advance_ns(&m, &q)) { 10 case '-' : /* fallthrough */ 11 case '0' : /* fallthrough */ 12 case '1' : /* fallthrough */ 13 case '2' : /* fallthrough */ 14 case '3' : /* fallthrough */ 15 case '4' : /* fallthrough */ 16 case '5' : /* fallthrough */ 17 case '6' : /* fallthrough */ 18 case '7' : /* fallthrough */ 19 case '8' : /* fallthrough */ 20 case '9' : vdigits(&m, &q, ret, flags) ; return q; 21 case '"' : vstring_1(&m, &q, ret, flags) ; return q; 22 case 'n' : ret->vt = advance_dword(&m, &q, 1, V_NULL, VS_NULL) ; return q; 23 case 't' : ret->vt = advance_dword(&m, &q, 1, V_TRUE, VS_TRUE) ; return q; 24 case 'f' : ret->vt = advance_dword(&m, &q, 0, V_FALSE, VS_ALSE) ; return q; 25 case '[' : ret->vt = V_ARRAY ; return q; 26 case '{' : ret->vt = V_OBJECT ; return q; 27 case ':' : ret->vt = allow_control ? V_KEY_SEP : -ERR_INVAL ; return allow_control ? q : q - 1; 28 case ',' : ret->vt = allow_control ? V_ELEM_SEP : -ERR_INVAL ; return allow_control ? q : q - 1; 29 case ']' : ret->vt = allow_control ? V_ARRAY_END : -ERR_INVAL ; return allow_control ? q : q - 1; 30 case '}' : ret->vt = allow_control ? V_OBJECT_END : -ERR_INVAL ; return allow_control ? q : q - 1; 31 case 0 : ret->vt = V_EOF ; return q; 32 default : ret->vt = -ERR_INVAL ; return q - 1; 33 } 34 }