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
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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
4 deletions
+87
-4
json.hpp
src/json.hpp
+47
-0
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
...
@@ -7421,6 +7421,13 @@ class basic_json
return
parse
(
std
::
begin
(
array
),
std
::
end
(
array
),
cb
);
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
@brief deserialize from string literal
...
@@ -7462,6 +7469,15 @@ class basic_json
...
@@ -7462,6 +7469,15 @@ class basic_json
return
parser
(
input_adapter
::
create
(
s
),
cb
).
parse
(
true
);
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
@brief deserialize from stream
...
@@ -7497,6 +7513,11 @@ class basic_json
...
@@ -7497,6 +7513,11 @@ class basic_json
return
parser
(
input_adapter
::
create
(
i
),
cb
).
parse
(
true
);
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)
@copydoc parse(std::istream&, const parser_callback_t)
*/
*/
...
@@ -7506,6 +7527,11 @@ class basic_json
...
@@ -7506,6 +7527,11 @@ class basic_json
return
parser
(
input_adapter
::
create
(
i
),
cb
).
parse
(
true
);
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
@brief deserialize from an iterator range with contiguous storage
...
@@ -7561,6 +7587,15 @@ class basic_json
...
@@ -7561,6 +7587,15 @@ class basic_json
return
parser
(
input_adapter
::
create
(
first
,
last
),
cb
).
parse
(
true
);
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
@brief deserialize from a container with contiguous storage
...
@@ -7618,6 +7653,18 @@ class basic_json
...
@@ -7618,6 +7653,18 @@ class basic_json
return
parse
(
std
::
begin
(
c
),
std
::
end
(
c
),
cb
);
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
@brief deserialize from stream
@deprecated This stream operator is deprecated and will be removed in a
@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