Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
4f6b2b64
Unverified
Commit
4f6b2b64
authored
Mar 21, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
changed SAX interface
parent
2537677e
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
91 additions
and
83 deletions
+91
-83
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+21
-17
include/nlohmann/detail/input/json_sax.hpp
include/nlohmann/detail/input/json_sax.hpp
+9
-9
include/nlohmann/detail/input/lexer.hpp
include/nlohmann/detail/input/lexer.hpp
+2
-2
include/nlohmann/detail/input/parser.hpp
include/nlohmann/detail/input/parser.hpp
+6
-6
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+38
-34
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+2
-2
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+4
-4
test/src/unit-deserialization.cpp
test/src/unit-deserialization.cpp
+3
-3
test/src/unit-msgpack.cpp
test/src/unit-msgpack.cpp
+2
-2
test/src/unit-ubjson.cpp
test/src/unit-ubjson.cpp
+4
-4
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
4f6b2b64
...
...
@@ -267,7 +267,7 @@ class binary_reader
case
0x7F
:
// UTF-8 string (indefinite length)
{
string_t
s
;
return
get_cbor_string
(
s
)
and
sax
->
string
(
s
td
::
move
(
s
)
);
return
get_cbor_string
(
s
)
and
sax
->
string
(
s
);
}
// array (0x00..0x17 data items follow)
...
...
@@ -663,7 +663,7 @@ class binary_reader
case
0xBF
:
{
string_t
s
;
return
get_msgpack_string
(
s
)
and
sax
->
string
(
s
td
::
move
(
s
)
);
return
get_msgpack_string
(
s
)
and
sax
->
string
(
s
);
}
case
0xC0
:
// nil
...
...
@@ -740,7 +740,7 @@ class binary_reader
case
0xDB
:
// str 32
{
string_t
s
;
return
get_msgpack_string
(
s
)
and
sax
->
string
(
s
td
::
move
(
s
)
);
return
get_msgpack_string
(
s
)
and
sax
->
string
(
s
);
}
case
0xDC
:
// array 16
...
...
@@ -1062,13 +1062,13 @@ class binary_reader
return
false
;
}
string_t
key
;
if
(
len
!=
json_sax_t
::
no_limit
)
{
for
(
std
::
size_t
i
=
0
;
i
<
len
;
++
i
)
{
get
();
string_t
key
;
if
(
JSON_UNLIKELY
(
not
get_cbor_string
(
key
)
or
not
sax
->
key
(
std
::
move
(
key
))))
if
(
JSON_UNLIKELY
(
not
get_cbor_string
(
key
)
or
not
sax
->
key
(
key
)))
{
return
false
;
}
...
...
@@ -1077,14 +1077,14 @@ class binary_reader
{
return
false
;
}
key
.
clear
();
}
}
else
{
while
(
get
()
!=
0xFF
)
{
string_t
key
;
if
(
JSON_UNLIKELY
(
not
get_cbor_string
(
key
)
or
not
sax
->
key
(
std
::
move
(
key
))))
if
(
JSON_UNLIKELY
(
not
get_cbor_string
(
key
)
or
not
sax
->
key
(
key
)))
{
return
false
;
}
...
...
@@ -1093,6 +1093,7 @@ class binary_reader
{
return
false
;
}
key
.
clear
();
}
}
...
...
@@ -1214,11 +1215,11 @@ class binary_reader
return
false
;
}
string_t
key
;
for
(
std
::
size_t
i
=
0
;
i
<
len
;
++
i
)
{
get
();
string_t
key
;
if
(
JSON_UNLIKELY
(
not
get_msgpack_string
(
key
)
or
not
sax
->
key
(
std
::
move
(
key
))))
if
(
JSON_UNLIKELY
(
not
get_msgpack_string
(
key
)
or
not
sax
->
key
(
key
)))
{
return
false
;
}
...
...
@@ -1227,6 +1228,7 @@ class binary_reader
{
return
false
;
}
key
.
clear
();
}
return
sax
->
end_object
();
...
...
@@ -1485,13 +1487,14 @@ class binary_reader
auto
last_token
=
get_token_string
();
return
sax
->
parse_error
(
chars_read
,
last_token
,
parse_error
::
create
(
113
,
chars_read
,
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x"
+
last_token
));
}
return
sax
->
string
(
string_t
(
1
,
static_cast
<
char
>
(
current
)));
string_t
s
(
1
,
static_cast
<
char
>
(
current
));
return
sax
->
string
(
s
);
}
case
'S'
:
// string
{
string_t
s
;
return
get_ubjson_string
(
s
)
and
sax
->
string
(
s
td
::
move
(
s
)
);
return
get_ubjson_string
(
s
)
and
sax
->
string
(
s
);
}
case
'['
:
// array
...
...
@@ -1581,6 +1584,7 @@ class binary_reader
return
false
;
}
string_t
key
;
if
(
size_and_type
.
first
!=
string_t
::
npos
)
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
(
size_and_type
.
first
)))
...
...
@@ -1592,8 +1596,7 @@ class binary_reader
{
for
(
std
::
size_t
i
=
0
;
i
<
size_and_type
.
first
;
++
i
)
{
string_t
key
;
if
(
JSON_UNLIKELY
(
not
get_ubjson_string
(
key
)
or
not
sax
->
key
(
std
::
move
(
key
))))
if
(
JSON_UNLIKELY
(
not
get_ubjson_string
(
key
)
or
not
sax
->
key
(
key
)))
{
return
false
;
}
...
...
@@ -1601,14 +1604,14 @@ class binary_reader
{
return
false
;
}
key
.
clear
();
}
}
else
{
for
(
std
::
size_t
i
=
0
;
i
<
size_and_type
.
first
;
++
i
)
{
string_t
key
;
if
(
JSON_UNLIKELY
(
not
get_ubjson_string
(
key
)
or
not
sax
->
key
(
std
::
move
(
key
))))
if
(
JSON_UNLIKELY
(
not
get_ubjson_string
(
key
)
or
not
sax
->
key
(
key
)))
{
return
false
;
}
...
...
@@ -1616,6 +1619,7 @@ class binary_reader
{
return
false
;
}
key
.
clear
();
}
}
}
...
...
@@ -1628,8 +1632,7 @@ class binary_reader
while
(
current
!=
'}'
)
{
string_t
key
;
if
(
JSON_UNLIKELY
(
not
get_ubjson_string
(
key
,
false
)
or
not
sax
->
key
(
std
::
move
(
key
))))
if
(
JSON_UNLIKELY
(
not
get_ubjson_string
(
key
,
false
)
or
not
sax
->
key
(
key
)))
{
return
false
;
}
...
...
@@ -1638,6 +1641,7 @@ class binary_reader
return
false
;
}
get_ignore_noop
();
key
.
clear
();
}
}
...
...
include/nlohmann/detail/input/json_sax.hpp
View file @
4f6b2b64
...
...
@@ -68,7 +68,7 @@ struct json_sax
@param[in] val string value
@return whether parsing should proceed
*/
virtual
bool
string
(
string_t
&
&
val
)
=
0
;
virtual
bool
string
(
string_t
&
val
)
=
0
;
/*!
@brief the beginning of an object was read
...
...
@@ -83,7 +83,7 @@ struct json_sax
@param[in] val object key
@return whether parsing should proceed
*/
virtual
bool
key
(
string_t
&
&
val
)
=
0
;
virtual
bool
key
(
string_t
&
val
)
=
0
;
/*!
@brief the end of an object was read
...
...
@@ -165,7 +165,7 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
string
(
string_t
&
&
val
)
override
bool
string
(
string_t
&
val
)
override
{
handle_value
(
val
);
return
true
;
...
...
@@ -184,7 +184,7 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
key
(
string_t
&
&
val
)
override
bool
key
(
string_t
&
val
)
override
{
// add null at given key and store the reference for later
object_element
=
&
(
ref_stack
.
back
()
->
m_value
.
object
->
operator
[](
val
));
...
...
@@ -340,7 +340,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
string
(
string_t
&
&
val
)
override
bool
string
(
string_t
&
val
)
override
{
handle_value
(
val
);
return
true
;
...
...
@@ -362,9 +362,9 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
key
(
string_t
&
&
val
)
override
bool
key
(
string_t
&
val
)
override
{
BasicJsonType
k
=
BasicJsonType
(
std
::
forward
<
string_t
&&
>
(
val
)
);
BasicJsonType
k
=
BasicJsonType
(
val
);
const
bool
keep
=
callback
(
ref_stack
.
size
(),
parse_event_t
::
key
,
k
);
// add null at given key and store the reference for later
...
...
@@ -531,7 +531,7 @@ class json_sax_acceptor : public json_sax<BasicJsonType>
return
true
;
}
bool
string
(
string_t
&
&
)
override
bool
string
(
string_t
&
)
override
{
return
true
;
}
...
...
@@ -541,7 +541,7 @@ class json_sax_acceptor : public json_sax<BasicJsonType>
return
true
;
}
bool
key
(
string_t
&
&
)
override
bool
key
(
string_t
&
)
override
{
return
true
;
}
...
...
include/nlohmann/detail/input/lexer.hpp
View file @
4f6b2b64
...
...
@@ -1131,9 +1131,9 @@ scan_number_done:
}
/// return current string value (implicitly resets the token; useful only once)
string_t
&
&
move
_string
()
string_t
&
get
_string
()
{
return
std
::
move
(
token_buffer
)
;
return
token_buffer
;
}
/////////////////////
...
...
include/nlohmann/detail/input/parser.hpp
View file @
4f6b2b64
...
...
@@ -239,7 +239,7 @@ class parser
{
return
;
}
key
=
m_lexer
.
move
_string
();
key
=
m_lexer
.
get
_string
();
bool
keep_tag
=
false
;
if
(
keep
)
...
...
@@ -375,7 +375,7 @@ class parser
case
token_type
:
:
value_string
:
{
result
.
m_type
=
value_t
::
string
;
result
.
m_value
=
m_lexer
.
move
_string
();
result
.
m_value
=
m_lexer
.
get
_string
();
break
;
}
...
...
@@ -498,7 +498,7 @@ class parser
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
move
_string
())))
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
get
_string
())))
{
return
false
;
}
...
...
@@ -560,7 +560,7 @@ class parser
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
number_float
(
res
,
m_lexer
.
move
_string
())))
if
(
JSON_UNLIKELY
(
not
sax
->
number_float
(
res
,
m_lexer
.
get
_string
())))
{
return
false
;
}
...
...
@@ -606,7 +606,7 @@ class parser
case
token_type
:
:
value_string
:
{
if
(
JSON_UNLIKELY
(
not
sax
->
string
(
m_lexer
.
move
_string
())))
if
(
JSON_UNLIKELY
(
not
sax
->
string
(
m_lexer
.
get
_string
())))
{
return
false
;
}
...
...
@@ -706,7 +706,7 @@ class parser
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
move
_string
())))
if
(
JSON_UNLIKELY
(
not
sax
->
key
(
m_lexer
.
get
_string
())))
{
return
false
;
}
...
...
single_include/nlohmann/json.hpp
View file @
4f6b2b64
This diff is collapsed.
Click to expand it.
test/src/unit-cbor.cpp
View file @
4f6b2b64
...
...
@@ -64,7 +64,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
&
)
override
bool
string
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
@@ -74,7 +74,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
&
)
override
bool
key
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
test/src/unit-class_parser.cpp
View file @
4f6b2b64
...
...
@@ -67,7 +67,7 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
string
(
std
::
string
&
&
val
)
override
bool
string
(
std
::
string
&
val
)
override
{
events
.
push_back
(
"string("
+
val
+
")"
);
return
true
;
...
...
@@ -86,7 +86,7 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
key
(
std
::
string
&
&
val
)
override
bool
key
(
std
::
string
&
val
)
override
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
true
;
...
...
@@ -159,7 +159,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
&
)
override
bool
string
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
@@ -169,7 +169,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
&
)
override
bool
key
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
test/src/unit-deserialization.cpp
View file @
4f6b2b64
...
...
@@ -66,7 +66,7 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
string
(
std
::
string
&
&
val
)
override
bool
string
(
std
::
string
&
val
)
override
{
events
.
push_back
(
"string("
+
val
+
")"
);
return
true
;
...
...
@@ -85,7 +85,7 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
key
(
std
::
string
&
&
val
)
override
bool
key
(
std
::
string
&
val
)
override
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
true
;
...
...
@@ -143,7 +143,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
struct
SaxEventLoggerExitAfterKey
:
public
SaxEventLogger
{
bool
key
(
std
::
string
&
&
val
)
override
bool
key
(
std
::
string
&
val
)
override
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
false
;
...
...
test/src/unit-msgpack.cpp
View file @
4f6b2b64
...
...
@@ -64,7 +64,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
&
)
override
bool
string
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
@@ -74,7 +74,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
&
)
override
bool
key
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
test/src/unit-ubjson.cpp
View file @
4f6b2b64
...
...
@@ -64,7 +64,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
&
)
override
bool
string
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
@@ -74,7 +74,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
&
)
override
bool
key
(
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
...
...
@@ -1668,12 +1668,12 @@ TEST_CASE("UBJSON")
std
::
vector
<
uint8_t
>
vST1
=
{
'{'
,
'$'
,
'd'
,
'#'
,
'i'
,
2
,
'i'
,
1
,
'a'
};
CHECK_THROWS_AS
(
json
::
from_ubjson
(
vST1
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
json
::
from_ubjson
(
vST1
),
"[json.exception.parse_error.110] parse error at 10: unexpected end of input"
);
CHECK
(
json
::
from_ubjson
(
vST1
,
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_ubjson
(
vST1
,
true
,
false
).
is_discarded
());
std
::
vector
<
uint8_t
>
vST2
=
{
'{'
,
'#'
,
'i'
,
2
,
'i'
,
1
,
'a'
};
CHECK_THROWS_AS
(
json
::
from_ubjson
(
vST2
),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
json
::
from_ubjson
(
vST2
),
"[json.exception.parse_error.110] parse error at 8: unexpected end of input"
);
CHECK
(
json
::
from_ubjson
(
vST2
,
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_ubjson
(
vST2
,
true
,
false
).
is_discarded
());
}
}
...
...
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