header + cleanup
This commit is contained in:
parent
161c74a92e
commit
b2b68a0fa1
2 changed files with 72 additions and 67 deletions
66
src/json.hpp
66
src/json.hpp
|
@ -32,7 +32,6 @@ SOFTWARE.
|
|||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <ciso646>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
@ -44,6 +43,7 @@ SOFTWARE.
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <locale>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
|
@ -621,15 +621,14 @@ class basic_json
|
|||
> that implementations will agree exactly on their numeric values.
|
||||
|
||||
As this range is a subrange (when considered in conjunction with the
|
||||
number_integer_t type) of the exactly supported range [0, UINT64_MAX], this
|
||||
class's integer type is interoperable.
|
||||
number_integer_t type) of the exactly supported range [0, UINT64_MAX],
|
||||
this class's integer type is interoperable.
|
||||
|
||||
#### Storage
|
||||
|
||||
Integer number values are stored directly inside a @ref basic_json type.
|
||||
|
||||
@sa @ref number_float_t -- type for number values (floating-point)
|
||||
|
||||
@sa @ref number_integer_t -- type for number values (integer)
|
||||
|
||||
@since version 2.0.0
|
||||
|
@ -1416,8 +1415,8 @@ class basic_json
|
|||
|
||||
Create an unsigned integer number JSON value with a given content.
|
||||
|
||||
@tparam T helper type to compare number_unsigned_t and unsigned int
|
||||
(not visible in) the interface.
|
||||
@tparam T helper type to compare number_unsigned_t and unsigned int (not
|
||||
visible in) the interface.
|
||||
|
||||
@param[in] val an integer to create a JSON number from
|
||||
|
||||
|
@ -1481,8 +1480,8 @@ class basic_json
|
|||
disallows NaN values:
|
||||
> Numeric values that cannot be represented in the grammar below (such as
|
||||
> Infinity and NaN) are not permitted.
|
||||
In case the parameter @a val is not a number, a JSON null value is
|
||||
created instead.
|
||||
In case the parameter @a val is not a number, a JSON null value is created
|
||||
instead.
|
||||
|
||||
@complexity Constant.
|
||||
|
||||
|
@ -1555,8 +1554,8 @@ class basic_json
|
|||
|
||||
1. If the list is empty, an empty JSON object value `{}` is created.
|
||||
2. If the list consists of pairs whose first element is a string, a JSON
|
||||
object value is created where the first elements of the pairs are treated
|
||||
as keys and the second elements are as values.
|
||||
object value is created where the first elements of the pairs are
|
||||
treated as keys and the second elements are as values.
|
||||
3. In all other cases, an array is created.
|
||||
|
||||
The rules aim to create the best fit between a C++ initializer list and
|
||||
|
@ -1566,8 +1565,8 @@ class basic_json
|
|||
JSON object.
|
||||
2. C++ has now way of describing mapped types other than to list a list of
|
||||
pairs. As JSON requires that keys must be of type string, rule 2 is the
|
||||
weakest constraint one can pose on initializer lists to interpret them as
|
||||
an object.
|
||||
weakest constraint one can pose on initializer lists to interpret them
|
||||
as an object.
|
||||
3. In all other cases, the initializer list could not be interpreted as
|
||||
JSON object type, so interpreting it as JSON array type is safe.
|
||||
|
||||
|
@ -3709,7 +3708,7 @@ class basic_json
|
|||
|
||||
/*!
|
||||
@brief overload for a default value of type const char*
|
||||
@copydoc basic_json::value(const typename object_t::key_type&, ValueType)
|
||||
@copydoc basic_json::value(const typename object_t::key_type&, ValueType) const
|
||||
*/
|
||||
string_t value(const typename object_t::key_type& key, const char* default_value) const
|
||||
{
|
||||
|
@ -3753,7 +3752,7 @@ class basic_json
|
|||
@liveexample{The example below shows how object elements can be queried
|
||||
with a default value.,basic_json__value_ptr}
|
||||
|
||||
@sa @ref operator[](const json_ptr&) for unchecked access by reference
|
||||
@sa @ref operator[](const json_pointer&) for unchecked access by reference
|
||||
|
||||
@since version 2.0.2
|
||||
*/
|
||||
|
@ -3784,7 +3783,7 @@ class basic_json
|
|||
|
||||
/*!
|
||||
@brief overload for a default value of type const char*
|
||||
@copydoc basic_json::value(const json_pointer&, ValueType)
|
||||
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
||||
*/
|
||||
string_t value(const json_pointer& ptr, const char* default_value) const
|
||||
{
|
||||
|
@ -7386,7 +7385,7 @@ class basic_json
|
|||
: m_stream(s), m_buffer()
|
||||
{
|
||||
assert(m_stream != nullptr);
|
||||
getline(*m_stream, m_buffer);
|
||||
std::getline(*m_stream, m_buffer);
|
||||
m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
|
||||
assert(m_content != nullptr);
|
||||
m_start = m_cursor = m_content;
|
||||
|
@ -8379,8 +8378,8 @@ basic_json_parser_63:
|
|||
according to the nature of the escape. Some escapes create new
|
||||
characters (e.g., `"\\n"` is replaced by `"\n"`), some are copied
|
||||
as is (e.g., `"\\\\"`). Furthermore, Unicode escapes of the shape
|
||||
`"\\uxxxx"` need special care. In this case, @ref to_unicode takes
|
||||
care of the construction of the values.
|
||||
`"\\uxxxx"` need special care. In this case, to_unicode takes care
|
||||
of the construction of the values.
|
||||
2. Unescaped characters are copied as is.
|
||||
|
||||
@pre `m_cursor - m_start >= 2`, meaning the length of the last token
|
||||
|
@ -8398,9 +8397,9 @@ basic_json_parser_63:
|
|||
Proof (by contradiction): Assume the loop body does not terminate. As
|
||||
the loop body does not contain another loop, one of the called
|
||||
functions must never return. The called functions are `std::strtoul`
|
||||
and @ref to_unicode. Neither function can loop forever, so the loop
|
||||
body will never loop forever which contradicts the assumption that the
|
||||
loop body does not terminate, q.e.d.\n
|
||||
and to_unicode. Neither function can loop forever, so the loop body
|
||||
will never loop forever which contradicts the assumption that the loop
|
||||
body does not terminate, q.e.d.\n
|
||||
|
||||
Lemma: The loop condition for the for loop is eventually false.\n
|
||||
|
||||
|
@ -8408,15 +8407,15 @@ basic_json_parser_63:
|
|||
the above lemma, this can only be due to a tautological loop
|
||||
condition; that is, the loop condition i < m_cursor - 1 must always be
|
||||
true. Let x be the change of i for any loop iteration. Then
|
||||
m_start + 1 + x < m_cursor - 1 must hold to loop indefinitely.
|
||||
This can be rephrased to m_cursor - m_start - 2 > x. With the
|
||||
m_start + 1 + x < m_cursor - 1 must hold to loop indefinitely. This
|
||||
can be rephrased to m_cursor - m_start - 2 > x. With the
|
||||
precondition, we x <= 0, meaning that the loop condition holds
|
||||
indefinitly if i is always decreased. However, observe that the
|
||||
value of i is strictly increasing with each iteration, as it is
|
||||
incremented by 1 in the iteration expression and never
|
||||
decremented inside the loop body. Hence, the loop condition
|
||||
will eventually be false which contradicts the assumption that
|
||||
the loop condition is a tautology, q.e.d.
|
||||
indefinitly if i is always decreased. However, observe that the value
|
||||
of i is strictly increasing with each iteration, as it is incremented
|
||||
by 1 in the iteration expression and never decremented inside the loop
|
||||
body. Hence, the loop condition will eventually be false which
|
||||
contradicts the assumption that the loop condition is a tautology,
|
||||
q.e.d.
|
||||
|
||||
@return string value of current token without opening and closing
|
||||
quotes
|
||||
|
@ -10278,7 +10277,7 @@ struct hash<nlohmann::json>
|
|||
@brief user-defined string literal for JSON values
|
||||
|
||||
This operator implements a user-defined string literal for JSON objects. It
|
||||
can be used by adding \p "_json" to a string literal and returns a JSON object
|
||||
can be used by adding `"_json"` to a string literal and returns a JSON object
|
||||
if no parse error occurred.
|
||||
|
||||
@param[in] s a string representation of a JSON object
|
||||
|
@ -10294,6 +10293,13 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t)
|
|||
/*!
|
||||
@brief user-defined string literal for JSON pointer
|
||||
|
||||
This operator implements a user-defined string literal for JSON Pointers. It
|
||||
can be used by adding `"_json"` to a string literal and returns a JSON pointer
|
||||
object if no parse error occurred.
|
||||
|
||||
@param[in] s a string representation of a JSON Pointer
|
||||
@return a JSON pointer object
|
||||
|
||||
@since version 2.0.0
|
||||
*/
|
||||
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t)
|
||||
|
|
|
@ -32,7 +32,6 @@ SOFTWARE.
|
|||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <ciso646>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
@ -44,6 +43,7 @@ SOFTWARE.
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <locale>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
|
@ -621,15 +621,14 @@ class basic_json
|
|||
> that implementations will agree exactly on their numeric values.
|
||||
|
||||
As this range is a subrange (when considered in conjunction with the
|
||||
number_integer_t type) of the exactly supported range [0, UINT64_MAX], this
|
||||
class's integer type is interoperable.
|
||||
number_integer_t type) of the exactly supported range [0, UINT64_MAX],
|
||||
this class's integer type is interoperable.
|
||||
|
||||
#### Storage
|
||||
|
||||
Integer number values are stored directly inside a @ref basic_json type.
|
||||
|
||||
@sa @ref number_float_t -- type for number values (floating-point)
|
||||
|
||||
@sa @ref number_integer_t -- type for number values (integer)
|
||||
|
||||
@since version 2.0.0
|
||||
|
@ -1416,8 +1415,8 @@ class basic_json
|
|||
|
||||
Create an unsigned integer number JSON value with a given content.
|
||||
|
||||
@tparam T helper type to compare number_unsigned_t and unsigned int
|
||||
(not visible in) the interface.
|
||||
@tparam T helper type to compare number_unsigned_t and unsigned int (not
|
||||
visible in) the interface.
|
||||
|
||||
@param[in] val an integer to create a JSON number from
|
||||
|
||||
|
@ -1481,8 +1480,8 @@ class basic_json
|
|||
disallows NaN values:
|
||||
> Numeric values that cannot be represented in the grammar below (such as
|
||||
> Infinity and NaN) are not permitted.
|
||||
In case the parameter @a val is not a number, a JSON null value is
|
||||
created instead.
|
||||
In case the parameter @a val is not a number, a JSON null value is created
|
||||
instead.
|
||||
|
||||
@complexity Constant.
|
||||
|
||||
|
@ -1555,8 +1554,8 @@ class basic_json
|
|||
|
||||
1. If the list is empty, an empty JSON object value `{}` is created.
|
||||
2. If the list consists of pairs whose first element is a string, a JSON
|
||||
object value is created where the first elements of the pairs are treated
|
||||
as keys and the second elements are as values.
|
||||
object value is created where the first elements of the pairs are
|
||||
treated as keys and the second elements are as values.
|
||||
3. In all other cases, an array is created.
|
||||
|
||||
The rules aim to create the best fit between a C++ initializer list and
|
||||
|
@ -1566,8 +1565,8 @@ class basic_json
|
|||
JSON object.
|
||||
2. C++ has now way of describing mapped types other than to list a list of
|
||||
pairs. As JSON requires that keys must be of type string, rule 2 is the
|
||||
weakest constraint one can pose on initializer lists to interpret them as
|
||||
an object.
|
||||
weakest constraint one can pose on initializer lists to interpret them
|
||||
as an object.
|
||||
3. In all other cases, the initializer list could not be interpreted as
|
||||
JSON object type, so interpreting it as JSON array type is safe.
|
||||
|
||||
|
@ -3709,7 +3708,7 @@ class basic_json
|
|||
|
||||
/*!
|
||||
@brief overload for a default value of type const char*
|
||||
@copydoc basic_json::value(const typename object_t::key_type&, ValueType)
|
||||
@copydoc basic_json::value(const typename object_t::key_type&, ValueType) const
|
||||
*/
|
||||
string_t value(const typename object_t::key_type& key, const char* default_value) const
|
||||
{
|
||||
|
@ -3753,7 +3752,7 @@ class basic_json
|
|||
@liveexample{The example below shows how object elements can be queried
|
||||
with a default value.,basic_json__value_ptr}
|
||||
|
||||
@sa @ref operator[](const json_ptr&) for unchecked access by reference
|
||||
@sa @ref operator[](const json_pointer&) for unchecked access by reference
|
||||
|
||||
@since version 2.0.2
|
||||
*/
|
||||
|
@ -3784,7 +3783,7 @@ class basic_json
|
|||
|
||||
/*!
|
||||
@brief overload for a default value of type const char*
|
||||
@copydoc basic_json::value(const json_pointer&, ValueType)
|
||||
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
||||
*/
|
||||
string_t value(const json_pointer& ptr, const char* default_value) const
|
||||
{
|
||||
|
@ -7386,7 +7385,7 @@ class basic_json
|
|||
: m_stream(s), m_buffer()
|
||||
{
|
||||
assert(m_stream != nullptr);
|
||||
getline(*m_stream, m_buffer);
|
||||
std::getline(*m_stream, m_buffer);
|
||||
m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
|
||||
assert(m_content != nullptr);
|
||||
m_start = m_cursor = m_content;
|
||||
|
@ -7676,8 +7675,8 @@ class basic_json
|
|||
according to the nature of the escape. Some escapes create new
|
||||
characters (e.g., `"\\n"` is replaced by `"\n"`), some are copied
|
||||
as is (e.g., `"\\\\"`). Furthermore, Unicode escapes of the shape
|
||||
`"\\uxxxx"` need special care. In this case, @ref to_unicode takes
|
||||
care of the construction of the values.
|
||||
`"\\uxxxx"` need special care. In this case, to_unicode takes care
|
||||
of the construction of the values.
|
||||
2. Unescaped characters are copied as is.
|
||||
|
||||
@pre `m_cursor - m_start >= 2`, meaning the length of the last token
|
||||
|
@ -7695,9 +7694,9 @@ class basic_json
|
|||
Proof (by contradiction): Assume the loop body does not terminate. As
|
||||
the loop body does not contain another loop, one of the called
|
||||
functions must never return. The called functions are `std::strtoul`
|
||||
and @ref to_unicode. Neither function can loop forever, so the loop
|
||||
body will never loop forever which contradicts the assumption that the
|
||||
loop body does not terminate, q.e.d.\n
|
||||
and to_unicode. Neither function can loop forever, so the loop body
|
||||
will never loop forever which contradicts the assumption that the loop
|
||||
body does not terminate, q.e.d.\n
|
||||
|
||||
Lemma: The loop condition for the for loop is eventually false.\n
|
||||
|
||||
|
@ -7705,15 +7704,15 @@ class basic_json
|
|||
the above lemma, this can only be due to a tautological loop
|
||||
condition; that is, the loop condition i < m_cursor - 1 must always be
|
||||
true. Let x be the change of i for any loop iteration. Then
|
||||
m_start + 1 + x < m_cursor - 1 must hold to loop indefinitely.
|
||||
This can be rephrased to m_cursor - m_start - 2 > x. With the
|
||||
m_start + 1 + x < m_cursor - 1 must hold to loop indefinitely. This
|
||||
can be rephrased to m_cursor - m_start - 2 > x. With the
|
||||
precondition, we x <= 0, meaning that the loop condition holds
|
||||
indefinitly if i is always decreased. However, observe that the
|
||||
value of i is strictly increasing with each iteration, as it is
|
||||
incremented by 1 in the iteration expression and never
|
||||
decremented inside the loop body. Hence, the loop condition
|
||||
will eventually be false which contradicts the assumption that
|
||||
the loop condition is a tautology, q.e.d.
|
||||
indefinitly if i is always decreased. However, observe that the value
|
||||
of i is strictly increasing with each iteration, as it is incremented
|
||||
by 1 in the iteration expression and never decremented inside the loop
|
||||
body. Hence, the loop condition will eventually be false which
|
||||
contradicts the assumption that the loop condition is a tautology,
|
||||
q.e.d.
|
||||
|
||||
@return string value of current token without opening and closing
|
||||
quotes
|
||||
|
|
Loading…
Reference in a new issue