Merge branch 'develop' of https://github.com/nlohmann/json into clang_windows

 Conflicts:
	include/nlohmann/detail/input/binary_reader.hpp
	include/nlohmann/detail/input/json_sax.hpp
	include/nlohmann/detail/input/lexer.hpp
	include/nlohmann/detail/input/parser.hpp
	include/nlohmann/detail/json_pointer.hpp
	include/nlohmann/detail/output/serializer.hpp
	include/nlohmann/json.hpp
	single_include/nlohmann/json.hpp
This commit is contained in:
Niels Lohmann 2020-07-11 14:04:40 +02:00
commit dc06f100be
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
28 changed files with 1441 additions and 910 deletions

View file

@ -2,7 +2,6 @@
#include <algorithm> // generate_n
#include <array> // array
#include <cassert> // assert
#include <cmath> // ldexp
#include <cstddef> // size_t
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
@ -109,7 +108,7 @@ class binary_reader
break;
default: // LCOV_EXCL_LINE
assert(false); // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE
}
// strict mode: next byte must be EOF
@ -717,8 +716,8 @@ class binary_reader
{
const int exp = (half >> 10u) & 0x1Fu;
const unsigned int mant = half & 0x3FFu;
assert(0 <= exp&& exp <= 32);
assert(mant <= 1024);
JSON_ASSERT(0 <= exp&& exp <= 32);
JSON_ASSERT(mant <= 1024);
switch (exp)
{
case 0:
@ -2295,7 +2294,7 @@ class binary_reader
break;
default: // LCOV_EXCL_LINE
assert(false); // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE
}
return error_msg + " " + context + ": " + detail;

View file

@ -1,7 +1,6 @@
#pragma once
#include <array> // array
#include <cassert> // assert
#include <cstddef> // size_t
#include <cstdio> //FILE *
#include <cstring> // strlen
@ -297,13 +296,13 @@ class wide_string_input_adapter
{
fill_buffer<sizeof(WideCharType)>();
assert(utf8_bytes_filled > 0);
assert(utf8_bytes_index == 0);
JSON_ASSERT(utf8_bytes_filled > 0);
JSON_ASSERT(utf8_bytes_index == 0);
}
// use buffer
assert(utf8_bytes_filled > 0);
assert(utf8_bytes_index < utf8_bytes_filled);
JSON_ASSERT(utf8_bytes_filled > 0);
JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
return utf8_bytes[utf8_bytes_index++];
}

View file

@ -1,6 +1,5 @@
#pragma once
#include <cassert> // assert
#include <cstddef>
#include <string> // string
#include <utility> // move
@ -280,7 +279,7 @@ class json_sax_dom_parser
case 5:
JSON_THROW(*dynamic_cast<const detail::other_error*>(&ex));
default:
assert(false);
JSON_ASSERT(false);
// LCOV_EXCL_STOP
}
}
@ -309,7 +308,7 @@ class json_sax_dom_parser
return &root;
}
assert(ref_stack.back()->is_array() || ref_stack.back()->is_object());
JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
if (ref_stack.back()->is_array())
{
@ -317,8 +316,8 @@ class json_sax_dom_parser
return &(ref_stack.back()->m_value.array->back());
}
assert(ref_stack.back()->is_object());
assert(object_element);
JSON_ASSERT(ref_stack.back()->is_object());
JSON_ASSERT(object_element);
*object_element = BasicJsonType(std::forward<Value>(v));
return object_element;
}
@ -447,8 +446,8 @@ class json_sax_dom_callback_parser
*ref_stack.back() = discarded;
}
assert(!ref_stack.empty());
assert(!keep_stack.empty());
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(!keep_stack.empty());
ref_stack.pop_back();
keep_stack.pop_back();
@ -499,8 +498,8 @@ class json_sax_dom_callback_parser
}
}
assert(!ref_stack.empty());
assert(!keep_stack.empty());
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(!keep_stack.empty());
ref_stack.pop_back();
keep_stack.pop_back();
@ -534,7 +533,7 @@ class json_sax_dom_callback_parser
case 5:
JSON_THROW(*dynamic_cast<const detail::other_error*>(&ex));
default:
assert(false);
JSON_ASSERT(false);
// LCOV_EXCL_STOP
}
}
@ -565,7 +564,7 @@ class json_sax_dom_callback_parser
template<typename Value>
std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false)
{
assert(!keep_stack.empty());
JSON_ASSERT(!keep_stack.empty());
// do not handle this value if we know it would be added to a discarded
// container
@ -600,7 +599,7 @@ class json_sax_dom_callback_parser
}
// we now only expect arrays and objects
assert(ref_stack.back()->is_array() || ref_stack.back()->is_object());
JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
// array
if (ref_stack.back()->is_array())
@ -610,9 +609,9 @@ class json_sax_dom_callback_parser
}
// object
assert(ref_stack.back()->is_object());
JSON_ASSERT(ref_stack.back()->is_object());
// check if we should store an element for the current key
assert(!key_keep_stack.empty());
JSON_ASSERT(!key_keep_stack.empty());
const bool store_element = key_keep_stack.back();
key_keep_stack.pop_back();
@ -621,7 +620,7 @@ class json_sax_dom_callback_parser
return {false, nullptr};
}
assert(object_element);
JSON_ASSERT(object_element);
*object_element = std::move(value);
return {true, object_element};
}

View file

@ -135,7 +135,7 @@ class lexer : public lexer_base<BasicJsonType>
static char get_decimal_point() noexcept
{
const auto* loc = localeconv();
assert(loc != nullptr);
JSON_ASSERT(loc != nullptr);
return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);
}
@ -161,7 +161,7 @@ class lexer : public lexer_base<BasicJsonType>
int get_codepoint()
{
// this function only makes sense after reading `\u`
assert(current == 'u');
JSON_ASSERT(current == 'u');
int codepoint = 0;
const auto factors = { 12u, 8u, 4u, 0u };
@ -187,7 +187,7 @@ class lexer : public lexer_base<BasicJsonType>
}
}
assert(0x0000 <= codepoint && codepoint <= 0xFFFF);
JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
return codepoint;
}
@ -208,7 +208,7 @@ class lexer : public lexer_base<BasicJsonType>
*/
bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
{
assert(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
add(current);
for (auto range = ranges.begin(); range != ranges.end(); ++range)
@ -249,7 +249,7 @@ class lexer : public lexer_base<BasicJsonType>
reset();
// we entered the function by reading an open quote
assert(current == '\"');
JSON_ASSERT(current == '\"');
while (true)
{
@ -369,7 +369,7 @@ class lexer : public lexer_base<BasicJsonType>
}
// result of the above calculation yields a proper codepoint
assert(0x00 <= codepoint && codepoint <= 0x10FFFF);
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
// translate codepoint into bytes
if (codepoint < 0x80)
@ -998,7 +998,7 @@ class lexer : public lexer_base<BasicJsonType>
// all other characters are rejected outside scan_number()
default: // LCOV_EXCL_LINE
assert(false); // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE
}
scan_number_minus:
@ -1245,7 +1245,7 @@ scan_number_done:
const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
// we checked the number format before
assert(endptr == token_buffer.data() + token_buffer.size());
JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
if (errno == 0)
{
@ -1261,7 +1261,7 @@ scan_number_done:
const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
// we checked the number format before
assert(endptr == token_buffer.data() + token_buffer.size());
JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
if (errno == 0)
{
@ -1278,7 +1278,7 @@ scan_number_done:
strtof(value_float, token_buffer.data(), &endptr);
// we checked the number format before
assert(endptr == token_buffer.data() + token_buffer.size());
JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
return token_type::value_float;
}
@ -1292,7 +1292,7 @@ scan_number_done:
token_type scan_literal(const char_type* literal_text, const std::size_t length,
token_type return_type)
{
assert(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
for (std::size_t i = 1; i < length; ++i)
{
if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
@ -1384,7 +1384,7 @@ scan_number_done:
if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
{
assert(!token_string.empty());
JSON_ASSERT(!token_string.empty());
token_string.pop_back();
}
}

View file

@ -1,6 +1,5 @@
#pragma once
#include <cassert> // assert
#include <cmath> // isfinite
#include <cstdint> // uint8_t
#include <functional> // function
@ -383,7 +382,7 @@ class parser
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
assert(!states.empty());
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
@ -439,7 +438,7 @@ class parser
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
assert(!states.empty());
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;