@@ -24,9 +24,31 @@ static int lept_parse_null(lept_context* c, lept_value* v) {
2424 return LEPT_PARSE_OK ;
2525}
2626
27+ static int lept_parse_true (lept_context * c , lept_value * v ) {
28+ EXPECT (c , 't' );
29+ if (c -> json [0 ] != 'r' || c -> json [1 ] != 'u' || c -> json [2 ] != 'e' )
30+ return LEPT_PARSE_INVALID_VALUE ;
31+ c -> json += 3 ;
32+ v -> type = LEPT_TRUE ;
33+ return LEPT_PARSE_OK ;
34+ }
35+
36+ static int lept_parse_false (lept_context * c , lept_value * v ) {
37+ EXPECT (c , 'f' );
38+ if (c -> json [0 ] != 'a' || c -> json [1 ] != 'l' || c -> json [2 ] != 's' || c -> json [3 ] != 'e' )
39+ return LEPT_PARSE_INVALID_VALUE ;
40+ c -> json += 4 ;
41+ v -> type = LEPT_FALSE ;
42+ return LEPT_PARSE_OK ;
43+ }
44+
45+
46+
2747static int lept_parse_value (lept_context * c , lept_value * v ) {
2848 switch (* c -> json ) {
2949 case 'n' : return lept_parse_null (c , v );
50+ case 't' : return lept_parse_true (c , v );
51+ case 'f' : return lept_parse_false (c , v );
3052 case '\0' : return LEPT_PARSE_EXPECT_VALUE ;
3153 default : return LEPT_PARSE_INVALID_VALUE ;
3254 }
@@ -38,7 +60,13 @@ int lept_parse(lept_value* v, const char* json) {
3860 c .json = json ;
3961 v -> type = LEPT_NULL ;
4062 lept_parse_whitespace (& c );
41- return lept_parse_value (& c , v );
63+ int parse_value_state = lept_parse_value (& c , v );
64+ if (parse_value_state == LEPT_PARSE_OK )
65+ {
66+ lept_parse_whitespace (& c );
67+ if (* c .json != '\0' ) return LEPT_PARSE_ROOT_NOT_SINGULAR ;
68+ }
69+ return parse_value_state ;
4270}
4371
4472lept_type lept_get_type (const lept_value * v ) {
0 commit comments