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
b27d2adc
Unverified
Commit
b27d2adc
authored
Jun 16, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
accept functions to check if input is valid JSON #458
parent
d415293d
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
4 deletions
+87
-4
src/json.hpp
src/json.hpp
+47
-0
test/src/unit-deserialization.cpp
test/src/unit-deserialization.cpp
+40
-4
No files found.
src/json.hpp
View file @
b27d2adc
...
...
@@ -7421,6 +7421,13 @@ class basic_json
return
parse
(
std
::
begin
(
array
),
std
::
end
(
array
),
cb
);
}
template
<
class
T
,
std
::
size_t
N
>
static
bool
accept
(
T
(
&
array
)[
N
])
{
// delegate the call to the iterator-range accept overload
return
accept
(
std
::
begin
(
array
),
std
::
end
(
array
));
}
/*!
@brief deserialize from string literal
...
...
@@ -7462,6 +7469,15 @@ class basic_json
return
parser
(
input_adapter
::
create
(
s
),
cb
).
parse
(
true
);
}
template
<
typename
CharT
,
typename
std
::
enable_if
<
std
::
is_pointer
<
CharT
>
::
value
and
std
::
is_integral
<
typename
std
::
remove_pointer
<
CharT
>::
type
>::
value
and
sizeof
(
typename
std
::
remove_pointer
<
CharT
>::
type
)
==
1
,
int
>::
type
=
0
>
static
bool
accept
(
const
CharT
s
)
{
return
parser
(
input_adapter
::
create
(
s
)).
accept
(
true
);
}
/*!
@brief deserialize from stream
...
...
@@ -7497,6 +7513,11 @@ class basic_json
return
parser
(
input_adapter
::
create
(
i
),
cb
).
parse
(
true
);
}
static
bool
accept
(
std
::
istream
&
i
)
{
return
parser
(
input_adapter
::
create
(
i
)).
accept
(
true
);
}
/*!
@copydoc parse(std::istream&, const parser_callback_t)
*/
...
...
@@ -7506,6 +7527,11 @@ class basic_json
return
parser
(
input_adapter
::
create
(
i
),
cb
).
parse
(
true
);
}
static
bool
accept
(
std
::
istream
&&
i
)
{
return
parser
(
input_adapter
::
create
(
i
)).
accept
(
true
);
}
/*!
@brief deserialize from an iterator range with contiguous storage
...
...
@@ -7561,6 +7587,15 @@ class basic_json
return
parser
(
input_adapter
::
create
(
first
,
last
),
cb
).
parse
(
true
);
}
template
<
class
IteratorType
,
typename
std
::
enable_if
<
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
std
::
iterator_traits
<
IteratorType
>
::
iterator_category
>::
value
,
int
>::
type
=
0
>
static
bool
accept
(
IteratorType
first
,
IteratorType
last
)
{
return
parser
(
input_adapter
::
create
(
first
,
last
)).
accept
(
true
);
}
/*!
@brief deserialize from a container with contiguous storage
...
...
@@ -7618,6 +7653,18 @@ class basic_json
return
parse
(
std
::
begin
(
c
),
std
::
end
(
c
),
cb
);
}
template
<
class
ContiguousContainer
,
typename
std
::
enable_if
<
not
std
::
is_pointer
<
ContiguousContainer
>
::
value
and
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
std
::
iterator_traits
<
decltype
(
std
::
begin
(
std
::
declval
<
ContiguousContainer
const
>
()))
>::
iterator_category
>::
value
,
int
>::
type
=
0
>
static
bool
accept
(
const
ContiguousContainer
&
c
)
{
// delegate the call to the iterator-range accept overload
return
accept
(
std
::
begin
(
c
),
std
::
end
(
c
));
}
/*!
@brief deserialize from stream
@deprecated This stream operator is deprecated and will be removed in a
...
...
test/src/unit-deserialization.cpp
View file @
b27d2adc
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