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
faf2546a
Unverified
Commit
faf2546a
authored
Mar 06, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
simplified SAX-DOM parser
parent
5b9d03cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
json_sax.hpp
include/nlohmann/detail/input/json_sax.hpp
+7
-5
json.hpp
single_include/nlohmann/json.hpp
+7
-5
No files found.
include/nlohmann/detail/input/json_sax.hpp
View file @
faf2546a
...
@@ -176,7 +176,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -176,7 +176,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
bool
key
(
std
::
string
&&
val
)
override
bool
key
(
std
::
string
&&
val
)
override
{
{
last_key
=
val
;
// add null at given key and store the reference for later
object_element
=
&
(
ref_stack
.
back
()
->
m_value
.
object
->
operator
[](
val
));
return
true
;
return
true
;
}
}
...
@@ -219,8 +220,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -219,8 +220,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
BasicJsonType
root
;
BasicJsonType
root
;
/// stack to model hierarchy of values
/// stack to model hierarchy of values
std
::
vector
<
BasicJsonType
*>
ref_stack
;
std
::
vector
<
BasicJsonType
*>
ref_stack
;
/// helper
variable for object keys
/// helper
to hold the reference for the next object element
std
::
string
last_key
;
BasicJsonType
*
object_element
=
nullptr
;
/*!
/*!
@invariant If the ref stack is empty, then the passed value will be the new
@invariant If the ref stack is empty, then the passed value will be the new
...
@@ -247,8 +248,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -247,8 +248,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
}
}
else
else
{
{
BasicJsonType
&
r
=
ref_stack
.
back
()
->
m_value
.
object
->
operator
[](
last_key
)
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
assert
(
object_element
);
return
&
r
;
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
return
object_element
;
}
}
}
}
}
}
...
...
single_include/nlohmann/json.hpp
View file @
faf2546a
...
@@ -3310,7 +3310,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -3310,7 +3310,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
bool
key
(
std
::
string
&&
val
)
override
bool
key
(
std
::
string
&&
val
)
override
{
{
last_key
=
val
;
// add null at given key and store the reference for later
object_element
=
&
(
ref_stack
.
back
()
->
m_value
.
object
->
operator
[](
val
));
return
true
;
return
true
;
}
}
...
@@ -3353,8 +3354,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -3353,8 +3354,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
BasicJsonType
root
;
BasicJsonType
root
;
/// stack to model hierarchy of values
/// stack to model hierarchy of values
std
::
vector
<
BasicJsonType
*>
ref_stack
;
std
::
vector
<
BasicJsonType
*>
ref_stack
;
/// helper
variable for object keys
/// helper
to hold the reference for the next object element
std
::
string
last_key
;
BasicJsonType
*
object_element
=
nullptr
;
/*!
/*!
@invariant If the ref stack is empty, then the passed value will be the new
@invariant If the ref stack is empty, then the passed value will be the new
...
@@ -3381,8 +3382,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
...
@@ -3381,8 +3382,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
}
}
else
else
{
{
BasicJsonType
&
r
=
ref_stack
.
back
()
->
m_value
.
object
->
operator
[](
last_key
)
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
assert
(
object_element
);
return
&
r
;
*
object_element
=
BasicJsonType
(
std
::
forward
<
Value
>
(
v
));
return
object_element
;
}
}
}
}
}
}
...
...
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