Skip to content

Commit 602c3c4

Browse files
committed
update cppjson source code
1 parent ee1be9b commit 602c3c4

File tree

8 files changed

+77
-19
lines changed

8 files changed

+77
-19
lines changed

cpp_json/JsonAPI/Jsonparser.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,17 @@ namespace Jsonparser{
8484
}
8585
}
8686

87-
PARSE_RESULT parser::parse_string_raw(char **str, size_t &len) {
87+
PARSE_RESULT parser::parse_string_raw(string & s) {
8888
size_t head = this->stk.top;
8989
unsigned u, u2;
9090
stk.expect('\"');
9191
while(true){
9292
char ch = *stk.json++;
9393
switch(ch){
9494
case '\"':{
95-
len = this->stk.top - head;
96-
*str = (char*)stk.pop(len);
95+
size_t len = this->stk.top - head;
96+
char * p = (char *)stk.pop(len);
97+
while(len--) s += *p++;
9798
return PARSE_OK;
9899
}
99100
case '\\':
@@ -140,9 +141,8 @@ namespace Jsonparser{
140141

141142
PARSE_RESULT parser::parse_string(){
142143
PARSE_RESULT ret;
143-
char * s;
144-
size_t len;
145-
if((ret = parse_string_raw(&s, len)) == PARSE_OK) {
144+
string s;
145+
if((ret = parse_string_raw(s)) == PARSE_OK) {
146146
j.set_string(s);
147147
}
148148
return ret;
@@ -216,13 +216,12 @@ namespace Jsonparser{
216216
}
217217
while(true){
218218
if(*stk.json != '\"') return PARSE_MISS_KEY;
219-
char * str;
220-
size_t len;
221-
if((ret = parse_string_raw(&str, len)) != PARSE_OK)
219+
string s;
220+
if((ret = parse_string_raw(s)) != PARSE_OK)
222221
return ret;
223222
//we parse key and value and then we make_pair
224223
stk.parse_whitespace();
225-
string key(str, len);
224+
string key(s);
226225
if(*stk.json != ':') return PARSE_MISS_COLON;
227226
stk.json++;
228227
stk.parse_whitespace();

cpp_json/JsonAPI/Jsonparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ constexpr int PARSER_STACK_INIT_SIZE = 256;
4141
private:
4242
PARSE_RESULT parse_literal(const char * literal, JSON::JSON_TYPE type);
4343

44-
PARSE_RESULT parse_string_raw(char ** str, size_t & len);
44+
PARSE_RESULT parse_string_raw(string & s);
4545

4646
PARSE_RESULT parse_string();
4747

cpp_json/cmake-build-debug/CMakeFiles/cpp_json.dir/CXX.includecache

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
#IncludeRegexTransform:
88

9-
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Json.cpp
10-
Json.h
11-
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Json.h
12-
139
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Json.h
1410
iostream
1511
-
@@ -26,3 +22,25 @@ memory
2622
cerrno
2723
-
2824

25+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Jsonparser.h
26+
stack.h
27+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/stack.h
28+
Json.h
29+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Json.h
30+
31+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Jsonstringifier.h
32+
stack.h
33+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/stack.h
34+
Json.h
35+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Json.h
36+
37+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/stack.h
38+
Json.h
39+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Json.h
40+
41+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/main.cpp
42+
JsonAPI/Jsonparser.h
43+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Jsonparser.h
44+
JsonAPI/Jsonstringifier.h
45+
/Users/wocaibujiaoquanmei/iCloud 云盘(归档)/GitHub/cppjson/cpp_json/JsonAPI/Jsonstringifier.h
46+
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Start testing: Dec 17 10:18 CST
1+
Start testing: Dec 18 18:29 CST
22
----------------------------------------------------------
3-
End testing: Dec 17 10:18 CST
3+
End testing: Dec 18 18:29 CST

cpp_json/cmake-build-debug/cpp_json

4.89 KB
Binary file not shown.

cpp_json/main.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,50 @@
77
int main() {
88
JSON::json j, j2;
99
Jsonparser::parser p(j);
10-
p.parse("{\"key\":[true, false, {\"1\":true}, {\"2\": false}, \"sfjdls\", [true, {\"a\": false}]]}");
10+
p.parse("{\n"
11+
" \"name\": \"vue_test\",\n"
12+
" \"version\": \"0.1.0\",\n"
13+
" \"private\": true,\n"
14+
" \"scripts\": {\n"
15+
" \"serve\": \"vue-cli-service serve\",\n"
16+
" \"build\": \"vue-cli-service build\",\n"
17+
" \"lint\": \"vue-cli-service lint\"\n"
18+
" },\n"
19+
" \"dependencies\": {\n"
20+
" \"core-js\": \"^3.6.5\",\n"
21+
" \"vue\": \"^2.6.11\"\n"
22+
" },\n"
23+
" \"devDependencies\": {\n"
24+
" \"@vue/cli-plugin-babel\": \"~4.5.0\",\n"
25+
" \"@vue/cli-plugin-eslint\": \"~4.5.0\",\n"
26+
" \"@vue/cli-service\": \"~4.5.0\",\n"
27+
" \"babel-eslint\": \"^10.1.0\",\n"
28+
" \"eslint\": \"^6.7.2\",\n"
29+
" \"eslint-plugin-vue\": \"^6.2.2\",\n"
30+
" \"vue-template-compiler\": \"^2.6.11\"\n"
31+
" },\n"
32+
" \"eslintConfig\": {\n"
33+
" \"root\": true,\n"
34+
" \"env\": {\n"
35+
" \"node\": true\n"
36+
" },\n"
37+
" \"extends\": [\n"
38+
" \"plugin:vue/essential\",\n"
39+
" \"eslint:recommended\"\n"
40+
" ],\n"
41+
" \"parserOptions\": {\n"
42+
" \"parser\": \"babel-eslint\"\n"
43+
" },\n"
44+
" \"rules\": {}\n"
45+
" },\n"
46+
" \"browserslist\": [\n"
47+
" \"> 1%\",\n"
48+
" \"last 2 versions\",\n"
49+
" \"not dead\"\n"
50+
" ]\n"
51+
"}");
1152
Jsonparser::parser p2(j2);
12-
p2.parse("{\"key\":[true, false, {\"1\":true}, {\"2\": false}, \"sfjdls\", [true, {\"a\": false}]]}");
53+
//p2.parse("{\"key\":[true, false, {\"1\":true}, {\"2\": false}, \"sfjdls\", [true, {\"a\": false}]]}");
1354
cout << j.get_type_format() << ' ' << endl;
1455
Jsonstringifier::stringifier g;
1556
cout << g.stringify(j);

0 commit comments

Comments
 (0)