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
8c1d26e1
Unverified
Commit
8c1d26e1
authored
4 years ago
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add documentation and example for accept function
parent
543dcee3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
2 deletions
+84
-2
doc/examples/accept__string.cpp
doc/examples/accept__string.cpp
+26
-0
doc/examples/accept__string.link
doc/examples/accept__string.link
+1
-0
doc/examples/accept__string.output
doc/examples/accept__string.output
+1
-0
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+28
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+28
-1
No files found.
doc/examples/accept__string.cpp
0 → 100644
View file @
8c1d26e1
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using
json
=
nlohmann
::
json
;
int
main
()
{
// a valid JSON text
auto
valid_text
=
R"(
{
"numbers": [1, 2, 3]
}
)"
;
// an invalid JSON text
auto
invalid_text
=
R"(
{
"strings": ["extra", "comma", ]
}
)"
;
std
::
cout
<<
std
::
boolalpha
<<
json
::
accept
(
valid_text
)
<<
' '
<<
json
::
accept
(
invalid_text
)
<<
'\n'
;
}
This diff is collapsed.
Click to expand it.
doc/examples/accept__string.link
0 → 100644
View file @
8c1d26e1
<a target="_blank" href="https://wandbox.org/permlink/r5Tai1spihWHTdFA"><b>online</b></a>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
doc/examples/accept__string.output
0 → 100644
View file @
8c1d26e1
true false
This diff is collapsed.
Click to expand it.
include/nlohmann/json.hpp
View file @
8c1d26e1
...
@@ -6549,7 +6549,7 @@ class basic_json
...
@@ -6549,7 +6549,7 @@ class basic_json
/*!
/*!
@brief deserialize from a compatible input
@brief deserialize from a compatible input
This function reads from a compatible input. Examples are:
@tparam InputType A compatible input, for instance
- an std::istream object
- an std::istream object
- a FILE pointer
- a FILE pointer
- a C-style array of characters
- a C-style array of characters
...
@@ -6650,6 +6650,33 @@ class basic_json
...
@@ -6650,6 +6650,33 @@ class basic_json
return
result
;
return
result
;
}
}
/*!
@brief check if the input is valid JSON
Unlike the @ref parse(InputType&&, const parser_callback_t,const bool)
function, this function neither throws an exception in case of invalid JSON
input (i.e., a parse error) nor creates diagnostic information.
@tparam InputType A compatible input, for instance
- an std::istream object
- a FILE pointer
- a C-style array of characters
- a pointer to a null-terminated string of single byte characters
- an object obj for which begin(obj) and end(obj) produces a valid pair of
iterators.
@param[in] i input to read from
@return Whether the input read from @a i is valid JSON.
@complexity Linear in the length of the input. The parser is a predictive
LL(1) parser.
@note A UTF-8 byte order mark is silently ignored.
@liveexample{The example below demonstrates the `accept()` function reading
from a string.,accept__string}
*/
template
<
typename
InputType
>
template
<
typename
InputType
>
static
bool
accept
(
InputType
&&
i
)
static
bool
accept
(
InputType
&&
i
)
{
{
...
...
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
8c1d26e1
...
@@ -22327,7 +22327,7 @@ class basic_json
...
@@ -22327,7 +22327,7 @@ class basic_json
/*!
/*!
@brief deserialize from a compatible input
@brief deserialize from a compatible input
This function reads from a compatible input. Examples are:
@tparam InputType A compatible input, for instance
- an std::istream object
- an std::istream object
- a FILE pointer
- a FILE pointer
- a C-style array of characters
- a C-style array of characters
...
@@ -22428,6 +22428,33 @@ class basic_json
...
@@ -22428,6 +22428,33 @@ class basic_json
return
result
;
return
result
;
}
}
/*!
@brief check if the input is valid JSON
Unlike the @ref parse(InputType&&, const parser_callback_t,const bool)
function, this function neither throws an exception in case of invalid JSON
input (i.e., a parse error) nor creates diagnostic information.
@tparam InputType A compatible input, for instance
- an std::istream object
- a FILE pointer
- a C-style array of characters
- a pointer to a null-terminated string of single byte characters
- an object obj for which begin(obj) and end(obj) produces a valid pair of
iterators.
@param[in] i input to read from
@return Whether the input read from @a i is valid JSON.
@complexity Linear in the length of the input. The parser is a predictive
LL(1) parser.
@note A UTF-8 byte order mark is silently ignored.
@liveexample{The example below demonstrates the `accept()` function reading
from a string.,accept__string}
*/
template
<
typename
InputType
>
template
<
typename
InputType
>
static
bool
accept
(
InputType
&&
i
)
static
bool
accept
(
InputType
&&
i
)
{
{
...
...
This diff is collapsed.
Click to expand it.
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