1pub enum CheckResult {
2 Ok,
3 Null,
4 TypeMismatch(&'static str),
5 SyntaxErr(super::SyntaxErr),
6}
7
8use super::utils;
9
10#[inline]
11pub fn check(json: &[u8], idx: &mut usize) -> CheckResult {
12 let byte = match utils::get_or_unexpected_end(json, idx) {
13 Ok(byte) => byte,
14 Err(e) => return CheckResult::SyntaxErr(e),
15 };
16
17 match byte {
18 b'[' => {
19 *idx += 1;
20 CheckResult::Ok
21 }
22
23 b'"' => {
24 if let Err(e) = utils::skip_string(json, idx) {
25 CheckResult::SyntaxErr(e)
26 } else {
27 CheckResult::TypeMismatch("string")
28 }
29 }
30
31 b'n' => {
33 if let Err(e) = utils::skip_null(json, idx, "[") {
34 CheckResult::SyntaxErr(e)
35 } else {
36 CheckResult::Null
37 }
38 }
39
40 b'f' => {
41 if let Err(e) = utils::skip_false(json, idx, "[") {
42 CheckResult::SyntaxErr(e)
43 } else {
44 CheckResult::TypeMismatch("boolean")
45 }
46 }
47
48 b't' => {
49 return if let Err(e) = utils::skip_true(json, idx, "[") {
50 CheckResult::SyntaxErr(e)
51 } else {
52 CheckResult::TypeMismatch("boolean")
53 }
54 }
55
56 b'{' => {
57 return if let Err(e) = utils::skip_object(json, idx) {
58 CheckResult::SyntaxErr(e)
59 } else {
60 CheckResult::TypeMismatch("object")
61 }
62 }
63
64 b'0'..=b'9' => {
65 utils::skip_number(json, idx);
66 CheckResult::TypeMismatch("number")
67 }
68
69 _ => CheckResult::SyntaxErr(super::SyntaxErr::unexpected_token("[", &[byte], idx)),
70 }
71}