🔨 add NLOHMANN_JSON prefix and undef macros
This commit is contained in:
parent
1720bfedd1
commit
897362191d
20 changed files with 4055 additions and 2294 deletions
|
@ -66,7 +66,7 @@ class binary_reader
|
|||
|
||||
@return
|
||||
*/
|
||||
HEDLEY_NON_NULL(3)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(3)
|
||||
bool sax_parse(const input_format_t format,
|
||||
json_sax_t* sax_,
|
||||
const bool strict = true)
|
||||
|
@ -108,7 +108,7 @@ class binary_reader
|
|||
get();
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(current != std::char_traits<char>::eof()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(current != std::char_traits<char>::eof()))
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(),
|
||||
parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value")));
|
||||
|
@ -144,12 +144,12 @@ class binary_reader
|
|||
std::int32_t document_size;
|
||||
get_number<std::int32_t, true>(input_format_t::bson, document_size);
|
||||
|
||||
if (HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/false)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ class binary_reader
|
|||
while (true)
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "cstring")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "cstring")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ class binary_reader
|
|||
template<typename NumberType>
|
||||
bool get_bson_string(const NumberType len, string_t& result)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(len < 1))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(len < 1))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "string length must be at least 1, is " + std::to_string(len), "string")));
|
||||
|
@ -293,13 +293,13 @@ class binary_reader
|
|||
string_t key;
|
||||
while (int element_type = get())
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "element list")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "element list")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t element_type_parse_position = chars_read;
|
||||
if (HEDLEY_UNLIKELY(not get_bson_cstr(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_bson_cstr(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ class binary_reader
|
|||
return false;
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -330,12 +330,12 @@ class binary_reader
|
|||
std::int32_t document_size;
|
||||
get_number<std::int32_t, true>(input_format_t::bson, document_size);
|
||||
|
||||
if (HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/true)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/true)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -620,12 +620,12 @@ class binary_reader
|
|||
case 0xF9: // Half-Precision Float (two-byte IEEE 754)
|
||||
{
|
||||
const int byte1_raw = get();
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const int byte2_raw = get();
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -698,7 +698,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_cbor_string(string_t& result)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "string")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "string")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -787,7 +787,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_cbor_array(const std::size_t len)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_array(len)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -796,7 +796,7 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -806,7 +806,7 @@ class binary_reader
|
|||
{
|
||||
while (get() != 0xFF)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not parse_cbor_internal(false)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_cbor_internal(false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -823,7 +823,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_cbor_object(const std::size_t len)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_object(len)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -834,12 +834,12 @@ class binary_reader
|
|||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -850,12 +850,12 @@ class binary_reader
|
|||
{
|
||||
while (get() != 0xFF)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1244,7 +1244,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_msgpack_string(string_t& result)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::msgpack, "string")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::msgpack, "string")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1320,14 +1320,14 @@ class binary_reader
|
|||
*/
|
||||
bool get_msgpack_array(const std::size_t len)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_array(len)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not parse_msgpack_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1342,7 +1342,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_msgpack_object(const std::size_t len)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_object(len)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1351,12 +1351,12 @@ class binary_reader
|
|||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_UNLIKELY(not get_msgpack_string(key) or not sax->key(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_msgpack_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not parse_msgpack_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1403,7 +1403,7 @@ class binary_reader
|
|||
get(); // TODO(niels): may we ignore N here?
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1457,7 +1457,7 @@ class binary_reader
|
|||
case 'U':
|
||||
{
|
||||
std::uint8_t number;
|
||||
if (HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1468,7 +1468,7 @@ class binary_reader
|
|||
case 'i':
|
||||
{
|
||||
std::int8_t number;
|
||||
if (HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1479,7 +1479,7 @@ class binary_reader
|
|||
case 'I':
|
||||
{
|
||||
std::int16_t number;
|
||||
if (HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1490,7 +1490,7 @@ class binary_reader
|
|||
case 'l':
|
||||
{
|
||||
std::int32_t number;
|
||||
if (HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1501,7 +1501,7 @@ class binary_reader
|
|||
case 'L':
|
||||
{
|
||||
std::int64_t number;
|
||||
if (HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1537,15 +1537,15 @@ class binary_reader
|
|||
if (current == '$')
|
||||
{
|
||||
result.second = get(); // must not ignore 'N', because 'N' maybe the type
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "type")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "type")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
get_ignore_noop();
|
||||
if (HEDLEY_UNLIKELY(current != '#'))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(current != '#'))
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1628,11 +1628,11 @@ class binary_reader
|
|||
case 'C': // char
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "char")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "char")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (HEDLEY_UNLIKELY(current > 127))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(current > 127))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char")));
|
||||
|
@ -1667,14 +1667,14 @@ class binary_reader
|
|||
bool get_ubjson_array()
|
||||
{
|
||||
std::pair<std::size_t, int> size_and_type;
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size_and_type.first != string_t::npos)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_array(size_and_type.first)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_array(size_and_type.first)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1685,7 +1685,7 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1696,7 +1696,7 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1705,14 +1705,14 @@ class binary_reader
|
|||
}
|
||||
else
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (current != ']')
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not parse_ubjson_internal(false)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal(false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1729,7 +1729,7 @@ class binary_reader
|
|||
bool get_ubjson_object()
|
||||
{
|
||||
std::pair<std::size_t, int> size_and_type;
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1737,7 +1737,7 @@ class binary_reader
|
|||
string_t key;
|
||||
if (size_and_type.first != string_t::npos)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_object(size_and_type.first)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_object(size_and_type.first)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1746,11 +1746,11 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1761,11 +1761,11 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1775,18 +1775,18 @@ class binary_reader
|
|||
}
|
||||
else
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (current != '}')
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not get_ubjson_string(key, false) or not sax->key(key)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key, false) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1852,7 +1852,7 @@ class binary_reader
|
|||
for (std::size_t i = 0; i < sizeof(NumberType); ++i)
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(format, "number")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1896,7 +1896,7 @@ class binary_reader
|
|||
std::generate_n(std::back_inserter(result), len, [this, &success, &format]()
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_UNLIKELY(not unexpect_eof(format, "string")))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "string")))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
@ -1910,10 +1910,10 @@ class binary_reader
|
|||
@param[in] context further context information (for diagnostics)
|
||||
@return whether the last read character is not EOF
|
||||
*/
|
||||
HEDLEY_NON_NULL(3)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(3)
|
||||
bool unexpect_eof(const input_format_t format, const char* context) const
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(current == std::char_traits<char>::eof()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(current == std::char_traits<char>::eof()))
|
||||
{
|
||||
return sax->parse_error(chars_read, "<end of file>",
|
||||
parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context)));
|
||||
|
|
|
@ -55,7 +55,7 @@ Input adapter for stdio file access. This adapter read only 1 byte and do not us
|
|||
class file_input_adapter : public input_adapter_protocol
|
||||
{
|
||||
public:
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
explicit file_input_adapter(std::FILE* f) noexcept
|
||||
: m_file(f)
|
||||
{}
|
||||
|
@ -131,7 +131,7 @@ class input_stream_adapter : public input_adapter_protocol
|
|||
class input_buffer_adapter : public input_adapter_protocol
|
||||
{
|
||||
public:
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
input_buffer_adapter(const char* b, const std::size_t l) noexcept
|
||||
: cursor(b), limit(b + l)
|
||||
{}
|
||||
|
@ -145,7 +145,7 @@ class input_buffer_adapter : public input_adapter_protocol
|
|||
|
||||
std::char_traits<char>::int_type get_character() noexcept override
|
||||
{
|
||||
if (HEDLEY_LIKELY(cursor < limit))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(cursor < limit))
|
||||
{
|
||||
return std::char_traits<char>::to_int_type(*(cursor++));
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ class input_adapter
|
|||
{
|
||||
public:
|
||||
// native support
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
input_adapter(std::FILE* file)
|
||||
: ia(std::make_shared<file_input_adapter>(file)) {}
|
||||
/// input adapter for input stream
|
||||
|
@ -404,7 +404,7 @@ class input_adapter
|
|||
"each element in the iterator range must have the size of 1 byte");
|
||||
|
||||
const auto len = static_cast<size_t>(std::distance(first, last));
|
||||
if (HEDLEY_LIKELY(len > 0))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(len > 0))
|
||||
{
|
||||
// there is at least one element: use the address of first
|
||||
ia = std::make_shared<input_buffer_adapter>(reinterpret_cast<const char*>(&(*first)), len);
|
||||
|
|
|
@ -206,7 +206,7 @@ class json_sax_dom_parser
|
|||
{
|
||||
ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
|
||||
|
||||
if (HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
{
|
||||
JSON_THROW(out_of_range::create(408,
|
||||
"excessive object size: " + std::to_string(len)));
|
||||
|
@ -232,7 +232,7 @@ class json_sax_dom_parser
|
|||
{
|
||||
ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
|
||||
|
||||
if (HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
{
|
||||
JSON_THROW(out_of_range::create(408,
|
||||
"excessive array size: " + std::to_string(len)));
|
||||
|
@ -288,7 +288,7 @@ class json_sax_dom_parser
|
|||
object to which we can add elements
|
||||
*/
|
||||
template<typename Value>
|
||||
HEDLEY_RETURNS_NON_NULL
|
||||
NLOHMANN_JSON_HEDLEY_RETURNS_NON_NULL
|
||||
BasicJsonType* handle_value(Value&& v)
|
||||
{
|
||||
if (ref_stack.empty())
|
||||
|
@ -395,7 +395,7 @@ class json_sax_dom_callback_parser
|
|||
ref_stack.push_back(val.second);
|
||||
|
||||
// check object limit
|
||||
if (ref_stack.back() and HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (ref_stack.back() and NLOHMANN_JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
{
|
||||
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len)));
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ class json_sax_dom_callback_parser
|
|||
ref_stack.push_back(val.second);
|
||||
|
||||
// check array limit
|
||||
if (ref_stack.back() and HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (ref_stack.back() and NLOHMANN_JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
{
|
||||
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len)));
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class lexer
|
|||
};
|
||||
|
||||
/// return name of values of type token_type (only used for errors)
|
||||
HEDLEY_RETURNS_NON_NULL
|
||||
NLOHMANN_JSON_HEDLEY_RETURNS_NON_NULL
|
||||
static const char* token_type_name(const token_type t) noexcept
|
||||
{
|
||||
switch (t)
|
||||
|
@ -201,7 +201,7 @@ class lexer
|
|||
for (auto range = ranges.begin(); range != ranges.end(); ++range)
|
||||
{
|
||||
get();
|
||||
if (HEDLEY_LIKELY(*range <= current and current <= *(++range)))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(*range <= current and current <= *(++range)))
|
||||
{
|
||||
add(current);
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ class lexer
|
|||
const int codepoint1 = get_codepoint();
|
||||
int codepoint = codepoint1; // start with codepoint1
|
||||
|
||||
if (HEDLEY_UNLIKELY(codepoint1 == -1))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
|
||||
{
|
||||
error_message = "invalid string: '\\u' must be followed by 4 hex digits";
|
||||
return token_type::parse_error;
|
||||
|
@ -310,18 +310,18 @@ class lexer
|
|||
if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
|
||||
{
|
||||
// expect next \uxxxx entry
|
||||
if (HEDLEY_LIKELY(get() == '\\' and get() == 'u'))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(get() == '\\' and get() == 'u'))
|
||||
{
|
||||
const int codepoint2 = get_codepoint();
|
||||
|
||||
if (HEDLEY_UNLIKELY(codepoint2 == -1))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
|
||||
{
|
||||
error_message = "invalid string: '\\u' must be followed by 4 hex digits";
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
||||
// check if codepoint2 is a low surrogate
|
||||
if (HEDLEY_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
|
||||
{
|
||||
// overwrite codepoint
|
||||
codepoint = static_cast<int>(
|
||||
|
@ -348,7 +348,7 @@ class lexer
|
|||
}
|
||||
else
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
|
||||
{
|
||||
error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
|
||||
return token_type::parse_error;
|
||||
|
@ -723,7 +723,7 @@ class lexer
|
|||
case 0xDE:
|
||||
case 0xDF:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not next_byte_in_range({0x80, 0xBF})))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not next_byte_in_range({0x80, 0xBF})))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -733,7 +733,7 @@ class lexer
|
|||
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
|
||||
case 0xE0:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -757,7 +757,7 @@ class lexer
|
|||
case 0xEE:
|
||||
case 0xEF:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -767,7 +767,7 @@ class lexer
|
|||
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
|
||||
case 0xED:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -777,7 +777,7 @@ class lexer
|
|||
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
|
||||
case 0xF0:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -789,7 +789,7 @@ class lexer
|
|||
case 0xF2:
|
||||
case 0xF3:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ class lexer
|
|||
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
|
||||
case 0xF4:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -816,19 +816,19 @@ class lexer
|
|||
}
|
||||
}
|
||||
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
static void strtof(float& f, const char* str, char** endptr) noexcept
|
||||
{
|
||||
f = std::strtof(str, endptr);
|
||||
}
|
||||
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
static void strtof(double& f, const char* str, char** endptr) noexcept
|
||||
{
|
||||
f = std::strtod(str, endptr);
|
||||
}
|
||||
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
static void strtof(long double& f, const char* str, char** endptr) noexcept
|
||||
{
|
||||
f = std::strtold(str, endptr);
|
||||
|
@ -1204,14 +1204,14 @@ scan_number_done:
|
|||
@param[in] length the length of the passed literal text
|
||||
@param[in] return_type the token type to return on success
|
||||
*/
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
token_type scan_literal(const char* literal_text, const std::size_t length,
|
||||
token_type return_type)
|
||||
{
|
||||
assert(current == literal_text[0]);
|
||||
for (std::size_t i = 1; i < length; ++i)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(get() != literal_text[i]))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(get() != literal_text[i]))
|
||||
{
|
||||
error_message = "invalid literal";
|
||||
return token_type::parse_error;
|
||||
|
@ -1257,7 +1257,7 @@ scan_number_done:
|
|||
current = ia->get_character();
|
||||
}
|
||||
|
||||
if (HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
|
||||
{
|
||||
token_string.push_back(std::char_traits<char>::to_char_type(current));
|
||||
}
|
||||
|
@ -1298,7 +1298,7 @@ scan_number_done:
|
|||
--position.chars_read_current_line;
|
||||
}
|
||||
|
||||
if (HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
|
||||
{
|
||||
assert(not token_string.empty());
|
||||
token_string.pop_back();
|
||||
|
@ -1377,7 +1377,7 @@ scan_number_done:
|
|||
}
|
||||
|
||||
/// return syntax error message
|
||||
HEDLEY_RETURNS_NON_NULL
|
||||
NLOHMANN_JSON_HEDLEY_RETURNS_NON_NULL
|
||||
constexpr const char* get_error_message() const noexcept
|
||||
{
|
||||
return error_message;
|
||||
|
|
|
@ -147,7 +147,7 @@ class parser
|
|||
}
|
||||
|
||||
template <typename SAX>
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
bool sax_parse(SAX* sax, const bool strict = true)
|
||||
{
|
||||
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
|
||||
|
@ -167,7 +167,7 @@ class parser
|
|||
|
||||
private:
|
||||
template <typename SAX>
|
||||
HEDLEY_NON_NULL(2)
|
||||
NLOHMANN_JSON_HEDLEY_NON_NULL(2)
|
||||
bool sax_parse_internal(SAX* sax)
|
||||
{
|
||||
// stack to remember the hierarchy of structured values we are parsing
|
||||
|
@ -185,7 +185,7 @@ class parser
|
|||
{
|
||||
case token_type::begin_object:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ class parser
|
|||
// closing } -> we are done
|
||||
if (get_token() == token_type::end_object)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->end_object()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->end_object()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -201,20 +201,20 @@ class parser
|
|||
}
|
||||
|
||||
// parse key
|
||||
if (HEDLEY_UNLIKELY(last_token != token_type::value_string))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(),
|
||||
exception_message(token_type::value_string, "object key")));
|
||||
}
|
||||
if (HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse separator (:)
|
||||
if (HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
|
@ -232,7 +232,7 @@ class parser
|
|||
|
||||
case token_type::begin_array:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ class parser
|
|||
// closing ] -> we are done
|
||||
if (get_token() == token_type::end_array)
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->end_array()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->end_array()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -258,14 +258,14 @@ class parser
|
|||
{
|
||||
const auto res = m_lexer.get_number_float();
|
||||
|
||||
if (HEDLEY_UNLIKELY(not std::isfinite(res)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not std::isfinite(res)))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'"));
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ class parser
|
|||
|
||||
case token_type::literal_false:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->boolean(false)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->boolean(false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ class parser
|
|||
|
||||
case token_type::literal_null:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->null()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->null()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ class parser
|
|||
|
||||
case token_type::literal_true:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->boolean(true)))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->boolean(true)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ class parser
|
|||
|
||||
case token_type::value_integer:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->number_integer(m_lexer.get_number_integer())))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->number_integer(m_lexer.get_number_integer())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ class parser
|
|||
|
||||
case token_type::value_string:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->string(m_lexer.get_string())))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->string(m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ class parser
|
|||
|
||||
case token_type::value_unsigned:
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->number_unsigned(m_lexer.get_number_unsigned())))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->number_unsigned(m_lexer.get_number_unsigned())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -368,9 +368,9 @@ class parser
|
|||
}
|
||||
|
||||
// closing ]
|
||||
if (HEDLEY_LIKELY(last_token == token_type::end_array))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->end_array()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->end_array()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ class parser
|
|||
if (get_token() == token_type::value_separator)
|
||||
{
|
||||
// parse key
|
||||
if (HEDLEY_UNLIKELY(get_token() != token_type::value_string))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
|
@ -404,13 +404,13 @@ class parser
|
|||
exception_message(token_type::value_string, "object key")));
|
||||
}
|
||||
|
||||
if (HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse separator (:)
|
||||
if (HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
|
@ -424,9 +424,9 @@ class parser
|
|||
}
|
||||
|
||||
// closing }
|
||||
if (HEDLEY_LIKELY(last_token == token_type::end_object))
|
||||
if (NLOHMANN_JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
|
||||
{
|
||||
if (HEDLEY_UNLIKELY(not sax->end_object()))
|
||||
if (NLOHMANN_JSON_HEDLEY_UNLIKELY(not sax->end_object()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue