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
149d2fd0
Unverified
Commit
149d2fd0
authored
Mar 10, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💚
improved test coverage
parent
6399cd30
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
49 deletions
+38
-49
include/nlohmann/detail/input/parser.hpp
include/nlohmann/detail/input/parser.hpp
+13
-24
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+13
-24
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+12
-1
No files found.
include/nlohmann/detail/input/parser.hpp
View file @
149d2fd0
...
...
@@ -164,6 +164,8 @@ class parser
{
// never parse after a parse error was detected
assert
(
not
errored
);
// this function is only called when a callback is given
assert
(
callback
);
// start with a discarded value
if
(
not
result
.
is_discarded
())
...
...
@@ -178,12 +180,9 @@ class parser
{
if
(
keep
)
{
if
(
callback
)
{
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
);
}
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
);
if
(
not
callback
or
keep
)
if
(
keep
)
{
// explicitly set result to object to cope with {}
result
.
m_type
=
value_t
::
object
;
...
...
@@ -197,7 +196,7 @@ class parser
// closing } -> we are done
if
(
last_token
==
token_type
::
end_object
)
{
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -220,15 +219,8 @@ class parser
bool
keep_tag
=
false
;
if
(
keep
)
{
if
(
callback
)
{
BasicJsonType
k
(
key
);
keep_tag
=
callback
(
depth
,
parse_event_t
::
key
,
k
);
}
else
{
keep_tag
=
true
;
}
BasicJsonType
k
(
key
);
keep_tag
=
callback
(
depth
,
parse_event_t
::
key
,
k
);
}
// parse separator (:)
...
...
@@ -270,7 +262,7 @@ class parser
break
;
}
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -282,12 +274,9 @@ class parser
{
if
(
keep
)
{
if
(
callback
)
{
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
);
}
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
);
if
(
not
callback
or
keep
)
if
(
keep
)
{
// explicitly set result to array to cope with []
result
.
m_type
=
value_t
::
array
;
...
...
@@ -301,7 +290,7 @@ class parser
// closing ] -> we are done
if
(
last_token
==
token_type
::
end_array
)
{
if
(
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -344,7 +333,7 @@ class parser
break
;
}
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -432,7 +421,7 @@ class parser
}
}
if
(
keep
and
callback
and
not
callback
(
depth
,
parse_event_t
::
value
,
result
))
if
(
keep
and
not
callback
(
depth
,
parse_event_t
::
value
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
single_include/nlohmann/json.hpp
View file @
149d2fd0
...
...
@@ -3641,6 +3641,8 @@ class parser
{
// never parse after a parse error was detected
assert
(
not
errored
);
// this function is only called when a callback is given
assert
(
callback
);
// start with a discarded value
if
(
not
result
.
is_discarded
())
...
...
@@ -3655,12 +3657,9 @@ class parser
{
if
(
keep
)
{
if
(
callback
)
{
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
);
}
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
);
if
(
not
callback
or
keep
)
if
(
keep
)
{
// explicitly set result to object to cope with {}
result
.
m_type
=
value_t
::
object
;
...
...
@@ -3674,7 +3673,7 @@ class parser
// closing } -> we are done
if
(
last_token
==
token_type
::
end_object
)
{
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -3697,15 +3696,8 @@ class parser
bool
keep_tag
=
false
;
if
(
keep
)
{
if
(
callback
)
{
BasicJsonType
k
(
key
);
keep_tag
=
callback
(
depth
,
parse_event_t
::
key
,
k
);
}
else
{
keep_tag
=
true
;
}
BasicJsonType
k
(
key
);
keep_tag
=
callback
(
depth
,
parse_event_t
::
key
,
k
);
}
// parse separator (:)
...
...
@@ -3747,7 +3739,7 @@ class parser
break
;
}
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -3759,12 +3751,9 @@ class parser
{
if
(
keep
)
{
if
(
callback
)
{
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
);
}
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
);
if
(
not
callback
or
keep
)
if
(
keep
)
{
// explicitly set result to array to cope with []
result
.
m_type
=
value_t
::
array
;
...
...
@@ -3778,7 +3767,7 @@ class parser
// closing ] -> we are done
if
(
last_token
==
token_type
::
end_array
)
{
if
(
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -3821,7 +3810,7 @@ class parser
break
;
}
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
@@ -3909,7 +3898,7 @@ class parser
}
}
if
(
keep
and
callback
and
not
callback
(
depth
,
parse_event_t
::
value
,
result
))
if
(
keep
and
not
callback
(
depth
,
parse_event_t
::
value
,
result
))
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
...
...
test/src/unit-class_parser.cpp
View file @
149d2fd0
...
...
@@ -176,7 +176,18 @@ bool accept_helper(const std::string& s)
CHECK_NOTHROW
(
json
::
sax_parse
(
s
,
&
el
));
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
)).
accept
(
false
)
==
not
el
.
errored
);
// 5. return result
// 5. parse with simple callback
json
::
parser_callback_t
cb
=
[](
int
,
json
::
parse_event_t
,
json
&
)
{
return
true
;
};
json
j_cb
=
json
::
parse
(
s
,
cb
,
false
);
const
bool
ok_noexcept_cb
=
not
j_cb
.
is_discarded
();
// 6. check if this approach came to the same result
CHECK
(
ok_noexcept
==
ok_noexcept_cb
);
// 7. return result
return
ok_accept
;
}
...
...
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