Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
943d6410
Unverified
Commit
943d6410
authored
Mar 18, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
some refactoring
parent
22929fe1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
94 deletions
+74
-94
json_sax.hpp
include/nlohmann/detail/input/json_sax.hpp
+22
-32
parser.hpp
include/nlohmann/detail/input/parser.hpp
+15
-15
json.hpp
single_include/nlohmann/json.hpp
+37
-47
No files found.
include/nlohmann/detail/input/json_sax.hpp
View file @
943d6410
...
@@ -278,23 +278,17 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -278,23 +278,17 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
}
}
else
else
{
{
switch
(
ref_stack
.
back
()
->
m_type
)
assert
(
ref_stack
.
back
()
->
is_array
()
or
ref_stack
.
back
()
->
is_object
());
if
(
ref_stack
.
back
()
->
is_array
())
{
{
case
value_t
:
:
array
:
ref_stack
.
back
()
->
m_value
.
array
->
emplace_back
(
std
::
forward
<
Value
>
(
v
));
{
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
ref_stack
.
back
()
->
m_value
.
array
->
push_back
(
BasicJsonType
(
std
::
forward
<
Value
>
(
v
)));
}
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
else
}
{
assert
(
object_element
);
case
value_t
:
:
object
:
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
{
return
object_element
;
assert
(
object_element
);
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
return
object_element
;
}
default
:
assert
(
false
);
// LCOV_EXCL_LINE
}
}
}
}
}
}
...
@@ -397,6 +391,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
...
@@ -397,6 +391,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
object_end
,
*
ref_stack
.
back
());
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
object_end
,
*
ref_stack
.
back
());
if
(
not
keep
)
if
(
not
keep
)
{
{
// discard object
*
ref_stack
.
back
()
=
discarded
;
*
ref_stack
.
back
()
=
discarded
;
}
}
...
@@ -426,6 +421,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
...
@@ -426,6 +421,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
array_end
,
*
ref_stack
.
back
());
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
array_end
,
*
ref_stack
.
back
());
if
(
not
keep
)
if
(
not
keep
)
{
{
// discard array
*
ref_stack
.
back
()
=
discarded
;
*
ref_stack
.
back
()
=
discarded
;
}
}
...
@@ -487,23 +483,17 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
...
@@ -487,23 +483,17 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
}
}
else
else
{
{
switch
(
ref_stack
.
back
()
->
m_type
)
assert
(
ref_stack
.
back
()
->
is_array
()
or
ref_stack
.
back
()
->
is_object
());
if
(
ref_stack
.
back
()
->
is_array
())
{
{
case
value_t
:
:
array
:
ref_stack
.
back
()
->
m_value
.
array
->
emplace_back
(
std
::
forward
<
Value
>
(
v
));
{
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
ref_stack
.
back
()
->
m_value
.
array
->
push_back
(
BasicJsonType
(
std
::
forward
<
Value
>
(
v
)));
}
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
else
}
{
assert
(
object_element
);
case
value_t
:
:
object
:
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
{
return
object_element
;
assert
(
object_element
);
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
return
object_element
;
}
default
:
assert
(
false
);
// LCOV_EXCL_LINE
}
}
}
}
}
}
...
...
include/nlohmann/detail/input/parser.hpp
View file @
943d6410
...
@@ -468,7 +468,7 @@ class parser
...
@@ -468,7 +468,7 @@ class parser
{
{
case
token_type
:
:
begin_object
:
case
token_type
:
:
begin_object
:
{
{
if
(
not
sax
->
start_object
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -479,7 +479,7 @@ class parser
...
@@ -479,7 +479,7 @@ class parser
// closing } -> we are done
// closing } -> we are done
if
(
last_token
==
token_type
::
end_object
)
if
(
last_token
==
token_type
::
end_object
)
{
{
if
(
not
sax
->
end_object
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_object
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -495,7 +495,7 @@ class parser
...
@@ -495,7 +495,7 @@ class parser
}
}
else
else
{
{
if
(
not
sax
->
key
(
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -520,7 +520,7 @@ class parser
...
@@ -520,7 +520,7 @@ class parser
case
token_type
:
:
begin_array
:
case
token_type
:
:
begin_array
:
{
{
if
(
not
sax
->
start_array
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -531,7 +531,7 @@ class parser
...
@@ -531,7 +531,7 @@ class parser
// closing ] -> we are done
// closing ] -> we are done
if
(
last_token
==
token_type
::
end_array
)
if
(
last_token
==
token_type
::
end_array
)
{
{
if
(
not
sax
->
end_array
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_array
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -557,7 +557,7 @@ class parser
...
@@ -557,7 +557,7 @@ class parser
}
}
else
else
{
{
if
(
not
sax
->
number_float
(
res
,
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
number_float
(
res
,
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -567,7 +567,7 @@ class parser
...
@@ -567,7 +567,7 @@ class parser
case
token_type
:
:
literal_false
:
case
token_type
:
:
literal_false
:
{
{
if
(
not
sax
->
boolean
(
false
))
if
(
JSON_UNLIKELY
(
not
sax
->
boolean
(
false
)
))
{
{
return
false
;
return
false
;
}
}
...
@@ -576,7 +576,7 @@ class parser
...
@@ -576,7 +576,7 @@ class parser
case
token_type
:
:
literal_null
:
case
token_type
:
:
literal_null
:
{
{
if
(
not
sax
->
null
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
null
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -585,7 +585,7 @@ class parser
...
@@ -585,7 +585,7 @@ class parser
case
token_type
:
:
literal_true
:
case
token_type
:
:
literal_true
:
{
{
if
(
not
sax
->
boolean
(
true
))
if
(
JSON_UNLIKELY
(
not
sax
->
boolean
(
true
)
))
{
{
return
false
;
return
false
;
}
}
...
@@ -594,7 +594,7 @@ class parser
...
@@ -594,7 +594,7 @@ class parser
case
token_type
:
:
value_integer
:
case
token_type
:
:
value_integer
:
{
{
if
(
not
sax
->
number_integer
(
m_lexer
.
get_number_integer
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
number_integer
(
m_lexer
.
get_number_integer
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -603,7 +603,7 @@ class parser
...
@@ -603,7 +603,7 @@ class parser
case
token_type
:
:
value_string
:
case
token_type
:
:
value_string
:
{
{
if
(
not
sax
->
string
(
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
string
(
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -612,7 +612,7 @@ class parser
...
@@ -612,7 +612,7 @@ class parser
case
token_type
:
:
value_unsigned
:
case
token_type
:
:
value_unsigned
:
{
{
if
(
not
sax
->
number_unsigned
(
m_lexer
.
get_number_unsigned
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
number_unsigned
(
m_lexer
.
get_number_unsigned
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -664,7 +664,7 @@ class parser
...
@@ -664,7 +664,7 @@ class parser
// closing ]
// closing ]
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_array
))
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_array
))
{
{
if
(
not
sax
->
end_array
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_array
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -703,7 +703,7 @@ class parser
...
@@ -703,7 +703,7 @@ class parser
}
}
else
else
{
{
if
(
not
sax
->
key
(
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -726,7 +726,7 @@ class parser
...
@@ -726,7 +726,7 @@ class parser
// closing }
// closing }
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_object
))
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_object
))
{
{
if
(
not
sax
->
end_object
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_object
()
))
{
{
return
false
;
return
false
;
}
}
...
...
single_include/nlohmann/json.hpp
View file @
943d6410
...
@@ -3415,23 +3415,17 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -3415,23 +3415,17 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
}
}
else
else
{
{
switch
(
ref_stack
.
back
()
->
m_type
)
assert
(
ref_stack
.
back
()
->
is_array
()
or
ref_stack
.
back
()
->
is_object
());
if
(
ref_stack
.
back
()
->
is_array
())
{
{
case
value_t
:
:
array
:
ref_stack
.
back
()
->
m_value
.
array
->
emplace_back
(
std
::
forward
<
Value
>
(
v
));
{
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
ref_stack
.
back
()
->
m_value
.
array
->
push_back
(
BasicJsonType
(
std
::
forward
<
Value
>
(
v
)));
}
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
else
}
{
assert
(
object_element
);
case
value_t
:
:
object
:
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
{
return
object_element
;
assert
(
object_element
);
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
return
object_element
;
}
default
:
assert
(
false
);
// LCOV_EXCL_LINE
}
}
}
}
}
}
...
@@ -3534,6 +3528,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
...
@@ -3534,6 +3528,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
object_end
,
*
ref_stack
.
back
());
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
object_end
,
*
ref_stack
.
back
());
if
(
not
keep
)
if
(
not
keep
)
{
{
// discard object
*
ref_stack
.
back
()
=
discarded
;
*
ref_stack
.
back
()
=
discarded
;
}
}
...
@@ -3563,6 +3558,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
...
@@ -3563,6 +3558,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
array_end
,
*
ref_stack
.
back
());
const
bool
keep
=
callback
(
ref_stack
.
size
()
-
1
,
parse_event_t
::
array_end
,
*
ref_stack
.
back
());
if
(
not
keep
)
if
(
not
keep
)
{
{
// discard array
*
ref_stack
.
back
()
=
discarded
;
*
ref_stack
.
back
()
=
discarded
;
}
}
...
@@ -3624,23 +3620,17 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
...
@@ -3624,23 +3620,17 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
}
}
else
else
{
{
switch
(
ref_stack
.
back
()
->
m_type
)
assert
(
ref_stack
.
back
()
->
is_array
()
or
ref_stack
.
back
()
->
is_object
());
if
(
ref_stack
.
back
()
->
is_array
())
{
{
case
value_t
:
:
array
:
ref_stack
.
back
()
->
m_value
.
array
->
emplace_back
(
std
::
forward
<
Value
>
(
v
));
{
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
ref_stack
.
back
()
->
m_value
.
array
->
push_back
(
BasicJsonType
(
std
::
forward
<
Value
>
(
v
)));
}
return
&
(
ref_stack
.
back
()
->
m_value
.
array
->
back
());
else
}
{
assert
(
object_element
);
case
value_t
:
:
object
:
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
{
return
object_element
;
assert
(
object_element
);
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
return
object_element
;
}
default
:
assert
(
false
);
// LCOV_EXCL_LINE
}
}
}
}
}
}
...
@@ -4201,7 +4191,7 @@ class parser
...
@@ -4201,7 +4191,7 @@ class parser
{
{
case
token_type
:
:
begin_object
:
case
token_type
:
:
begin_object
:
{
{
if
(
not
sax
->
start_object
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4212,7 +4202,7 @@ class parser
...
@@ -4212,7 +4202,7 @@ class parser
// closing } -> we are done
// closing } -> we are done
if
(
last_token
==
token_type
::
end_object
)
if
(
last_token
==
token_type
::
end_object
)
{
{
if
(
not
sax
->
end_object
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_object
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4228,7 +4218,7 @@ class parser
...
@@ -4228,7 +4218,7 @@ class parser
}
}
else
else
{
{
if
(
not
sax
->
key
(
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -4253,7 +4243,7 @@ class parser
...
@@ -4253,7 +4243,7 @@ class parser
case
token_type
:
:
begin_array
:
case
token_type
:
:
begin_array
:
{
{
if
(
not
sax
->
start_array
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4264,7 +4254,7 @@ class parser
...
@@ -4264,7 +4254,7 @@ class parser
// closing ] -> we are done
// closing ] -> we are done
if
(
last_token
==
token_type
::
end_array
)
if
(
last_token
==
token_type
::
end_array
)
{
{
if
(
not
sax
->
end_array
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_array
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4290,7 +4280,7 @@ class parser
...
@@ -4290,7 +4280,7 @@ class parser
}
}
else
else
{
{
if
(
not
sax
->
number_float
(
res
,
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
number_float
(
res
,
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -4300,7 +4290,7 @@ class parser
...
@@ -4300,7 +4290,7 @@ class parser
case
token_type
:
:
literal_false
:
case
token_type
:
:
literal_false
:
{
{
if
(
not
sax
->
boolean
(
false
))
if
(
JSON_UNLIKELY
(
not
sax
->
boolean
(
false
)
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4309,7 +4299,7 @@ class parser
...
@@ -4309,7 +4299,7 @@ class parser
case
token_type
:
:
literal_null
:
case
token_type
:
:
literal_null
:
{
{
if
(
not
sax
->
null
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
null
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4318,7 +4308,7 @@ class parser
...
@@ -4318,7 +4308,7 @@ class parser
case
token_type
:
:
literal_true
:
case
token_type
:
:
literal_true
:
{
{
if
(
not
sax
->
boolean
(
true
))
if
(
JSON_UNLIKELY
(
not
sax
->
boolean
(
true
)
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4327,7 +4317,7 @@ class parser
...
@@ -4327,7 +4317,7 @@ class parser
case
token_type
:
:
value_integer
:
case
token_type
:
:
value_integer
:
{
{
if
(
not
sax
->
number_integer
(
m_lexer
.
get_number_integer
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
number_integer
(
m_lexer
.
get_number_integer
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -4336,7 +4326,7 @@ class parser
...
@@ -4336,7 +4326,7 @@ class parser
case
token_type
:
:
value_string
:
case
token_type
:
:
value_string
:
{
{
if
(
not
sax
->
string
(
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
string
(
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -4345,7 +4335,7 @@ class parser
...
@@ -4345,7 +4335,7 @@ class parser
case
token_type
:
:
value_unsigned
:
case
token_type
:
:
value_unsigned
:
{
{
if
(
not
sax
->
number_unsigned
(
m_lexer
.
get_number_unsigned
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
number_unsigned
(
m_lexer
.
get_number_unsigned
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -4397,7 +4387,7 @@ class parser
...
@@ -4397,7 +4387,7 @@ class parser
// closing ]
// closing ]
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_array
))
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_array
))
{
{
if
(
not
sax
->
end_array
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_array
()
))
{
{
return
false
;
return
false
;
}
}
...
@@ -4436,7 +4426,7 @@ class parser
...
@@ -4436,7 +4426,7 @@ class parser
}
}
else
else
{
{
if
(
not
sax
->
key
(
m_lexer
.
move_string
(
)))
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
move_string
()
)))
{
{
return
false
;
return
false
;
}
}
...
@@ -4459,7 +4449,7 @@ class parser
...
@@ -4459,7 +4449,7 @@ class parser
// closing }
// closing }
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_object
))
if
(
JSON_LIKELY
(
last_token
==
token_type
::
end_object
))
{
{
if
(
not
sax
->
end_object
(
))
if
(
JSON_UNLIKELY
(
not
sax
->
end_object
()
))
{
{
return
false
;
return
false
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment