Skip to content

Commit 4fed7e8

Browse files
authored
Update leptjson.h
1 parent 72baede commit 4fed7e8

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

my_json_tutorial01/leptjson.h

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,51 @@ enum class lept_type { LNULL, FALSE, TRUE, NUMBER, STRING, ARRAY, OBJECT }; //JS
77

88
struct lept_value
99
{
10+
union {
11+
struct { char *s; size_t len; };
12+
double n;//json number
13+
};
1014
lept_type type;
15+
1116
};
1217

18+
1319
enum
1420
{
15-
LEPT_PARSE_OK = 0,
21+
LEPT_PARSE_OK = 0, //parse ok
1622
LEPT_PARSE_EXECPT_VALUE, //若一个 JSON 只含有空白
1723
LEPT_PARSE_INVALID_VALUE, //既不是空白 也不是含有其它字符
18-
LEPT_PARSE_ROOT_NOT_SINGULAR // 若一个值之后,在空白之后还有其他字符
24+
LEPT_PARSE_ROOT_NOT_SINGULAR, // 若一个值之后,在空白之后还有其他字符
25+
LEPT_PARSE_NUMBER_TOO_BIG, //数字太大了
26+
LEPT_PARSE_MISS_QUOTATION_MARK, //引号问题
1927
};
2028

29+
// is json right?
30+
int lept_parse(lept_value &v, const char *json);
31+
32+
33+
//parse lept_value is what lept_type
34+
lept_type lept_get_type(const lept_value &v);
35+
36+
double lept_get_number(const lept_value &v);
37+
38+
//获得lept.string
39+
char *lept_get_string(const lept_value &v);
40+
41+
//获得lept.string_length
42+
int lept_get_string_length(const lept_value &v);
43+
44+
45+
46+
47+
#include<cstring>
48+
#include<cassert>
49+
50+
void lept_set_string(lept_value &v, const char* s, size_t len);
2151

22-
int lept_parse(lept_value &v, const char *json); // equlity a json if ok
23-
lept_type lept_get_type(const lept_value& v); //parse lept_value is what lept_type
52+
void lept_free(lept_value &v);
2453

54+
#define lept_init(v) do{ v.type = lept_type::LNULL; }while(0)
2555

2656

2757
#endif // !LEPTJSON_H__

0 commit comments

Comments
 (0)