@@ -15,6 +15,24 @@ static void lept_parse_whitespace(lept_context* c) {
1515 c -> json = p ;
1616}
1717
18+ static int lept_parse_true (lept_context * c , lept_value * v ) {
19+ EXPECT (c , 't' );
20+ if (c -> json [0 ] != 'r' || c -> json [1 ] != 'u' || c -> json [2 ] != 'e' )
21+ return LEPT_PARSE_INVALID_VALUE ;
22+ c -> json += 3 ;
23+ v -> type = LEPT_TRUE ;
24+ return LEPT_PARSE_OK ;
25+ }
26+
27+ static int lept_parse_false (lept_context * c , lept_value * v ) {
28+ EXPECT (c , 'f' );
29+ if (c -> json [0 ] != 'a' || c -> json [1 ] != 'l' || c -> json [2 ] != 's' || c -> json [3 ] != 'e' )
30+ return LEPT_PARSE_INVALID_VALUE ;
31+ c -> json += 4 ;
32+ v -> type = LEPT_FALSE ;
33+ return LEPT_PARSE_OK ;
34+ }
35+
1836static int lept_parse_null (lept_context * c , lept_value * v ) {
1937 EXPECT (c , 'n' );
2038 if (c -> json [0 ] != 'u' || c -> json [1 ] != 'l' || c -> json [2 ] != 'l' )
@@ -27,18 +45,26 @@ static int lept_parse_null(lept_context* c, lept_value* v) {
2745static int lept_parse_value (lept_context * c , lept_value * v ) {
2846 switch (* c -> json ) {
2947 case 'n' : return lept_parse_null (c , v );
48+ case 't' : return lept_parse_true (c , v );
49+ case 'f' : return lept_parse_false (c , v );
3050 case '\0' : return LEPT_PARSE_EXPECT_VALUE ;
3151 default : return LEPT_PARSE_INVALID_VALUE ;
3252 }
3353}
3454
3555int lept_parse (lept_value * v , const char * json ) {
3656 lept_context c ;
57+ int ret ;
3758 assert (v != NULL );
3859 c .json = json ;
3960 v -> type = LEPT_NULL ;
4061 lept_parse_whitespace (& c );
41- return lept_parse_value (& c , v );
62+ if ((ret = lept_parse_value (& c , v )) == LEPT_PARSE_OK ) {
63+ lept_parse_whitespace (& c );
64+ if (* c .json != 0 )
65+ ret = LEPT_PARSE_ROOT_NOT_SINGULAR ;
66+ }
67+ return ret ;
4268}
4369
4470lept_type lept_get_type (const lept_value * v ) {
0 commit comments