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
76763787
Commit
76763787
authored
Jan 03, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💄
cleanup
parent
f8d640b1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
48 deletions
+52
-48
json.hpp
src/json.hpp
+26
-24
json.hpp.re2c
src/json.hpp.re2c
+26
-24
No files found.
src/json.hpp
View file @
76763787
...
@@ -153,7 +153,8 @@ default)
...
@@ -153,7 +153,8 @@ default)
@requirement The class satisfies the following concept requirements:
@requirement The class satisfies the following concept requirements:
- Basic
- Basic
- [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible):
- [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible):
JSON values can be default constructed. The result will be a JSON null value.
JSON values can be default constructed. The result will be a JSON null
value.
- [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible):
- [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible):
A JSON value can be constructed from an rvalue argument.
A JSON value can be constructed from an rvalue argument.
- [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible):
- [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible):
...
@@ -168,8 +169,8 @@ default)
...
@@ -168,8 +169,8 @@ default)
- [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType):
- [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType):
JSON values have
JSON values have
[standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout):
[standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout):
All non-static data members are private and standard layout types, the
class
All non-static data members are private and standard layout types, the
has no virtual functions or (virtual) base classes.
class
has no virtual functions or (virtual) base classes.
- Library-wide
- Library-wide
- [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable):
- [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable):
JSON values can be compared with `==`, see @ref
JSON values can be compared with `==`, see @ref
...
@@ -1894,13 +1895,15 @@ class basic_json
...
@@ -1894,13 +1895,15 @@ class basic_json
case
value_t
:
:
object
:
case
value_t
:
:
object
:
{
{
m_value
.
object
=
create
<
object_t
>
(
first
.
m_it
.
object_iterator
,
last
.
m_it
.
object_iterator
);
m_value
.
object
=
create
<
object_t
>
(
first
.
m_it
.
object_iterator
,
last
.
m_it
.
object_iterator
);
break
;
break
;
}
}
case
value_t
:
:
array
:
case
value_t
:
:
array
:
{
{
m_value
.
array
=
create
<
array_t
>
(
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
);
m_value
.
array
=
create
<
array_t
>
(
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
);
break
;
break
;
}
}
...
@@ -3084,7 +3087,7 @@ class basic_json
...
@@ -3084,7 +3087,7 @@ class basic_json
template
<
typename
ValueType
,
typename
std
::
enable_if
<
template
<
typename
ValueType
,
typename
std
::
enable_if
<
not
std
::
is_pointer
<
ValueType
>::
value
and
not
std
::
is_pointer
<
ValueType
>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
#ifndef _MSC_VER //
F
ix for issue #167 operator<< abiguity under VS2015
#ifndef _MSC_VER //
f
ix for issue #167 operator<< abiguity under VS2015
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
#endif
#endif
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
...
@@ -3750,11 +3753,9 @@ class basic_json
...
@@ -3750,11 +3753,9 @@ class basic_json
return
default_value
;
return
default_value
;
}
}
}
}
else
{
throw
std
::
domain_error
(
"cannot use value() with "
+
type_name
());
throw
std
::
domain_error
(
"cannot use value() with "
+
type_name
());
}
}
}
/*!
/*!
@brief overload for a default value of type const char*
@brief overload for a default value of type const char*
...
@@ -5065,8 +5066,8 @@ class basic_json
...
@@ -5065,8 +5066,8 @@ class basic_json
/*!
/*!
@brief add an object to an object if key does not exist
@brief add an object to an object if key does not exist
Inserts a new element into a JSON object constructed in-place with the
given
Inserts a new element into a JSON object constructed in-place with the
@a args if there is no element with the key in the container. If the
given
@a args if there is no element with the key in the container. If the
function is called on a JSON null value, an empty object is created before
function is called on a JSON null value, an empty object is created before
appending the value created from @a args.
appending the value created from @a args.
...
@@ -5131,8 +5132,8 @@ class basic_json
...
@@ -5131,8 +5132,8 @@ class basic_json
@throw std::domain_error if @a pos is not an iterator of *this; example:
@throw std::domain_error if @a pos is not an iterator of *this; example:
`"iterator does not fit current value"`
`"iterator does not fit current value"`
@complexity Constant plus linear in the distance between pos and end of
the
@complexity Constant plus linear in the distance between pos and end of
container.
the
container.
@liveexample{The example shows how `insert()` is used.,insert}
@liveexample{The example shows how `insert()` is used.,insert}
...
@@ -5358,8 +5359,8 @@ class basic_json
...
@@ -5358,8 +5359,8 @@ class basic_json
@param[in,out] other array to exchange the contents with
@param[in,out] other array to exchange the contents with
@throw std::domain_error when JSON value is not an array; example:
`"cannot
@throw std::domain_error when JSON value is not an array; example:
use swap() with string"`
`"cannot
use swap() with string"`
@complexity Constant.
@complexity Constant.
...
@@ -6332,8 +6333,9 @@ class basic_json
...
@@ -6332,8 +6333,9 @@ class basic_json
if
(
j
.
m_value
.
number_integer
>=
0
)
if
(
j
.
m_value
.
number_integer
>=
0
)
{
{
// MessagePack does not differentiate between positive
// MessagePack does not differentiate between positive
// signed integers and unsigned integers. Therefore, we used
// signed integers and unsigned integers. Therefore, we
// the code from the value_t::number_unsigned case here.
// used the code from the value_t::number_unsigned case
// here.
if
(
j
.
m_value
.
number_unsigned
<
128
)
if
(
j
.
m_value
.
number_unsigned
<
128
)
{
{
// positive fixnum
// positive fixnum
...
@@ -6608,8 +6610,8 @@ class basic_json
...
@@ -6608,8 +6610,8 @@ class basic_json
}
}
else
else
{
{
// The conversions below encode the sign in the first
byte,
// The conversions below encode the sign in the first
// and the value is converted to a positive number.
//
byte,
and the value is converted to a positive number.
const
auto
positive_number
=
-
1
-
j
.
m_value
.
number_integer
;
const
auto
positive_number
=
-
1
-
j
.
m_value
.
number_integer
;
if
(
j
.
m_value
.
number_integer
>=
-
24
)
if
(
j
.
m_value
.
number_integer
>=
-
24
)
{
{
...
@@ -6814,12 +6816,12 @@ class basic_json
...
@@ -6814,12 +6816,12 @@ class basic_json
To secure the access to the byte vector during CBOR/MessagePack
To secure the access to the byte vector during CBOR/MessagePack
deserialization, bytes are copied from the vector into buffers. This
deserialization, bytes are copied from the vector into buffers. This
function checks if the number of bytes to copy (@a len) does not exceed
the
function checks if the number of bytes to copy (@a len) does not exceed
size @s size of the vector. Additionally, an @a offset is given from where
the size @s size of the vector. Additionally, an @a offset is given from
to start reading the bytes.
where
to start reading the bytes.
This function checks whether reading the bytes is safe; that is, offset is
a
This function checks whether reading the bytes is safe; that is, offset is
valid index in the vector, offset+len
a
valid index in the vector, offset+len
@param[in] size size of the byte vector
@param[in] size size of the byte vector
@param[in] len number of bytes to read
@param[in] len number of bytes to read
...
...
src/json.hpp.re2c
View file @
76763787
...
@@ -153,7 +153,8 @@ default)
...
@@ -153,7 +153,8 @@ default)
@requirement The class satisfies the following concept requirements:
@requirement The class satisfies the following concept requirements:
- Basic
- Basic
- [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible):
- [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible):
JSON values can be default constructed. The result will be a JSON null value.
JSON values can be default constructed. The result will be a JSON null
value.
- [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible):
- [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible):
A JSON value can be constructed from an rvalue argument.
A JSON value can be constructed from an rvalue argument.
- [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible):
- [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible):
...
@@ -168,8 +169,8 @@ default)
...
@@ -168,8 +169,8 @@ default)
- [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType):
- [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType):
JSON values have
JSON values have
[standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout):
[standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout):
All non-static data members are private and standard layout types, the
class
All non-static data members are private and standard layout types, the
has no virtual functions or (virtual) base classes.
class
has no virtual functions or (virtual) base classes.
- Library-wide
- Library-wide
- [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable):
- [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable):
JSON values can be compared with `==`, see @ref
JSON values can be compared with `==`, see @ref
...
@@ -1894,13 +1895,15 @@ class basic_json
...
@@ -1894,13 +1895,15 @@ class basic_json
case value_t::object:
case value_t::object:
{
{
m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
m_value.object = create<object_t>(first.m_it.object_iterator,
last.m_it.object_iterator);
break;
break;
}
}
case value_t::array:
case value_t::array:
{
{
m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
m_value.array = create<array_t>(first.m_it.array_iterator,
last.m_it.array_iterator);
break;
break;
}
}
...
@@ -3084,7 +3087,7 @@ class basic_json
...
@@ -3084,7 +3087,7 @@ class basic_json
template < typename ValueType, typename std::enable_if <
template < typename ValueType, typename std::enable_if <
not std::is_pointer<ValueType>::value and
not std::is_pointer<ValueType>::value and
not std::is_same<ValueType, typename string_t::value_type>::value
not std::is_same<ValueType, typename string_t::value_type>::value
#ifndef _MSC_VER //
F
ix for issue #167 operator<< abiguity under VS2015
#ifndef _MSC_VER //
f
ix for issue #167 operator<< abiguity under VS2015
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#endif
#endif
, int >::type = 0 >
, int >::type = 0 >
...
@@ -3750,11 +3753,9 @@ class basic_json
...
@@ -3750,11 +3753,9 @@ class basic_json
return default_value;
return default_value;
}
}
}
}
else
{
throw std::domain_error("cannot use value() with " + type_name());
throw std::domain_error("cannot use value() with " + type_name());
}
}
}
/*!
/*!
@brief overload for a default value of type const char*
@brief overload for a default value of type const char*
...
@@ -5065,8 +5066,8 @@ class basic_json
...
@@ -5065,8 +5066,8 @@ class basic_json
/*!
/*!
@brief add an object to an object if key does not exist
@brief add an object to an object if key does not exist
Inserts a new element into a JSON object constructed in-place with the
given
Inserts a new element into a JSON object constructed in-place with the
@a args if there is no element with the key in the container. If the
given
@a args if there is no element with the key in the container. If the
function is called on a JSON null value, an empty object is created before
function is called on a JSON null value, an empty object is created before
appending the value created from @a args.
appending the value created from @a args.
...
@@ -5131,8 +5132,8 @@ class basic_json
...
@@ -5131,8 +5132,8 @@ class basic_json
@throw std::domain_error if @a pos is not an iterator of *this; example:
@throw std::domain_error if @a pos is not an iterator of *this; example:
`"iterator does not fit current value"`
`"iterator does not fit current value"`
@complexity Constant plus linear in the distance between pos and end of
the
@complexity Constant plus linear in the distance between pos and end of
container.
the
container.
@liveexample{The example shows how `insert()` is used.,insert}
@liveexample{The example shows how `insert()` is used.,insert}
...
@@ -5358,8 +5359,8 @@ class basic_json
...
@@ -5358,8 +5359,8 @@ class basic_json
@param[in,out] other array to exchange the contents with
@param[in,out] other array to exchange the contents with
@throw std::domain_error when JSON value is not an array; example:
`"cannot
@throw std::domain_error when JSON value is not an array; example:
use swap() with string"`
`"cannot
use swap() with string"`
@complexity Constant.
@complexity Constant.
...
@@ -6332,8 +6333,9 @@ class basic_json
...
@@ -6332,8 +6333,9 @@ class basic_json
if (j.m_value.number_integer >= 0)
if (j.m_value.number_integer >= 0)
{
{
// MessagePack does not differentiate between positive
// MessagePack does not differentiate between positive
// signed integers and unsigned integers. Therefore, we used
// signed integers and unsigned integers. Therefore, we
// the code from the value_t::number_unsigned case here.
// used the code from the value_t::number_unsigned case
// here.
if (j.m_value.number_unsigned < 128)
if (j.m_value.number_unsigned < 128)
{
{
// positive fixnum
// positive fixnum
...
@@ -6608,8 +6610,8 @@ class basic_json
...
@@ -6608,8 +6610,8 @@ class basic_json
}
}
else
else
{
{
// The conversions below encode the sign in the first
byte,
// The conversions below encode the sign in the first
// and the value is converted to a positive number.
//
byte,
and the value is converted to a positive number.
const auto positive_number = -1 - j.m_value.number_integer;
const auto positive_number = -1 - j.m_value.number_integer;
if (j.m_value.number_integer >= -24)
if (j.m_value.number_integer >= -24)
{
{
...
@@ -6814,12 +6816,12 @@ class basic_json
...
@@ -6814,12 +6816,12 @@ class basic_json
To secure the access to the byte vector during CBOR/MessagePack
To secure the access to the byte vector during CBOR/MessagePack
deserialization, bytes are copied from the vector into buffers. This
deserialization, bytes are copied from the vector into buffers. This
function checks if the number of bytes to copy (@a len) does not exceed
the
function checks if the number of bytes to copy (@a len) does not exceed
size @s size of the vector. Additionally, an @a offset is given from where
the size @s size of the vector. Additionally, an @a offset is given from
to start reading the bytes.
where
to start reading the bytes.
This function checks whether reading the bytes is safe; that is, offset is
a
This function checks whether reading the bytes is safe; that is, offset is
valid index in the vector, offset+len
a
valid index in the vector, offset+len
@param[in] size size of the byte vector
@param[in] size size of the byte vector
@param[in] len number of bytes to read
@param[in] len number of bytes to read
...
...
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