Merge branch 'feature/hedley' into develop
This commit is contained in:
commit
a501365ea2
35 changed files with 5861 additions and 959 deletions
11
Makefile
11
Makefile
|
@ -616,3 +616,14 @@ clean:
|
|||
rm -fr build_coverage build_benchmarks fuzz-testing clang_analyze_build pvs_studio_build infer_build clang_sanitize_build cmake_build
|
||||
$(MAKE) clean -Cdoc
|
||||
$(MAKE) clean -Ctest
|
||||
|
||||
##########################################################################
|
||||
# Thirdparty code
|
||||
##########################################################################
|
||||
|
||||
update_hedley:
|
||||
rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp
|
||||
curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp
|
||||
gsed -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp
|
||||
grep "[[:blank:]]*#[[:blank:]]*undef" include/nlohmann/thirdparty/hedley/hedley.hpp | grep -v "__" | sort | uniq | gsed 's/ //g' | gsed 's/undef/undef /g' > include/nlohmann/thirdparty/hedley/hedley_undef.hpp
|
||||
$(MAKE) amalgamate
|
||||
|
|
|
@ -1076,6 +1076,8 @@ The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed und
|
|||
|
||||
The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](http://opensource.org/licenses/MIT) (see above). Copyright © 2009 [Florian Loitsch](http://florian.loitsch.com/)
|
||||
|
||||
The class contains a copy of [Hedley](https://nemequ.github.io/hedley/) from Evan Nemerson which is licensed as [CC0-1.0](http://creativecommons.org/publicdomain/zero/1.0/).
|
||||
|
||||
## Contact
|
||||
|
||||
If you have questions regarding the library, I would like to invite you to [open an issue at GitHub](https://github.com/nlohmann/json/issues/new/choose). Please describe your request, problem, or question as detailed as possible, and also mention the version of the library you are using as well as the version of your compiler and operating system. Opening an issue at GitHub allows other users and contributors to this library to collaborate. For instance, I have little experience with MSVC, and most issues in this regard have been solved by a growing community. If you have a look at the [closed issues](https://github.com/nlohmann/json/issues?q=is%3Aissue+is%3Aclosed), you will see that we react quite timely in most cases.
|
||||
|
@ -1285,6 +1287,7 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||
- [**git-update-ghpages**](https://github.com/rstacruz/git-update-ghpages) to upload the documentation to gh-pages
|
||||
- [**GitHub Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
|
||||
- [**Google Benchmark**](https://github.com/google/benchmark) to implement the benchmarks
|
||||
- [**Hedley**](https://nemequ.github.io/hedley/) to avoid re-inventing several compiler-agnostic feature macros
|
||||
- [**lcov**](http://ltp.sourceforge.net/coverage/lcov.php) to process coverage information and create a HTML view
|
||||
- [**libFuzzer**](http://llvm.org/docs/LibFuzzer.html) to implement fuzz testing for OSS-Fuzz
|
||||
- [**OSS-Fuzz**](https://github.com/google/oss-fuzz) for continuous fuzz testing of the library ([project repository](https://github.com/google/oss-fuzz/tree/master/projects/json))
|
||||
|
|
|
@ -61,6 +61,8 @@ doxygen: create_output create_links
|
|||
$(SED) -i 's@template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>@@g' html/*.html
|
||||
$(SED) -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >@@g' html/*.html
|
||||
$(SED) -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >@@g' html/*.html
|
||||
$(SED) -i 's@JSON_HEDLEY_RETURNS_NON_NULL@@g' html/*.html
|
||||
$(SED) -i 's@JSON_HEDLEY_WARN_UNUSED_RESULT@@g' html/*.html
|
||||
|
||||
upload: clean doxygen check_output
|
||||
scripts/git-update-ghpages nlohmann/json html
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace detail
|
|||
template<typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_null()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_null()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
|||
template<typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_boolean()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_boolean()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
|
|||
template<typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_string()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ template <
|
|||
int > = 0 >
|
||||
void from_json(const BasicJsonType& j, ConstructibleStringType& s)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_string()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ template<typename BasicJsonType, typename T, typename Allocator,
|
|||
enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
|
||||
void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ template<typename BasicJsonType, typename T,
|
|||
enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
|
||||
void from_json(const BasicJsonType& j, std::valarray<T>& l)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
|
|||
j.template get<typename ConstructibleArrayType::value_type>(),
|
||||
void())
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " +
|
||||
std::string(j.type_name())));
|
||||
|
@ -249,7 +249,7 @@ template<typename BasicJsonType, typename ConstructibleObjectType,
|
|||
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
|
||||
void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_object()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -332,14 +332,14 @@ template <typename BasicJsonType, typename Key, typename Value, typename Compare
|
|||
typename BasicJsonType::string_t, Key>::value>>
|
||||
void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
|
||||
}
|
||||
m.clear();
|
||||
for (const auto& p : j)
|
||||
{
|
||||
if (JSON_UNLIKELY(not p.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name())));
|
||||
}
|
||||
|
@ -352,14 +352,14 @@ template <typename BasicJsonType, typename Key, typename Value, typename Hash, t
|
|||
typename BasicJsonType::string_t, Key>::value>>
|
||||
void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
|
||||
}
|
||||
m.clear();
|
||||
for (const auto& p : j)
|
||||
{
|
||||
if (JSON_UNLIKELY(not p.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name())));
|
||||
}
|
||||
|
@ -386,4 +386,4 @@ namespace
|
|||
{
|
||||
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
|
||||
} // namespace
|
||||
} // namespace nlohmann
|
||||
} // namespace nlohmann
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <cstring> // memcpy, memmove
|
||||
#include <limits> // numeric_limits
|
||||
#include <type_traits> // conditional
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
|
@ -818,6 +819,7 @@ v = buf * 10^decimal_exponent
|
|||
len is the length of the buffer (number of decimal digits)
|
||||
The buffer must be large enough, i.e. >= max_digits10.
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline void grisu2(char* buf, int& len, int& decimal_exponent,
|
||||
diyfp m_minus, diyfp v, diyfp m_plus)
|
||||
{
|
||||
|
@ -877,6 +879,7 @@ len is the length of the buffer (number of decimal digits)
|
|||
The buffer must be large enough, i.e. >= max_digits10.
|
||||
*/
|
||||
template <typename FloatType>
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
|
||||
{
|
||||
static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
|
||||
|
@ -915,6 +918,8 @@ void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
|
|||
@return a pointer to the element following the exponent.
|
||||
@pre -1000 < e < 1000
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
inline char* append_exponent(char* buf, int e)
|
||||
{
|
||||
assert(e > -1000);
|
||||
|
@ -965,6 +970,8 @@ notation. Otherwise it will be printed in exponential notation.
|
|||
@pre min_exp < 0
|
||||
@pre max_exp > 0
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
inline char* format_buffer(char* buf, int len, int decimal_exponent,
|
||||
int min_exp, int max_exp)
|
||||
{
|
||||
|
@ -1048,6 +1055,8 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
|
|||
@note The result is NOT null-terminated.
|
||||
*/
|
||||
template <typename FloatType>
|
||||
JSON_HEDLEY_NON_NULL(1, 2)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
char* to_chars(char* first, const char* last, FloatType value)
|
||||
{
|
||||
static_cast<void>(last); // maybe unused - fix warning
|
||||
|
|
|
@ -341,4 +341,4 @@ namespace
|
|||
{
|
||||
constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
|
||||
} // namespace
|
||||
} // namespace nlohmann
|
||||
} // namespace nlohmann
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <string> // to_string
|
||||
|
||||
#include <nlohmann/detail/input/position_t.hpp>
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
|
@ -46,6 +47,7 @@ class exception : public std::exception
|
|||
{
|
||||
public:
|
||||
/// returns the explanatory string
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return m.what();
|
||||
|
@ -55,6 +57,7 @@ class exception : public std::exception
|
|||
const int id;
|
||||
|
||||
protected:
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
|
||||
|
||||
static std::string name(const std::string& ename, int id_)
|
||||
|
@ -207,6 +210,7 @@ class invalid_iterator : public exception
|
|||
}
|
||||
|
||||
private:
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
invalid_iterator(int id_, const char* what_arg)
|
||||
: exception(id_, what_arg) {}
|
||||
};
|
||||
|
@ -260,6 +264,7 @@ class type_error : public exception
|
|||
}
|
||||
|
||||
private:
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
|
||||
};
|
||||
|
||||
|
@ -306,6 +311,7 @@ class out_of_range : public exception
|
|||
}
|
||||
|
||||
private:
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
|
||||
};
|
||||
|
||||
|
@ -343,6 +349,7 @@ class other_error : public exception
|
|||
}
|
||||
|
||||
private:
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
|
||||
};
|
||||
} // namespace detail
|
||||
|
|
|
@ -66,6 +66,7 @@ class binary_reader
|
|||
|
||||
@return
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
bool sax_parse(const input_format_t format,
|
||||
json_sax_t* sax_,
|
||||
const bool strict = true)
|
||||
|
@ -107,7 +108,7 @@ class binary_reader
|
|||
get();
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(current != std::char_traits<char>::eof()))
|
||||
if (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")));
|
||||
|
@ -143,12 +144,12 @@ class binary_reader
|
|||
std::int32_t document_size;
|
||||
get_number<std::int32_t, true>(input_format_t::bson, document_size);
|
||||
|
||||
if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not parse_bson_element_list(/*is_array*/false)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -169,7 +170,7 @@ class binary_reader
|
|||
while (true)
|
||||
{
|
||||
get();
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::bson, "cstring")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::bson, "cstring")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -197,7 +198,7 @@ class binary_reader
|
|||
template<typename NumberType>
|
||||
bool get_bson_string(const NumberType len, string_t& result)
|
||||
{
|
||||
if (JSON_UNLIKELY(len < 1))
|
||||
if (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")));
|
||||
|
@ -292,13 +293,13 @@ class binary_reader
|
|||
string_t key;
|
||||
while (int element_type = get())
|
||||
{
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::bson, "element list")))
|
||||
if (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 (JSON_UNLIKELY(not get_bson_cstr(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_bson_cstr(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -308,7 +309,7 @@ class binary_reader
|
|||
return false;
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -329,12 +330,12 @@ class binary_reader
|
|||
std::int32_t document_size;
|
||||
get_number<std::int32_t, true>(input_format_t::bson, document_size);
|
||||
|
||||
if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not parse_bson_element_list(/*is_array*/true)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_bson_element_list(/*is_array*/true)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -619,12 +620,12 @@ class binary_reader
|
|||
case 0xF9: // Half-Precision Float (two-byte IEEE 754)
|
||||
{
|
||||
const int byte1_raw = get();
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const int byte2_raw = get();
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -697,7 +698,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_cbor_string(string_t& result)
|
||||
{
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::cbor, "string")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "string")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -786,7 +787,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_cbor_array(const std::size_t len)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_array(len)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -795,7 +796,7 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (JSON_UNLIKELY(not parse_cbor_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -805,7 +806,7 @@ class binary_reader
|
|||
{
|
||||
while (get() != 0xFF)
|
||||
{
|
||||
if (JSON_UNLIKELY(not parse_cbor_internal(false)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal(false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -822,7 +823,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_cbor_object(const std::size_t len)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_object(len)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -833,12 +834,12 @@ class binary_reader
|
|||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not parse_cbor_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -849,12 +850,12 @@ class binary_reader
|
|||
{
|
||||
while (get() != 0xFF)
|
||||
{
|
||||
if (JSON_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not parse_cbor_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1243,7 +1244,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_msgpack_string(string_t& result)
|
||||
{
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::msgpack, "string")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::msgpack, "string")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1319,14 +1320,14 @@ class binary_reader
|
|||
*/
|
||||
bool get_msgpack_array(const std::size_t len)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_array(len)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (JSON_UNLIKELY(not parse_msgpack_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1341,7 +1342,7 @@ class binary_reader
|
|||
*/
|
||||
bool get_msgpack_object(const std::size_t len)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_object(len)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1350,12 +1351,12 @@ class binary_reader
|
|||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_UNLIKELY(not get_msgpack_string(key) or not sax->key(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_msgpack_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not parse_msgpack_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1402,7 +1403,7 @@ class binary_reader
|
|||
get(); // TODO(niels): may we ignore N here?
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1456,7 +1457,7 @@ class binary_reader
|
|||
case 'U':
|
||||
{
|
||||
std::uint8_t number;
|
||||
if (JSON_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1467,7 +1468,7 @@ class binary_reader
|
|||
case 'i':
|
||||
{
|
||||
std::int8_t number;
|
||||
if (JSON_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1478,7 +1479,7 @@ class binary_reader
|
|||
case 'I':
|
||||
{
|
||||
std::int16_t number;
|
||||
if (JSON_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1489,7 +1490,7 @@ class binary_reader
|
|||
case 'l':
|
||||
{
|
||||
std::int32_t number;
|
||||
if (JSON_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1500,7 +1501,7 @@ class binary_reader
|
|||
case 'L':
|
||||
{
|
||||
std::int64_t number;
|
||||
if (JSON_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_number(input_format_t::ubjson, number)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1536,15 +1537,15 @@ class binary_reader
|
|||
if (current == '$')
|
||||
{
|
||||
result.second = get(); // must not ignore 'N', because 'N' maybe the type
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "type")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "type")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
get_ignore_noop();
|
||||
if (JSON_UNLIKELY(current != '#'))
|
||||
if (JSON_HEDLEY_UNLIKELY(current != '#'))
|
||||
{
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "value")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1627,11 +1628,11 @@ class binary_reader
|
|||
case 'C': // char
|
||||
{
|
||||
get();
|
||||
if (JSON_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "char")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::ubjson, "char")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (JSON_UNLIKELY(current > 127))
|
||||
if (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")));
|
||||
|
@ -1666,14 +1667,14 @@ class binary_reader
|
|||
bool get_ubjson_array()
|
||||
{
|
||||
std::pair<std::size_t, int> size_and_type;
|
||||
if (JSON_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size_and_type.first != string_t::npos)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_array(size_and_type.first)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(size_and_type.first)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1684,7 +1685,7 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (JSON_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1695,7 +1696,7 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (JSON_UNLIKELY(not parse_ubjson_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1704,14 +1705,14 @@ class binary_reader
|
|||
}
|
||||
else
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (current != ']')
|
||||
{
|
||||
if (JSON_UNLIKELY(not parse_ubjson_internal(false)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal(false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1728,7 +1729,7 @@ class binary_reader
|
|||
bool get_ubjson_object()
|
||||
{
|
||||
std::pair<std::size_t, int> size_and_type;
|
||||
if (JSON_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1736,7 +1737,7 @@ class binary_reader
|
|||
string_t key;
|
||||
if (size_and_type.first != string_t::npos)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_object(size_and_type.first)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(size_and_type.first)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1745,11 +1746,11 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (JSON_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (JSON_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_value(size_and_type.second)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1760,11 +1761,11 @@ class binary_reader
|
|||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (JSON_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (JSON_UNLIKELY(not parse_ubjson_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1774,18 +1775,18 @@ class binary_reader
|
|||
}
|
||||
else
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (current != '}')
|
||||
{
|
||||
if (JSON_UNLIKELY(not get_ubjson_string(key, false) or not sax->key(key)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key, false) or not sax->key(key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (JSON_UNLIKELY(not parse_ubjson_internal()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1851,7 +1852,7 @@ class binary_reader
|
|||
for (std::size_t i = 0; i < sizeof(NumberType); ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_UNLIKELY(not unexpect_eof(format, "number")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1895,7 +1896,7 @@ class binary_reader
|
|||
std::generate_n(std::back_inserter(result), len, [this, &success, &format]()
|
||||
{
|
||||
get();
|
||||
if (JSON_UNLIKELY(not unexpect_eof(format, "string")))
|
||||
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "string")))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
@ -1909,9 +1910,10 @@ class binary_reader
|
|||
@param[in] context further context information (for diagnostics)
|
||||
@return whether the last read character is not EOF
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
bool unexpect_eof(const input_format_t format, const char* context) const
|
||||
{
|
||||
if (JSON_UNLIKELY(current == std::char_traits<char>::eof()))
|
||||
if (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,6 +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:
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
explicit file_input_adapter(std::FILE* f) noexcept
|
||||
: m_file(f)
|
||||
{}
|
||||
|
@ -130,6 +131,7 @@ class input_stream_adapter : public input_adapter_protocol
|
|||
class input_buffer_adapter : public input_adapter_protocol
|
||||
{
|
||||
public:
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
input_buffer_adapter(const char* b, const std::size_t l) noexcept
|
||||
: cursor(b), limit(b + l)
|
||||
{}
|
||||
|
@ -143,7 +145,7 @@ class input_buffer_adapter : public input_adapter_protocol
|
|||
|
||||
std::char_traits<char>::int_type get_character() noexcept override
|
||||
{
|
||||
if (JSON_LIKELY(cursor < limit))
|
||||
if (JSON_HEDLEY_LIKELY(cursor < limit))
|
||||
{
|
||||
return std::char_traits<char>::to_int_type(*(cursor++));
|
||||
}
|
||||
|
@ -333,6 +335,7 @@ class input_adapter
|
|||
{
|
||||
public:
|
||||
// native support
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
input_adapter(std::FILE* file)
|
||||
: ia(std::make_shared<file_input_adapter>(file)) {}
|
||||
/// input adapter for input stream
|
||||
|
@ -401,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 (JSON_LIKELY(len > 0))
|
||||
if (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 (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (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 (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (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,6 +288,7 @@ class json_sax_dom_parser
|
|||
object to which we can add elements
|
||||
*/
|
||||
template<typename Value>
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
BasicJsonType* handle_value(Value&& v)
|
||||
{
|
||||
if (ref_stack.empty())
|
||||
|
@ -394,7 +395,7 @@ class json_sax_dom_callback_parser
|
|||
ref_stack.push_back(val.second);
|
||||
|
||||
// check object limit
|
||||
if (ref_stack.back() and JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (ref_stack.back() and 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)));
|
||||
}
|
||||
|
@ -457,7 +458,7 @@ class json_sax_dom_callback_parser
|
|||
ref_stack.push_back(val.second);
|
||||
|
||||
// check array limit
|
||||
if (ref_stack.back() and JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
|
||||
if (ref_stack.back() and 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,6 +59,8 @@ class lexer
|
|||
};
|
||||
|
||||
/// return name of values of type token_type (only used for errors)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
JSON_HEDLEY_CONST
|
||||
static const char* token_type_name(const token_type t) noexcept
|
||||
{
|
||||
switch (t)
|
||||
|
@ -118,6 +120,7 @@ class lexer
|
|||
/////////////////////
|
||||
|
||||
/// return the locale-dependent decimal point
|
||||
JSON_HEDLEY_PURE
|
||||
static char get_decimal_point() noexcept
|
||||
{
|
||||
const auto loc = localeconv();
|
||||
|
@ -200,7 +203,7 @@ class lexer
|
|||
for (auto range = ranges.begin(); range != ranges.end(); ++range)
|
||||
{
|
||||
get();
|
||||
if (JSON_LIKELY(*range <= current and current <= *(++range)))
|
||||
if (JSON_HEDLEY_LIKELY(*range <= current and current <= *(++range)))
|
||||
{
|
||||
add(current);
|
||||
}
|
||||
|
@ -299,7 +302,7 @@ class lexer
|
|||
const int codepoint1 = get_codepoint();
|
||||
int codepoint = codepoint1; // start with codepoint1
|
||||
|
||||
if (JSON_UNLIKELY(codepoint1 == -1))
|
||||
if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
|
||||
{
|
||||
error_message = "invalid string: '\\u' must be followed by 4 hex digits";
|
||||
return token_type::parse_error;
|
||||
|
@ -309,18 +312,18 @@ class lexer
|
|||
if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
|
||||
{
|
||||
// expect next \uxxxx entry
|
||||
if (JSON_LIKELY(get() == '\\' and get() == 'u'))
|
||||
if (JSON_HEDLEY_LIKELY(get() == '\\' and get() == 'u'))
|
||||
{
|
||||
const int codepoint2 = get_codepoint();
|
||||
|
||||
if (JSON_UNLIKELY(codepoint2 == -1))
|
||||
if (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 (JSON_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
|
||||
if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
|
||||
{
|
||||
// overwrite codepoint
|
||||
codepoint = static_cast<int>(
|
||||
|
@ -347,7 +350,7 @@ class lexer
|
|||
}
|
||||
else
|
||||
{
|
||||
if (JSON_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
|
||||
if (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;
|
||||
|
@ -722,7 +725,7 @@ class lexer
|
|||
case 0xDE:
|
||||
case 0xDF:
|
||||
{
|
||||
if (JSON_UNLIKELY(not next_byte_in_range({0x80, 0xBF})))
|
||||
if (JSON_HEDLEY_UNLIKELY(not next_byte_in_range({0x80, 0xBF})))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -732,7 +735,7 @@ class lexer
|
|||
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
|
||||
case 0xE0:
|
||||
{
|
||||
if (JSON_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -756,7 +759,7 @@ class lexer
|
|||
case 0xEE:
|
||||
case 0xEF:
|
||||
{
|
||||
if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -766,7 +769,7 @@ class lexer
|
|||
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
|
||||
case 0xED:
|
||||
{
|
||||
if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -776,7 +779,7 @@ class lexer
|
|||
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
|
||||
case 0xF0:
|
||||
{
|
||||
if (JSON_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -788,7 +791,7 @@ class lexer
|
|||
case 0xF2:
|
||||
case 0xF3:
|
||||
{
|
||||
if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -798,7 +801,7 @@ class lexer
|
|||
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
|
||||
case 0xF4:
|
||||
{
|
||||
if (JSON_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
|
||||
{
|
||||
return token_type::parse_error;
|
||||
}
|
||||
|
@ -815,16 +818,19 @@ class lexer
|
|||
}
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
static void strtof(float& f, const char* str, char** endptr) noexcept
|
||||
{
|
||||
f = std::strtof(str, endptr);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
static void strtof(double& f, const char* str, char** endptr) noexcept
|
||||
{
|
||||
f = std::strtod(str, endptr);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
static void strtof(long double& f, const char* str, char** endptr) noexcept
|
||||
{
|
||||
f = std::strtold(str, endptr);
|
||||
|
@ -1200,13 +1206,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
|
||||
*/
|
||||
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 (JSON_UNLIKELY(get() != literal_text[i]))
|
||||
if (JSON_HEDLEY_UNLIKELY(get() != literal_text[i]))
|
||||
{
|
||||
error_message = "invalid literal";
|
||||
return token_type::parse_error;
|
||||
|
@ -1252,7 +1259,7 @@ scan_number_done:
|
|||
current = ia->get_character();
|
||||
}
|
||||
|
||||
if (JSON_LIKELY(current != std::char_traits<char>::eof()))
|
||||
if (JSON_HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
|
||||
{
|
||||
token_string.push_back(std::char_traits<char>::to_char_type(current));
|
||||
}
|
||||
|
@ -1293,7 +1300,7 @@ scan_number_done:
|
|||
--position.chars_read_current_line;
|
||||
}
|
||||
|
||||
if (JSON_LIKELY(current != std::char_traits<char>::eof()))
|
||||
if (JSON_HEDLEY_LIKELY(current != std::char_traits<char>::eof()))
|
||||
{
|
||||
assert(not token_string.empty());
|
||||
token_string.pop_back();
|
||||
|
@ -1372,6 +1379,7 @@ scan_number_done:
|
|||
}
|
||||
|
||||
/// return syntax error message
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
constexpr const char* get_error_message() const noexcept
|
||||
{
|
||||
return error_message;
|
||||
|
|
|
@ -147,6 +147,7 @@ class parser
|
|||
}
|
||||
|
||||
template <typename SAX>
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
bool sax_parse(SAX* sax, const bool strict = true)
|
||||
{
|
||||
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
|
||||
|
@ -166,6 +167,7 @@ class parser
|
|||
|
||||
private:
|
||||
template <typename SAX>
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
bool sax_parse_internal(SAX* sax)
|
||||
{
|
||||
// stack to remember the hierarchy of structured values we are parsing
|
||||
|
@ -183,7 +185,7 @@ class parser
|
|||
{
|
||||
case token_type::begin_object:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -191,7 +193,7 @@ class parser
|
|||
// closing } -> we are done
|
||||
if (get_token() == token_type::end_object)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->end_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->end_object()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -199,20 +201,20 @@ class parser
|
|||
}
|
||||
|
||||
// parse key
|
||||
if (JSON_UNLIKELY(last_token != token_type::value_string))
|
||||
if (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 (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse separator (:)
|
||||
if (JSON_UNLIKELY(get_token() != token_type::name_separator))
|
||||
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
|
@ -230,7 +232,7 @@ class parser
|
|||
|
||||
case token_type::begin_array:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -238,7 +240,7 @@ class parser
|
|||
// closing ] -> we are done
|
||||
if (get_token() == token_type::end_array)
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->end_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->end_array()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -256,14 +258,14 @@ class parser
|
|||
{
|
||||
const auto res = m_lexer.get_number_float();
|
||||
|
||||
if (JSON_UNLIKELY(not std::isfinite(res)))
|
||||
if (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 (JSON_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -273,7 +275,7 @@ class parser
|
|||
|
||||
case token_type::literal_false:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->boolean(false)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->boolean(false)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -282,7 +284,7 @@ class parser
|
|||
|
||||
case token_type::literal_null:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->null()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->null()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -291,7 +293,7 @@ class parser
|
|||
|
||||
case token_type::literal_true:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->boolean(true)))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->boolean(true)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -300,7 +302,7 @@ class parser
|
|||
|
||||
case token_type::value_integer:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->number_integer(m_lexer.get_number_integer())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->number_integer(m_lexer.get_number_integer())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -309,7 +311,7 @@ class parser
|
|||
|
||||
case token_type::value_string:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->string(m_lexer.get_string())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->string(m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -318,7 +320,7 @@ class parser
|
|||
|
||||
case token_type::value_unsigned:
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->number_unsigned(m_lexer.get_number_unsigned())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->number_unsigned(m_lexer.get_number_unsigned())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -366,9 +368,9 @@ class parser
|
|||
}
|
||||
|
||||
// closing ]
|
||||
if (JSON_LIKELY(last_token == token_type::end_array))
|
||||
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->end_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->end_array()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -394,7 +396,7 @@ class parser
|
|||
if (get_token() == token_type::value_separator)
|
||||
{
|
||||
// parse key
|
||||
if (JSON_UNLIKELY(get_token() != token_type::value_string))
|
||||
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
|
@ -402,13 +404,13 @@ class parser
|
|||
exception_message(token_type::value_string, "object key")));
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse separator (:)
|
||||
if (JSON_UNLIKELY(get_token() != token_type::name_separator))
|
||||
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
|
@ -422,9 +424,9 @@ class parser
|
|||
}
|
||||
|
||||
// closing }
|
||||
if (JSON_LIKELY(last_token == token_type::end_object))
|
||||
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
|
||||
{
|
||||
if (JSON_UNLIKELY(not sax->end_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not sax->end_object()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -126,7 +126,8 @@ class iter_impl
|
|||
information refer to: https://github.com/nlohmann/json/issues/1608
|
||||
*/
|
||||
iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
|
||||
: m_object(other.m_object), m_it(other.m_it) {}
|
||||
: m_object(other.m_object), m_it(other.m_it)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@brief converting assignment
|
||||
|
@ -147,7 +148,8 @@ class iter_impl
|
|||
@note It is not checked whether @a other is initialized.
|
||||
*/
|
||||
iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
|
||||
: m_object(other.m_object), m_it(other.m_it) {}
|
||||
: m_object(other.m_object), m_it(other.m_it)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@brief converting assignment
|
||||
|
@ -162,6 +164,14 @@ class iter_impl
|
|||
return *this;
|
||||
}
|
||||
|
||||
/// @copydoc operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>&)
|
||||
iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept
|
||||
{
|
||||
m_object = other.m_object;
|
||||
m_it = other.m_it;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
@brief set the iterator to the first value
|
||||
|
@ -258,7 +268,7 @@ class iter_impl
|
|||
|
||||
default:
|
||||
{
|
||||
if (JSON_LIKELY(m_it.primitive_iterator.is_begin()))
|
||||
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
|
||||
{
|
||||
return *m_object;
|
||||
}
|
||||
|
@ -292,7 +302,7 @@ class iter_impl
|
|||
|
||||
default:
|
||||
{
|
||||
if (JSON_LIKELY(m_it.primitive_iterator.is_begin()))
|
||||
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
@ -395,7 +405,7 @@ class iter_impl
|
|||
bool operator==(const iter_impl& other) const
|
||||
{
|
||||
// if objects are not the same, the comparison is undefined
|
||||
if (JSON_UNLIKELY(m_object != other.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers"));
|
||||
}
|
||||
|
@ -431,7 +441,7 @@ class iter_impl
|
|||
bool operator<(const iter_impl& other) const
|
||||
{
|
||||
// if objects are not the same, the comparison is undefined
|
||||
if (JSON_UNLIKELY(m_object != other.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers"));
|
||||
}
|
||||
|
@ -591,7 +601,7 @@ class iter_impl
|
|||
|
||||
default:
|
||||
{
|
||||
if (JSON_LIKELY(m_it.primitive_iterator.get_value() == -n))
|
||||
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
|
||||
{
|
||||
return *m_object;
|
||||
}
|
||||
|
@ -609,7 +619,7 @@ class iter_impl
|
|||
{
|
||||
assert(m_object != nullptr);
|
||||
|
||||
if (JSON_LIKELY(m_object->is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(m_object->is_object()))
|
||||
{
|
||||
return m_it.object_iterator->first;
|
||||
}
|
||||
|
@ -632,5 +642,5 @@ class iter_impl
|
|||
/// the actual iterator of the associated instance
|
||||
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
} // namespace nlohmann
|
||||
|
|
|
@ -245,7 +245,7 @@ class json_pointer
|
|||
*/
|
||||
void pop_back()
|
||||
{
|
||||
if (JSON_UNLIKELY(empty()))
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent"));
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ class json_pointer
|
|||
*/
|
||||
const std::string& back()
|
||||
{
|
||||
if (JSON_UNLIKELY(empty()))
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent"));
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ class json_pointer
|
|||
const int res = std::stoi(s, &processed_chars);
|
||||
|
||||
// check if the string was completely read
|
||||
if (JSON_UNLIKELY(processed_chars != s.size()))
|
||||
if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'"));
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ class json_pointer
|
|||
|
||||
json_pointer top() const
|
||||
{
|
||||
if (JSON_UNLIKELY(empty()))
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent"));
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ class json_pointer
|
|||
case detail::value_t::array:
|
||||
{
|
||||
// error condition (cf. RFC 6901, Sect. 4)
|
||||
if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(106, 0,
|
||||
"array index '" + reference_token +
|
||||
|
@ -533,7 +533,7 @@ class json_pointer
|
|||
|
||||
case detail::value_t::array:
|
||||
{
|
||||
if (JSON_UNLIKELY(reference_token == "-"))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||
{
|
||||
// "-" always fails the range check
|
||||
JSON_THROW(detail::out_of_range::create(402,
|
||||
|
@ -542,7 +542,7 @@ class json_pointer
|
|||
}
|
||||
|
||||
// error condition (cf. RFC 6901, Sect. 4)
|
||||
if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(106, 0,
|
||||
"array index '" + reference_token +
|
||||
|
@ -598,7 +598,7 @@ class json_pointer
|
|||
|
||||
case detail::value_t::array:
|
||||
{
|
||||
if (JSON_UNLIKELY(reference_token == "-"))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||
{
|
||||
// "-" cannot be used for const access
|
||||
JSON_THROW(detail::out_of_range::create(402,
|
||||
|
@ -607,7 +607,7 @@ class json_pointer
|
|||
}
|
||||
|
||||
// error condition (cf. RFC 6901, Sect. 4)
|
||||
if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(106, 0,
|
||||
"array index '" + reference_token +
|
||||
|
@ -657,7 +657,7 @@ class json_pointer
|
|||
|
||||
case detail::value_t::array:
|
||||
{
|
||||
if (JSON_UNLIKELY(reference_token == "-"))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||
{
|
||||
// "-" always fails the range check
|
||||
JSON_THROW(detail::out_of_range::create(402,
|
||||
|
@ -666,7 +666,7 @@ class json_pointer
|
|||
}
|
||||
|
||||
// error condition (cf. RFC 6901, Sect. 4)
|
||||
if (JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1 and reference_token[0] == '0'))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(106, 0,
|
||||
"array index '" + reference_token +
|
||||
|
@ -784,7 +784,7 @@ class json_pointer
|
|||
}
|
||||
|
||||
// check if nonempty reference string begins with slash
|
||||
if (JSON_UNLIKELY(reference_string[0] != '/'))
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(107, 1,
|
||||
"JSON pointer must be empty or begin with '/' - was: '" +
|
||||
|
@ -819,9 +819,9 @@ class json_pointer
|
|||
assert(reference_token[pos] == '~');
|
||||
|
||||
// ~ must be followed by 0 or 1
|
||||
if (JSON_UNLIKELY(pos == reference_token.size() - 1 or
|
||||
(reference_token[pos + 1] != '0' and
|
||||
reference_token[pos + 1] != '1')))
|
||||
if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 or
|
||||
(reference_token[pos + 1] != '0' and
|
||||
reference_token[pos + 1] != '1')))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'"));
|
||||
}
|
||||
|
@ -946,7 +946,7 @@ class json_pointer
|
|||
static BasicJsonType
|
||||
unflatten(const BasicJsonType& value)
|
||||
{
|
||||
if (JSON_UNLIKELY(not value.is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not value.is_object()))
|
||||
{
|
||||
JSON_THROW(detail::type_error::create(314, "only objects can be unflattened"));
|
||||
}
|
||||
|
@ -956,7 +956,7 @@ class json_pointer
|
|||
// iterate the JSON object values
|
||||
for (const auto& element : *value.m_value.object)
|
||||
{
|
||||
if (JSON_UNLIKELY(not element.second.is_primitive()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not element.second.is_primitive()))
|
||||
{
|
||||
JSON_THROW(detail::type_error::create(315, "values in object must be primitive"));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility> // pair
|
||||
#include <nlohmann/thirdparty/hedley/hedley.hpp>
|
||||
|
||||
// This file contains all internal macro definitions
|
||||
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
|
||||
|
@ -38,32 +39,6 @@
|
|||
#pragma GCC diagnostic ignored "-Wdocumentation"
|
||||
#endif
|
||||
|
||||
// allow for portable deprecation warnings
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#define JSON_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define JSON_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define JSON_DEPRECATED
|
||||
#endif
|
||||
|
||||
// allow for portable nodiscard warnings
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(nodiscard)
|
||||
#if defined(__clang__) && !defined(JSON_HAS_CPP_17) // issue #1535
|
||||
#define JSON_NODISCARD
|
||||
#else
|
||||
#define JSON_NODISCARD [[nodiscard]]
|
||||
#endif
|
||||
#elif __has_cpp_attribute(gnu::warn_unused_result)
|
||||
#define JSON_NODISCARD [[gnu::warn_unused_result]]
|
||||
#else
|
||||
#define JSON_NODISCARD
|
||||
#endif
|
||||
#else
|
||||
#define JSON_NODISCARD
|
||||
#endif
|
||||
|
||||
// allow to disable exceptions
|
||||
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
|
||||
#define JSON_THROW(exception) throw exception
|
||||
|
@ -98,15 +73,6 @@
|
|||
#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
|
||||
#endif
|
||||
|
||||
// manual branch prediction
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#define JSON_LIKELY(x) __builtin_expect(x, 1)
|
||||
#define JSON_UNLIKELY(x) __builtin_expect(x, 0)
|
||||
#else
|
||||
#define JSON_LIKELY(x) x
|
||||
#define JSON_UNLIKELY(x) x
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@brief macro to briefly define a mapping between an enum and JSON
|
||||
@def NLOHMANN_JSON_SERIALIZE_ENUM
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
#undef JSON_CATCH
|
||||
#undef JSON_THROW
|
||||
#undef JSON_TRY
|
||||
#undef JSON_LIKELY
|
||||
#undef JSON_UNLIKELY
|
||||
#undef JSON_DEPRECATED
|
||||
#undef JSON_NODISCARD
|
||||
#undef JSON_HAS_CPP_14
|
||||
#undef JSON_HAS_CPP_17
|
||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||
#undef NLOHMANN_BASIC_JSON_TPL
|
||||
|
||||
#include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string> // string
|
||||
|
||||
#include <nlohmann/detail/input/binary_reader.hpp>
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
#include <nlohmann/detail/output/output_adapters.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
|
@ -714,7 +715,7 @@ class binary_writer
|
|||
static std::size_t calc_bson_entry_header_size(const string_t& name)
|
||||
{
|
||||
const auto it = name.find(static_cast<typename string_t::value_type>(0));
|
||||
if (JSON_UNLIKELY(it != BasicJsonType::string_t::npos))
|
||||
if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
|
||||
{
|
||||
JSON_THROW(out_of_range::create(409,
|
||||
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")"));
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <ostream> // basic_ostream
|
||||
#include <string> // basic_string
|
||||
#include <vector> // vector
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
|
@ -39,6 +40,7 @@ class output_vector_adapter : public output_adapter_protocol<CharType>
|
|||
v.push_back(c);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
void write_characters(const CharType* s, std::size_t length) override
|
||||
{
|
||||
std::copy(s, s + length, std::back_inserter(v));
|
||||
|
@ -62,6 +64,7 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
|
|||
stream.put(c);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
void write_characters(const CharType* s, std::size_t length) override
|
||||
{
|
||||
stream.write(s, static_cast<std::streamsize>(length));
|
||||
|
@ -85,6 +88,7 @@ class output_string_adapter : public output_adapter_protocol<CharType>
|
|||
str.push_back(c);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
void write_characters(const CharType* s, std::size_t length) override
|
||||
{
|
||||
str.append(s, length);
|
||||
|
|
|
@ -110,7 +110,7 @@ class serializer
|
|||
|
||||
// variable to hold indentation for recursive calls
|
||||
const auto new_indent = current_indent + indent_step;
|
||||
if (JSON_UNLIKELY(indent_string.size() < new_indent))
|
||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||
{
|
||||
indent_string.resize(indent_string.size() * 2, ' ');
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ class serializer
|
|||
|
||||
// variable to hold indentation for recursive calls
|
||||
const auto new_indent = current_indent + indent_step;
|
||||
if (JSON_UNLIKELY(indent_string.size() < new_indent))
|
||||
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
|
||||
{
|
||||
indent_string.resize(indent_string.size() * 2, ' ');
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ class serializer
|
|||
}
|
||||
|
||||
// we finished processing the string
|
||||
if (JSON_LIKELY(state == UTF8_ACCEPT))
|
||||
if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
|
||||
{
|
||||
// write buffer
|
||||
if (bytes > 0)
|
||||
|
|
|
@ -319,7 +319,7 @@ class basic_json
|
|||
|
||||
@since 2.1.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json meta()
|
||||
{
|
||||
basic_json result;
|
||||
|
@ -824,6 +824,7 @@ class basic_json
|
|||
|
||||
/// helper for exception-safe object creation
|
||||
template<typename T, typename... Args>
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
static T* create(Args&& ... args)
|
||||
{
|
||||
AllocatorType<T> alloc;
|
||||
|
@ -950,7 +951,7 @@ class basic_json
|
|||
default:
|
||||
{
|
||||
object = nullptr; // silence warning, see #821
|
||||
if (JSON_UNLIKELY(t == value_t::null))
|
||||
if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
|
||||
{
|
||||
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.6.1")); // LCOV_EXCL_LINE
|
||||
}
|
||||
|
@ -1427,7 +1428,7 @@ class basic_json
|
|||
}
|
||||
|
||||
// if object is wanted but impossible, throw an exception
|
||||
if (JSON_UNLIKELY(manual_type == value_t::object and not is_an_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object and not is_an_object))
|
||||
{
|
||||
JSON_THROW(type_error::create(301, "cannot create object from initializer list"));
|
||||
}
|
||||
|
@ -1494,7 +1495,7 @@ class basic_json
|
|||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json array(initializer_list_t init = {})
|
||||
{
|
||||
return basic_json(init, false, value_t::array);
|
||||
|
@ -1538,7 +1539,7 @@ class basic_json
|
|||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json object(initializer_list_t init = {})
|
||||
{
|
||||
return basic_json(init, false, value_t::object);
|
||||
|
@ -1637,7 +1638,7 @@ class basic_json
|
|||
assert(last.m_object != nullptr);
|
||||
|
||||
// make sure iterator fits the current value
|
||||
if (JSON_UNLIKELY(first.m_object != last.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(201, "iterators are not compatible"));
|
||||
}
|
||||
|
@ -1654,8 +1655,8 @@ class basic_json
|
|||
case value_t::number_unsigned:
|
||||
case value_t::string:
|
||||
{
|
||||
if (JSON_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
|
||||
or not last.m_it.primitive_iterator.is_end()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
|
||||
or not last.m_it.primitive_iterator.is_end()))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(204, "iterators out of range"));
|
||||
}
|
||||
|
@ -2368,7 +2369,7 @@ class basic_json
|
|||
/// get a boolean (explicit)
|
||||
boolean_t get_impl(boolean_t* /*unused*/) const
|
||||
{
|
||||
if (JSON_LIKELY(is_boolean()))
|
||||
if (JSON_HEDLEY_LIKELY(is_boolean()))
|
||||
{
|
||||
return m_value.boolean;
|
||||
}
|
||||
|
@ -2477,7 +2478,7 @@ class basic_json
|
|||
// delegate the call to get_ptr<>()
|
||||
auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
|
||||
|
||||
if (JSON_LIKELY(ptr != nullptr))
|
||||
if (JSON_HEDLEY_LIKELY(ptr != nullptr))
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
@ -2928,7 +2929,7 @@ class basic_json
|
|||
reference at(size_type idx)
|
||||
{
|
||||
// at only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
JSON_TRY
|
||||
{
|
||||
|
@ -2975,7 +2976,7 @@ class basic_json
|
|||
const_reference at(size_type idx) const
|
||||
{
|
||||
// at only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
JSON_TRY
|
||||
{
|
||||
|
@ -3026,7 +3027,7 @@ class basic_json
|
|||
reference at(const typename object_t::key_type& key)
|
||||
{
|
||||
// at only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
JSON_TRY
|
||||
{
|
||||
|
@ -3077,7 +3078,7 @@ class basic_json
|
|||
const_reference at(const typename object_t::key_type& key) const
|
||||
{
|
||||
// at only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
JSON_TRY
|
||||
{
|
||||
|
@ -3131,7 +3132,7 @@ class basic_json
|
|||
}
|
||||
|
||||
// operator[] only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
// fill up array with null values if given idx is outside range
|
||||
if (idx >= m_value.array->size())
|
||||
|
@ -3169,7 +3170,7 @@ class basic_json
|
|||
const_reference operator[](size_type idx) const
|
||||
{
|
||||
// const operator[] only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
return m_value.array->operator[](idx);
|
||||
}
|
||||
|
@ -3215,7 +3216,7 @@ class basic_json
|
|||
}
|
||||
|
||||
// operator[] only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
return m_value.object->operator[](key);
|
||||
}
|
||||
|
@ -3256,7 +3257,7 @@ class basic_json
|
|||
const_reference operator[](const typename object_t::key_type& key) const
|
||||
{
|
||||
// const operator[] only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
assert(m_value.object->find(key) != m_value.object->end());
|
||||
return m_value.object->find(key)->second;
|
||||
|
@ -3293,6 +3294,7 @@ class basic_json
|
|||
@since version 1.1.0
|
||||
*/
|
||||
template<typename T>
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
reference operator[](T* key)
|
||||
{
|
||||
// implicitly convert null to object
|
||||
|
@ -3304,7 +3306,7 @@ class basic_json
|
|||
}
|
||||
|
||||
// at only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
return m_value.object->operator[](key);
|
||||
}
|
||||
|
@ -3343,10 +3345,11 @@ class basic_json
|
|||
@since version 1.1.0
|
||||
*/
|
||||
template<typename T>
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
const_reference operator[](T* key) const
|
||||
{
|
||||
// at only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
assert(m_value.object->find(key) != m_value.object->end());
|
||||
return m_value.object->find(key)->second;
|
||||
|
@ -3410,7 +3413,7 @@ class basic_json
|
|||
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
|
||||
{
|
||||
// at only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
// if key is found, return value and given default value otherwise
|
||||
const auto it = find(key);
|
||||
|
@ -3482,7 +3485,7 @@ class basic_json
|
|||
ValueType value(const json_pointer& ptr, const ValueType& default_value) const
|
||||
{
|
||||
// at only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
// if pointer resolves a value, return it or use default value
|
||||
JSON_TRY
|
||||
|
@ -3502,6 +3505,7 @@ class basic_json
|
|||
@brief overload for a default value of type const char*
|
||||
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
string_t value(const json_pointer& ptr, const char* default_value) const
|
||||
{
|
||||
return value(ptr, string_t(default_value));
|
||||
|
@ -3646,7 +3650,7 @@ class basic_json
|
|||
IteratorType erase(IteratorType pos)
|
||||
{
|
||||
// make sure iterator fits the current value
|
||||
if (JSON_UNLIKELY(this != pos.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
|
||||
}
|
||||
|
@ -3661,7 +3665,7 @@ class basic_json
|
|||
case value_t::number_unsigned:
|
||||
case value_t::string:
|
||||
{
|
||||
if (JSON_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(205, "iterator out of range"));
|
||||
}
|
||||
|
@ -3751,7 +3755,7 @@ class basic_json
|
|||
IteratorType erase(IteratorType first, IteratorType last)
|
||||
{
|
||||
// make sure iterator fits the current value
|
||||
if (JSON_UNLIKELY(this != first.m_object or this != last.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(this != first.m_object or this != last.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value"));
|
||||
}
|
||||
|
@ -3766,8 +3770,8 @@ class basic_json
|
|||
case value_t::number_unsigned:
|
||||
case value_t::string:
|
||||
{
|
||||
if (JSON_LIKELY(not first.m_it.primitive_iterator.is_begin()
|
||||
or not last.m_it.primitive_iterator.is_end()))
|
||||
if (JSON_HEDLEY_LIKELY(not first.m_it.primitive_iterator.is_begin()
|
||||
or not last.m_it.primitive_iterator.is_end()))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(204, "iterators out of range"));
|
||||
}
|
||||
|
@ -3838,7 +3842,7 @@ class basic_json
|
|||
size_type erase(const typename object_t::key_type& key)
|
||||
{
|
||||
// this erase only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
return m_value.object->erase(key);
|
||||
}
|
||||
|
@ -3873,9 +3877,9 @@ class basic_json
|
|||
void erase(const size_type idx)
|
||||
{
|
||||
// this erase only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
if (JSON_UNLIKELY(idx >= size()))
|
||||
if (JSON_HEDLEY_UNLIKELY(idx >= size()))
|
||||
{
|
||||
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
|
||||
}
|
||||
|
@ -4384,7 +4388,7 @@ class basic_json
|
|||
future 4.0.0 of the library. Please use @ref items() instead;
|
||||
that is, replace `json::iterator_wrapper(j)` with `j.items()`.
|
||||
*/
|
||||
JSON_DEPRECATED
|
||||
JSON_HEDLEY_DEPRECATED(3.1.0)
|
||||
static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept
|
||||
{
|
||||
return ref.items();
|
||||
|
@ -4393,7 +4397,7 @@ class basic_json
|
|||
/*!
|
||||
@copydoc iterator_wrapper(reference)
|
||||
*/
|
||||
JSON_DEPRECATED
|
||||
JSON_HEDLEY_DEPRECATED(3.1.0)
|
||||
static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept
|
||||
{
|
||||
return ref.items();
|
||||
|
@ -4812,7 +4816,7 @@ class basic_json
|
|||
void push_back(basic_json&& val)
|
||||
{
|
||||
// push_back only works for null objects or arrays
|
||||
if (JSON_UNLIKELY(not(is_null() or is_array())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_array())))
|
||||
{
|
||||
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
|
||||
}
|
||||
|
@ -4849,7 +4853,7 @@ class basic_json
|
|||
void push_back(const basic_json& val)
|
||||
{
|
||||
// push_back only works for null objects or arrays
|
||||
if (JSON_UNLIKELY(not(is_null() or is_array())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_array())))
|
||||
{
|
||||
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
|
||||
}
|
||||
|
@ -4899,7 +4903,7 @@ class basic_json
|
|||
void push_back(const typename object_t::value_type& val)
|
||||
{
|
||||
// push_back only works for null objects or objects
|
||||
if (JSON_UNLIKELY(not(is_null() or is_object())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_object())))
|
||||
{
|
||||
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
|
||||
}
|
||||
|
@ -5002,7 +5006,7 @@ class basic_json
|
|||
reference emplace_back(Args&& ... args)
|
||||
{
|
||||
// emplace_back only works for null objects or arrays
|
||||
if (JSON_UNLIKELY(not(is_null() or is_array())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_array())))
|
||||
{
|
||||
JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name())));
|
||||
}
|
||||
|
@ -5055,7 +5059,7 @@ class basic_json
|
|||
std::pair<iterator, bool> emplace(Args&& ... args)
|
||||
{
|
||||
// emplace only works for null objects or arrays
|
||||
if (JSON_UNLIKELY(not(is_null() or is_object())))
|
||||
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_object())))
|
||||
{
|
||||
JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name())));
|
||||
}
|
||||
|
@ -5123,10 +5127,10 @@ class basic_json
|
|||
iterator insert(const_iterator pos, const basic_json& val)
|
||||
{
|
||||
// insert only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
// check if iterator pos fits to this JSON value
|
||||
if (JSON_UNLIKELY(pos.m_object != this))
|
||||
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
|
||||
}
|
||||
|
@ -5174,10 +5178,10 @@ class basic_json
|
|||
iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
|
||||
{
|
||||
// insert only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
// check if iterator pos fits to this JSON value
|
||||
if (JSON_UNLIKELY(pos.m_object != this))
|
||||
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
|
||||
}
|
||||
|
@ -5222,24 +5226,24 @@ class basic_json
|
|||
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
|
||||
{
|
||||
// insert only works for arrays
|
||||
if (JSON_UNLIKELY(not is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
|
||||
}
|
||||
|
||||
// check if iterator pos fits to this JSON value
|
||||
if (JSON_UNLIKELY(pos.m_object != this))
|
||||
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
|
||||
}
|
||||
|
||||
// check if range iterators belong to the same JSON object
|
||||
if (JSON_UNLIKELY(first.m_object != last.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(210, "iterators do not fit"));
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(first.m_object == this))
|
||||
if (JSON_HEDLEY_UNLIKELY(first.m_object == this))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container"));
|
||||
}
|
||||
|
@ -5275,13 +5279,13 @@ class basic_json
|
|||
iterator insert(const_iterator pos, initializer_list_t ilist)
|
||||
{
|
||||
// insert only works for arrays
|
||||
if (JSON_UNLIKELY(not is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not is_array()))
|
||||
{
|
||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
|
||||
}
|
||||
|
||||
// check if iterator pos fits to this JSON value
|
||||
if (JSON_UNLIKELY(pos.m_object != this))
|
||||
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
|
||||
}
|
||||
|
@ -5316,19 +5320,19 @@ class basic_json
|
|||
void insert(const_iterator first, const_iterator last)
|
||||
{
|
||||
// insert only works for objects
|
||||
if (JSON_UNLIKELY(not is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not is_object()))
|
||||
{
|
||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
|
||||
}
|
||||
|
||||
// check if range iterators belong to the same JSON object
|
||||
if (JSON_UNLIKELY(first.m_object != last.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(210, "iterators do not fit"));
|
||||
}
|
||||
|
||||
// passed iterators must belong to objects
|
||||
if (JSON_UNLIKELY(not first.m_object->is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not first.m_object->is_object()))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects"));
|
||||
}
|
||||
|
@ -5365,11 +5369,11 @@ class basic_json
|
|||
assert_invariant();
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not is_object()))
|
||||
{
|
||||
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name())));
|
||||
}
|
||||
if (JSON_UNLIKELY(not j.is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_object()))
|
||||
{
|
||||
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name())));
|
||||
}
|
||||
|
@ -5416,20 +5420,20 @@ class basic_json
|
|||
assert_invariant();
|
||||
}
|
||||
|
||||
if (JSON_UNLIKELY(not is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not is_object()))
|
||||
{
|
||||
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name())));
|
||||
}
|
||||
|
||||
// check if range iterators belong to the same JSON object
|
||||
if (JSON_UNLIKELY(first.m_object != last.m_object))
|
||||
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(210, "iterators do not fit"));
|
||||
}
|
||||
|
||||
// passed iterators must belong to objects
|
||||
if (JSON_UNLIKELY(not first.m_object->is_object()
|
||||
or not last.m_object->is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not first.m_object->is_object()
|
||||
or not last.m_object->is_object()))
|
||||
{
|
||||
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects"));
|
||||
}
|
||||
|
@ -5492,7 +5496,7 @@ class basic_json
|
|||
void swap(array_t& other)
|
||||
{
|
||||
// swap only works for arrays
|
||||
if (JSON_LIKELY(is_array()))
|
||||
if (JSON_HEDLEY_LIKELY(is_array()))
|
||||
{
|
||||
std::swap(*(m_value.array), other);
|
||||
}
|
||||
|
@ -5525,7 +5529,7 @@ class basic_json
|
|||
void swap(object_t& other)
|
||||
{
|
||||
// swap only works for objects
|
||||
if (JSON_LIKELY(is_object()))
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
std::swap(*(m_value.object), other);
|
||||
}
|
||||
|
@ -5558,7 +5562,7 @@ class basic_json
|
|||
void swap(string_t& other)
|
||||
{
|
||||
// swap only works for strings
|
||||
if (JSON_LIKELY(is_string()))
|
||||
if (JSON_HEDLEY_LIKELY(is_string()))
|
||||
{
|
||||
std::swap(*(m_value.string), other);
|
||||
}
|
||||
|
@ -6068,7 +6072,7 @@ class basic_json
|
|||
instead; that is, replace calls like `j >> o;` with `o << j;`.
|
||||
@since version 1.0.0; deprecated since version 3.0.0
|
||||
*/
|
||||
JSON_DEPRECATED
|
||||
JSON_HEDLEY_DEPRECATED(3.0.0)
|
||||
friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
|
||||
{
|
||||
return o << j;
|
||||
|
@ -6147,7 +6151,7 @@ class basic_json
|
|||
|
||||
@since version 2.0.3 (contiguous containers)
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json parse(detail::input_adapter&& i,
|
||||
const parser_callback_t cb = nullptr,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -6216,6 +6220,7 @@ class basic_json
|
|||
@since version 3.2.0
|
||||
*/
|
||||
template <typename SAX>
|
||||
JSON_HEDLEY_NON_NULL(2)
|
||||
static bool sax_parse(detail::input_adapter&& i, SAX* sax,
|
||||
input_format_t format = input_format_t::json,
|
||||
const bool strict = true)
|
||||
|
@ -6301,6 +6306,7 @@ class basic_json
|
|||
std::is_base_of<
|
||||
std::random_access_iterator_tag,
|
||||
typename std::iterator_traits<IteratorType>::iterator_category>::value, int>::type = 0>
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
static bool sax_parse(IteratorType first, IteratorType last, SAX* sax)
|
||||
{
|
||||
return parser(detail::input_adapter(first, last)).sax_parse(sax);
|
||||
|
@ -6314,7 +6320,7 @@ class basic_json
|
|||
instead; that is, replace calls like `j << i;` with `i >> j;`.
|
||||
@since version 1.0.0; deprecated since version 3.0.0
|
||||
*/
|
||||
JSON_DEPRECATED
|
||||
JSON_HEDLEY_DEPRECATED(3.0.0)
|
||||
friend std::istream& operator<<(basic_json& j, std::istream& i)
|
||||
{
|
||||
return operator>>(i, j);
|
||||
|
@ -6387,6 +6393,7 @@ class basic_json
|
|||
@since version 1.0.0, public since 2.1.0, `const char*` and `noexcept`
|
||||
since 3.0.0
|
||||
*/
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
const char* type_name() const noexcept
|
||||
{
|
||||
{
|
||||
|
@ -6916,7 +6923,7 @@ class basic_json
|
|||
@a strict parameter since 3.0.0; added @a allow_exceptions parameter
|
||||
since 3.2.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_cbor(detail::input_adapter&& i,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -6932,7 +6939,7 @@ class basic_json
|
|||
*/
|
||||
template<typename A1, typename A2,
|
||||
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_cbor(A1 && a1, A2 && a2,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7025,7 +7032,7 @@ class basic_json
|
|||
@a strict parameter since 3.0.0; added @a allow_exceptions parameter
|
||||
since 3.2.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_msgpack(detail::input_adapter&& i,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7041,7 +7048,7 @@ class basic_json
|
|||
*/
|
||||
template<typename A1, typename A2,
|
||||
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_msgpack(A1 && a1, A2 && a2,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7113,7 +7120,7 @@ class basic_json
|
|||
|
||||
@since version 3.1.0; added @a allow_exceptions parameter since 3.2.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_ubjson(detail::input_adapter&& i,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7129,7 +7136,7 @@ class basic_json
|
|||
*/
|
||||
template<typename A1, typename A2,
|
||||
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_ubjson(A1 && a1, A2 && a2,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7200,7 +7207,7 @@ class basic_json
|
|||
@sa @ref from_ubjson(detail::input_adapter&&, const bool, const bool) for the
|
||||
related UBJSON format
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_bson(detail::input_adapter&& i,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7216,7 +7223,7 @@ class basic_json
|
|||
*/
|
||||
template<typename A1, typename A2,
|
||||
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json from_bson(A1 && a1, A2 && a2,
|
||||
const bool strict = true,
|
||||
const bool allow_exceptions = true)
|
||||
|
@ -7590,7 +7597,7 @@ class basic_json
|
|||
else
|
||||
{
|
||||
const auto idx = json_pointer::array_index(last_path);
|
||||
if (JSON_UNLIKELY(static_cast<size_type>(idx) > parent.size()))
|
||||
if (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) > parent.size()))
|
||||
{
|
||||
// avoid undefined behavior
|
||||
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
|
||||
|
@ -7621,7 +7628,7 @@ class basic_json
|
|||
{
|
||||
// perform range check
|
||||
auto it = parent.find(last_path);
|
||||
if (JSON_LIKELY(it != parent.end()))
|
||||
if (JSON_HEDLEY_LIKELY(it != parent.end()))
|
||||
{
|
||||
parent.erase(it);
|
||||
}
|
||||
|
@ -7638,7 +7645,7 @@ class basic_json
|
|||
};
|
||||
|
||||
// type check: top level value must be an array
|
||||
if (JSON_UNLIKELY(not json_patch.is_array()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not json_patch.is_array()))
|
||||
{
|
||||
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects"));
|
||||
}
|
||||
|
@ -7658,13 +7665,13 @@ class basic_json
|
|||
const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
|
||||
|
||||
// check if desired value is present
|
||||
if (JSON_UNLIKELY(it == val.m_value.object->end()))
|
||||
if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
|
||||
{
|
||||
JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'"));
|
||||
}
|
||||
|
||||
// check if result is of type string
|
||||
if (JSON_UNLIKELY(string_type and not it->second.is_string()))
|
||||
if (JSON_HEDLEY_UNLIKELY(string_type and not it->second.is_string()))
|
||||
{
|
||||
JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'"));
|
||||
}
|
||||
|
@ -7674,7 +7681,7 @@ class basic_json
|
|||
};
|
||||
|
||||
// type check: every element of the array must be an object
|
||||
if (JSON_UNLIKELY(not val.is_object()))
|
||||
if (JSON_HEDLEY_UNLIKELY(not val.is_object()))
|
||||
{
|
||||
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects"));
|
||||
}
|
||||
|
@ -7752,7 +7759,7 @@ class basic_json
|
|||
}
|
||||
|
||||
// throw an exception if test fails
|
||||
if (JSON_UNLIKELY(not success))
|
||||
if (JSON_HEDLEY_UNLIKELY(not success))
|
||||
{
|
||||
JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump()));
|
||||
}
|
||||
|
@ -7805,7 +7812,7 @@ class basic_json
|
|||
|
||||
@since version 2.0.0
|
||||
*/
|
||||
JSON_NODISCARD
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static basic_json diff(const basic_json& source, const basic_json& target,
|
||||
const std::string& path = "")
|
||||
{
|
||||
|
@ -8097,6 +8104,7 @@ if no parse error occurred.
|
|||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::parse(s, s + n);
|
||||
|
@ -8115,6 +8123,7 @@ object if no parse error occurred.
|
|||
|
||||
@since version 2.0.0
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::json_pointer(std::string(s, n));
|
||||
|
|
1505
include/nlohmann/thirdparty/hedley/hedley.hpp
vendored
Normal file
1505
include/nlohmann/thirdparty/hedley/hedley.hpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
121
include/nlohmann/thirdparty/hedley/hedley_undef.hpp
vendored
Normal file
121
include/nlohmann/thirdparty/hedley/hedley_undef.hpp
vendored
Normal file
|
@ -0,0 +1,121 @@
|
|||
#undef JSON_HEDLEY_ALWAYS_INLINE
|
||||
#undef JSON_HEDLEY_ARM_VERSION
|
||||
#undef JSON_HEDLEY_ARM_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_ARRAY_PARAM
|
||||
#undef JSON_HEDLEY_ASSUME
|
||||
#undef JSON_HEDLEY_BEGIN_C_DECLS
|
||||
#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
|
||||
#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
|
||||
#undef JSON_HEDLEY_CLANG_HAS_FEATURE
|
||||
#undef JSON_HEDLEY_CLANG_HAS_WARNING
|
||||
#undef JSON_HEDLEY_COMPCERT_VERSION
|
||||
#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_CONCAT
|
||||
#undef JSON_HEDLEY_CONCAT_EX
|
||||
#undef JSON_HEDLEY_CONST
|
||||
#undef JSON_HEDLEY_CONSTEXPR
|
||||
#undef JSON_HEDLEY_CONST_CAST
|
||||
#undef JSON_HEDLEY_CPP_CAST
|
||||
#undef JSON_HEDLEY_CRAY_VERSION
|
||||
#undef JSON_HEDLEY_CRAY_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_C_DECL
|
||||
#undef JSON_HEDLEY_DEPRECATED
|
||||
#undef JSON_HEDLEY_DEPRECATED_FOR
|
||||
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
|
||||
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
|
||||
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
|
||||
#undef JSON_HEDLEY_DIAGNOSTIC_POP
|
||||
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
|
||||
#undef JSON_HEDLEY_DMC_VERSION
|
||||
#undef JSON_HEDLEY_DMC_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
|
||||
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_END_C_DECLS
|
||||
#undef JSON_HEDLEY_FALL_THROUGH
|
||||
#undef JSON_HEDLEY_FLAGS
|
||||
#undef JSON_HEDLEY_FLAGS_CAST
|
||||
#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_GCC_HAS_BUILTIN
|
||||
#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_GCC_HAS_EXTENSION
|
||||
#undef JSON_HEDLEY_GCC_HAS_FEATURE
|
||||
#undef JSON_HEDLEY_GCC_HAS_WARNING
|
||||
#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_GCC_VERSION
|
||||
#undef JSON_HEDLEY_GCC_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
|
||||
#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
|
||||
#undef JSON_HEDLEY_GNUC_HAS_FEATURE
|
||||
#undef JSON_HEDLEY_GNUC_HAS_WARNING
|
||||
#undef JSON_HEDLEY_GNUC_VERSION
|
||||
#undef JSON_HEDLEY_GNUC_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_HAS_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_HAS_BUILTIN
|
||||
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
|
||||
#undef JSON_HEDLEY_HAS_EXTENSION
|
||||
#undef JSON_HEDLEY_HAS_FEATURE
|
||||
#undef JSON_HEDLEY_HAS_WARNING
|
||||
#undef JSON_HEDLEY_IAR_VERSION
|
||||
#undef JSON_HEDLEY_IAR_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_IBM_VERSION
|
||||
#undef JSON_HEDLEY_IBM_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_IMPORT
|
||||
#undef JSON_HEDLEY_INLINE
|
||||
#undef JSON_HEDLEY_INTEL_VERSION
|
||||
#undef JSON_HEDLEY_INTEL_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_IS_CONSTANT
|
||||
#undef JSON_HEDLEY_LIKELY
|
||||
#undef JSON_HEDLEY_MALLOC
|
||||
#undef JSON_HEDLEY_MESSAGE
|
||||
#undef JSON_HEDLEY_MSVC_VERSION
|
||||
#undef JSON_HEDLEY_MSVC_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_NEVER_INLINE
|
||||
#undef JSON_HEDLEY_NON_NULL
|
||||
#undef JSON_HEDLEY_NO_RETURN
|
||||
#undef JSON_HEDLEY_NO_THROW
|
||||
#undef JSON_HEDLEY_PELLES_VERSION
|
||||
#undef JSON_HEDLEY_PELLES_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_PGI_VERSION
|
||||
#undef JSON_HEDLEY_PGI_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_PREDICT
|
||||
#undef JSON_HEDLEY_PRINTF_FORMAT
|
||||
#undef JSON_HEDLEY_PRIVATE
|
||||
#undef JSON_HEDLEY_PUBLIC
|
||||
#undef JSON_HEDLEY_PURE
|
||||
#undef JSON_HEDLEY_REINTERPRET_CAST
|
||||
#undef JSON_HEDLEY_REQUIRE
|
||||
#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
|
||||
#undef JSON_HEDLEY_REQUIRE_MSG
|
||||
#undef JSON_HEDLEY_RESTRICT
|
||||
#undef JSON_HEDLEY_RETURNS_NON_NULL
|
||||
#undef JSON_HEDLEY_SENTINEL
|
||||
#undef JSON_HEDLEY_STATIC_ASSERT
|
||||
#undef JSON_HEDLEY_STATIC_CAST
|
||||
#undef JSON_HEDLEY_STRINGIFY
|
||||
#undef JSON_HEDLEY_STRINGIFY_EX
|
||||
#undef JSON_HEDLEY_SUNPRO_VERSION
|
||||
#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_TINYC_VERSION
|
||||
#undef JSON_HEDLEY_TINYC_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_TI_VERSION
|
||||
#undef JSON_HEDLEY_TI_VERSION_CHECK
|
||||
#undef JSON_HEDLEY_UNAVAILABLE
|
||||
#undef JSON_HEDLEY_UNLIKELY
|
||||
#undef JSON_HEDLEY_UNPREDICTABLE
|
||||
#undef JSON_HEDLEY_UNREACHABLE
|
||||
#undef JSON_HEDLEY_UNREACHABLE_RETURN
|
||||
#undef JSON_HEDLEY_VERSION
|
||||
#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
|
||||
#undef JSON_HEDLEY_VERSION_DECODE_MINOR
|
||||
#undef JSON_HEDLEY_VERSION_DECODE_REVISION
|
||||
#undef JSON_HEDLEY_VERSION_ENCODE
|
||||
#undef JSON_HEDLEY_WARNING
|
||||
#undef JSON_HEDLEY_WARN_UNUSED_RESULT
|
File diff suppressed because it is too large
Load diff
|
@ -112,8 +112,9 @@ TEST_CASE("BSON")
|
|||
0x00,
|
||||
0x00, 0x00, 0x00, 0x80
|
||||
};
|
||||
CHECK_THROWS_AS(json::from_bson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_bson(v), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BSON string: string length must be at least 1, is -2147483648");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_bson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_bson(v), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BSON string: string length must be at least 1, is -2147483648");
|
||||
}
|
||||
|
||||
SECTION("objects")
|
||||
|
@ -692,8 +693,9 @@ TEST_CASE("Incomplete BSON Input")
|
|||
'e', 'n', 't' // unexpected EOF
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_bson(incomplete_bson),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
|
||||
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BSON cstring: unexpected end of input");
|
||||
|
||||
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
|
||||
|
@ -710,8 +712,9 @@ TEST_CASE("Incomplete BSON Input")
|
|||
0x08, // entry: boolean, unexpected EOF
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_bson(incomplete_bson),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BSON cstring: unexpected end of input");
|
||||
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
|
||||
|
||||
|
@ -733,8 +736,9 @@ TEST_CASE("Incomplete BSON Input")
|
|||
// missing input data...
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_bson(incomplete_bson),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
|
||||
"[json.exception.parse_error.110] parse error at byte 28: syntax error while parsing BSON element list: unexpected end of input");
|
||||
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
|
||||
|
||||
|
@ -749,8 +753,9 @@ TEST_CASE("Incomplete BSON Input")
|
|||
0x0D, 0x00, // size (incomplete), unexpected EOF
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_bson(incomplete_bson),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BSON number: unexpected end of input");
|
||||
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
|
||||
|
||||
|
@ -791,8 +796,9 @@ TEST_CASE("Unsupported BSON input")
|
|||
0x00 // end marker
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::from_bson(bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_bson(bson),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_bson(bson), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_bson(bson),
|
||||
"[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF");
|
||||
CHECK(json::from_bson(bson, true, false).is_discarded());
|
||||
|
||||
|
|
|
@ -836,15 +836,17 @@ TEST_CASE("CBOR")
|
|||
{
|
||||
SECTION("no byte follows")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xf9})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xf9})),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xf9})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xf9})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({0xf9}), true, false).is_discarded());
|
||||
}
|
||||
SECTION("only one byte follows")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c}), true, false).is_discarded());
|
||||
}
|
||||
|
@ -1319,86 +1321,88 @@ TEST_CASE("CBOR")
|
|||
{
|
||||
SECTION("empty byte vector")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>()),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>()),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input");
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>(), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("too short byte vector")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x18})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x19})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x19, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1a})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x62})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x62, 0x60})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x7F})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x7F, 0x60})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x82, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x9F, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61, 0xF5})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xA1, 0x61, 0X61})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0X61})), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x18})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x19})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x19, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x62})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x62, 0x60})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x7F})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x7F, 0x60})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x82, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x9F, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61, 0xF5})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xA1, 0x61, 0X61})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0X61})), json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x18})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x18})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x19})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x19})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x19, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x19, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1a})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1a})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing CBOR number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x62})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x62})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x62, 0x60})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x62, 0x60})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x7F})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x7F})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x7F, 0x60})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x7F, 0x60})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x82, 0x01})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x82, 0x01})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x9F, 0x01})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x9F, 0x01})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61, 0xF5})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61, 0xF5})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xA1, 0x61, 0x61})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xA1, 0x61, 0x61})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61})),
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input");
|
||||
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x18}), true, false).is_discarded());
|
||||
|
@ -1431,13 +1435,14 @@ TEST_CASE("CBOR")
|
|||
{
|
||||
SECTION("concrete examples")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0x1c})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0x1c})),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1c})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0x1c})),
|
||||
"[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0x1C");
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x1c}), true, false).is_discarded());
|
||||
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xf8})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xf8})),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xf8})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xf8})),
|
||||
"[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0xF8");
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({0xf8}), true, false).is_discarded());
|
||||
}
|
||||
|
@ -1488,7 +1493,8 @@ TEST_CASE("CBOR")
|
|||
0xf8
|
||||
})
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)}), true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
|
@ -1496,8 +1502,9 @@ TEST_CASE("CBOR")
|
|||
|
||||
SECTION("invalid string in map")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01})),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01})),
|
||||
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xFF");
|
||||
CHECK(json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01}), true, false).is_discarded());
|
||||
}
|
||||
|
@ -1514,8 +1521,9 @@ TEST_CASE("CBOR")
|
|||
|
||||
SECTION("strict mode")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: expected end of input; last byte: 0xF6");
|
||||
CHECK(json::from_cbor(vec, true, false).is_discarded());
|
||||
}
|
||||
|
|
|
@ -406,8 +406,9 @@ TEST_CASE("parser class")
|
|||
// uses an iterator range.
|
||||
std::string s = "\"1\"";
|
||||
s[1] = '\0';
|
||||
CHECK_THROWS_AS(json::parse(s.begin(), s.end()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0000 (NUL) must be escaped to \\u0000; last read: '\"<U+0000>'");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(s.begin(), s.end()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0000 (NUL) must be escaped to \\u0000; last read: '\"<U+0000>'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1219,19 +1220,21 @@ TEST_CASE("parser class")
|
|||
}
|
||||
}
|
||||
|
||||
json _;
|
||||
|
||||
// missing part of a surrogate pair
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\"'");
|
||||
// invalid surrogate pair
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\\uD80C\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\\u0000\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD80C\\uFFFF\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\uD80C\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\\uD80C\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\\u0000\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\\uFFFF\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'");
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\u0000\""),
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\\u0000\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'");
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\uFFFF\""),
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\\uFFFF\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'");
|
||||
}
|
||||
|
||||
|
@ -1679,12 +1682,13 @@ TEST_CASE("parser class")
|
|||
|
||||
CHECK(json::parse("{\"foo\": true:", cb, false).is_discarded());
|
||||
|
||||
CHECK_THROWS_AS(json::parse("{\"foo\": true:", cb), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("{\"foo\": true:", cb),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse("{\"foo\": true:", cb), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("{\"foo\": true:", cb),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing object - unexpected ':'; expected '}'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("1.18973e+4932", cb), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(json::parse("1.18973e+4932", cb),
|
||||
CHECK_THROWS_AS(_ = json::parse("1.18973e+4932", cb), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("1.18973e+4932", cb),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'");
|
||||
}
|
||||
|
||||
|
|
|
@ -1052,9 +1052,10 @@ TEST_CASE("constructors")
|
|||
|
||||
SECTION("object with error")
|
||||
{
|
||||
CHECK_THROWS_AS(json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH(json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
|
||||
CHECK_THROWS_WITH(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
|
||||
"[json.exception.type_error.301] cannot create object from initializer list");
|
||||
}
|
||||
|
||||
|
|
|
@ -269,8 +269,10 @@ TEST_CASE("deserialization")
|
|||
ss3 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss4 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss5 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
CHECK_THROWS_AS(json::parse(ss1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(ss2),
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(ss1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(ss2),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
|
||||
CHECK(not json::accept(ss3));
|
||||
|
||||
|
@ -293,8 +295,9 @@ TEST_CASE("deserialization")
|
|||
SECTION("string")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
CHECK_THROWS_AS(json::parse(s), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(s),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(s), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(s),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
|
||||
CHECK(not json::accept(s));
|
||||
|
||||
|
@ -430,7 +433,8 @@ TEST_CASE("deserialization")
|
|||
SECTION("empty container")
|
||||
{
|
||||
std::vector<uint8_t> v;
|
||||
CHECK_THROWS_AS(json::parse(v), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(v), json::parse_error&);
|
||||
CHECK(not json::accept(v));
|
||||
|
||||
SaxEventLogger l;
|
||||
|
@ -614,8 +618,9 @@ TEST_CASE("deserialization")
|
|||
SECTION("case 6")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xDF, 0x7F};
|
||||
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(std::begin(v), std::end(v)),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::begin(v), std::end(v)),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '\"\x7f\xdf\x7f'");
|
||||
CHECK(not json::accept(std::begin(v), std::end(v)));
|
||||
|
||||
|
@ -801,12 +806,13 @@ TEST_CASE("deserialization")
|
|||
|
||||
SECTION("BOM only")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse(bom), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(bom),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(bom), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(bom),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
|
||||
|
||||
CHECK_THROWS_AS(json::parse(std::istringstream(bom)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(std::istringstream(bom)),
|
||||
CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom)),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
|
||||
|
||||
SaxEventLogger l;
|
||||
|
@ -840,12 +846,13 @@ TEST_CASE("deserialization")
|
|||
|
||||
SECTION("2 byte of BOM")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse(bom.substr(0, 2)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(bom.substr(0, 2)),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(bom.substr(0, 2)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(bom.substr(0, 2)),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 2))), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(std::istringstream(bom.substr(0, 2))),
|
||||
CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom.substr(0, 2))), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 2))),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'");
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
|
@ -865,12 +872,13 @@ TEST_CASE("deserialization")
|
|||
|
||||
SECTION("1 byte of BOM")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse(bom.substr(0, 1)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(bom.substr(0, 1)),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(bom.substr(0, 1)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(bom.substr(0, 1)),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 1))), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(std::istringstream(bom.substr(0, 1))),
|
||||
CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom.substr(0, 1))), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 1))),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'");
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
|
@ -925,8 +933,9 @@ TEST_CASE("deserialization")
|
|||
else
|
||||
{
|
||||
// any variation is an error
|
||||
CHECK_THROWS_AS(json::parse(s + "null"), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::parse(std::istringstream(s + "null")), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(s + "null"), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse(std::istringstream(s + "null")), json::parse_error&);
|
||||
|
||||
SaxEventLogger l;
|
||||
CHECK(not json::sax_parse(s + "null", &l));
|
||||
|
|
|
@ -1128,71 +1128,73 @@ TEST_CASE("MessagePack")
|
|||
{
|
||||
SECTION("empty byte vector")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>()),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>()),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>(), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("too short byte vector")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x87})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcc})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcd})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xce})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x87})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcc})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})), json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x87})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0x87})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xce})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})),
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input");
|
||||
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), true, false).is_discarded());
|
||||
|
@ -1220,13 +1222,14 @@ TEST_CASE("MessagePack")
|
|||
{
|
||||
SECTION("concrete examples")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xc1})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xc1})),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc1})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xc1})),
|
||||
"[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc6}), true, false).is_discarded());
|
||||
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xc6})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xc6})),
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc6})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0xc6})),
|
||||
"[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC6");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc6}), true, false).is_discarded());
|
||||
}
|
||||
|
@ -1245,7 +1248,8 @@ TEST_CASE("MessagePack")
|
|||
0xd4, 0xd5, 0xd6, 0xd7, 0xd8
|
||||
})
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)}), true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
|
@ -1253,8 +1257,9 @@ TEST_CASE("MessagePack")
|
|||
|
||||
SECTION("invalid string in map")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})),
|
||||
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01}), true, false).is_discarded());
|
||||
}
|
||||
|
@ -1270,8 +1275,9 @@ TEST_CASE("MessagePack")
|
|||
|
||||
SECTION("strict mode")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(vec),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack value: expected end of input; last byte: 0xC0");
|
||||
CHECK(json::from_msgpack(vec, true, false).is_discarded());
|
||||
}
|
||||
|
|
|
@ -696,8 +696,9 @@ TEST_CASE("regression tests")
|
|||
|
||||
SECTION("issue #329 - serialized value not always can be parsed")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse("22e2222"), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(json::parse("22e2222"),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse("22e2222"), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("22e2222"),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '22e2222'");
|
||||
}
|
||||
|
||||
|
@ -762,8 +763,9 @@ TEST_CASE("regression tests")
|
|||
SECTION("issue #366 - json::parse on failed stream gets stuck")
|
||||
{
|
||||
std::ifstream f("file_not_found.json");
|
||||
CHECK_THROWS_AS(json::parse(f), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse(f), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(f), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
|
||||
}
|
||||
|
||||
SECTION("issue #367 - calling stream at EOF")
|
||||
|
@ -958,50 +960,55 @@ TEST_CASE("regression tests")
|
|||
{
|
||||
// original test case
|
||||
std::vector<uint8_t> vec {0x65, 0xf5, 0x0a, 0x48, 0x21};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input");
|
||||
}
|
||||
|
||||
SECTION("issue #407 - Heap-buffer-overflow (OSS-Fuzz issue 343)")
|
||||
{
|
||||
json _;
|
||||
|
||||
// original test case: incomplete float64
|
||||
std::vector<uint8_t> vec1 {0xcb, 0x8f, 0x0a};
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec1),
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
|
||||
// related test case: incomplete float32
|
||||
std::vector<uint8_t> vec2 {0xca, 0x8f, 0x0a};
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec2),
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input");
|
||||
|
||||
// related test case: incomplete Half-Precision Float (CBOR)
|
||||
std::vector<uint8_t> vec3 {0xf9, 0x8f};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec3),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec3),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input");
|
||||
|
||||
// related test case: incomplete Single-Precision Float (CBOR)
|
||||
std::vector<uint8_t> vec4 {0xfa, 0x8f, 0x0a};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec4), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec4),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec4), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec4),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input");
|
||||
|
||||
// related test case: incomplete Double-Precision Float (CBOR)
|
||||
std::vector<uint8_t> vec5 {0xfb, 0x8f, 0x0a};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec5), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec5),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec5), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec5),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input");
|
||||
}
|
||||
|
||||
SECTION("issue #408 - Heap-buffer-overflow (OSS-Fuzz issue 344)")
|
||||
{
|
||||
json _;
|
||||
|
||||
// original test case
|
||||
std::vector<uint8_t> vec1 {0x87};
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec1),
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input");
|
||||
|
||||
// more test cases for MessagePack
|
||||
|
@ -1014,7 +1021,7 @@ TEST_CASE("regression tests")
|
|||
})
|
||||
{
|
||||
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
||||
}
|
||||
|
||||
// more test cases for CBOR
|
||||
|
@ -1029,37 +1036,39 @@ TEST_CASE("regression tests")
|
|||
})
|
||||
{
|
||||
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
|
||||
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&);
|
||||
}
|
||||
|
||||
// special case: empty input
|
||||
std::vector<uint8_t> vec2;
|
||||
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec2),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input");
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec2),
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_msgpack(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input");
|
||||
}
|
||||
|
||||
SECTION("issue #411 - Heap-buffer-overflow (OSS-Fuzz issue 366)")
|
||||
{
|
||||
json _;
|
||||
|
||||
// original test case: empty UTF-8 string (indefinite length)
|
||||
std::vector<uint8_t> vec1 {0x7f};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec1),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input");
|
||||
|
||||
// related test case: empty array (indefinite length)
|
||||
std::vector<uint8_t> vec2 {0x9f};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec2),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input");
|
||||
|
||||
// related test case: empty map (indefinite length)
|
||||
std::vector<uint8_t> vec3 {0xbf};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec3),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec3),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input");
|
||||
}
|
||||
|
||||
|
@ -1086,26 +1095,28 @@ TEST_CASE("regression tests")
|
|||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60
|
||||
};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec),
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec),
|
||||
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98");
|
||||
|
||||
// related test case: nonempty UTF-8 string (indefinite length)
|
||||
std::vector<uint8_t> vec1 {0x7f, 0x61, 0x61};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec1),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input");
|
||||
|
||||
// related test case: nonempty array (indefinite length)
|
||||
std::vector<uint8_t> vec2 {0x9f, 0x01};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec2),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input");
|
||||
|
||||
// related test case: nonempty map (indefinite length)
|
||||
std::vector<uint8_t> vec3 {0xbf, 0x61, 0x61, 0x01};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec3),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec3),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input");
|
||||
}
|
||||
|
||||
|
@ -1139,8 +1150,10 @@ TEST_CASE("regression tests")
|
|||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
|
||||
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa
|
||||
};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec1),
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec1),
|
||||
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4");
|
||||
|
||||
// related test case: double-precision
|
||||
|
@ -1153,15 +1166,16 @@ TEST_CASE("regression tests")
|
|||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
|
||||
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb
|
||||
};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_cbor(vec2),
|
||||
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4");
|
||||
}
|
||||
|
||||
SECTION("issue #452 - Heap-buffer-overflow (OSS-Fuzz issue 585)")
|
||||
{
|
||||
std::vector<uint8_t> vec = {'-', '0', '1', '2', '2', '7', '4'};
|
||||
CHECK_THROWS_AS(json::parse(vec), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #454 - doubles are printed as integers")
|
||||
|
@ -1309,8 +1323,9 @@ TEST_CASE("regression tests")
|
|||
|
||||
SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)")
|
||||
{
|
||||
json _;
|
||||
std::vector<uint8_t> vec = {'"', '\\', '"', 'X', '"', '"'};
|
||||
CHECK_THROWS_AS(json::parse(vec), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #600 - how does one convert a map in Json back to std::map?")
|
||||
|
@ -1349,7 +1364,8 @@ TEST_CASE("regression tests")
|
|||
SECTION("issue #602 - BOM not skipped when using json:parse(iterator)")
|
||||
{
|
||||
std::string i = "\xef\xbb\xbf{\n \"foo\": true\n}";
|
||||
CHECK_NOTHROW(json::parse(i.begin(), i.end()));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(i.begin(), i.end()));
|
||||
}
|
||||
|
||||
SECTION("issue #702 - conversion from valarray<double> to json fails to build")
|
||||
|
@ -1412,7 +1428,8 @@ TEST_CASE("regression tests")
|
|||
); // handle different exceptions as 'file not found', 'permission denied'
|
||||
|
||||
is.open("test/data/regression/working_file.json");
|
||||
CHECK_NOTHROW(nlohmann::json::parse(is));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = nlohmann::json::parse(is));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1425,7 +1442,8 @@ TEST_CASE("regression tests")
|
|||
|
||||
is.open("test/data/json_nlohmann_tests/all_unicode.json.cbor",
|
||||
std::ios_base::in | std::ios_base::binary);
|
||||
CHECK_NOTHROW(nlohmann::json::from_cbor(is));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = nlohmann::json::from_cbor(is));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1505,13 +1523,14 @@ TEST_CASE("regression tests")
|
|||
|
||||
SECTION("issue #962 - Timeout (OSS-Fuzz 6034)")
|
||||
{
|
||||
json _;
|
||||
std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
|
||||
// "[json.exception.out_of_range.408] excessive array size: 8658170730974374167");
|
||||
|
||||
v_ubjson[0] = '{';
|
||||
CHECK_THROWS_AS(json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
|
||||
// "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
|
||||
}
|
||||
|
|
|
@ -79,7 +79,8 @@ TEST_CASE("compliance tests from json.org")
|
|||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
CHECK_THROWS_AS(json::parse(f), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,36 +388,36 @@ TEST_CASE("json.org examples")
|
|||
SECTION("FILE 1.json")
|
||||
{
|
||||
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/1.json", "r"), &std::fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 2.json")
|
||||
{
|
||||
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/2.json", "r"), &std::fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 3.json")
|
||||
{
|
||||
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/3.json", "r"), &std::fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 4.json")
|
||||
{
|
||||
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/4.json", "r"), &std::fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 5.json")
|
||||
{
|
||||
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/5.json", "r"), &std::fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -810,7 +811,8 @@ TEST_CASE("nst's JSONTestSuite")
|
|||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
CHECK_THROWS_AS(json::parse(f), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1027,7 +1029,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
CHECK_NOTHROW(json::parse(f));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f));
|
||||
std::ifstream f2(filename);
|
||||
CHECK(json::accept(f2));
|
||||
}
|
||||
|
@ -1228,7 +1231,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
CHECK_THROWS_AS(json::parse(f), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
|
||||
std::ifstream f2(filename);
|
||||
CHECK(not json::accept(f2));
|
||||
}
|
||||
|
@ -1293,7 +1297,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
CHECK_NOTHROW(json::parse(f));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f));
|
||||
std::ifstream f2(filename);
|
||||
CHECK(json::accept(f2));
|
||||
}
|
||||
|
@ -1343,7 +1348,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
|||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
CHECK_THROWS_AS(json::parse(f), json::exception&); // could be parse_error or out_of_range
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(f), json::exception&); // could be parse_error or out_of_range
|
||||
std::ifstream f2(filename);
|
||||
CHECK(not json::accept(f2));
|
||||
}
|
||||
|
|
|
@ -1301,8 +1301,9 @@ TEST_CASE("UBJSON")
|
|||
|
||||
SECTION("strict mode")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_ubjson(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vec),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vec),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: expected end of input; last byte: 0x5A");
|
||||
}
|
||||
}
|
||||
|
@ -1311,8 +1312,9 @@ TEST_CASE("UBJSON")
|
|||
{
|
||||
// larger than max int64
|
||||
json j = 9223372036854775808llu;
|
||||
CHECK_THROWS_AS(json::to_ubjson(j), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(json::to_ubjson(j), "[json.exception.out_of_range.407] integer number 9223372036854775808 cannot be represented by UBJSON as it does not fit int64");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::to_ubjson(j), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(_ = json::to_ubjson(j), "[json.exception.out_of_range.407] integer number 9223372036854775808 cannot be represented by UBJSON as it does not fit int64");
|
||||
}
|
||||
|
||||
SECTION("excessive size")
|
||||
|
@ -1320,27 +1322,29 @@ TEST_CASE("UBJSON")
|
|||
SECTION("array")
|
||||
{
|
||||
std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int, json::parse_event_t, const json&)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
CHECK_THROWS_AS(json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
||||
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
std::vector<uint8_t> v_ubjson = {'{', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int, json::parse_event_t, const json&)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
CHECK_THROWS_AS(json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
||||
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1531,8 +1535,9 @@ TEST_CASE("UBJSON")
|
|||
{
|
||||
SECTION("empty byte vector")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_ubjson(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(std::vector<uint8_t>()),
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(std::vector<uint8_t>()),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
}
|
||||
|
||||
|
@ -1541,15 +1546,17 @@ TEST_CASE("UBJSON")
|
|||
SECTION("eof after C byte")
|
||||
{
|
||||
std::vector<uint8_t> v = {'C'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input");
|
||||
}
|
||||
|
||||
SECTION("byte out of range")
|
||||
{
|
||||
std::vector<uint8_t> v = {'C', 130};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1558,15 +1565,17 @@ TEST_CASE("UBJSON")
|
|||
SECTION("eof after S byte")
|
||||
{
|
||||
std::vector<uint8_t> v = {'S'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
}
|
||||
|
||||
SECTION("invalid byte")
|
||||
{
|
||||
std::vector<uint8_t> v = {'S', '1', 'a'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x31");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x31");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1575,138 +1584,144 @@ TEST_CASE("UBJSON")
|
|||
SECTION("optimized array: no size following type")
|
||||
{
|
||||
std::vector<uint8_t> v = {'[', '$', 'i', 2};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x02");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x02");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("strings")
|
||||
{
|
||||
std::vector<uint8_t> vS = {'S'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vS), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vS, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> v = {'S', 'i', '2', 'a'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON string: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON string: unexpected end of input");
|
||||
CHECK(json::from_ubjson(v, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vC = {'C'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vC), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vC), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vC, true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("sizes")
|
||||
{
|
||||
std::vector<uint8_t> vU = {'[', '#', 'U'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vU), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vU), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vU, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vi = {'[', '#', 'i'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vi), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vi), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vi, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vI = {'[', '#', 'I'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vI), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vI), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vI, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vl = {'[', '#', 'l'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vl), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vl), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vl, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vL = {'[', '#', 'L'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vL), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vL), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vL, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> v0 = {'[', '#', 'T', ']'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v0), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x54");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v0), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x54");
|
||||
CHECK(json::from_ubjson(v0, true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("types")
|
||||
{
|
||||
std::vector<uint8_t> v0 = {'[', '$'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v0), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing UBJSON type: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v0), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing UBJSON type: unexpected end of input");
|
||||
CHECK(json::from_ubjson(v0, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vi = {'[', '$', '#'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vi), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vi), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vi, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vT = {'[', '$', 'T'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vT), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vT), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vT), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vT), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vT, true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("arrays")
|
||||
{
|
||||
std::vector<uint8_t> vST = {'[', '$', 'i', '#', 'i', 2, 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vST), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vST), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vST, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vS = {'[', '#', 'i', 2, 'i', 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vS), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vS, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> v = {'[', 'i', 2, 'i', 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(v, true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("objects")
|
||||
{
|
||||
std::vector<uint8_t> vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vST), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vST), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vST, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vT = {'{', '$', 'i', 'i', 1, 'a', 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vT), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x69");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vT), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x69");
|
||||
CHECK(json::from_ubjson(vT, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vS), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vS, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> v = {'{', 'i', 1, 'a', 'i', 1};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(v, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(v2, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> v3 = {'{', 'i', 1, 'a'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(v3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v3), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(v3, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vST1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vST1), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON number: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vST1, true, false).is_discarded());
|
||||
|
||||
std::vector<uint8_t> vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'};
|
||||
CHECK_THROWS_AS(json::from_ubjson(vST2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_ubjson(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vST2), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON value: unexpected end of input");
|
||||
CHECK(json::from_ubjson(vST2, true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,13 +158,14 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte
|
|||
|
||||
CAPTURE(json_string)
|
||||
|
||||
json _;
|
||||
if (success_expected)
|
||||
{
|
||||
CHECK_NOTHROW(json::parse(json_string));
|
||||
CHECK_NOTHROW(_ = json::parse(json_string));
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse(json_string), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1051,7 +1052,8 @@ TEST_CASE("Unicode" * doctest::skip())
|
|||
|
||||
json_text += "\"";
|
||||
CAPTURE(json_text)
|
||||
CHECK_NOTHROW(json::parse(json_text));
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(json_text));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1059,32 +1061,34 @@ TEST_CASE("Unicode" * doctest::skip())
|
|||
{
|
||||
SECTION("incorrect surrogate values")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse("\"\\uDC00\\uDC00\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uDC00\\uDC00\""),
|
||||
json _;
|
||||
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uDC00\\uDC00\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uDC00\\uDC00\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uDC00'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD7FF\\uDC00\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD7FF\\uDC00\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD7FF\\uDC00\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD7FF\\uDC00\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uD7FF\\uDC00'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD800]\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD800]\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD800]\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD800]\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800]'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD800\\v\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD800\\v\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\v\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\v\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 9: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\v'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD800\\u123\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD800\\u123\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\u123\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\u123\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\uD800\\u123\"'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD800\\uDBFF\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD800\\uDBFF\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\uDBFF\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\uDBFF\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uDBFF'");
|
||||
|
||||
CHECK_THROWS_AS(json::parse("\"\\uD800\\uE000\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::parse("\"\\uD800\\uE000\""),
|
||||
CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\uE000\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\uE000\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uE000'");
|
||||
}
|
||||
}
|
||||
|
@ -1203,8 +1207,9 @@ TEST_CASE("Unicode" * doctest::skip())
|
|||
|
||||
SECTION("error for incomplete/wrong BOM")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parse("\xef\xbb"), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::parse("\xef\xbb\xbb"), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse("\xef\xbb"), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse("\xef\xbb\xbb"), json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1215,6 +1220,7 @@ void roundtrip(bool success_expected, const std::string& s);
|
|||
void roundtrip(bool success_expected, const std::string& s)
|
||||
{
|
||||
CAPTURE(s)
|
||||
json _;
|
||||
|
||||
// create JSON string value
|
||||
json j = s;
|
||||
|
@ -1230,11 +1236,11 @@ void roundtrip(bool success_expected, const std::string& s)
|
|||
if (s[0] != '\0')
|
||||
{
|
||||
// parsing JSON text succeeds
|
||||
CHECK_NOTHROW(json::parse(ps));
|
||||
CHECK_NOTHROW(_ = json::parse(ps));
|
||||
}
|
||||
|
||||
// roundtrip succeeds
|
||||
CHECK_NOTHROW(json::parse(j.dump()));
|
||||
CHECK_NOTHROW(_ = json::parse(j.dump()));
|
||||
|
||||
// after roundtrip, the same string is stored
|
||||
json jr = json::parse(j.dump());
|
||||
|
@ -1246,7 +1252,7 @@ void roundtrip(bool success_expected, const std::string& s)
|
|||
CHECK_THROWS_AS(j.dump(), json::type_error&);
|
||||
|
||||
// parsing JSON text fails
|
||||
CHECK_THROWS_AS(json::parse(ps), json::parse_error&);
|
||||
CHECK_THROWS_AS(_ = json::parse(ps), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ TEST_CASE("wide strings")
|
|||
if (wstring_is_utf16())
|
||||
{
|
||||
std::wstring w = L"\"\xDBFF";
|
||||
CHECK_THROWS_AS(json::parse(w), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +90,8 @@ TEST_CASE("wide strings")
|
|||
if (wstring_is_utf16())
|
||||
{
|
||||
std::u16string w = u"\"\xDBFF";
|
||||
CHECK_THROWS_AS(json::parse(w), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +110,8 @@ TEST_CASE("wide strings")
|
|||
if (u32string_is_utf32())
|
||||
{
|
||||
std::u32string w = U"\"\x110000";
|
||||
CHECK_THROWS_AS(json::parse(w), json::parse_error&);
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue