Unverified Commit 48681290 authored by Niels Lohmann's avatar Niels Lohmann Committed by GitHub

Merge pull request #2259 from nlohmann/clang_windows

Make library work with Clang on Windows
parents cbafed34 4d286947
name: Windows
on: [push, pull_request]
jobs:
clang9:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: install Clang
run: curl -fsSL -o LLVM9.exe https://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe ; 7z x LLVM9.exe -y -o"C:/Program Files/LLVM"
- name: cmake
run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: build
run: cmake --build build --parallel 10
- name: test
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
clang10:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: install Clang
run: curl -fsSL -o LLVM10.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe ; 7z x LLVM10.exe -y -o"C:/Program Files/LLVM"
- name: cmake
run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: build
run: cmake --build build --parallel 10
- name: test
run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure
......@@ -37,7 +37,7 @@ struct adl_serializer
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template <typename BasicJsonType, typename ValueType>
template<typename BasicJsonType, typename ValueType>
static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void())
......
#pragma once
// Header <ciso646> is removed in C++20.
// See <https://github.com/nlohmann/json/issues/2089> for more information.
#if __cplusplus <= 201703L
#include <ciso646> // and, not, or
#endif
......@@ -7,7 +7,6 @@
#include <limits> // numeric_limits
#include <type_traits> // conditional
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
......@@ -37,7 +36,7 @@ For a detailed description of the algorithm see:
namespace dtoa_impl
{
template <typename Target, typename Source>
template<typename Target, typename Source>
Target reinterpret_bits(const Source source)
{
static_assert(sizeof(Target) == sizeof(Source), "size mismatch");
......@@ -178,7 +177,7 @@ boundaries.
@pre value must be finite and positive
*/
template <typename FloatType>
template<typename FloatType>
boundaries compute_boundaries(FloatType value)
{
JSON_ASSERT(std::isfinite(value));
......@@ -231,7 +230,7 @@ boundaries compute_boundaries(FloatType value)
// -----------------+------+------+-------------+-------------+--- (B)
// v- m- v m+ v+
const bool lower_boundary_is_closer = F == 0 and E > 1;
const bool lower_boundary_is_closer = F == 0 && E > 1;
const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
const diyfp m_minus = lower_boundary_is_closer
? diyfp(4 * v.f - 1, v.e - 2) // (B)
......@@ -566,8 +565,8 @@ inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t d
// integer arithmetic.
while (rest < dist
and delta - rest >= ten_k
and (rest + ten_k < dist or dist - rest > rest + ten_k - dist))
&& delta - rest >= ten_k
&& (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
{
JSON_ASSERT(buf[len - 1] != '0');
buf[len - 1]--;
......@@ -878,7 +877,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.
*/
template <typename FloatType>
template<typename FloatType>
JSON_HEDLEY_NON_NULL(1)
void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
{
......@@ -985,7 +984,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
// k is the length of the buffer (number of decimal digits)
// n is the position of the decimal point relative to the start of the buffer.
if (k <= n and n <= max_exp)
if (k <= n && n <= max_exp)
{
// digits[000]
// len <= max_exp + 2
......@@ -997,7 +996,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
return buf + (static_cast<size_t>(n) + 2);
}
if (0 < n and n <= max_exp)
if (0 < n && n <= max_exp)
{
// dig.its
// len <= max_digits10 + 1
......@@ -1009,7 +1008,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
return buf + (static_cast<size_t>(k) + 1U);
}
if (min_exp < n and n <= 0)
if (min_exp < n && n <= 0)
{
// 0.[000]digits
// len <= 2 + (-min_exp - 1) + max_digits10
......@@ -1054,7 +1053,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
@note The buffer must be large enough.
@note The result is NOT null-terminated.
*/
template <typename FloatType>
template<typename FloatType>
JSON_HEDLEY_NON_NULL(1, 2)
JSON_HEDLEY_RETURNS_NON_NULL
char* to_chars(char* first, const char* last, FloatType value)
......
......@@ -9,7 +9,6 @@
#include <valarray> // valarray
#include <vector> // vector
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/iterators/iteration_proxy.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
......@@ -56,9 +55,9 @@ struct external_constructor<value_t::string>
j.assert_invariant();
}
template<typename BasicJsonType, typename CompatibleStringType,
enable_if_t<not std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
int> = 0>
template < typename BasicJsonType, typename CompatibleStringType,
enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
int > = 0 >
static void construct(BasicJsonType& j, const CompatibleStringType& str)
{
j.m_type = value_t::string;
......@@ -144,9 +143,9 @@ struct external_constructor<value_t::array>
j.assert_invariant();
}
template<typename BasicJsonType, typename CompatibleArrayType,
enable_if_t<not std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
int> = 0>
template < typename BasicJsonType, typename CompatibleArrayType,
enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
int > = 0 >
static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
{
using std::begin;
......@@ -203,8 +202,8 @@ struct external_constructor<value_t::object>
j.assert_invariant();
}
template<typename BasicJsonType, typename CompatibleObjectType,
enable_if_t<not std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int> = 0>
template < typename BasicJsonType, typename CompatibleObjectType,
enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 >
static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
{
using std::begin;
......@@ -275,20 +274,20 @@ void to_json(BasicJsonType& j, const std::vector<bool>& e)
external_constructor<value_t::array>::construct(j, e);
}
template <typename BasicJsonType, typename CompatibleArrayType,
enable_if_t<is_compatible_array_type<BasicJsonType,
CompatibleArrayType>::value and
not is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value and
not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and
not std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value and
not is_basic_json<CompatibleArrayType>::value,
int> = 0>
template < typename BasicJsonType, typename CompatibleArrayType,
enable_if_t < is_compatible_array_type<BasicJsonType,
CompatibleArrayType>::value&&
!is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
!is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
!std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
!is_basic_json<CompatibleArrayType>::value,
int > = 0 >
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
{
external_constructor<value_t::array>::construct(j, arr);
}
template <typename BasicJsonType>
template<typename BasicJsonType>
void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
{
external_constructor<value_t::binary>::construct(j, bin);
......@@ -307,8 +306,8 @@ void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
external_constructor<value_t::array>::construct(j, std::move(arr));
}
template<typename BasicJsonType, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value and not is_basic_json<CompatibleObjectType>::value, int> = 0>
template < typename BasicJsonType, typename CompatibleObjectType,
enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 >
void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
{
external_constructor<value_t::object>::construct(j, obj);
......@@ -322,9 +321,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
template <
typename BasicJsonType, typename T, std::size_t N,
enable_if_t<not std::is_constructible<typename BasicJsonType::string_t,
const T(&)[N]>::value,
int> = 0 >
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
const T(&)[N]>::value,
int > = 0 >
void to_json(BasicJsonType& j, const T(&arr)[N])
{
external_constructor<value_t::array>::construct(j, arr);
......@@ -337,8 +336,8 @@ void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
}
// for https://github.com/nlohmann/json/pull/1134
template < typename BasicJsonType, typename T,
enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
template<typename BasicJsonType, typename T,
enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
void to_json(BasicJsonType& j, const T& b)
{
j = { {b.key(), b.value()} };
......
......@@ -250,7 +250,7 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
utf8_bytes_filled = 2;
}
else if (0xD800 > wc or wc >= 0xE000)
else if (0xD800 > wc || wc >= 0xE000)
{
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u)));
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
......@@ -259,7 +259,7 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
}
else
{
if (JSON_HEDLEY_UNLIKELY(not input.empty()))
if (JSON_HEDLEY_UNLIKELY(!input.empty()))
{
const auto wc2 = static_cast<unsigned int>(input.get_character());
const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
......@@ -402,9 +402,9 @@ using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const
// Null-delimited strings, and the like.
template < typename CharT,
typename std::enable_if <
std::is_pointer<CharT>::value and
not std::is_array<CharT>::value and
std::is_integral<typename std::remove_pointer<CharT>::type>::value and
std::is_pointer<CharT>::value&&
!std::is_array<CharT>::value&&
std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
sizeof(typename std::remove_pointer<CharT>::type) == 1,
int >::type = 0 >
contiguous_bytes_input_adapter input_adapter(CharT b)
......@@ -426,12 +426,12 @@ auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
class span_input_adapter
{
public:
template<typename CharT,
typename std::enable_if<
std::is_pointer<CharT>::value and
std::is_integral<typename std::remove_pointer<CharT>::type>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1,
int>::type = 0>
template < typename CharT,
typename std::enable_if <
std::is_pointer<CharT>::value&&
std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
sizeof(typename std::remove_pointer<CharT>::type) == 1,
int >::type = 0 >
span_input_adapter(CharT b, std::size_t l)
: ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
......
......@@ -217,7 +217,7 @@ class json_sax_dom_parser
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
......@@ -243,7 +243,7 @@ class json_sax_dom_parser
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));
......@@ -308,7 +308,7 @@ class json_sax_dom_parser
return &root;
}
JSON_ASSERT(ref_stack.back()->is_array() or ref_stack.back()->is_object());
JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
if (ref_stack.back()->is_array())
{
......@@ -413,7 +413,7 @@ class json_sax_dom_callback_parser
ref_stack.push_back(val.second);
// check object limit
if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len)));
}
......@@ -430,7 +430,7 @@ class json_sax_dom_callback_parser
key_keep_stack.push_back(keep);
// add discarded value at given key and store the reference for later
if (keep and ref_stack.back())
if (keep && ref_stack.back())
{
object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
}
......@@ -440,18 +440,18 @@ class json_sax_dom_callback_parser
bool end_object()
{
if (ref_stack.back() and not callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
if (ref_stack.back() && !callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
{
// discard object
*ref_stack.back() = discarded;
}
JSON_ASSERT(not ref_stack.empty());
JSON_ASSERT(not keep_stack.empty());
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(!keep_stack.empty());
ref_stack.pop_back();
keep_stack.pop_back();
if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_structured())
if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
{
// remove discarded value
for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
......@@ -476,7 +476,7 @@ class json_sax_dom_callback_parser
ref_stack.push_back(val.second);
// check array limit
if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len)));
}
......@@ -491,20 +491,20 @@ class json_sax_dom_callback_parser
if (ref_stack.back())
{
keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
if (not keep)
if (!keep)
{
// discard array
*ref_stack.back() = discarded;
}
}
JSON_ASSERT(not ref_stack.empty());
JSON_ASSERT(not keep_stack.empty());
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(!keep_stack.empty());
ref_stack.pop_back();
keep_stack.pop_back();
// remove discarded value
if (not keep and not ref_stack.empty() and ref_stack.back()->is_array())
if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
{
ref_stack.back()->m_value.array->pop_back();
}
......@@ -564,11 +564,11 @@ class json_sax_dom_callback_parser
template<typename Value>
std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false)
{
JSON_ASSERT(not keep_stack.empty());
JSON_ASSERT(!keep_stack.empty());
// do not handle this value if we know it would be added to a discarded
// container
if (not keep_stack.back())
if (!keep_stack.back())
{
return {false, nullptr};
}
......@@ -577,10 +577,10 @@ class json_sax_dom_callback_parser
auto value = BasicJsonType(std::forward<Value>(v));
// check callback
const bool keep = skip_callback or callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);
const bool keep = skip_callback || callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);
// do not handle this value if we just learnt it shall be discarded
if (not keep)
if (!keep)
{
return {false, nullptr};
}
......@@ -593,13 +593,13 @@ class json_sax_dom_callback_parser
// skip this value if we already decided to skip the parent
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
if (not ref_stack.back())
if (!ref_stack.back())
{
return {false, nullptr};
}
// we now only expect arrays and objects
JSON_ASSERT(ref_stack.back()->is_array() or ref_stack.back()->is_object());
JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
// array
if (ref_stack.back()->is_array())
......@@ -611,11 +611,11 @@ class json_sax_dom_callback_parser
// object
JSON_ASSERT(ref_stack.back()->is_object());
// check if we should store an element for the current key
JSON_ASSERT(not key_keep_stack.empty());
JSON_ASSERT(!key_keep_stack.empty());
const bool store_element = key_keep_stack.back();
key_keep_stack.pop_back();
if (not store_element)
if (!store_element)
{
return {false, nullptr};
}
......
......@@ -169,15 +169,15 @@ class lexer : public lexer_base<BasicJsonType>
{
get();
if (current >= '0' and current <= '9')
if (current >= '0' && current <= '9')
{
codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
}
else if (current >= 'A' and current <= 'F')
else if (current >= 'A' && current <= 'F')
{
codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
}
else if (current >= 'a' and current <= 'f')
else if (current >= 'a' && current <= 'f')
{
codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
}
......@@ -187,7 +187,7 @@ class lexer : public lexer_base<BasicJsonType>
}
}
JSON_ASSERT(0x0000 <= codepoint and codepoint <= 0xFFFF);
JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
return codepoint;
}
......@@ -208,13 +208,13 @@ class lexer : public lexer_base<BasicJsonType>
*/
bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
{
JSON_ASSERT(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6);
JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
add(current);
for (auto range = ranges.begin(); range != ranges.end(); ++range)
{
get();
if (JSON_HEDLEY_LIKELY(*range <= current and current <= *(++range)))
if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
{
add(current);
}
......@@ -320,10 +320,10 @@ class lexer : public lexer_base<BasicJsonType>
}
// check if code point is a high surrogate
if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
{
// expect next \uxxxx entry
if (JSON_HEDLEY_LIKELY(get() == '\\' and get() == 'u'))
if (JSON_HEDLEY_LIKELY(get() == '\\' && get() == 'u'))
{
const int codepoint2 = get_codepoint();
......@@ -334,7 +334,7 @@ class lexer : public lexer_base<BasicJsonType>
}
// check if codepoint2 is a low surrogate
if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
{
// overwrite codepoint
codepoint = static_cast<int>(
......@@ -361,7 +361,7 @@ class lexer : public lexer_base<BasicJsonType>
}
else
{
if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
{
error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
return token_type::parse_error;
......@@ -369,7 +369,7 @@ class lexer : public lexer_base<BasicJsonType>
}
// result of the above calculation yields a proper codepoint
JSON_ASSERT(0x00 <= codepoint and codepoint <= 0x10FFFF);
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
// translate codepoint into bytes
if (codepoint < 0x80)
......@@ -736,7 +736,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xDE:
case 0xDF:
{
if (JSON_HEDLEY_UNLIKELY(not next_byte_in_range({0x80, 0xBF})))
if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
{
return token_type::parse_error;
}
......@@ -746,7 +746,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
case 0xE0:
{
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
{
return token_type::parse_error;
}
......@@ -770,7 +770,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xEE:
case 0xEF:
{
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
{
return token_type::parse_error;
}
......@@ -780,7 +780,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
case 0xED:
{
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
{
return token_type::parse_error;
}
......@@ -790,7 +790,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
case 0xF0:
{
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
{
return token_type::parse_error;
}
......@@ -802,7 +802,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xF2:
case 0xF3:
{
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
{
return token_type::parse_error;
}
......@@ -812,7 +812,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
case 0xF4:
{
if (JSON_HEDLEY_UNLIKELY(not (next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
{
return token_type::parse_error;
}
......@@ -1384,7 +1384,7 @@ scan_number_done:
if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
{
JSON_ASSERT(not token_string.empty());
JSON_ASSERT(!token_string.empty());
token_string.pop_back();
}
}
......@@ -1480,7 +1480,7 @@ scan_number_done:
if (get() == 0xEF)
{
// check if we completely parse the BOM
return get() == 0xBB and get() == 0xBF;
return get() == 0xBB && get() == 0xBF;
}
// the first character is not the beginning of the BOM; unget it to
......@@ -1495,13 +1495,13 @@ scan_number_done:
{
get();
}
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
}
token_type scan()
{
// initially, skip the BOM
if (position.chars_read_total == 0 and not skip_bom())
if (position.chars_read_total == 0 && !skip_bom())
{
error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
return token_type::parse_error;
......@@ -1511,9 +1511,9 @@ scan_number_done:
skip_whitespace();
// ignore comments
if (ignore_comments and current == '/')
if (ignore_comments && current == '/')
{
if (not scan_comment())
if (!scan_comment())
{
return token_type::parse_error;
}
......@@ -1521,6 +1521,7 @@ scan_number_done:
// skip following whitespace
skip_whitespace();
}
while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
switch (current)
{
......
......@@ -91,7 +91,7 @@ class parser
result.assert_invariant();
// in strict mode, input must be completely read
if (strict and (get_token() != token_type::end_of_input))
if (strict && (get_token() != token_type::end_of_input))
{
sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
......@@ -120,7 +120,7 @@ class parser
result.assert_invariant();
// in strict mode, input must be completely read
if (strict and (get_token() != token_type::end_of_input))
if (strict && (get_token() != token_type::end_of_input))
{
sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
......@@ -149,7 +149,7 @@ class parser
return sax_parse(&sax_acceptor, strict);
}
template <typename SAX>
template<typename SAX>
JSON_HEDLEY_NON_NULL(2)
bool sax_parse(SAX* sax, const bool strict = true)
{
......@@ -157,7 +157,7 @@ class parser
const bool result = sax_parse_internal(sax);
// strict mode: next byte must be EOF
if (result and strict and (get_token() != token_type::end_of_input))
if (result && strict && (get_token() != token_type::end_of_input))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
......@@ -169,7 +169,7 @@ class parser
}
private:
template <typename SAX>
template<typename SAX>
JSON_HEDLEY_NON_NULL(2)
bool sax_parse_internal(SAX* sax)
{
......@@ -181,14 +181,14 @@ class parser
while (true)
{
if (not skip_to_state_evaluation)
if (!skip_to_state_evaluation)
{
// invariant: get_token() was called before each iteration
switch (last_token)
{
case token_type::begin_object:
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
{
return false;
}
......@@ -196,7 +196,7 @@ class parser
// closing } -> we are done
if (get_token() == token_type::end_object)
{
if (JSON_HEDLEY_UNLIKELY(not sax->end_object()))
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
......@@ -211,7 +211,7 @@ class parser
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}
if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
......@@ -235,7 +235,7 @@ class parser
case token_type::begin_array:
{
if (JSON_HEDLEY_UNLIKELY(not sax->start_array(std::size_t(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
{
return false;
}
......@@ -243,7 +243,7 @@ class parser
// closing ] -> we are done
if (get_token() == token_type::end_array)
{
if (JSON_HEDLEY_UNLIKELY(not sax->end_array()))
if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
{
return false;
}
......@@ -261,14 +261,14 @@ class parser
{
const auto res = m_lexer.get_number_float();
if (JSON_HEDLEY_UNLIKELY(not std::isfinite(res)))
if (JSON_HEDLEY_UNLIKELY(!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_HEDLEY_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
{
return false;
}
......@@ -278,7 +278,7 @@ class parser
case token_type::literal_false:
{
if (JSON_HEDLEY_UNLIKELY(not sax->boolean(false)))
if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false)))
{
return false;
}
......@@ -287,7 +287,7 @@ class parser
case token_type::literal_null:
{
if (JSON_HEDLEY_UNLIKELY(not sax->null()))
if (JSON_HEDLEY_UNLIKELY(!sax->null()))
{
return false;
}
......@@ -296,7 +296,7 @@ class parser
case token_type::literal_true:
{
if (JSON_HEDLEY_UNLIKELY(not sax->boolean(true)))
if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true)))
{
return false;
}
......@@ -305,7 +305,7 @@ class parser
case token_type::value_integer:
{
if (JSON_HEDLEY_UNLIKELY(not sax->number_integer(m_lexer.get_number_integer())))
if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
{
return false;
}
......@@ -314,7 +314,7 @@ class parser
case token_type::value_string:
{
if (JSON_HEDLEY_UNLIKELY(not sax->string(m_lexer.get_string())))
if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
{
return false;
}
......@@ -323,7 +323,7 @@ class parser
case token_type::value_unsigned:
{
if (JSON_HEDLEY_UNLIKELY(not sax->number_unsigned(m_lexer.get_number_unsigned())))
if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
{
return false;
}
......@@ -373,7 +373,7 @@ class parser
// closing ]
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
{
if (JSON_HEDLEY_UNLIKELY(not sax->end_array()))
if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
{
return false;
}
......@@ -382,7 +382,7 @@ class parser
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(not states.empty());
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
......@@ -407,7 +407,7 @@ class parser
exception_message(token_type::value_string, "object key")));
}
if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string())))
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
......@@ -429,7 +429,7 @@ class parser
// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
{
if (JSON_HEDLEY_UNLIKELY(not sax->end_object()))
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
......@@ -438,7 +438,7 @@ class parser
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(not states.empty());
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
......@@ -462,7 +462,7 @@ class parser
{
std::string error_msg = "syntax error ";
if (not context.empty())
if (!context.empty())
{
error_msg += "while parsing " + context + " ";
}
......
......@@ -3,7 +3,6 @@
#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
#include <type_traits> // conditional, is_const, remove_const
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/iterators/internal_iterator.hpp>
#include <nlohmann/detail/iterators/primitive_iterator.hpp>
......@@ -423,7 +422,7 @@ class iter_impl
*/
bool operator!=(const iter_impl& other) const
{
return not operator==(other);
return !operator==(other);
}
/*!
......@@ -459,7 +458,7 @@ class iter_impl
*/
bool operator<=(const iter_impl& other) const
{
return not other.operator < (*this);
return !other.operator < (*this);
}
/*!
......@@ -468,7 +467,7 @@ class iter_impl
*/
bool operator>(const iter_impl& other) const
{
return not operator<=(other);
return !operator<=(other);
}
/*!
......@@ -477,7 +476,7 @@ class iter_impl
*/
bool operator>=(const iter_impl& other) const
{
return not operator<(other);
return !operator<(other);
}
/*!
......
......@@ -19,7 +19,7 @@ void int_to_string( string_type& target, std::size_t value )
using std::to_string;
target = to_string(value);
}
template <typename IteratorType> class iteration_proxy_value
template<typename IteratorType> class iteration_proxy_value
{
public:
using difference_type = std::ptrdiff_t;
......@@ -133,7 +133,7 @@ template<typename IteratorType> class iteration_proxy
// Structured Bindings Support
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
// And see https://github.com/nlohmann/json/pull/1391
template <std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
{
return i.key();
......@@ -141,7 +141,7 @@ auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decl
// Structured Bindings Support
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
// And see https://github.com/nlohmann/json/pull/1391
template <std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
{
return i.value();
......@@ -160,11 +160,11 @@ namespace std
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
template <typename IteratorType>
template<typename IteratorType>
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
: public std::integral_constant<std::size_t, 2> {};
template <std::size_t N, typename IteratorType>
template<std::size_t N, typename IteratorType>
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
{
public:
......
......@@ -9,10 +9,10 @@ namespace nlohmann
{
namespace detail
{
template <typename It, typename = void>
template<typename It, typename = void>
struct iterator_types {};
template <typename It>
template<typename It>
struct iterator_types <
It,
void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
......@@ -27,18 +27,18 @@ struct iterator_types <
// This is required as some compilers implement std::iterator_traits in a way that
// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.
template <typename T, typename = void>
template<typename T, typename = void>
struct iterator_traits
{
};
template <typename T>
template<typename T>
struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
: iterator_types<T>
{
};
template <typename T>
template<typename T>
struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
{
using iterator_category = std::random_access_iterator_tag;
......
......@@ -335,7 +335,7 @@ class json_pointer
using size_type = typename BasicJsonType::size_type;
// error condition (cf. RFC 6901, Sect. 4)
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 and s[0] == '0'))
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
{
JSON_THROW(detail::parse_error::create(106, 0,
"array index '" + s +
......@@ -343,7 +343,7 @@ class json_pointer
}
// error condition (cf. RFC 6901, Sect. 4)
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 and not (s[0] >= '1' and s[0] <= '9')))
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
{
JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number"));
}
......@@ -483,7 +483,7 @@ class json_pointer
});
// change value to array for numbers or "-" or to object otherwise
*ptr = (nums or reference_token == "-")
*ptr = (nums || reference_token == "-")
? detail::value_t::array
: detail::value_t::object;
}
......@@ -665,7 +665,7 @@ class json_pointer
{
case detail::value_t::object:
{
if (not ptr->contains(reference_token))
if (!ptr->contains(reference_token))
{
// we did not find the key in the object
return false;
......@@ -682,21 +682,21 @@ class json_pointer
// "-" always fails the range check
return false;
}
if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 and not ("0" <= reference_token and reference_token <= "9")))
if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9")))
{
// invalid char
return false;
}
if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
{
if (JSON_HEDLEY_UNLIKELY(not ('1' <= reference_token[0] and reference_token[0] <= '9')))
if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
{
// first char should be between '1' and '9'
return false;
}
for (std::size_t i = 1; i < reference_token.size(); i++)
{
if (JSON_HEDLEY_UNLIKELY(not ('0' <= reference_token[i] and reference_token[i] <= '9')))
if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9')))
{
// other char should be between '0' and '9'
return false;
......@@ -783,8 +783,8 @@ class json_pointer
JSON_ASSERT(reference_token[pos] == '~');
// ~ must be followed by 0 or 1
if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 or
(reference_token[pos + 1] != '0' and
if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
(reference_token[pos + 1] != '0' &&
reference_token[pos + 1] != '1')))
{
JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'"));
......@@ -815,7 +815,7 @@ class json_pointer
static void replace_substring(std::string& s, const std::string& f,
const std::string& t)
{
JSON_ASSERT(not f.empty());
JSON_ASSERT(!f.empty());
for (auto pos = s.find(f); // find first occurrence of f
pos != std::string::npos; // make sure f was found
s.replace(pos, f.size(), t), // replace with t, and
......@@ -910,7 +910,7 @@ class json_pointer
static BasicJsonType
unflatten(const BasicJsonType& value)
{
if (JSON_HEDLEY_UNLIKELY(not value.is_object()))
if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
{
JSON_THROW(detail::type_error::create(314, "only objects can be unflattened"));
}
......@@ -920,7 +920,7 @@ class json_pointer
// iterate the JSON object values
for (const auto& element : *value.m_value.object)
{
if (JSON_HEDLEY_UNLIKELY(not element.second.is_primitive()))
if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
{
JSON_THROW(detail::type_error::create(315, "values in object must be primitive"));
}
......@@ -966,7 +966,7 @@ class json_pointer
friend bool operator!=(json_pointer const& lhs,
json_pointer const& rhs) noexcept
{
return not (lhs == rhs);
return !(lhs == rhs);
}
/// the reference tokens
......
......@@ -3,8 +3,6 @@
#include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
#include <nlohmann/detail/boolean_operators.hpp>
namespace nlohmann
{
namespace detail
......
......@@ -19,39 +19,39 @@ struct nonesuch
void operator=(nonesuch&&) = delete;
};
template <class Default,
class AlwaysVoid,
template <class...> class Op,
class... Args>
template<class Default,
class AlwaysVoid,
template<class...> class Op,
class... Args>
struct detector
{
using value_t = std::false_type;
using type = Default;
};
template <class Default, template <class...> class Op, class... Args>
template<class Default, template<class...> class Op, class... Args>
struct detector<Default, void_t<Op<Args...>>, Op, Args...>
{
using value_t = std::true_type;
using type = Op<Args...>;
};
template <template <class...> class Op, class... Args>
template<template<class...> class Op, class... Args>
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
template <template <class...> class Op, class... Args>
template<template<class...> class Op, class... Args>
using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
template <class Default, template <class...> class Op, class... Args>
template<class Default, template<class...> class Op, class... Args>
using detected_or = detector<Default, void, Op, Args...>;
template <class Default, template <class...> class Op, class... Args>
template<class Default, template<class...> class Op, class... Args>
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
template <class Expected, template <class...> class Op, class... Args>
template<class Expected, template<class...> class Op, class... Args>
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
template <class To, template <class...> class Op, class... Args>
template<class To, template<class...> class Op, class... Args>
using is_detected_convertible =
std::is_convertible<detected_t<Op, Args...>, To>;
} // namespace detail
......
......@@ -11,53 +11,53 @@ namespace nlohmann
{
namespace detail
{
template <typename T>
template<typename T>
using null_function_t = decltype(std::declval<T&>().null());
template <typename T>
template<typename T>
using boolean_function_t =
decltype(std::declval<T&>().boolean(std::declval<bool>()));
template <typename T, typename Integer>
template<typename T, typename Integer>
using number_integer_function_t =
decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
template <typename T, typename Unsigned>
template<typename T, typename Unsigned>
using number_unsigned_function_t =
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
template <typename T, typename Float, typename String>
template<typename T, typename Float, typename String>
using number_float_function_t = decltype(std::declval<T&>().number_float(
std::declval<Float>(), std::declval<const String&>()));
template <typename T, typename String>
template<typename T, typename String>
using string_function_t =
decltype(std::declval<T&>().string(std::declval<String&>()));
template <typename T>
template<typename T>
using start_object_function_t =
decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
template <typename T, typename String>
template<typename T, typename String>
using key_function_t =
decltype(std::declval<T&>().key(std::declval<String&>()));
template <typename T>
template<typename T>
using end_object_function_t = decltype(std::declval<T&>().end_object());
template <typename T>
template<typename T>
using start_array_function_t =
decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
template <typename T>
template<typename T>
using end_array_function_t = decltype(std::declval<T&>().end_array());
template <typename T, typename Exception>
template<typename T, typename Exception>
using parse_error_function_t = decltype(std::declval<T&>().parse_error(
std::declval<std::size_t>(), std::declval<const std::string&>(),
std::declval<const Exception&>()));
template <typename SAX, typename BasicJsonType>
template<typename SAX, typename BasicJsonType>
struct is_sax
{
private:
......@@ -89,7 +89,7 @@ struct is_sax
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
};
template <typename SAX, typename BasicJsonType>
template<typename SAX, typename BasicJsonType>
struct is_sax_static_asserts
{
private:
......
......@@ -4,10 +4,10 @@ namespace nlohmann
{
namespace detail
{
template <typename ...Ts> struct make_void
template<typename ...Ts> struct make_void
{
using type = void;
};
template <typename ...Ts> using void_t = typename make_void<Ts...>::type;
template<typename ...Ts> using void_t = typename make_void<Ts...>::type;
} // namespace detail
} // namespace nlohmann
......@@ -12,7 +12,6 @@
#include <type_traits> // is_same
#include <utility> // move
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/conversions/to_chars.hpp>
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
......@@ -204,7 +203,7 @@ class serializer
}
// last element
JSON_ASSERT(not val.m_value.array->empty());
JSON_ASSERT(!val.m_value.array->empty());
o->write_characters(indent_string.c_str(), new_indent);
dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
......@@ -225,7 +224,7 @@ class serializer
}
// last element
JSON_ASSERT(not val.m_value.array->empty());
JSON_ASSERT(!val.m_value.array->empty());
dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
o->write_character(']');
......@@ -259,7 +258,7 @@ class serializer
o->write_characters("\"bytes\": [", 10);
if (not val.m_value.binary->empty())
if (!val.m_value.binary->empty())
{
for (auto i = val.m_value.binary->cbegin();
i != val.m_value.binary->cend() - 1; ++i)
......@@ -290,7 +289,7 @@ class serializer
{
o->write_characters("{\"bytes\":[", 10);
if (not val.m_value.binary->empty())
if (!val.m_value.binary->empty())
{
for (auto i = val.m_value.binary->cbegin();
i != val.m_value.binary->cend() - 1; ++i)
......@@ -451,7 +450,7 @@ class serializer
{
// escape control characters (0x00..0x1F) or, if
// ensure_ascii parameter is used, non-ASCII characters
if ((codepoint <= 0x1F) or (ensure_ascii and (codepoint >= 0x7F)))
if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
{
if (codepoint <= 0xFFFF)
{
......@@ -565,7 +564,7 @@ class serializer
default: // decode found yet incomplete multi-byte code point
{
if (not ensure_ascii)
if (!ensure_ascii)
{
// code point will not be escaped - copy byte to buffer
string_buffer[bytes++] = s[i];
......@@ -669,11 +668,11 @@ class serializer
@param[in] x integer number (signed or unsigned) to dump
@tparam NumberType either @a number_integer_t or @a number_unsigned_t
*/
template<typename NumberType, detail::enable_if_t<
std::is_same<NumberType, number_unsigned_t>::value or
std::is_same<NumberType, number_integer_t>::value or
std::is_same<NumberType, binary_char_t>::value,
int> = 0>
template < typename NumberType, detail::enable_if_t <
std::is_same<NumberType, number_unsigned_t>::value ||
std::is_same<NumberType, number_integer_t>::value ||
std::is_same<NumberType, binary_char_t>::value,
int > = 0 >
void dump_integer(NumberType x)
{
static constexpr std::array<std::array<char, 2>, 100> digits_to_99
......@@ -702,7 +701,7 @@ class serializer
// use a pointer to fill the buffer
auto buffer_ptr = number_buffer.begin();
const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not(x >= 0); // see issue #755
const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0); // see issue #755
number_unsigned_t abs_value;
unsigned int n_chars;
......@@ -763,7 +762,7 @@ class serializer
void dump_float(number_float_t x)
{
// NaN / inf
if (not std::isfinite(x))
if (!std::isfinite(x))
{
o->write_characters("null", 4);
return;
......@@ -775,8 +774,8 @@ class serializer
//
// NB: The test below works if <long double> == <double>.
static constexpr bool is_ieee_single_or_double
= (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 24 and std::numeric_limits<number_float_t>::max_exponent == 128) or
(std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 53 and std::numeric_limits<number_float_t>::max_exponent == 1024);
= (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
(std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
}
......@@ -813,7 +812,7 @@ class serializer
}
// convert decimal point to '.'
if (decimal_point != '\0' and decimal_point != '.')
if (decimal_point != '\0' && decimal_point != '.')
{
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
if (dec_pos != number_buffer.end())
......@@ -829,7 +828,7 @@ class serializer
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
[](char c)
{
return c == '.' or c == 'e';
return c == '.' || c == 'e';
});
if (value_is_int_like)
......@@ -915,7 +914,7 @@ class serializer
*/
inline number_unsigned_t remove_sign(number_integer_t x) noexcept
{
JSON_ASSERT(x < 0 and x < (std::numeric_limits<number_integer_t>::max)());
JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
return static_cast<number_unsigned_t>(-(x + 1)) + 1;
}
......
......@@ -5,8 +5,6 @@
#include <cstdint> // uint8_t
#include <string> // string
#include <nlohmann/detail/boolean_operators.hpp>
namespace nlohmann
{
namespace detail
......@@ -77,7 +75,7 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
const auto l_index = static_cast<std::size_t>(lhs);
const auto r_index = static_cast<std::size_t>(rhs);
return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
}
} // namespace detail
} // namespace nlohmann
This diff is collapsed.
This diff is collapsed.
......@@ -55,7 +55,7 @@ TEST_CASE("algorithms")
{
CHECK(std::any_of(j_array.begin(), j_array.end(), [](const json & value)
{
return value.is_string() and value.get<std::string>() == "foo";
return value.is_string() && value.get<std::string>() == "foo";
}));
CHECK(std::any_of(j_object.begin(), j_object.end(), [](const json & value)
{
......@@ -139,14 +139,14 @@ TEST_CASE("algorithms")
{
CHECK(std::equal(j_array.begin(), j_array.end(), j_array.begin()));
CHECK(std::equal(j_object.begin(), j_object.end(), j_object.begin()));
CHECK(not std::equal(j_array.begin(), j_array.end(), j_object.begin()));
CHECK(!std::equal(j_array.begin(), j_array.end(), j_object.begin()));
}
SECTION("using user-defined comparison")
{
// compare objects only by size of its elements
json j_array2 = {13, 29, 3, {"Hello", "World"}, true, false, {{"one", 1}, {"two", 2}, {"three", 3}}, "foo", "baz"};
CHECK(not std::equal(j_array.begin(), j_array.end(), j_array2.begin()));
CHECK(!std::equal(j_array.begin(), j_array.end(), j_array2.begin()));
CHECK(std::equal(j_array.begin(), j_array.end(), j_array2.begin(),
[](const json & a, const json & b)
{
......@@ -213,7 +213,7 @@ TEST_CASE("algorithms")
return v.is_string();
});
CHECK(std::distance(j_array.begin(), it) == 2);
CHECK(not it[2].is_string());
CHECK(!it[2].is_string());
}
}
......
......@@ -44,7 +44,7 @@ static int assert_counter;
using nlohmann::json;
// the test assumes exceptions to work
#if not defined(JSON_NOEXCEPTION)
#if !defined(JSON_NOEXCEPTION)
TEST_CASE("JSON_ASSERT(x)")
{
SECTION("basic_json(first, second)")
......
......@@ -766,7 +766,7 @@ TEST_CASE("Incomplete BSON Input")
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
SaxCountdown scp(0);
CHECK(not json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
}
SECTION("Incomplete BSON Input 2")
......@@ -784,7 +784,7 @@ TEST_CASE("Incomplete BSON Input")
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
SaxCountdown scp(0);
CHECK(not json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
}
SECTION("Incomplete BSON Input 3")
......@@ -808,7 +808,7 @@ TEST_CASE("Incomplete BSON Input")
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
SaxCountdown scp(1);
CHECK(not json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
}
SECTION("Incomplete BSON Input 4")
......@@ -825,7 +825,7 @@ TEST_CASE("Incomplete BSON Input")
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
SaxCountdown scp(0);
CHECK(not json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
}
SECTION("Improve coverage")
......@@ -835,7 +835,7 @@ TEST_CASE("Incomplete BSON Input")
json j = {{"key", "value"}};
auto bson_vec = json::to_bson(j);
SaxCountdown scp(2);
CHECK(not json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
}
SECTION("array")
......@@ -846,7 +846,7 @@ TEST_CASE("Incomplete BSON Input")
};
auto bson_vec = json::to_bson(j);
SaxCountdown scp(2);
CHECK(not json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
}
}
}
......@@ -887,7 +887,7 @@ TEST_CASE("Unsupported BSON input")
CHECK(json::from_bson(bson, true, false).is_discarded());
SaxCountdown scp(0);
CHECK(not json::sax_parse(bson, &scp, json::input_format_t::bson));
CHECK(!json::sax_parse(bson, &scp, json::input_format_t::bson));
}
TEST_CASE("BSON numerical data")
......
......@@ -1077,7 +1077,7 @@ TEST_CASE("CBOR")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
json::number_float_t d = j;
CHECK(not std::isfinite(d));
CHECK(!std::isfinite(d));
CHECK(j.dump() == "null");
}
......@@ -1869,7 +1869,7 @@ TEST_CASE("CBOR")
{
const auto result = json::from_cbor(vec, false);
CHECK(result == json());
CHECK(not json::from_cbor(vec, false, false).is_discarded());
CHECK(!json::from_cbor(vec, false, false).is_discarded());
}
SECTION("strict mode")
......@@ -1889,21 +1889,21 @@ TEST_CASE("CBOR")
{
std::vector<uint8_t> v = {0x83, 0x01, 0x02, 0x03};
SaxCountdown scp(0);
CHECK(not json::sax_parse(v, &scp, json::input_format_t::cbor));
CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
}
SECTION("start_object(len)")
{
std::vector<uint8_t> v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4};
SaxCountdown scp(0);
CHECK(not json::sax_parse(v, &scp, json::input_format_t::cbor));
CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
}
SECTION("key()")
{
std::vector<uint8_t> v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4};
SaxCountdown scp(1);
CHECK(not json::sax_parse(v, &scp, json::input_format_t::cbor));
CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
}
}
}
......@@ -1954,7 +1954,7 @@ TEST_CASE("single CBOR roundtrip")
}
}
#if not defined(JSON_NOEXCEPTION)
#if !defined(JSON_NOEXCEPTION)
TEST_CASE("CBOR regressions")
{
SECTION("fuzz test results")
......@@ -2274,7 +2274,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
}
}
#if not defined(JSON_NOEXCEPTION)
#if !defined(JSON_NOEXCEPTION)
TEST_CASE("all CBOR first bytes")
{
// these bytes will fail immediately with exception parse_error.112
......
......@@ -224,7 +224,7 @@ TEST_CASE("const_iterator class")
json::const_iterator it = j.cbegin();
CHECK((it.m_it.primitive_iterator.m_it == 1));
it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("number")
......@@ -235,7 +235,7 @@ TEST_CASE("const_iterator class")
it++;
CHECK((it.m_it.primitive_iterator.m_it == 1));
it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......@@ -275,7 +275,7 @@ TEST_CASE("const_iterator class")
json::const_iterator it = j.cbegin();
CHECK((it.m_it.primitive_iterator.m_it == 1));
++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("number")
......@@ -286,7 +286,7 @@ TEST_CASE("const_iterator class")
++it;
CHECK((it.m_it.primitive_iterator.m_it == 1));
++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......@@ -335,7 +335,7 @@ TEST_CASE("const_iterator class")
it--;
CHECK((it.m_it.primitive_iterator.m_it == 0));
it--;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......@@ -384,7 +384,7 @@ TEST_CASE("const_iterator class")
--it;
CHECK((it.m_it.primitive_iterator.m_it == 0));
--it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......
......@@ -208,7 +208,7 @@ TEST_CASE("iterator class")
json::iterator it = j.begin();
CHECK((it.m_it.primitive_iterator.m_it == 1));
it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("number")
......@@ -219,7 +219,7 @@ TEST_CASE("iterator class")
it++;
CHECK((it.m_it.primitive_iterator.m_it == 1));
it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......@@ -259,7 +259,7 @@ TEST_CASE("iterator class")
json::iterator it = j.begin();
CHECK((it.m_it.primitive_iterator.m_it == 1));
++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("number")
......@@ -270,7 +270,7 @@ TEST_CASE("iterator class")
++it;
CHECK((it.m_it.primitive_iterator.m_it == 1));
++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......@@ -319,7 +319,7 @@ TEST_CASE("iterator class")
it--;
CHECK((it.m_it.primitive_iterator.m_it == 0));
it--;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......@@ -368,7 +368,7 @@ TEST_CASE("iterator class")
--it;
CHECK((it.m_it.primitive_iterator.m_it == 0));
--it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1));
}
SECTION("object")
......
......@@ -254,7 +254,7 @@ bool accept_helper(const std::string& s)
// 1. parse s without exceptions
json j;
CHECK_NOTHROW(json::parser(nlohmann::detail::input_adapter(s), nullptr, false).parse(true, j));
const bool ok_noexcept = not j.is_discarded();
const bool ok_noexcept = !j.is_discarded();
// 2. accept s
const bool ok_accept = json::parser(nlohmann::detail::input_adapter(s)).accept(true);
......@@ -265,7 +265,7 @@ bool accept_helper(const std::string& s)
// 4. parse with SAX (compare with relaxed accept result)
SaxEventLogger el;
CHECK_NOTHROW(json::sax_parse(s, &el, json::input_format_t::json, false));
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == not el.errored);
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
// 5. parse with simple callback
json::parser_callback_t cb = [](int, json::parse_event_t, json&)
......@@ -273,7 +273,7 @@ bool accept_helper(const std::string& s)
return true;
};
json j_cb = json::parse(s, cb, false);
const bool ok_noexcept_cb = not j_cb.is_discarded();
const bool ok_noexcept_cb = !j_cb.is_discarded();
// 6. check if this approach came to the same result
CHECK(ok_noexcept == ok_noexcept_cb);
......@@ -314,7 +314,7 @@ void comments_helper(const std::string& s)
{
CAPTURE(json_with_comment)
CHECK_THROWS_AS(_ = json::parse(json_with_comment), json::parse_error);
CHECK(not json::accept(json_with_comment));
CHECK(!json::accept(json_with_comment));
CHECK_NOTHROW(_ = json::parse(json_with_comment, nullptr, true, true));
CHECK(json::accept(json_with_comment, true));
......@@ -941,7 +941,7 @@ TEST_CASE("parser class")
SECTION("overflow")
{
// overflows during parsing
CHECK(not accept_helper("1.18973e+4932"));
CHECK(!accept_helper("1.18973e+4932"));
}
SECTION("invalid numbers")
......@@ -1616,7 +1616,7 @@ TEST_CASE("parser class")
{
json j_filtered1 = json::parse(structured_array, [](int, json::parse_event_t e, const json & parsed)
{
if (e == json::parse_event_t::object_end and parsed.contains("foo"))
if (e == json::parse_event_t::object_end && parsed.contains("foo"))
{
return false;
}
......@@ -1655,7 +1655,7 @@ TEST_CASE("parser class")
json j_object = json::parse(s_object, [](int, json::parse_event_t e, const json&)
{
static bool first = true;
if (e == json::parse_event_t::object_end and first)
if (e == json::parse_event_t::object_end && first)
{
first = false;
return false;
......@@ -1674,7 +1674,7 @@ TEST_CASE("parser class")
json j_array = json::parse(s_array, [](int, json::parse_event_t e, const json&)
{
static bool first = true;
if (e == json::parse_event_t::array_end and first)
if (e == json::parse_event_t::array_end && first)
{
first = false;
return false;
......
......@@ -165,7 +165,7 @@ TEST_CASE("lexicographical comparison operators")
CAPTURE(i)
CAPTURE(j)
// check definition
CHECK( (j_values[i] != j_values[j]) == not(j_values[i] == j_values[j]) );
CHECK( (j_values[i] != j_values[j]) == !(j_values[i] == j_values[j]) );
}
}
......@@ -173,8 +173,8 @@ TEST_CASE("lexicographical comparison operators")
json j_null;
CHECK( (j_null != nullptr) == false);
CHECK( (nullptr != j_null) == false);
CHECK( (j_null != nullptr) == not(j_null == nullptr));
CHECK( (nullptr != j_null) == not(nullptr == j_null));
CHECK( (j_null != nullptr) == !(j_null == nullptr));
CHECK( (nullptr != j_null) == !(nullptr == j_null));
}
SECTION("comparison: less")
......@@ -234,7 +234,7 @@ TEST_CASE("lexicographical comparison operators")
CAPTURE(i)
CAPTURE(j)
// check definition
CHECK( (j_values[i] <= j_values[j]) == not(j_values[j] < j_values[i]) );
CHECK( (j_values[i] <= j_values[j]) == !(j_values[j] < j_values[i]) );
}
}
}
......@@ -262,7 +262,7 @@ TEST_CASE("lexicographical comparison operators")
CAPTURE(i)
CAPTURE(j)
// check definition
CHECK( (j_values[i] >= j_values[j]) == not(j_values[i] < j_values[j]) );
CHECK( (j_values[i] >= j_values[j]) == !(j_values[i] < j_values[j]) );
}
}
}
......
......@@ -847,7 +847,7 @@ TEST_CASE("constructors")
// check round trip of NaN
json::number_float_t d = j;
CHECK((std::isnan(d) and std::isnan(n)) == true);
CHECK((std::isnan(d) && std::isnan(n)) == true);
// check that NaN is serialized to null
CHECK(j.dump() == "null");
......
......@@ -272,7 +272,7 @@ TEST_CASE("value conversion")
json(json::value_t::null).get<std::vector<json>>(),
"[json.exception.type_error.302] type must be array, but is null");
#if not defined(JSON_NOEXCEPTION)
#if !defined(JSON_NOEXCEPTION)
SECTION("reserve is called on containers that supports it")
{
// make sure all values are properly copied
......
This diff is collapsed.
......@@ -1072,7 +1072,7 @@ TEST_CASE("element access 2")
}
}
#if not defined(JSON_NOEXCEPTION)
#if !defined(JSON_NOEXCEPTION)
TEST_CASE("element access 2 (throwing tests)")
{
SECTION("object")
......
This diff is collapsed.
......@@ -231,12 +231,12 @@ TEST_CASE("iterators 1")
{
SECTION("!(begin != begin)")
{
CHECK(not(j.begin() != j.begin()));
CHECK(!(j.begin() != j.begin()));
}
SECTION("!(end != end)")
{
CHECK(not(j.end() != j.end()));
CHECK(!(j.end() != j.end()));
}
SECTION("begin < end")
......@@ -286,7 +286,7 @@ TEST_CASE("iterators 1")
SECTION("!(begin == end)")
{
CHECK(not(j.begin() == j.end()));
CHECK(!(j.begin() == j.end()));
}
SECTION("begin != end")
......
This diff is collapsed.
......@@ -101,10 +101,10 @@ TEST_CASE("JSON pointers")
CHECK(j["/foo/1"_json_pointer] == j["foo"][1]);
CHECK(j.contains(json::json_pointer("/foo/0")));
CHECK(j.contains(json::json_pointer("/foo/1")));
CHECK(not j.contains(json::json_pointer("/foo/3")));
CHECK(not j.contains(json::json_pointer("/foo/+")));
CHECK(not j.contains(json::json_pointer("/foo/1+2")));
CHECK(not j.contains(json::json_pointer("/foo/-")));
CHECK(!j.contains(json::json_pointer("/foo/3")));
CHECK(!j.contains(json::json_pointer("/foo/+")));
CHECK(!j.contains(json::json_pointer("/foo/1+2")));
CHECK(!j.contains(json::json_pointer("/foo/-")));
// checked array access
CHECK(j.at(json::json_pointer("/foo/0")) == j["foo"][0]);
......@@ -147,19 +147,19 @@ TEST_CASE("JSON pointers")
// unescaped access
// access to nonexisting values yield object creation
CHECK(not j.contains(json::json_pointer("/a/b")));
CHECK(!j.contains(json::json_pointer("/a/b")));
CHECK_NOTHROW(j[json::json_pointer("/a/b")] = 42);
CHECK(j.contains(json::json_pointer("/a/b")));
CHECK(j["a"]["b"] == json(42));
CHECK(not j.contains(json::json_pointer("/a/c/1")));
CHECK(!j.contains(json::json_pointer("/a/c/1")));
CHECK_NOTHROW(j[json::json_pointer("/a/c/1")] = 42);
CHECK(j["a"]["c"] == json({nullptr, 42}));
CHECK(j.contains(json::json_pointer("/a/c/1")));
CHECK(not j.contains(json::json_pointer("/a/d/-")));
CHECK(!j.contains(json::json_pointer("/a/d/-")));
CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42);
CHECK(not j.contains(json::json_pointer("/a/d/-")));
CHECK(!j.contains(json::json_pointer("/a/d/-")));
CHECK(j["a"]["d"] == json::array({42}));
// "/a/b" works for JSON {"a": {"b": 42}}
CHECK(json({{"a", {{"b", 42}}}})[json::json_pointer("/a/b")] == json(42));
......@@ -172,7 +172,7 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range&);
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer),
"[json.exception.out_of_range.404] unresolved reference token 'foo'");
CHECK(not j_primitive.contains(json::json_pointer("/foo")));
CHECK(!j_primitive.contains(json::json_pointer("/foo")));
}
SECTION("const access")
......@@ -272,7 +272,7 @@ TEST_CASE("JSON pointers")
CHECK(j.contains("/foo"_json_pointer));
CHECK(j.contains("/foo/0"_json_pointer));
CHECK(j.contains("/foo/1"_json_pointer));
CHECK(not j.contains("/foo/-"_json_pointer));
CHECK(!j.contains("/foo/-"_json_pointer));
}
}
......@@ -314,10 +314,10 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH(j_const.at("/01"_json_pointer),
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'");
CHECK(not j.contains("/01"_json_pointer));
CHECK(not j.contains("/01"_json_pointer));
CHECK(not j_const.contains("/01"_json_pointer));
CHECK(not j_const.contains("/01"_json_pointer));
CHECK(!j.contains("/01"_json_pointer));
CHECK(!j.contains("/01"_json_pointer));
CHECK(!j_const.contains("/01"_json_pointer));
CHECK(!j_const.contains("/01"_json_pointer));
// error with incorrect numbers
CHECK_THROWS_AS(j["/one"_json_pointer] = 1, json::parse_error&);
......@@ -379,10 +379,10 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH(j_const.at("/one"_json_pointer) == 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number");
CHECK(not j.contains("/one"_json_pointer));
CHECK(not j.contains("/one"_json_pointer));
CHECK(not j_const.contains("/one"_json_pointer));
CHECK(not j_const.contains("/one"_json_pointer));
CHECK(!j.contains("/one"_json_pointer));
CHECK(!j.contains("/one"_json_pointer));
CHECK(!j_const.contains("/one"_json_pointer));
CHECK(!j_const.contains("/one"_json_pointer));
CHECK_THROWS_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), json::parse_error&);
CHECK_THROWS_WITH(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(),
......@@ -396,7 +396,7 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_AS(j_const["/-"_json_pointer], json::out_of_range&);
CHECK_THROWS_WITH(j_const["/-"_json_pointer],
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK(not j_const.contains("/-"_json_pointer));
CHECK(!j_const.contains("/-"_json_pointer));
// error when using "-" with at
CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range&);
......@@ -405,7 +405,7 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_AS(j_const.at("/-"_json_pointer), json::out_of_range&);
CHECK_THROWS_WITH(j_const.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK(not j_const.contains("/-"_json_pointer));
CHECK(!j_const.contains("/-"_json_pointer));
}
SECTION("const access")
......@@ -421,13 +421,13 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_AS(j.at("/3"_json_pointer), json::out_of_range&);
CHECK_THROWS_WITH(j.at("/3"_json_pointer),
"[json.exception.out_of_range.401] array index 3 is out of range");
CHECK(not j.contains("/3"_json_pointer));
CHECK(!j.contains("/3"_json_pointer));
// assign to nonexisting index (with gap)
CHECK_THROWS_AS(j.at("/5"_json_pointer), json::out_of_range&);
CHECK_THROWS_WITH(j.at("/5"_json_pointer),
"[json.exception.out_of_range.401] array index 5 is out of range");
CHECK(not j.contains("/5"_json_pointer));
CHECK(!j.contains("/5"_json_pointer));
// assign to "-"
CHECK_THROWS_AS(j["/-"_json_pointer], json::out_of_range&);
......@@ -436,7 +436,7 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range&);
CHECK_THROWS_WITH(j.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK(not j.contains("/-"_json_pointer));
CHECK(!j.contains("/-"_json_pointer));
}
}
......
......@@ -114,7 +114,7 @@ TEST_CASE("modifiers")
json k = j;
j.clear();
CHECK(not j.empty());
CHECK(!j.empty());
CHECK(j == json(json::value_t::binary));
CHECK(j == json(k.type()));
}
......@@ -125,7 +125,7 @@ TEST_CASE("modifiers")
json k = j;
j.clear();
CHECK(not j.empty());
CHECK(!j.empty());
CHECK(j == json(json::value_t::binary));
CHECK(j == json(k.type()));
}
......
This diff is collapsed.
......@@ -59,12 +59,12 @@ static_assert(noexcept(nlohmann::to_json(*j, 2.5)), "");
static_assert(noexcept(nlohmann::to_json(*j, true)), "");
static_assert(noexcept(nlohmann::to_json(*j, test{})), "");
static_assert(noexcept(nlohmann::to_json(*j, pod{})), "");
static_assert(not noexcept(nlohmann::to_json(*j, pod_bis{})), "");
static_assert(!noexcept(nlohmann::to_json(*j, pod_bis{})), "");
static_assert(noexcept(json(2)), "");
static_assert(noexcept(json(test{})), "");
static_assert(noexcept(json(pod{})), "");
static_assert(noexcept(j->get<pod>()), "");
static_assert(not noexcept(j->get<pod_bis>()), "");
static_assert(!noexcept(j->get<pod_bis>()), "");
static_assert(noexcept(json(pod{})), "");
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment