From b1008403bb9d16be4b4f858faa222a4952a3f409 Mon Sep 17 00:00:00 2001 From: realaltffour <56314286+realaltffour@users.noreply.github.com> Date: Sat, 11 Apr 2020 16:02:29 +0300 Subject: [PATCH] Add init module. - Update .clang-format's IndentWidth - Apply new .clang-format. - Add init module. --- .clang-format | 2 +- src/data.cpp | 5 +- src/main.cpp | 31 +- src/modules/init.cpp | 10 +- src/modules/init.h | 6 +- vendor/json.hpp | 1702 +++++++++++++++++++++--------------------- 6 files changed, 883 insertions(+), 873 deletions(-) diff --git a/.clang-format b/.clang-format index b5d9155..1936c3e 100644 --- a/.clang-format +++ b/.clang-format @@ -22,7 +22,7 @@ ColumnLimit: '80' CompactNamespaces: 'true' IncludeBlocks: Preserve IndentWidth: '2' -SpaceBeforeParens: Never +SpaceBeforeParens: 'ControlStatements' SpaceBeforeRangeBasedForLoopColon: 'false' SpaceInEmptyParentheses: 'false' SpacesBeforeTrailingComments: '1' diff --git a/src/data.cpp b/src/data.cpp index a5fe747..e83b820 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -51,9 +51,8 @@ void writeDB(DB db, const std::string& dest) { try { std::ofstream f(dest); json j = db; - std::cout << "hello" << std::endl; f << j; - } catch(std::exception& ex) { + } catch (std::exception& ex) { std::cout << "Failed writing database to: " << dest << std::endl; std::cout << "Error: " << ex.what() << std::endl; } @@ -65,7 +64,7 @@ void loadDB(DB& db, const std::string& src) { json j; f >> j; db = j; - } catch(const std::exception& ex) { + } catch (const std::exception& ex) { std::cout << "Failed loading database from: " << src << std::endl; std::cout << "Error: " << ex.what() << std::endl; } diff --git a/src/main.cpp b/src/main.cpp index 251b5e2..0785af7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,10 +8,16 @@ #include "modules/init.h" Module* get_Mod(std::string name) { - if(true) {} + if (name == "init") { + return init_new(); + } return nullptr; }; -void dispatch_Mod(Module* mod, std::string args){}; +void dispatch_Mod(std::string mod, std::string args) { + if (mod == "init") { + init_dispatch(args); + } +}; int main(int argc, const char* argv[]) { using namespace boost::program_options; @@ -36,35 +42,34 @@ int main(int argc, const char* argv[]) { vm); notify(vm); - if(vm.count("help")) { + if (vm.count("help")) { std::cout << general << "\n"; exit(0); - } else if(vm.count("help-module")) { + } else if (vm.count("help-module")) { auto name = vm["help-module"].as(); auto module = get_Mod(name); - if(!module) { + if (!module) { std::cout << "Module not found.\n"; exit(1); } std::cout << module->desc << "\n"; - } else if(vm.count("module")) { - auto name = vm["module"].as(); - auto module = get_Mod(name); - if(!module) { + } else if (vm.count("module")) { + auto name = vm["module"].as(); + if (!get_Mod(name)) { std::cout << "Module not found.\n"; exit(1); } - if(vm.count("module-args")) { + if (vm.count("module-args")) { auto args = vm["module-args"].as(); - dispatch_Mod(module, args); + dispatch_Mod(name, args); } else - dispatch_Mod(module, ""); + dispatch_Mod(name, ""); } else { std::cout << general << "\n"; exit(0); } - } catch(const error& ex) { cerr << ex.what() << '\n'; } + } catch (const error& ex) { cerr << ex.what() << '\n'; } return 0; } diff --git a/src/modules/init.cpp b/src/modules/init.cpp index 2eb0c2a..1b70593 100644 --- a/src/modules/init.cpp +++ b/src/modules/init.cpp @@ -24,14 +24,14 @@ void init_create(init_args arg) { writeDB(db, ".db"); } -void init_dispatch() { +void init_dispatch(std::string arguments) { init_args arg; init_create(arg); } -init_mod init_new() { - init_mod mod; - mod.name = "Init"; - mod.desc = "Creates skidjular directory in $(pwd)"; +init_mod* init_new() { + init_mod* mod = new init_mod{}; + mod->name = "Init"; + mod->desc = "Creates skidjular directory in $(pwd)"; return mod; } diff --git a/src/modules/init.h b/src/modules/init.h index d0f9976..5f922b0 100644 --- a/src/modules/init.h +++ b/src/modules/init.h @@ -11,8 +11,8 @@ struct init_args {}; struct init_mod : init_args, Module {}; -init_mod init_new(); -void init_create(init_args arg); -void init_dispatch(std::string arguments); +init_mod* init_new(); +void init_create(init_args arg); +void init_dispatch(std::string arguments); #endif diff --git a/vendor/json.hpp b/vendor/json.hpp index 63f791a..d7a6608 100644 --- a/vendor/json.hpp +++ b/vendor/json.hpp @@ -784,7 +784,7 @@ struct position_t { #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x #endif -#if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ defined(__clang__) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || \ @@ -1087,10 +1087,10 @@ struct position_t { #if defined(JSON_HEDLEY_UNREACHABLE_RETURN) #undef JSON_HEDLEY_UNREACHABLE_RETURN #endif -#if(JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && \ - (!defined(JSON_HEDLEY_ARM_VERSION))) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ +#if (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && \ + (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 5) #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) @@ -1126,10 +1126,10 @@ struct position_t { #else #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) #endif -#elif(JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && \ - !defined(JSON_HEDLEY_ARM_VERSION)) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ +#elif (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && \ + !defined(JSON_HEDLEY_ARM_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 5) #define JSON_HEDLEY_ASSUME(expr) \ ((void)((expr) ? 1 : (__builtin_unreachable(), 1))) @@ -1364,7 +1364,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP #if defined(JSON_HEDLEY_INLINE) #undef JSON_HEDLEY_INLINE #endif -#if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ (defined(__cplusplus) && (__cplusplus >= 199711L)) #define JSON_HEDLEY_INLINE inline #elif defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_ARM_VERSION_CHECK(6, 2, 0) @@ -1558,13 +1558,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP __builtin_types_compatible_p( \ __typeof__((1 ? (void*)((intptr_t)((expr)*0)) : (int*)0)), int*) #endif -#elif(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ - !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ - !defined(JSON_HEDLEY_PGI_VERSION)) || \ - JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \ - JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \ - JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) || \ - JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \ +#elif (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5, 3, 0) #if defined(__INTPTR_TYPE__) #define JSON_HEDLEY_IS_CONSTEXPR_(expr) \ @@ -1626,8 +1626,8 @@ JSON_HEDLEY_DIAGNOSTIC_POP JSON_HEDLEY_GCC_VERSION_CHECK(6, 0, 0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || defined(_Static_assert)) #define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) -#elif(defined(__cplusplus) && (__cplusplus >= 201103L)) || \ - JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || \ +#elif (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || \ (defined(__cplusplus) && JSON_HEDLEY_TI_VERSION_CHECK(8, 3, 0)) #define JSON_HEDLEY_STATIC_ASSERT(expr, message) \ JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_( \ @@ -1859,13 +1859,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP // exclude unsupported compilers #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) #if defined(__clang__) -#if(__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < \ +#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < \ 30400 #error \ "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #endif #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) -#if(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 #error \ "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" #endif @@ -1873,11 +1873,11 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif // C++ language standard detection -#if(defined(__cplusplus) && __cplusplus >= 201703L) || \ +#if (defined(__cplusplus) && __cplusplus >= 201703L) || \ (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 -#elif(defined(__cplusplus) && __cplusplus >= 201402L) || \ +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || \ (defined(_HAS_CXX14) && _HAS_CXX14 == 1) #define JSON_HAS_CPP_14 #endif @@ -1895,19 +1895,19 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif // allow to disable exceptions -#if(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \ - defined(_CPPUNWIND)) && \ +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \ + defined(_CPPUNWIND)) && \ !defined(JSON_NOEXCEPTION) #define JSON_THROW(exception) throw exception #define JSON_TRY try -#define JSON_CATCH(exception) catch(exception) -#define JSON_INTERNAL_CATCH(exception) catch(exception) +#define JSON_CATCH(exception) catch (exception) +#define JSON_INTERNAL_CATCH(exception) catch (exception) #else #include #define JSON_THROW(exception) std::abort() -#define JSON_TRY if(true) -#define JSON_CATCH(exception) if(false) -#define JSON_INTERNAL_CATCH(exception) if(false) +#define JSON_TRY if (true) +#define JSON_CATCH(exception) if (false) +#define JSON_INTERNAL_CATCH(exception) if (false) #endif // override exception macros @@ -3125,7 +3125,7 @@ namespace nlohmann { namespace detail { template void from_json(const BasicJsonType& j, typename std::nullptr_t& n) { - if(JSON_HEDLEY_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()))); } @@ -3141,7 +3141,7 @@ template < typename BasicJsonType::boolean_t>::value, int> = 0> void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) { - switch(static_cast(j)) { + switch (static_cast(j)) { case value_t::number_unsigned: { val = static_cast( *j.template get_ptr< @@ -3169,7 +3169,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) { template void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) { - if(JSON_HEDLEY_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()))); } @@ -3178,7 +3178,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) { template void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) { - if(JSON_HEDLEY_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()))); } @@ -3194,7 +3194,7 @@ template < ConstructibleStringType>::value, int> = 0> void from_json(const BasicJsonType& j, ConstructibleStringType& s) { - if(JSON_HEDLEY_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()))); } @@ -3235,7 +3235,7 @@ template ::value, int> = 0> void from_json(const BasicJsonType& j, std::forward_list& l) { - if(JSON_HEDLEY_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()))); } @@ -3249,7 +3249,7 @@ template ::value, int> = 0> void from_json(const BasicJsonType& j, std::valarray& l) { - if(JSON_HEDLEY_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()))); } @@ -3260,7 +3260,7 @@ void from_json(const BasicJsonType& j, std::valarray& l) { template auto from_json(const BasicJsonType& j, T (&arr)[N]) -> decltype(j.template get(), void()) { - for(std::size_t i = 0; i < N; ++i) { arr[i] = j.at(i).template get(); } + for (std::size_t i = 0; i < N; ++i) { arr[i] = j.at(i).template get(); } } template @@ -3275,7 +3275,7 @@ auto from_json_array_impl(const BasicJsonType& j, std::array& arr, priority_tag<2> /*unused*/) -> decltype(j.template get(), void()) { - for(std::size_t i = 0; i < N; ++i) { arr[i] = j.at(i).template get(); } + for (std::size_t i = 0; i < N; ++i) { arr[i] = j.at(i).template get(); } } template @@ -3336,7 +3336,7 @@ auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) -> decltype(from_json_array_impl(j, arr, priority_tag<3>{}), j.template get(), void()) { - if(JSON_HEDLEY_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()))); } @@ -3351,7 +3351,7 @@ template < ConstructibleObjectType>::value, int> = 0> void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) { - if(JSON_HEDLEY_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()))); } @@ -3392,7 +3392,7 @@ template < typename BasicJsonType::boolean_t>::value, int> = 0> void from_json(const BasicJsonType& j, ArithmeticType& val) { - switch(static_cast(j)) { + switch (static_cast(j)) { case value_t::number_unsigned: { val = static_cast( *j.template get_ptr< @@ -3453,13 +3453,13 @@ template ::value>> void from_json(const BasicJsonType& j, std::map& m) { - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not p.is_array())) { + for (const auto& p: j) { + 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()))); } @@ -3478,13 +3478,13 @@ template ::value>> void from_json(const BasicJsonType& j, std::unordered_map& m) { - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not p.is_array())) { + for (const auto& p: j) { + 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()))); } @@ -3593,10 +3593,10 @@ class iteration_proxy_value { const string_type& key() const { assert(anchor.m_object != nullptr); - switch(anchor.m_object->type()) { + switch (anchor.m_object->type()) { // use integer array index as key case value_t::array: { - if(array_index != array_index_last) { + if (array_index != array_index_last) { int_to_string(array_index_str, array_index); array_index_last = array_index; } @@ -3815,7 +3815,7 @@ struct external_constructor { j.m_type = value_t::array; j.m_value = value_t::array; j.m_value.array->reserve(arr.size()); - for(const bool x: arr) { j.m_value.array->push_back(x); } + for (const bool x: arr) { j.m_value.array->push_back(x); } j.assert_invariant(); } @@ -3827,7 +3827,7 @@ struct external_constructor { j.m_type = value_t::array; j.m_value = value_t::array; j.m_value.array->resize(arr.size()); - if(arr.size() > 0) { + if (arr.size() > 0) { std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin()); } j.assert_invariant(); @@ -4211,7 +4211,7 @@ class input_stream_adapter : public input_adapter_protocol { std::char_traits::int_type get_character() override { auto res = sb.sbumpc(); // set eof manually, as we don't use the istream interface. - if(res == EOF) { + if (res == EOF) { is.clear(is.rdstate() | std::ios::eofbit); } return res; @@ -4238,7 +4238,7 @@ class input_buffer_adapter : public input_adapter_protocol { ~input_buffer_adapter() override = default; std::char_traits::int_type get_character() noexcept override { - if(JSON_HEDLEY_LIKELY(cursor < limit)) { + if (JSON_HEDLEY_LIKELY(cursor < limit)) { assert(cursor != nullptr and limit != nullptr); return std::char_traits::to_int_type(*(cursor++)); } @@ -4264,7 +4264,7 @@ struct wide_string_input_helper { size_t& utf8_bytes_filled) { utf8_bytes_index = 0; - if(current_wchar == str.size()) { + if (current_wchar == str.size()) { utf8_bytes[0] = std::char_traits::eof(); utf8_bytes_filled = 1; } else { @@ -4272,17 +4272,17 @@ struct wide_string_input_helper { const auto wc = static_cast(str[current_wchar++]); // UTF-32 to UTF-8 encoding - if(wc < 0x80) { + if (wc < 0x80) { utf8_bytes[0] = static_cast::int_type>(wc); utf8_bytes_filled = 1; - } else if(wc <= 0x7FF) { + } else if (wc <= 0x7FF) { utf8_bytes[0] = static_cast::int_type>( 0xC0u | ((wc >> 6u) & 0x1Fu)); utf8_bytes[1] = static_cast::int_type>( 0x80u | (wc & 0x3Fu)); utf8_bytes_filled = 2; - } else if(wc <= 0xFFFF) { + } else if (wc <= 0xFFFF) { utf8_bytes[0] = static_cast::int_type>( 0xE0u | ((wc >> 12u) & 0x0Fu)); utf8_bytes[1] = static_cast::int_type>( @@ -4290,7 +4290,7 @@ struct wide_string_input_helper { utf8_bytes[2] = static_cast::int_type>( 0x80u | (wc & 0x3Fu)); utf8_bytes_filled = 3; - } else if(wc <= 0x10FFFF) { + } else if (wc <= 0x10FFFF) { utf8_bytes[0] = static_cast::int_type>( 0xF0u | ((wc >> 18u) & 0x07u)); utf8_bytes[1] = static_cast::int_type>( @@ -4321,7 +4321,7 @@ struct wide_string_input_helper { size_t& utf8_bytes_filled) { utf8_bytes_index = 0; - if(current_wchar == str.size()) { + if (current_wchar == str.size()) { utf8_bytes[0] = std::char_traits::eof(); utf8_bytes_filled = 1; } else { @@ -4329,17 +4329,17 @@ struct wide_string_input_helper { const auto wc = static_cast(str[current_wchar++]); // UTF-16 to UTF-8 encoding - if(wc < 0x80) { + if (wc < 0x80) { utf8_bytes[0] = static_cast::int_type>(wc); utf8_bytes_filled = 1; - } else if(wc <= 0x7FF) { + } else if (wc <= 0x7FF) { utf8_bytes[0] = static_cast::int_type>( 0xC0u | ((wc >> 6u))); utf8_bytes[1] = static_cast::int_type>( 0x80u | (wc & 0x3Fu)); utf8_bytes_filled = 2; - } else if(0xD800 > wc or wc >= 0xE000) { + } else if (0xD800 > wc or wc >= 0xE000) { utf8_bytes[0] = static_cast::int_type>( 0xE0u | ((wc >> 12u))); utf8_bytes[1] = static_cast::int_type>( @@ -4348,7 +4348,7 @@ struct wide_string_input_helper { 0x80u | (wc & 0x3Fu)); utf8_bytes_filled = 3; } else { - if(current_wchar < str.size()) { + if (current_wchar < str.size()) { const auto wc2 = static_cast(str[current_wchar++]); const auto charcode = @@ -4386,7 +4386,7 @@ class wide_string_input_adapter : public input_adapter_protocol { std::char_traits::int_type get_character() noexcept override { // check if buffer needs to be filled - if(utf8_bytes_index == utf8_bytes_filled) { + if (utf8_bytes_index == utf8_bytes_filled) { fill_buffer(); assert(utf8_bytes_filled > 0); @@ -4501,7 +4501,7 @@ class input_adapter { "each element in the iterator range must have the size of 1 byte"); const auto len = static_cast(std::distance(first, last)); - if(JSON_HEDLEY_LIKELY(len > 0)) { + if (JSON_HEDLEY_LIKELY(len > 0)) { // there is at least one element: use the address of first ia = std::make_shared( reinterpret_cast(&(*first)), len); @@ -4737,8 +4737,8 @@ class json_sax_dom_parser { bool start_object(std::size_t len) { 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) and + len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create( 408, "excessive object size: " + std::to_string(len))); } @@ -4760,8 +4760,8 @@ class json_sax_dom_parser { bool start_array(std::size_t len) { 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) and + len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create( 408, "excessive array size: " + std::to_string(len))); } @@ -4778,9 +4778,9 @@ class json_sax_dom_parser { const std::string& /*unused*/, const detail::exception& ex) { errored = true; - if(allow_exceptions) { + if (allow_exceptions) { // determine the proper exception type from the id - switch((ex.id / 100) % 100) { + switch ((ex.id / 100) % 100) { case 1: JSON_THROW(*static_cast(&ex)); case 4: @@ -4814,14 +4814,14 @@ class json_sax_dom_parser { */ template JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType* handle_value(Value&& v) { - if(ref_stack.empty()) { + if (ref_stack.empty()) { root = BasicJsonType(std::forward(v)); return &root; } assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); - if(ref_stack.back()->is_array()) { + if (ref_stack.back()->is_array()) { ref_stack.back()->m_value.array->emplace_back( std::forward(v)); return &(ref_stack.back()->m_value.array->back()); @@ -4913,9 +4913,9 @@ 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() 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))); } @@ -4932,7 +4932,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 and ref_stack.back()) { object_element = &( ref_stack.back()->m_value.object->operator[](val) = discarded); } @@ -4941,9 +4941,9 @@ class json_sax_dom_callback_parser { } bool end_object() { - if(ref_stack.back() and - not callback(static_cast(ref_stack.size()) - 1, - parse_event_t::object_end, *ref_stack.back())) { + if (ref_stack.back() and + not callback(static_cast(ref_stack.size()) - 1, + parse_event_t::object_end, *ref_stack.back())) { // discard object *ref_stack.back() = discarded; } @@ -4953,12 +4953,12 @@ class json_sax_dom_callback_parser { ref_stack.pop_back(); keep_stack.pop_back(); - if(not ref_stack.empty() and ref_stack.back() and - ref_stack.back()->is_object()) { + if (not ref_stack.empty() and ref_stack.back() and + ref_stack.back()->is_object()) { // remove discarded value - for(auto it = ref_stack.back()->begin(); - it != ref_stack.back()->end(); ++it) { - if(it->is_discarded()) { + for (auto it = ref_stack.back()->begin(); + it != ref_stack.back()->end(); ++it) { + if (it->is_discarded()) { ref_stack.back()->erase(it); break; } @@ -4977,9 +4977,9 @@ 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() 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))); } @@ -4990,10 +4990,10 @@ class json_sax_dom_callback_parser { bool end_array() { bool keep = true; - if(ref_stack.back()) { + if (ref_stack.back()) { keep = callback(static_cast(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back()); - if(not keep) { + if (not keep) { // discard array *ref_stack.back() = discarded; } @@ -5005,8 +5005,8 @@ class json_sax_dom_callback_parser { keep_stack.pop_back(); // remove discarded value - if(not keep and not ref_stack.empty() and - ref_stack.back()->is_array()) { + if (not keep and not ref_stack.empty() and + ref_stack.back()->is_array()) { ref_stack.back()->m_value.array->pop_back(); } @@ -5017,9 +5017,9 @@ class json_sax_dom_callback_parser { const std::string& /*unused*/, const detail::exception& ex) { errored = true; - if(allow_exceptions) { + if (allow_exceptions) { // determine the proper exception type from the id - switch((ex.id / 100) % 100) { + switch ((ex.id / 100) % 100) { case 1: JSON_THROW(*static_cast(&ex)); case 4: @@ -5068,7 +5068,7 @@ class json_sax_dom_callback_parser { // do not handle this value if we know it would be added to a discarded // container - if(not keep_stack.back()) { + if (not keep_stack.back()) { return {false, nullptr}; } @@ -5081,18 +5081,18 @@ class json_sax_dom_callback_parser { parse_event_t::value, value); // do not handle this value if we just learnt it shall be discarded - if(not keep) { + if (not keep) { return {false, nullptr}; } - if(ref_stack.empty()) { + if (ref_stack.empty()) { root = std::move(value); return {true, &root}; } // 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 (not ref_stack.back()) { return {false, nullptr}; } @@ -5100,7 +5100,7 @@ class json_sax_dom_callback_parser { assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); // array - if(ref_stack.back()->is_array()) { + if (ref_stack.back()->is_array()) { ref_stack.back()->m_value.array->push_back(std::move(value)); return {true, &(ref_stack.back()->m_value.array->back())}; } @@ -5112,7 +5112,7 @@ class json_sax_dom_callback_parser { const bool store_element = key_keep_stack.back(); key_keep_stack.pop_back(); - if(not store_element) { + if (not store_element) { return {false, nullptr}; } @@ -5413,7 +5413,7 @@ class binary_reader { sax = sax_; bool result = false; - switch(format) { + switch (format) { case input_format_t::bson: result = parse_bson_internal(); break; case input_format_t::cbor: result = parse_cbor_internal(); break; @@ -5431,14 +5431,15 @@ class binary_reader { } // strict mode: next byte must be EOF - if(result and strict) { - if(format == input_format_t::ubjson) { + if (result and strict) { + if (format == input_format_t::ubjson) { get_ignore_noop(); } else { get(); } - if(JSON_HEDLEY_UNLIKELY(current != std::char_traits::eof())) { + if (JSON_HEDLEY_UNLIKELY(current != + std::char_traits::eof())) { return sax->parse_error( chars_read, get_token_string(), parse_error::create( @@ -5478,12 +5479,12 @@ class binary_reader { std::int32_t document_size; get_number(input_format_t::bson, document_size); - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY( - not parse_bson_element_list(/*is_array*/ false))) { + if (JSON_HEDLEY_UNLIKELY( + not parse_bson_element_list(/*is_array*/ false))) { return false; } @@ -5499,13 +5500,13 @@ class binary_reader { */ bool get_bson_cstr(string_t& result) { auto out = std::back_inserter(result); - while(true) { + while (true) { get(); - if(JSON_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::bson, "cstring"))) { + if (JSON_HEDLEY_UNLIKELY( + not unexpect_eof(input_format_t::bson, "cstring"))) { return false; } - if(current == 0x00) { + if (current == 0x00) { return true; } *out++ = static_cast(current); @@ -5527,7 +5528,7 @@ class binary_reader { */ template bool get_bson_string(const NumberType len, string_t& result) { - if(JSON_HEDLEY_UNLIKELY(len < 1)) { + if (JSON_HEDLEY_UNLIKELY(len < 1)) { auto last_token = get_token_string(); return sax->parse_error( chars_read, last_token, @@ -5558,7 +5559,7 @@ class binary_reader { bool parse_bson_element_internal( const int element_type, const std::size_t element_type_parse_position) { - switch(element_type) { + switch (element_type) { case 0x01: // double { double number; @@ -5641,23 +5642,23 @@ class binary_reader { */ bool parse_bson_element_list(const bool is_array) { string_t key; - while(int element_type = get()) { - if(JSON_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::bson, "element list"))) { + while (int element_type = get()) { + 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_HEDLEY_UNLIKELY(not get_bson_cstr(key))) { + if (JSON_HEDLEY_UNLIKELY(not get_bson_cstr(key))) { return false; } - if(not is_array and not sax->key(key)) { + if (not is_array and not sax->key(key)) { return false; } - if(JSON_HEDLEY_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; } @@ -5676,12 +5677,12 @@ class binary_reader { std::int32_t document_size; get_number(input_format_t::bson, document_size); - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY( - not parse_bson_element_list(/*is_array*/ true))) { + if (JSON_HEDLEY_UNLIKELY( + not parse_bson_element_list(/*is_array*/ true))) { return false; } @@ -5700,7 +5701,7 @@ class binary_reader { @return whether a valid CBOR value was passed to the SAX parser */ bool parse_cbor_internal(const bool get_char = true) { - switch(get_char ? get() : current) { + switch (get_char ? get() : current) { // EOF case std::char_traits::eof(): return unexpect_eof(input_format_t::cbor, "value"); @@ -5987,13 +5988,13 @@ class binary_reader { case 0xF9: // Half-Precision Float (two-byte IEEE 754) { const int byte1_raw = get(); - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::cbor, "number"))) { + if (JSON_HEDLEY_UNLIKELY( + not unexpect_eof(input_format_t::cbor, "number"))) { return false; } @@ -6015,7 +6016,7 @@ class binary_reader { const unsigned int mant = half & 0x3FFu; assert(0 <= exp and exp <= 32); assert(mant <= 1024); - switch(exp) { + switch (exp) { case 0: return std::ldexp(mant, -24); case 31: return (mant == 0) @@ -6073,12 +6074,12 @@ class binary_reader { @return whether string creation completed */ bool get_cbor_string(string_t& result) { - if(JSON_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::cbor, "string"))) { + if (JSON_HEDLEY_UNLIKELY( + not unexpect_eof(input_format_t::cbor, "string"))) { return false; } - switch(current) { + switch (current) { // UTF-8 string (0x00..0x17 bytes follow) case 0x60: case 0x61: @@ -6139,9 +6140,9 @@ class binary_reader { case 0x7F: // UTF-8 string (indefinite length) { - while(get() != 0xFF) { + while (get() != 0xFF) { string_t chunk; - if(not get_cbor_string(chunk)) { + if (not get_cbor_string(chunk)) { return false; } result.append(chunk); @@ -6171,19 +6172,19 @@ class binary_reader { @return whether array creation completed */ bool get_cbor_array(const std::size_t len) { - if(JSON_HEDLEY_UNLIKELY(not sax->start_array(len))) { + if (JSON_HEDLEY_UNLIKELY(not sax->start_array(len))) { return false; } - if(len != std::size_t(-1)) { - for(std::size_t i = 0; i < len; ++i) { - if(JSON_HEDLEY_UNLIKELY(not parse_cbor_internal())) { + if (len != std::size_t(-1)) { + for (std::size_t i = 0; i < len; ++i) { + if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal())) { return false; } } } else { - while(get() != 0xFF) { - if(JSON_HEDLEY_UNLIKELY(not parse_cbor_internal(false))) { + while (get() != 0xFF) { + if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal(false))) { return false; } } @@ -6198,32 +6199,32 @@ class binary_reader { @return whether object creation completed */ bool get_cbor_object(const std::size_t len) { - if(JSON_HEDLEY_UNLIKELY(not sax->start_object(len))) { + if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len))) { return false; } string_t key; - if(len != std::size_t(-1)) { - for(std::size_t i = 0; i < len; ++i) { + if (len != std::size_t(-1)) { + for (std::size_t i = 0; i < len; ++i) { get(); - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not parse_cbor_internal())) { + if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal())) { return false; } key.clear(); } } else { - while(get() != 0xFF) { - if(JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or - not sax->key(key))) { + while (get() != 0xFF) { + if (JSON_HEDLEY_UNLIKELY(not get_cbor_string(key) or + not sax->key(key))) { return false; } - if(JSON_HEDLEY_UNLIKELY(not parse_cbor_internal())) { + if (JSON_HEDLEY_UNLIKELY(not parse_cbor_internal())) { return false; } key.clear(); @@ -6241,7 +6242,7 @@ class binary_reader { @return whether a valid MessagePack value was passed to the SAX parser */ bool parse_msgpack_internal() { - switch(get()) { + switch (get()) { // EOF case std::char_traits::eof(): return unexpect_eof(input_format_t::msgpack, "value"); @@ -6628,12 +6629,12 @@ class binary_reader { @return whether string creation completed */ bool get_msgpack_string(string_t& result) { - if(JSON_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::msgpack, "string"))) { + if (JSON_HEDLEY_UNLIKELY( + not unexpect_eof(input_format_t::msgpack, "string"))) { return false; } - switch(current) { + switch (current) { // fixstr case 0xA0: case 0xA1: @@ -6714,12 +6715,12 @@ class binary_reader { @return whether array creation completed */ bool get_msgpack_array(const std::size_t len) { - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not parse_msgpack_internal())) { + for (std::size_t i = 0; i < len; ++i) { + if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal())) { return false; } } @@ -6732,19 +6733,19 @@ class binary_reader { @return whether object creation completed */ bool get_msgpack_object(const std::size_t len) { - if(JSON_HEDLEY_UNLIKELY(not sax->start_object(len))) { + if (JSON_HEDLEY_UNLIKELY(not sax->start_object(len))) { return false; } string_t key; - for(std::size_t i = 0; i < len; ++i) { + for (std::size_t i = 0; i < len; ++i) { get(); - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not parse_msgpack_internal())) { + if (JSON_HEDLEY_UNLIKELY(not parse_msgpack_internal())) { return false; } key.clear(); @@ -6783,16 +6784,16 @@ class binary_reader { @return whether string creation completed */ bool get_ubjson_string(string_t& result, const bool get_char = true) { - if(get_char) { + if (get_char) { get(); // TODO(niels): may we ignore N here? } - if(JSON_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::ubjson, "value"))) { + if (JSON_HEDLEY_UNLIKELY( + not unexpect_eof(input_format_t::ubjson, "value"))) { return false; } - switch(current) { + switch (current) { case 'U': { std::uint8_t len; return get_number(input_format_t::ubjson, len) and @@ -6843,11 +6844,11 @@ class binary_reader { @return whether size determination completed */ bool get_ubjson_size_value(std::size_t& result) { - switch(get_ignore_noop()) { + switch (get_ignore_noop()) { case 'U': { std::uint8_t number; - if(JSON_HEDLEY_UNLIKELY( - not get_number(input_format_t::ubjson, number))) { + if (JSON_HEDLEY_UNLIKELY( + not get_number(input_format_t::ubjson, number))) { return false; } result = static_cast(number); @@ -6856,8 +6857,8 @@ class binary_reader { case 'i': { std::int8_t number; - if(JSON_HEDLEY_UNLIKELY( - not get_number(input_format_t::ubjson, number))) { + if (JSON_HEDLEY_UNLIKELY( + not get_number(input_format_t::ubjson, number))) { return false; } result = static_cast(number); @@ -6866,8 +6867,8 @@ class binary_reader { case 'I': { std::int16_t number; - if(JSON_HEDLEY_UNLIKELY( - not get_number(input_format_t::ubjson, number))) { + if (JSON_HEDLEY_UNLIKELY( + not get_number(input_format_t::ubjson, number))) { return false; } result = static_cast(number); @@ -6876,8 +6877,8 @@ class binary_reader { case 'l': { std::int32_t number; - if(JSON_HEDLEY_UNLIKELY( - not get_number(input_format_t::ubjson, number))) { + if (JSON_HEDLEY_UNLIKELY( + not get_number(input_format_t::ubjson, number))) { return false; } result = static_cast(number); @@ -6886,8 +6887,8 @@ class binary_reader { case 'L': { std::int64_t number; - if(JSON_HEDLEY_UNLIKELY( - not get_number(input_format_t::ubjson, number))) { + if (JSON_HEDLEY_UNLIKELY( + not get_number(input_format_t::ubjson, number))) { return false; } result = static_cast(number); @@ -6926,18 +6927,18 @@ class binary_reader { get_ignore_noop(); - if(current == '$') { + if (current == '$') { result.second = get(); // must not ignore 'N', because 'N' maybe the type - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(current != '#')) { - if(JSON_HEDLEY_UNLIKELY( - not unexpect_eof(input_format_t::ubjson, "value"))) { + if (JSON_HEDLEY_UNLIKELY(current != '#')) { + if (JSON_HEDLEY_UNLIKELY( + not unexpect_eof(input_format_t::ubjson, "value"))) { return false; } auto last_token = get_token_string(); @@ -6955,7 +6956,7 @@ class binary_reader { return get_ubjson_size_value(result.first); } - if(current == '#') { + if (current == '#') { return get_ubjson_size_value(result.first); } @@ -6967,7 +6968,7 @@ class binary_reader { @return whether value creation completed */ bool get_ubjson_value(const int prefix) { - switch(prefix) { + switch (prefix) { case std::char_traits::eof(): // EOF return unexpect_eof(input_format_t::ubjson, "value"); @@ -7026,11 +7027,11 @@ class binary_reader { case 'C': // char { get(); - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(current > 127)) { + if (JSON_HEDLEY_UNLIKELY(current > 127)) { auto last_token = get_token_string(); return sax->parse_error( chars_read, last_token, @@ -7077,39 +7078,39 @@ class binary_reader { */ bool get_ubjson_array() { std::pair size_and_type; - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY( - not sax->start_array(size_and_type.first))) { + if (size_and_type.first != string_t::npos) { + if (JSON_HEDLEY_UNLIKELY( + not sax->start_array(size_and_type.first))) { return false; } - if(size_and_type.second != 0) { - if(size_and_type.second != 'N') { - for(std::size_t i = 0; i < size_and_type.first; ++i) { - if(JSON_HEDLEY_UNLIKELY( - not get_ubjson_value(size_and_type.second))) { + if (size_and_type.second != 0) { + if (size_and_type.second != 'N') { + for (std::size_t i = 0; i < size_and_type.first; ++i) { + if (JSON_HEDLEY_UNLIKELY( + not get_ubjson_value(size_and_type.second))) { return false; } } } } else { - for(std::size_t i = 0; i < size_and_type.first; ++i) { - if(JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal())) { + for (std::size_t i = 0; i < size_and_type.first; ++i) { + if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal())) { return false; } } } } else { - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not parse_ubjson_internal(false))) { + while (current != ']') { + if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal(false))) { return false; } get_ignore_noop(); @@ -7124,52 +7125,52 @@ class binary_reader { */ bool get_ubjson_object() { std::pair size_and_type; - if(JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type))) { + if (JSON_HEDLEY_UNLIKELY(not get_ubjson_size_type(size_and_type))) { return false; } string_t key; - if(size_and_type.first != string_t::npos) { - if(JSON_HEDLEY_UNLIKELY( - not sax->start_object(size_and_type.first))) { + if (size_and_type.first != string_t::npos) { + if (JSON_HEDLEY_UNLIKELY( + not sax->start_object(size_and_type.first))) { return false; } - if(size_and_type.second != 0) { - for(std::size_t i = 0; i < size_and_type.first; ++i) { - if(JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or - not sax->key(key))) { + if (size_and_type.second != 0) { + for (std::size_t i = 0; i < size_and_type.first; ++i) { + if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or + not sax->key(key))) { return false; } - if(JSON_HEDLEY_UNLIKELY( - not get_ubjson_value(size_and_type.second))) { + if (JSON_HEDLEY_UNLIKELY( + not get_ubjson_value(size_and_type.second))) { return false; } key.clear(); } } else { - for(std::size_t i = 0; i < size_and_type.first; ++i) { - if(JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or - not sax->key(key))) { + for (std::size_t i = 0; i < size_and_type.first; ++i) { + if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key) or + not sax->key(key))) { return false; } - if(JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal())) { + if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal())) { return false; } key.clear(); } } } else { - if(JSON_HEDLEY_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_HEDLEY_UNLIKELY(not get_ubjson_string(key, false) or - not sax->key(key))) { + while (current != '}') { + if (JSON_HEDLEY_UNLIKELY(not get_ubjson_string(key, false) or + not sax->key(key))) { return false; } - if(JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal())) { + if (JSON_HEDLEY_UNLIKELY(not parse_ubjson_internal())) { return false; } get_ignore_noop(); @@ -7202,7 +7203,7 @@ class binary_reader { @return character read from the input after ignoring all 'N' entries */ int get_ignore_noop() { - do { get(); } while(current == 'N'); + do { get(); } while (current == 'N'); return current; } @@ -7224,14 +7225,14 @@ class binary_reader { bool get_number(const input_format_t format, NumberType& result) { // step 1: read input into array with system's byte order std::array vec; - for(std::size_t i = 0; i < sizeof(NumberType); ++i) { + for (std::size_t i = 0; i < sizeof(NumberType); ++i) { get(); - if(JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "number"))) { + if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "number"))) { return false; } // reverse byte order prior to conversion if necessary - if(is_little_endian != InputIsLittleEndian) { + if (is_little_endian != InputIsLittleEndian) { vec[sizeof(NumberType) - i - 1] = static_cast(current); } else { @@ -7266,7 +7267,7 @@ class binary_reader { std::generate_n( std::back_inserter(result), len, [this, &success, &format]() { get(); - if(JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "string"))) { + if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(format, "string"))) { success = false; } return static_cast(current); @@ -7281,7 +7282,7 @@ class binary_reader { */ JSON_HEDLEY_NON_NULL(3) bool unexpect_eof(const input_format_t format, const char* context) const { - if(JSON_HEDLEY_UNLIKELY(current == std::char_traits::eof())) { + if (JSON_HEDLEY_UNLIKELY(current == std::char_traits::eof())) { return sax->parse_error( chars_read, "", parse_error::create( @@ -7313,7 +7314,7 @@ class binary_reader { const std::string& context) const { std::string error_msg = "syntax error while parsing "; - switch(format) { + switch (format) { case input_format_t::cbor: error_msg += "CBOR"; break; case input_format_t::msgpack: error_msg += "MessagePack"; break; @@ -7414,7 +7415,7 @@ class lexer { JSON_HEDLEY_RETURNS_NON_NULL JSON_HEDLEY_CONST static const char* token_type_name(const token_type t) noexcept { - switch(t) { + switch (t) { case token_type::uninitialized: return ""; case token_type::literal_true: return "true literal"; case token_type::literal_false: return "false literal"; @@ -7488,16 +7489,16 @@ class lexer { int codepoint = 0; const auto factors = {12u, 8u, 4u, 0u}; - for(const auto factor: factors) { + for (const auto factor: factors) { get(); - if(current >= '0' and current <= '9') { + if (current >= '0' and current <= '9') { codepoint += static_cast( (static_cast(current) - 0x30u) << factor); - } else if(current >= 'A' and current <= 'F') { + } else if (current >= 'A' and current <= 'F') { codepoint += static_cast( (static_cast(current) - 0x37u) << factor); - } else if(current >= 'a' and current <= 'f') { + } else if (current >= 'a' and current <= 'f') { codepoint += static_cast( (static_cast(current) - 0x57u) << factor); } else { @@ -7528,10 +7529,10 @@ class lexer { assert(ranges.size() == 2 or ranges.size() == 4 or ranges.size() == 6); add(current); - for(auto range = ranges.begin(); range != ranges.end(); ++range) { + 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 and + current <= *(++range))) { add(current); } else { error_message = "invalid string: ill-formed UTF-8 byte"; @@ -7564,9 +7565,9 @@ class lexer { // we entered the function by reading an open quote assert(current == '\"'); - while(true) { + while (true) { // get next character - switch(get()) { + switch (get()) { // end of file while parsing string case std::char_traits::eof(): { error_message = "invalid string: missing closing quote"; @@ -7580,7 +7581,7 @@ class lexer { // escapes case '\\': { - switch(get()) { + switch (get()) { // quotation mark case '\"': add('\"'); break; // reverse solidus @@ -7603,20 +7604,21 @@ class lexer { const int codepoint1 = get_codepoint(); int codepoint = codepoint1; // start with codepoint1 - if(JSON_HEDLEY_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; } // check if code point is a high surrogate - if(0xD800 <= codepoint1 and codepoint1 <= 0xDBFF) { + if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF) { // expect next \uxxxx entry - if(JSON_HEDLEY_LIKELY(get() == '\\' and - get() == 'u')) { + if (JSON_HEDLEY_LIKELY(get() == '\\' and + get() == 'u')) { const int codepoint2 = get_codepoint(); - if(JSON_HEDLEY_UNLIKELY(codepoint2 == -1)) { + if (JSON_HEDLEY_UNLIKELY(codepoint2 == + -1)) { error_message = "invalid string: '\\u' " "must be followed by " "4 hex digits"; @@ -7624,9 +7626,9 @@ class lexer { } // check if codepoint2 is a low surrogate - if(JSON_HEDLEY_LIKELY( - 0xDC00 <= codepoint2 and - codepoint2 <= 0xDFFF)) { + if (JSON_HEDLEY_LIKELY( + 0xDC00 <= codepoint2 and + codepoint2 <= 0xDFFF)) { // overwrite codepoint codepoint = static_cast( // high surrogate occupies the most @@ -7660,8 +7662,9 @@ class lexer { return token_type::parse_error; } } else { - if(JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 and - codepoint1 <= 0xDFFF)) { + if (JSON_HEDLEY_UNLIKELY( + 0xDC00 <= codepoint1 and + codepoint1 <= 0xDFFF)) { error_message = "invalid string: surrogate " "U+DC00..U+DFFF " @@ -7675,10 +7678,10 @@ class lexer { assert(0x00 <= codepoint and codepoint <= 0x10FFFF); // translate codepoint into bytes - if(codepoint < 0x80) { + if (codepoint < 0x80) { // 1-byte characters: 0xxxxxxx (ASCII) add(codepoint); - } else if(codepoint <= 0x7FF) { + } else if (codepoint <= 0x7FF) { // 2-byte characters: 110xxxxx 10xxxxxx add(static_cast( 0xC0u | @@ -7688,7 +7691,7 @@ class lexer { 0x80u | (static_cast(codepoint) & 0x3Fu))); - } else if(codepoint <= 0xFFFF) { + } else if (codepoint <= 0xFFFF) { // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx add(static_cast( 0xE0u | @@ -8094,8 +8097,8 @@ class lexer { case 0xDD: case 0xDE: case 0xDF: { - if(JSON_HEDLEY_UNLIKELY( - not next_byte_in_range({0x80, 0xBF}))) { + if (JSON_HEDLEY_UNLIKELY( + not next_byte_in_range({0x80, 0xBF}))) { return token_type::parse_error; } break; @@ -8103,8 +8106,8 @@ class lexer { // 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(not( + next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF})))) { return token_type::parse_error; } break; @@ -8126,8 +8129,8 @@ class lexer { case 0xEC: case 0xEE: case 0xEF: { - if(JSON_HEDLEY_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; } break; @@ -8135,8 +8138,8 @@ class lexer { // 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(not( + next_byte_in_range({0x80, 0x9F, 0x80, 0xBF})))) { return token_type::parse_error; } break; @@ -8144,8 +8147,8 @@ class lexer { // 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(not(next_byte_in_range( + {0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) { return token_type::parse_error; } break; @@ -8155,8 +8158,8 @@ class lexer { case 0xF1: case 0xF2: case 0xF3: { - if(JSON_HEDLEY_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; } break; @@ -8164,8 +8167,8 @@ class lexer { // 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(not(next_byte_in_range( + {0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF})))) { return token_type::parse_error; } break; @@ -8249,7 +8252,7 @@ class lexer { token_type number_type = token_type::value_unsigned; // state (init): we just found out we need to scan a number - switch(current) { + switch (current) { case '-': { add(current); goto scan_number_minus; @@ -8281,7 +8284,7 @@ class lexer { scan_number_minus: // state: we just parsed a leading minus sign number_type = token_type::value_integer; - switch(get()) { + switch (get()) { case '0': { add(current); goto scan_number_zero; @@ -8308,7 +8311,7 @@ class lexer { scan_number_zero: // state: we just parse a zero (maybe with a leading minus sign) - switch(get()) { + switch (get()) { case '.': { add(decimal_point_char); goto scan_number_decimal1; @@ -8325,7 +8328,7 @@ class lexer { scan_number_any1: // state: we just parsed a number 0-9 (maybe with a leading minus sign) - switch(get()) { + switch (get()) { case '0': case '1': case '2': @@ -8357,7 +8360,7 @@ class lexer { scan_number_decimal1: // state: we just parsed a decimal point number_type = token_type::value_float; - switch(get()) { + switch (get()) { case '0': case '1': case '2': @@ -8380,7 +8383,7 @@ class lexer { scan_number_decimal2: // we just parsed at least one number after a decimal point - switch(get()) { + switch (get()) { case '0': case '1': case '2': @@ -8407,7 +8410,7 @@ class lexer { scan_number_exponent: // we just parsed an exponent number_type = token_type::value_float; - switch(get()) { + switch (get()) { case '+': case '-': { add(current); @@ -8437,7 +8440,7 @@ class lexer { scan_number_sign: // we just parsed an exponent sign - switch(get()) { + switch (get()) { case '0': case '1': case '2': @@ -8461,7 +8464,7 @@ class lexer { scan_number_any2: // we just parsed a number after the exponent or exponent sign - switch(get()) { + switch (get()) { case '0': case '1': case '2': @@ -8488,27 +8491,27 @@ class lexer { errno = 0; // try to parse integers first and fall back to floats - if(number_type == token_type::value_unsigned) { + if (number_type == token_type::value_unsigned) { const auto x = std::strtoull(token_buffer.data(), &endptr, 10); // we checked the number format before assert(endptr == token_buffer.data() + token_buffer.size()); - if(errno == 0) { + if (errno == 0) { value_unsigned = static_cast(x); - if(value_unsigned == x) { + if (value_unsigned == x) { return token_type::value_unsigned; } } - } else if(number_type == token_type::value_integer) { + } else if (number_type == token_type::value_integer) { const auto x = std::strtoll(token_buffer.data(), &endptr, 10); // we checked the number format before assert(endptr == token_buffer.data() + token_buffer.size()); - if(errno == 0) { + if (errno == 0) { value_integer = static_cast(x); - if(value_integer == x) { + if (value_integer == x) { return token_type::value_integer; } } @@ -8534,8 +8537,8 @@ class lexer { 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_HEDLEY_UNLIKELY(get() != literal_text[i])) { + for (std::size_t i = 1; i < length; ++i) { + if (JSON_HEDLEY_UNLIKELY(get() != literal_text[i])) { error_message = "invalid literal"; return token_type::parse_error; } @@ -8568,19 +8571,19 @@ class lexer { ++position.chars_read_total; ++position.chars_read_current_line; - if(next_unget) { + if (next_unget) { // just reset the next_unget variable and work with current next_unget = false; } else { current = ia->get_character(); } - if(JSON_HEDLEY_LIKELY(current != std::char_traits::eof())) { + if (JSON_HEDLEY_LIKELY(current != std::char_traits::eof())) { token_string.push_back( std::char_traits::to_char_type(current)); } - if(current == '\n') { + if (current == '\n') { ++position.lines_read; position.chars_read_current_line = 0; } @@ -8603,15 +8606,15 @@ class lexer { // in case we "unget" a newline, we have to also decrement the // lines_read - if(position.chars_read_current_line == 0) { - if(position.lines_read > 0) { + if (position.chars_read_current_line == 0) { + if (position.lines_read > 0) { --position.lines_read; } } else { --position.chars_read_current_line; } - if(JSON_HEDLEY_LIKELY(current != std::char_traits::eof())) { + if (JSON_HEDLEY_LIKELY(current != std::char_traits::eof())) { assert(not token_string.empty()); token_string.pop_back(); } @@ -8663,8 +8666,8 @@ class lexer { std::string get_token_string() const { // escape control characters std::string result; - for(const auto c: token_string) { - if('\x00' <= c and c <= '\x1F') { + for (const auto c: token_string) { + if ('\x00' <= c and c <= '\x1F') { // escape control characters std::array cs{{}}; (std::snprintf)(cs.data(), cs.size(), "", @@ -8694,7 +8697,7 @@ class lexer { @return true iff there is no BOM or the correct BOM has been skipped */ bool skip_bom() { - if(get() == 0xEF) { + if (get() == 0xEF) { // check if we completely parse the BOM return get() == 0xBB and get() == 0xBF; } @@ -8707,7 +8710,7 @@ class lexer { token_type scan() { // initially, skip the BOM - if(position.chars_read_total == 0 and not skip_bom()) { + if (position.chars_read_total == 0 and not skip_bom()) { error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given"; return token_type::parse_error; } @@ -8715,10 +8718,10 @@ class lexer { // read next character and ignore whitespace do { get(); - } while(current == ' ' or current == '\t' or current == '\n' or - current == '\r'); + } while (current == ' ' or current == '\t' or current == '\n' or + current == '\r'); - switch(current) { + switch (current) { // structural characters case '[': return token_type::begin_array; case ']': return token_type::end_array; @@ -8877,14 +8880,14 @@ class parser { @throw parse_error.103 if to_unicode fails */ void parse(const bool strict, BasicJsonType& result) { - if(callback) { + if (callback) { json_sax_dom_callback_parser sdp(result, callback, allow_exceptions); sax_parse_internal(&sdp); result.assert_invariant(); // in strict mode, input must be completely read - if(strict and (get_token() != token_type::end_of_input)) { + if (strict and (get_token() != token_type::end_of_input)) { sdp.parse_error( m_lexer.get_position(), m_lexer.get_token_string(), parse_error::create( @@ -8893,14 +8896,14 @@ class parser { } // in case of an error, return discarded value - if(sdp.is_errored()) { + if (sdp.is_errored()) { result = value_t::discarded; return; } // set top-level value to null if it was discarded by the callback // function - if(result.is_discarded()) { + if (result.is_discarded()) { result = nullptr; } } else { @@ -8909,7 +8912,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 and (get_token() != token_type::end_of_input)) { sdp.parse_error( m_lexer.get_position(), m_lexer.get_token_string(), parse_error::create( @@ -8918,7 +8921,7 @@ class parser { } // in case of an error, return discarded value - if(sdp.is_errored()) { + if (sdp.is_errored()) { result = value_t::discarded; return; } @@ -8943,7 +8946,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 and strict and (get_token() != token_type::end_of_input)) { return sax->parse_error( m_lexer.get_position(), m_lexer.get_token_string(), parse_error::create( @@ -8964,27 +8967,27 @@ class parser { // value to avoid a goto (see comment where set to true) bool skip_to_state_evaluation = false; - while(true) { - if(not skip_to_state_evaluation) { + while (true) { + if (not skip_to_state_evaluation) { // invariant: get_token() was called before each iteration - switch(last_token) { + switch (last_token) { case token_type::begin_object: { - if(JSON_HEDLEY_UNLIKELY( - not sax->start_object(std::size_t(-1)))) { + if (JSON_HEDLEY_UNLIKELY( + not sax->start_object(std::size_t(-1)))) { return false; } // closing } -> we are done - if(get_token() == token_type::end_object) { - if(JSON_HEDLEY_UNLIKELY(not sax->end_object())) { + if (get_token() == token_type::end_object) { + if (JSON_HEDLEY_UNLIKELY(not sax->end_object())) { return false; } break; } // parse key - if(JSON_HEDLEY_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(), @@ -8993,14 +8996,14 @@ 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( + not sax->key(m_lexer.get_string()))) { return false; } // parse separator (:) - if(JSON_HEDLEY_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(), @@ -9020,14 +9023,14 @@ class parser { } case token_type::begin_array: { - if(JSON_HEDLEY_UNLIKELY( - not sax->start_array(std::size_t(-1)))) { + if (JSON_HEDLEY_UNLIKELY( + not sax->start_array(std::size_t(-1)))) { return false; } // closing ] -> we are done - if(get_token() == token_type::end_array) { - if(JSON_HEDLEY_UNLIKELY(not sax->end_array())) { + if (get_token() == token_type::end_array) { + if (JSON_HEDLEY_UNLIKELY(not sax->end_array())) { return false; } break; @@ -9043,7 +9046,7 @@ class parser { case token_type::value_float: { const auto res = m_lexer.get_number_float(); - if(JSON_HEDLEY_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(), @@ -9052,8 +9055,8 @@ class parser { m_lexer.get_token_string() + "'")); } - if(JSON_HEDLEY_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; } @@ -9061,45 +9064,45 @@ class parser { } case token_type::literal_false: { - if(JSON_HEDLEY_UNLIKELY(not sax->boolean(false))) { + if (JSON_HEDLEY_UNLIKELY(not sax->boolean(false))) { return false; } break; } case token_type::literal_null: { - if(JSON_HEDLEY_UNLIKELY(not sax->null())) { + if (JSON_HEDLEY_UNLIKELY(not sax->null())) { return false; } break; } case token_type::literal_true: { - if(JSON_HEDLEY_UNLIKELY(not sax->boolean(true))) { + if (JSON_HEDLEY_UNLIKELY(not sax->boolean(true))) { return false; } break; } case token_type::value_integer: { - if(JSON_HEDLEY_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; } break; } case token_type::value_string: { - if(JSON_HEDLEY_UNLIKELY( - not sax->string(m_lexer.get_string()))) { + if (JSON_HEDLEY_UNLIKELY( + not sax->string(m_lexer.get_string()))) { return false; } break; } case token_type::value_unsigned: { - if(JSON_HEDLEY_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; } break; @@ -9130,23 +9133,23 @@ class parser { } // we reached this line after we successfully parsed a value - if(states.empty()) { + if (states.empty()) { // empty stack: we reached the end of the hierarchy: done return true; } - if(states.back()) // array + if (states.back()) // array { // comma -> next value - if(get_token() == token_type::value_separator) { + if (get_token() == token_type::value_separator) { // parse a new value get_token(); continue; } // closing ] - if(JSON_HEDLEY_LIKELY(last_token == token_type::end_array)) { - if(JSON_HEDLEY_UNLIKELY(not sax->end_array())) { + if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array)) { + if (JSON_HEDLEY_UNLIKELY(not sax->end_array())) { return false; } @@ -9168,10 +9171,10 @@ class parser { } else // object { // comma -> next value - if(get_token() == token_type::value_separator) { + if (get_token() == token_type::value_separator) { // parse key - if(JSON_HEDLEY_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(), parse_error::create( @@ -9180,14 +9183,14 @@ class parser { "object key"))); } - if(JSON_HEDLEY_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_HEDLEY_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(), parse_error::create( @@ -9202,8 +9205,8 @@ class parser { } // closing } - if(JSON_HEDLEY_LIKELY(last_token == token_type::end_object)) { - if(JSON_HEDLEY_UNLIKELY(not sax->end_object())) { + if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object)) { + if (JSON_HEDLEY_UNLIKELY(not sax->end_object())) { return false; } @@ -9235,13 +9238,13 @@ class parser { const std::string& context) { std::string error_msg = "syntax error "; - if(not context.empty()) { + if (not context.empty()) { error_msg += "while parsing " + context + " "; } error_msg += "- "; - if(last_token == token_type::parse_error) { + if (last_token == token_type::parse_error) { error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" + m_lexer.get_token_string() + "'"; } else { @@ -9249,7 +9252,7 @@ class parser { std::string(lexer_t::token_type_name(last_token)); } - if(expected != token_type::uninitialized) { + if (expected != token_type::uninitialized) { error_msg += "; expected " + std::string(lexer_t::token_type_name(expected)); } @@ -9495,7 +9498,7 @@ class iter_impl { explicit iter_impl(pointer object) noexcept : m_object(object) { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { m_it.object_iterator = typename object_t::iterator(); break; @@ -9577,7 +9580,7 @@ class iter_impl { void set_begin() noexcept { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { m_it.object_iterator = m_object->m_value.object->begin(); break; @@ -9608,7 +9611,7 @@ class iter_impl { void set_end() noexcept { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { m_it.object_iterator = m_object->m_value.object->end(); break; @@ -9634,7 +9637,7 @@ class iter_impl { reference operator*() const { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { assert(m_it.object_iterator != m_object->m_value.object->end()); return m_it.object_iterator->second; @@ -9649,7 +9652,7 @@ class iter_impl { JSON_THROW(invalid_iterator::create(214, "cannot get value")); default: { - if(JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) { + if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) { return *m_object; } @@ -9665,7 +9668,7 @@ class iter_impl { pointer operator->() const { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { assert(m_it.object_iterator != m_object->m_value.object->end()); return &(m_it.object_iterator->second); @@ -9677,7 +9680,7 @@ class iter_impl { } default: { - if(JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) { + if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) { return m_object; } @@ -9703,7 +9706,7 @@ class iter_impl { iter_impl& operator++() { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { std::advance(m_it.object_iterator, 1); break; @@ -9740,7 +9743,7 @@ class iter_impl { iter_impl& operator--() { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: { std::advance(m_it.object_iterator, -1); break; @@ -9766,14 +9769,14 @@ class iter_impl { */ bool operator==(const iter_impl& other) const { // if objects are not the same, the comparison is undefined - if(JSON_HEDLEY_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")); } assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: return (m_it.object_iterator == other.m_it.object_iterator); @@ -9800,14 +9803,14 @@ class iter_impl { */ bool operator<(const iter_impl& other) const { // if objects are not the same, the comparison is undefined - if(JSON_HEDLEY_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")); } assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: JSON_THROW(invalid_iterator::create( 213, "cannot compare order of object iterators")); @@ -9852,7 +9855,7 @@ class iter_impl { iter_impl& operator+=(difference_type i) { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: JSON_THROW(invalid_iterator::create( 209, "cannot use offsets with object iterators")); @@ -9916,7 +9919,7 @@ class iter_impl { difference_type operator-(const iter_impl& other) const { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: JSON_THROW(invalid_iterator::create( 209, "cannot use offsets with object iterators")); @@ -9936,7 +9939,7 @@ class iter_impl { reference operator[](difference_type n) const { assert(m_object != nullptr); - switch(m_object->m_type) { + switch (m_object->m_type) { case value_t::object: JSON_THROW(invalid_iterator::create( 208, "cannot use operator[] for object iterators")); @@ -9947,8 +9950,8 @@ class iter_impl { JSON_THROW(invalid_iterator::create(214, "cannot get value")); default: { - if(JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == - -n)) { + if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == + -n)) { return *m_object; } @@ -9964,7 +9967,7 @@ class iter_impl { const typename object_t::key_type& key() const { assert(m_object != nullptr); - if(JSON_HEDLEY_LIKELY(m_object->is_object())) { + if (JSON_HEDLEY_LIKELY(m_object->is_object())) { return m_it.object_iterator->first; } @@ -10322,7 +10325,7 @@ class json_pointer { @since version 3.6.0 */ json_pointer parent_pointer() const { - if(empty()) { + if (empty()) { return *this; } @@ -10346,7 +10349,7 @@ class json_pointer { @since version 3.6.0 */ void pop_back() { - if(JSON_HEDLEY_UNLIKELY(empty())) { + if (JSON_HEDLEY_UNLIKELY(empty())) { JSON_THROW(detail::out_of_range::create( 405, "JSON pointer has no parent")); } @@ -10369,7 +10372,7 @@ class json_pointer { @since version 3.6.0 */ const std::string& back() const { - if(JSON_HEDLEY_UNLIKELY(empty())) { + if (JSON_HEDLEY_UNLIKELY(empty())) { JSON_THROW(detail::out_of_range::create( 405, "JSON pointer has no parent")); } @@ -10429,7 +10432,7 @@ class json_pointer { const int res = std::stoi(s, &processed_chars); // check if the string was completely read - if(JSON_HEDLEY_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 + "'")); } @@ -10438,7 +10441,7 @@ class json_pointer { } json_pointer top() const { - if(JSON_HEDLEY_UNLIKELY(empty())) { + if (JSON_HEDLEY_UNLIKELY(empty())) { JSON_THROW(detail::out_of_range::create( 405, "JSON pointer has no parent")); } @@ -10462,10 +10465,10 @@ class json_pointer { // in case no reference tokens exist, return a reference to the JSON // value j which will be overwritten by a primitive value - for(const auto& reference_token: reference_tokens) { - switch(result->type()) { + for (const auto& reference_token: reference_tokens) { + switch (result->type()) { case detail::value_t::null: { - if(reference_token == "0") { + if (reference_token == "0") { // start a new array if reference token is 0 result = &result->operator[](0); } else { @@ -10533,9 +10536,9 @@ class json_pointer { */ BasicJsonType& get_unchecked(BasicJsonType* ptr) const { using size_type = typename BasicJsonType::size_type; - for(const auto& reference_token: reference_tokens) { + for (const auto& reference_token: reference_tokens) { // convert null values to arrays or objects before continuing - if(ptr->is_null()) { + if (ptr->is_null()) { // check if reference token is a number const bool nums = std::all_of( reference_token.begin(), reference_token.end(), @@ -10548,7 +10551,7 @@ class json_pointer { : detail::value_t::object; } - switch(ptr->type()) { + switch (ptr->type()) { case detail::value_t::object: { // use unchecked object access ptr = &ptr->operator[](reference_token); @@ -10557,15 +10560,15 @@ class json_pointer { case detail::value_t::array: { // error condition (cf. RFC 6901, Sect. 4) - if(JSON_HEDLEY_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 + "' must not begin with '0'")); } - if(reference_token == "-") { + if (reference_token == "-") { // explicitly treat "-" as index beyond the end ptr = &ptr->operator[](ptr->m_value.array->size()); } else { @@ -10602,8 +10605,8 @@ class json_pointer { */ BasicJsonType& get_checked(BasicJsonType* ptr) const { using size_type = typename BasicJsonType::size_type; - for(const auto& reference_token: reference_tokens) { - switch(ptr->type()) { + for (const auto& reference_token: reference_tokens) { + switch (ptr->type()) { case detail::value_t::object: { // note: at performs range check ptr = &ptr->at(reference_token); @@ -10611,7 +10614,7 @@ class json_pointer { } case detail::value_t::array: { - if(JSON_HEDLEY_UNLIKELY(reference_token == "-")) { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check JSON_THROW(detail::out_of_range::create( 402, @@ -10621,8 +10624,8 @@ class json_pointer { } // error condition (cf. RFC 6901, Sect. 4) - if(JSON_HEDLEY_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 + @@ -10668,8 +10671,8 @@ class json_pointer { */ const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const { using size_type = typename BasicJsonType::size_type; - for(const auto& reference_token: reference_tokens) { - switch(ptr->type()) { + for (const auto& reference_token: reference_tokens) { + switch (ptr->type()) { case detail::value_t::object: { // use unchecked object access ptr = &ptr->operator[](reference_token); @@ -10677,7 +10680,7 @@ class json_pointer { } case detail::value_t::array: { - if(JSON_HEDLEY_UNLIKELY(reference_token == "-")) { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" cannot be used for const access JSON_THROW(detail::out_of_range::create( 402, @@ -10687,8 +10690,8 @@ class json_pointer { } // error condition (cf. RFC 6901, Sect. 4) - if(JSON_HEDLEY_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 + @@ -10727,8 +10730,8 @@ class json_pointer { */ const BasicJsonType& get_checked(const BasicJsonType* ptr) const { using size_type = typename BasicJsonType::size_type; - for(const auto& reference_token: reference_tokens) { - switch(ptr->type()) { + for (const auto& reference_token: reference_tokens) { + switch (ptr->type()) { case detail::value_t::object: { // note: at performs range check ptr = &ptr->at(reference_token); @@ -10736,7 +10739,7 @@ class json_pointer { } case detail::value_t::array: { - if(JSON_HEDLEY_UNLIKELY(reference_token == "-")) { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check JSON_THROW(detail::out_of_range::create( 402, @@ -10746,8 +10749,8 @@ class json_pointer { } // error condition (cf. RFC 6901, Sect. 4) - if(JSON_HEDLEY_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 + @@ -10784,10 +10787,10 @@ class json_pointer { */ bool contains(const BasicJsonType* ptr) const { using size_type = typename BasicJsonType::size_type; - for(const auto& reference_token: reference_tokens) { - switch(ptr->type()) { + for (const auto& reference_token: reference_tokens) { + switch (ptr->type()) { case detail::value_t::object: { - if(not ptr->contains(reference_token)) { + if (not ptr->contains(reference_token)) { // we did not find the key in the object return false; } @@ -10797,14 +10800,14 @@ class json_pointer { } case detail::value_t::array: { - if(JSON_HEDLEY_UNLIKELY(reference_token == "-")) { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) { // "-" always fails the range check return false; } // error condition (cf. RFC 6901, Sect. 4) - if(JSON_HEDLEY_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 + @@ -10814,7 +10817,7 @@ class json_pointer { JSON_TRY { const auto idx = static_cast( array_index(reference_token)); - if(idx >= ptr->size()) { + if (idx >= ptr->size()) { // index out of range return false; } @@ -10856,12 +10859,12 @@ class json_pointer { std::vector result; // special case: empty reference string -> no reference tokens - if(reference_string.empty()) { + if (reference_string.empty()) { return result; } // check if nonempty reference string begins with slash - if(JSON_HEDLEY_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: '" + @@ -10871,7 +10874,7 @@ class json_pointer { // extract the reference tokens: // - slash: position of the last read slash (or end of string) // - start: position after the previous slash - for( + for ( // search for the first slash after the first character std::size_t slash = reference_string.find_first_of('/', 1), // set the beginning of the first reference token @@ -10889,15 +10892,15 @@ class json_pointer { reference_string.substr(start, slash - start); // check reference tokens are properly escaped - for(std::size_t pos = reference_token.find_first_of('~'); - pos != std::string::npos; - pos = reference_token.find_first_of('~', pos + 1)) { + for (std::size_t pos = reference_token.find_first_of('~'); + pos != std::string::npos; + pos = reference_token.find_first_of('~', pos + 1)) { 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 - 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 " @@ -10930,10 +10933,10 @@ class json_pointer { const std::string& f, const std::string& t) { assert(not 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 - pos = s.find(f, pos + t.size())) // find next occurrence of f + 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 + pos = s.find(f, pos + t.size())) // find next occurrence of f {} } @@ -10960,15 +10963,15 @@ class json_pointer { static void flatten(const std::string& reference_string, const BasicJsonType& value, BasicJsonType& result) { - switch(value.type()) { + switch (value.type()) { case detail::value_t::array: { - if(value.m_value.array->empty()) { + if (value.m_value.array->empty()) { // flatten empty array as null result[reference_string] = nullptr; } else { // iterate array and use index as reference string - for(std::size_t i = 0; i < value.m_value.array->size(); - ++i) { + for (std::size_t i = 0; i < value.m_value.array->size(); + ++i) { flatten(reference_string + "/" + std::to_string(i), value.m_value.array->operator[](i), result); } @@ -10977,12 +10980,12 @@ class json_pointer { } case detail::value_t::object: { - if(value.m_value.object->empty()) { + if (value.m_value.object->empty()) { // flatten empty object as null result[reference_string] = nullptr; } else { // iterate object and use keys as reference string - for(const auto& element: *value.m_value.object) { + for (const auto& element: *value.m_value.object) { flatten(reference_string + "/" + escape(element.first), element.second, result); } @@ -11009,7 +11012,7 @@ class json_pointer { @throw type_error.313 if value cannot be unflattened */ static BasicJsonType unflatten(const BasicJsonType& value) { - if(JSON_HEDLEY_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")); } @@ -11017,8 +11020,8 @@ class json_pointer { BasicJsonType result; // iterate the JSON object values - for(const auto& element: *value.m_value.object) { - if(JSON_HEDLEY_UNLIKELY(not element.second.is_primitive())) { + for (const auto& element: *value.m_value.object) { + if (JSON_HEDLEY_UNLIKELY(not element.second.is_primitive())) { JSON_THROW(detail::type_error::create( 315, "values in object must be primitive")); } @@ -11113,7 +11116,7 @@ class json_ref { ~json_ref() = default; value_type moved_or_copied() const { - if(is_rvalue) { + if (is_rvalue) { return std::move(*value_ref); } return *value_ref; @@ -11285,7 +11288,7 @@ class binary_writer { @pre j.type() == value_t::object */ void write_bson(const BasicJsonType& j) { - switch(j.type()) { + switch (j.type()) { case value_t::object: { write_bson_object(*j.m_value.object); break; @@ -11304,7 +11307,7 @@ class binary_writer { @param[in] j JSON value to serialize */ void write_cbor(const BasicJsonType& j) { - switch(j.type()) { + switch (j.type()) { case value_t::null: { oa->write_character(to_char_type(0xF6)); break; @@ -11317,25 +11320,25 @@ class binary_writer { } case value_t::number_integer: { - if(j.m_value.number_integer >= 0) { + if (j.m_value.number_integer >= 0) { // CBOR does not differentiate between positive signed // integers and unsigned integers. Therefore, we used the // code from the value_t::number_unsigned case here. - if(j.m_value.number_integer <= 0x17) { + if (j.m_value.number_integer <= 0x17) { write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x18)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x19)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x1A)); write_number(static_cast( j.m_value.number_integer)); @@ -11348,21 +11351,21 @@ class binary_writer { // The conversions below encode the sign in the first // byte, and the value is converted to a positive number. const auto positive_number = -1 - j.m_value.number_integer; - if(j.m_value.number_integer >= -24) { + if (j.m_value.number_integer >= -24) { write_number( static_cast(0x20 + positive_number)); - } else if(positive_number <= - (std::numeric_limits::max)()) { + } else if (positive_number <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x38)); write_number( static_cast(positive_number)); - } else if(positive_number <= - (std::numeric_limits::max)()) { + } else if (positive_number <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x39)); write_number( static_cast(positive_number)); - } else if(positive_number <= - (std::numeric_limits::max)()) { + } else if (positive_number <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x3A)); write_number( static_cast(positive_number)); @@ -11376,21 +11379,21 @@ class binary_writer { } case value_t::number_unsigned: { - if(j.m_value.number_unsigned <= 0x17) { + if (j.m_value.number_unsigned <= 0x17) { write_number( static_cast(j.m_value.number_unsigned)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x18)); write_number( static_cast(j.m_value.number_unsigned)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x19)); write_number( static_cast(j.m_value.number_unsigned)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x1A)); write_number( static_cast(j.m_value.number_unsigned)); @@ -11412,20 +11415,20 @@ class binary_writer { case value_t::string: { // step 1: write control byte and the string length const auto N = j.m_value.string->size(); - if(N <= 0x17) { + if (N <= 0x17) { write_number(static_cast(0x60 + N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x78)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x79)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x7A)); write_number(static_cast(N)); } // LCOV_EXCL_START - else if(N <= (std::numeric_limits::max)()) { + else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x7B)); write_number(static_cast(N)); } @@ -11441,54 +11444,54 @@ class binary_writer { case value_t::array: { // step 1: write control byte and the array size const auto N = j.m_value.array->size(); - if(N <= 0x17) { + if (N <= 0x17) { write_number(static_cast(0x80 + N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x98)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x99)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x9A)); write_number(static_cast(N)); } // LCOV_EXCL_START - else if(N <= (std::numeric_limits::max)()) { + else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0x9B)); write_number(static_cast(N)); } // LCOV_EXCL_STOP // step 2: write each element - for(const auto& el: *j.m_value.array) { write_cbor(el); } + for (const auto& el: *j.m_value.array) { write_cbor(el); } break; } case value_t::object: { // step 1: write control byte and the object size const auto N = j.m_value.object->size(); - if(N <= 0x17) { + if (N <= 0x17) { write_number(static_cast(0xA0 + N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0xB8)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0xB9)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0xBA)); write_number(static_cast(N)); } // LCOV_EXCL_START - else if(N <= (std::numeric_limits::max)()) { + else if (N <= (std::numeric_limits::max)()) { oa->write_character(to_char_type(0xBB)); write_number(static_cast(N)); } // LCOV_EXCL_STOP // step 2: write each element - for(const auto& el: *j.m_value.object) { + for (const auto& el: *j.m_value.object) { write_cbor(el.first); write_cbor(el.second); } @@ -11503,7 +11506,7 @@ class binary_writer { @param[in] j JSON value to serialize */ void write_msgpack(const BasicJsonType& j) { - switch(j.type()) { + switch (j.type()) { case value_t::null: // nil { oa->write_character(to_char_type(0xC0)); @@ -11518,72 +11521,75 @@ class binary_writer { } case value_t::number_integer: { - if(j.m_value.number_integer >= 0) { + if (j.m_value.number_integer >= 0) { // MessagePack does not differentiate between positive // signed integers and unsigned integers. Therefore, we used // the code from the value_t::number_unsigned case here. - if(j.m_value.number_unsigned < 128) { + if (j.m_value.number_unsigned < 128) { // positive fixnum write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 8 oa->write_character(to_char_type(0xCC)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 16 oa->write_character(to_char_type(0xCD)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 32 oa->write_character(to_char_type(0xCE)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 64 oa->write_character(to_char_type(0xCF)); write_number(static_cast( j.m_value.number_integer)); } } else { - if(j.m_value.number_integer >= -32) { + if (j.m_value.number_integer >= -32) { // negative fixnum write_number( static_cast(j.m_value.number_integer)); - } else if(j.m_value.number_integer >= - (std::numeric_limits::min)() and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer >= + (std::numeric_limits::min)() and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { // int 8 oa->write_character(to_char_type(0xD0)); write_number( static_cast(j.m_value.number_integer)); - } else if(j.m_value.number_integer >= - (std::numeric_limits::min)() and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer >= + (std::numeric_limits< + std::int16_t>::min)() and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { // int 16 oa->write_character(to_char_type(0xD1)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_integer >= - (std::numeric_limits::min)() and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer >= + (std::numeric_limits< + std::int32_t>::min)() and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { // int 32 oa->write_character(to_char_type(0xD2)); write_number(static_cast( j.m_value.number_integer)); - } else if(j.m_value.number_integer >= - (std::numeric_limits::min)() and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_integer >= + (std::numeric_limits< + std::int64_t>::min)() and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { // int 64 oa->write_character(to_char_type(0xD3)); write_number(static_cast( @@ -11594,30 +11600,30 @@ class binary_writer { } case value_t::number_unsigned: { - if(j.m_value.number_unsigned < 128) { + if (j.m_value.number_unsigned < 128) { // positive fixnum write_number( static_cast(j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 8 oa->write_character(to_char_type(0xCC)); write_number( static_cast(j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 16 oa->write_character(to_char_type(0xCD)); write_number( static_cast(j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 32 oa->write_character(to_char_type(0xCE)); write_number( static_cast(j.m_value.number_integer)); - } else if(j.m_value.number_unsigned <= - (std::numeric_limits::max)()) { + } else if (j.m_value.number_unsigned <= + (std::numeric_limits::max)()) { // uint 64 oa->write_character(to_char_type(0xCF)); write_number( @@ -11636,18 +11642,18 @@ class binary_writer { case value_t::string: { // step 1: write control byte and the string length const auto N = j.m_value.string->size(); - if(N <= 31) { + if (N <= 31) { // fixstr write_number(static_cast(0xA0 | N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // str 8 oa->write_character(to_char_type(0xD9)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // str 16 oa->write_character(to_char_type(0xDA)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // str 32 oa->write_character(to_char_type(0xDB)); write_number(static_cast(N)); @@ -11663,42 +11669,42 @@ class binary_writer { case value_t::array: { // step 1: write control byte and the array size const auto N = j.m_value.array->size(); - if(N <= 15) { + if (N <= 15) { // fixarray write_number(static_cast(0x90 | N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // array 16 oa->write_character(to_char_type(0xDC)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // array 32 oa->write_character(to_char_type(0xDD)); write_number(static_cast(N)); } // step 2: write each element - for(const auto& el: *j.m_value.array) { write_msgpack(el); } + for (const auto& el: *j.m_value.array) { write_msgpack(el); } break; } case value_t::object: { // step 1: write control byte and the object size const auto N = j.m_value.object->size(); - if(N <= 15) { + if (N <= 15) { // fixmap write_number(static_cast(0x80 | (N & 0xF))); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // map 16 oa->write_character(to_char_type(0xDE)); write_number(static_cast(N)); - } else if(N <= (std::numeric_limits::max)()) { + } else if (N <= (std::numeric_limits::max)()) { // map 32 oa->write_character(to_char_type(0xDF)); write_number(static_cast(N)); } // step 2: write each element - for(const auto& el: *j.m_value.object) { + for (const auto& el: *j.m_value.object) { write_msgpack(el.first); write_msgpack(el.second); } @@ -11719,16 +11725,16 @@ class binary_writer { const bool use_count, const bool use_type, const bool add_prefix = true) { - switch(j.type()) { + switch (j.type()) { case value_t::null: { - if(add_prefix) { + if (add_prefix) { oa->write_character(to_char_type('Z')); } break; } case value_t::boolean: { - if(add_prefix) { + if (add_prefix) { oa->write_character(j.m_value.boolean ? to_char_type('T') : to_char_type('F')); } @@ -11754,7 +11760,7 @@ class binary_writer { } case value_t::string: { - if(add_prefix) { + if (add_prefix) { oa->write_character(to_char_type('S')); } write_number_with_ubjson_prefix(j.m_value.string->size(), true); @@ -11765,12 +11771,12 @@ class binary_writer { } case value_t::array: { - if(add_prefix) { + if (add_prefix) { oa->write_character(to_char_type('[')); } bool prefix_required = true; - if(use_type and not j.m_value.array->empty()) { + if (use_type and not j.m_value.array->empty()) { assert(use_count); const CharType first_prefix = ubjson_prefix(j.front()); const bool same_prefix = std::all_of( @@ -11779,24 +11785,24 @@ class binary_writer { return ubjson_prefix(v) == first_prefix; }); - if(same_prefix) { + if (same_prefix) { prefix_required = false; oa->write_character(to_char_type('$')); oa->write_character(first_prefix); } } - if(use_count) { + if (use_count) { oa->write_character(to_char_type('#')); write_number_with_ubjson_prefix(j.m_value.array->size(), true); } - for(const auto& el: *j.m_value.array) { + for (const auto& el: *j.m_value.array) { write_ubjson(el, use_count, use_type, prefix_required); } - if(not use_count) { + if (not use_count) { oa->write_character(to_char_type(']')); } @@ -11804,12 +11810,12 @@ class binary_writer { } case value_t::object: { - if(add_prefix) { + if (add_prefix) { oa->write_character(to_char_type('{')); } bool prefix_required = true; - if(use_type and not j.m_value.object->empty()) { + if (use_type and not j.m_value.object->empty()) { assert(use_count); const CharType first_prefix = ubjson_prefix(j.front()); const bool same_prefix = std::all_of( @@ -11818,20 +11824,20 @@ class binary_writer { return ubjson_prefix(v) == first_prefix; }); - if(same_prefix) { + if (same_prefix) { prefix_required = false; oa->write_character(to_char_type('$')); oa->write_character(first_prefix); } } - if(use_count) { + if (use_count) { oa->write_character(to_char_type('#')); write_number_with_ubjson_prefix(j.m_value.object->size(), true); } - for(const auto& el: *j.m_value.object) { + for (const auto& el: *j.m_value.object) { write_number_with_ubjson_prefix(el.first.size(), true); oa->write_characters( reinterpret_cast(el.first.c_str()), @@ -11840,7 +11846,7 @@ class binary_writer { prefix_required); } - if(not use_count) { + if (not use_count) { oa->write_character(to_char_type('}')); } @@ -11863,7 +11869,7 @@ class binary_writer { static std::size_t calc_bson_entry_header_size(const string_t& name) { const auto it = name.find(static_cast(0)); - if(JSON_HEDLEY_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) + ")")); @@ -11938,8 +11944,8 @@ class binary_writer { @brief Writes a BSON element with key @a name and integer @a value */ void write_bson_integer(const string_t& name, const std::int64_t value) { - if((std::numeric_limits::min)() <= value and - value <= (std::numeric_limits::max)()) { + if ((std::numeric_limits::min)() <= value and + value <= (std::numeric_limits::max)()) { write_bson_entry_header(name, 0x10); // int32 write_number(static_cast(value)); } else { @@ -11963,12 +11969,12 @@ class binary_writer { @brief Writes a BSON element with key @a name and unsigned @a value */ void write_bson_unsigned(const string_t& name, const std::uint64_t value) { - if(value <= static_cast( - (std::numeric_limits::max)())) { + if (value <= static_cast( + (std::numeric_limits::max)())) { write_bson_entry_header(name, 0x10 /* int32 */); write_number(static_cast(value)); - } else if(value <= static_cast( - (std::numeric_limits::max)())) { + } else if (value <= static_cast( + (std::numeric_limits::max)())) { write_bson_entry_header(name, 0x12 /* int64 */); write_number(static_cast(value)); } else { @@ -12019,7 +12025,7 @@ class binary_writer { std::size_t array_index = 0ul; - for(const auto& el: value) { + for (const auto& el: value) { write_bson_element(std::to_string(array_index++), el); } @@ -12036,7 +12042,7 @@ class binary_writer { static std::size_t calc_bson_element_size(const string_t& name, const BasicJsonType& j) { const auto header_size = calc_bson_entry_header_size(name); - switch(j.type()) { + switch (j.type()) { case value_t::object: return header_size + calc_bson_object_size(*j.m_value.object); @@ -12076,7 +12082,7 @@ class binary_writer { @return The size of the BSON entry */ void write_bson_element(const string_t& name, const BasicJsonType& j) { - switch(j.type()) { + switch (j.type()) { case value_t::object: return write_bson_object_entry(name, *j.m_value.object); @@ -12134,7 +12140,7 @@ class binary_writer { write_number( static_cast(calc_bson_object_size(value))); - for(const auto& el: value) { write_bson_element(el.first, el.second); } + for (const auto& el: value) { write_bson_element(el.first, el.second); } oa->write_character(to_char_type(0x00)); } @@ -12173,7 +12179,7 @@ class binary_writer { int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix) { - if(add_prefix) { + if (add_prefix) { oa->write_character(get_ubjson_float_prefix(n)); } write_number(n); @@ -12185,32 +12191,32 @@ class binary_writer { int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix) { - if(n <= static_cast( - (std::numeric_limits::max)())) { - if(add_prefix) { + if (n <= static_cast( + (std::numeric_limits::max)())) { + if (add_prefix) { oa->write_character(to_char_type('i')); // int8 } write_number(static_cast(n)); - } else if(n <= (std::numeric_limits::max)()) { - if(add_prefix) { + } else if (n <= (std::numeric_limits::max)()) { + if (add_prefix) { oa->write_character(to_char_type('U')); // uint8 } write_number(static_cast(n)); - } else if(n <= static_cast( - (std::numeric_limits::max)())) { - if(add_prefix) { + } else if (n <= static_cast( + (std::numeric_limits::max)())) { + if (add_prefix) { oa->write_character(to_char_type('I')); // int16 } write_number(static_cast(n)); - } else if(n <= static_cast( - (std::numeric_limits::max)())) { - if(add_prefix) { + } else if (n <= static_cast( + (std::numeric_limits::max)())) { + if (add_prefix) { oa->write_character(to_char_type('l')); // int32 } write_number(static_cast(n)); - } else if(n <= static_cast( - (std::numeric_limits::max)())) { - if(add_prefix) { + } else if (n <= static_cast( + (std::numeric_limits::max)())) { + if (add_prefix) { oa->write_character(to_char_type('L')); // int64 } write_number(static_cast(n)); @@ -12230,35 +12236,35 @@ class binary_writer { int>::type = 0> void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix) { - if((std::numeric_limits::min)() <= n and - n <= (std::numeric_limits::max)()) { - if(add_prefix) { + if ((std::numeric_limits::min)() <= n and + n <= (std::numeric_limits::max)()) { + if (add_prefix) { oa->write_character(to_char_type('i')); // int8 } write_number(static_cast(n)); - } else if(static_cast( - (std::numeric_limits::min)()) <= n and - n <= static_cast( - (std::numeric_limits::max)())) { - if(add_prefix) { + } else if (static_cast( + (std::numeric_limits::min)()) <= n and + n <= static_cast( + (std::numeric_limits::max)())) { + if (add_prefix) { oa->write_character(to_char_type('U')); // uint8 } write_number(static_cast(n)); - } else if((std::numeric_limits::min)() <= n and - n <= (std::numeric_limits::max)()) { - if(add_prefix) { + } else if ((std::numeric_limits::min)() <= n and + n <= (std::numeric_limits::max)()) { + if (add_prefix) { oa->write_character(to_char_type('I')); // int16 } write_number(static_cast(n)); - } else if((std::numeric_limits::min)() <= n and - n <= (std::numeric_limits::max)()) { - if(add_prefix) { + } else if ((std::numeric_limits::min)() <= n and + n <= (std::numeric_limits::max)()) { + if (add_prefix) { oa->write_character(to_char_type('l')); // int32 } write_number(static_cast(n)); - } else if((std::numeric_limits::min)() <= n and - n <= (std::numeric_limits::max)()) { - if(add_prefix) { + } else if ((std::numeric_limits::min)() <= n and + n <= (std::numeric_limits::max)()) { + if (add_prefix) { oa->write_character(to_char_type('L')); // int64 } write_number(static_cast(n)); @@ -12283,34 +12289,34 @@ class binary_writer { value that does not fit the previous limits. */ CharType ubjson_prefix(const BasicJsonType& j) const noexcept { - switch(j.type()) { + switch (j.type()) { case value_t::null: return 'Z'; case value_t::boolean: return j.m_value.boolean ? 'T' : 'F'; case value_t::number_integer: { - if((std::numeric_limits::min)() <= - j.m_value.number_integer and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + if ((std::numeric_limits::min)() <= + j.m_value.number_integer and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { return 'i'; } - if((std::numeric_limits::min)() <= - j.m_value.number_integer and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + if ((std::numeric_limits::min)() <= + j.m_value.number_integer and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { return 'U'; } - if((std::numeric_limits::min)() <= - j.m_value.number_integer and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + if ((std::numeric_limits::min)() <= + j.m_value.number_integer and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { return 'I'; } - if((std::numeric_limits::min)() <= - j.m_value.number_integer and - j.m_value.number_integer <= - (std::numeric_limits::max)()) { + if ((std::numeric_limits::min)() <= + j.m_value.number_integer and + j.m_value.number_integer <= + (std::numeric_limits::max)()) { return 'l'; } // no check and assume int64_t (see note above) @@ -12318,24 +12324,24 @@ class binary_writer { } case value_t::number_unsigned: { - if(j.m_value.number_unsigned <= - static_cast( - (std::numeric_limits::max)())) { + if (j.m_value.number_unsigned <= + static_cast( + (std::numeric_limits::max)())) { return 'i'; } - if(j.m_value.number_unsigned <= - static_cast( - (std::numeric_limits::max)())) { + if (j.m_value.number_unsigned <= + static_cast( + (std::numeric_limits::max)())) { return 'U'; } - if(j.m_value.number_unsigned <= - static_cast( - (std::numeric_limits::max)())) { + if (j.m_value.number_unsigned <= + static_cast( + (std::numeric_limits::max)())) { return 'I'; } - if(j.m_value.number_unsigned <= - static_cast( - (std::numeric_limits::max)())) { + if (j.m_value.number_unsigned <= + static_cast( + (std::numeric_limits::max)())) { return 'l'; } // no check and assume int64_t (see note above) @@ -12386,7 +12392,7 @@ class binary_writer { std::memcpy(vec.data(), &n, sizeof(NumberType)); // step 2: write array to output (with possible reordering) - if(is_little_endian != OutputIsLittleEndian) { + if (is_little_endian != OutputIsLittleEndian) { // reverse byte order prior to conversion if necessary std::reverse(vec.begin(), vec.end()); } @@ -12602,7 +12608,7 @@ struct diyfp // f * 2^e static diyfp normalize(diyfp x) noexcept { assert(x.f != 0); - while((x.f >> 63u) == 0) { + while ((x.f >> 63u) == 0) { x.f <<= 1u; x.e--; } @@ -12906,33 +12912,33 @@ For n == 0, returns 1 and sets pow10 := 1. */ inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10) { // LCOV_EXCL_START - if(n >= 1000000000) { + if (n >= 1000000000) { pow10 = 1000000000; return 10; } // LCOV_EXCL_STOP - else if(n >= 100000000) { + else if (n >= 100000000) { pow10 = 100000000; return 9; - } else if(n >= 10000000) { + } else if (n >= 10000000) { pow10 = 10000000; return 8; - } else if(n >= 1000000) { + } else if (n >= 1000000) { pow10 = 1000000; return 7; - } else if(n >= 100000) { + } else if (n >= 100000) { pow10 = 100000; return 6; - } else if(n >= 10000) { + } else if (n >= 10000) { pow10 = 10000; return 5; - } else if(n >= 1000) { + } else if (n >= 1000) { pow10 = 1000; return 4; - } else if(n >= 100) { + } else if (n >= 100) { pow10 = 100; return 3; - } else if(n >= 10) { + } else if (n >= 10) { pow10 = 10; return 2; } else { @@ -12971,8 +12977,8 @@ inline void grisu2_round(char* buf, // The tests are written in this order to avoid overflow in unsigned // integer arithmetic. - while(rest < dist and delta - rest >= ten_k and - (rest + ten_k < dist or dist - rest > rest + ten_k - dist)) { + while (rest < dist and delta - rest >= ten_k and + (rest + ten_k < dist or dist - rest > rest + ten_k - dist)) { assert(buf[len - 1] != '0'); buf[len - 1]--; rest += ten_k; @@ -13057,7 +13063,7 @@ inline void grisu2_digit_gen(char* buffer, // rest * 2^e = (d[n-1]...d[0] * 2^-e + p2) * 2^e <= delta * 2^e int n = k; - while(n > 0) { + while (n > 0) { // Invariants: // M+ = buffer * 10^n + (p1 + p2 * 2^e) (buffer = 0 for n = k) // pow10 = 10^(n-1) <= p1 < 10^n @@ -13090,7 +13096,7 @@ inline void grisu2_digit_gen(char* buffer, // Since rest and delta share the same exponent e, it suffices to // compare the significands. const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2; - if(rest <= delta) { + if (rest <= delta) { // V = buffer * 10^n, with M- <= V <= M+. decimal_exponent += n; @@ -13158,7 +13164,7 @@ inline void grisu2_digit_gen(char* buffer, assert(p2 > delta); int m = 0; - for(;;) { + for (;;) { // Invariant: // M+ = buffer * 10^-m + 10^-m * (d[-m-1] / 10 + d[-m-2] / 10^2 + // ...) @@ -13196,7 +13202,7 @@ inline void grisu2_digit_gen(char* buffer, // p2 <= 10^m * delta delta *= 10; dist *= 10; - if(p2 <= delta) { + if (p2 <= delta) { break; } } @@ -13346,7 +13352,7 @@ inline char* append_exponent(char* buf, int e) { assert(e > -1000); assert(e < 1000); - if(e < 0) { + if (e < 0) { e = -e; *buf++ = '-'; } else { @@ -13354,12 +13360,12 @@ inline char* append_exponent(char* buf, int e) { } auto k = static_cast(e); - if(k < 10) { + if (k < 10) { // Always print at least two digits in the exponent. // This is for compatibility with printf("%g"). *buf++ = '0'; *buf++ = static_cast('0' + k); - } else if(k < 100) { + } else if (k < 100) { *buf++ = static_cast('0' + k / 10); k %= 10; *buf++ = static_cast('0' + k); @@ -13401,7 +13407,7 @@ inline char* format_buffer(char* buf, // 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 and n <= max_exp) { // digits[000] // len <= max_exp + 2 @@ -13412,7 +13418,7 @@ inline char* format_buffer(char* buf, return buf + (n + 2); } - if(0 < n and n <= max_exp) { + if (0 < n and n <= max_exp) { // dig.its // len <= max_digits10 + 1 @@ -13423,7 +13429,7 @@ inline char* format_buffer(char* buf, return buf + (k + 1); } - if(min_exp < n and n <= 0) { + if (min_exp < n and n <= 0) { // 0.[000]digits // len <= 2 + (-min_exp - 1) + max_digits10 @@ -13434,7 +13440,7 @@ inline char* format_buffer(char* buf, return buf + (2 + (-n) + k); } - if(k == 1) { + if (k == 1) { // dE+123 // len <= 1 + 5 @@ -13473,12 +13479,12 @@ JSON_HEDLEY_RETURNS_NON_NULL assert(std::isfinite(value)); // Use signbit(value) instead of (value < 0) since signbit works for -0. - if(std::signbit(value)) { + if (std::signbit(value)) { value = -value; *first++ = '-'; } - if(value == 0) // +-0 + if (value == 0) // +-0 { *first++ = '0'; // Make it look like a floating-point number (#362, #378) @@ -13596,27 +13602,27 @@ class serializer { const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent = 0) { - switch(val.m_type) { + switch (val.m_type) { case value_t::object: { - if(val.m_value.object->empty()) { + if (val.m_value.object->empty()) { o->write_characters("{}", 2); return; } - if(pretty_print) { + if (pretty_print) { o->write_characters("{\n", 2); // variable to hold indentation for recursive calls const auto new_indent = current_indent + indent_step; - if(JSON_HEDLEY_UNLIKELY(indent_string.size() < - new_indent)) { + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < + new_indent)) { indent_string.resize(indent_string.size() * 2, ' '); } // first n-1 elements auto i = val.m_value.object->cbegin(); - for(std::size_t cnt = 0; - cnt < val.m_value.object->size() - 1; ++cnt, ++i) { + for (std::size_t cnt = 0; + cnt < val.m_value.object->size() - 1; ++cnt, ++i) { o->write_characters(indent_string.c_str(), new_indent); o->write_character('\"'); dump_escaped(i->first, ensure_ascii); @@ -13644,8 +13650,8 @@ class serializer { // first n-1 elements auto i = val.m_value.object->cbegin(); - for(std::size_t cnt = 0; - cnt < val.m_value.object->size() - 1; ++cnt, ++i) { + for (std::size_t cnt = 0; + cnt < val.m_value.object->size() - 1; ++cnt, ++i) { o->write_character('\"'); dump_escaped(i->first, ensure_ascii); o->write_characters("\":", 2); @@ -13670,24 +13676,24 @@ class serializer { } case value_t::array: { - if(val.m_value.array->empty()) { + if (val.m_value.array->empty()) { o->write_characters("[]", 2); return; } - if(pretty_print) { + if (pretty_print) { o->write_characters("[\n", 2); // variable to hold indentation for recursive calls const auto new_indent = current_indent + indent_step; - if(JSON_HEDLEY_UNLIKELY(indent_string.size() < - new_indent)) { + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < + new_indent)) { indent_string.resize(indent_string.size() * 2, ' '); } // first n-1 elements - for(auto i = val.m_value.array->cbegin(); - i != val.m_value.array->cend() - 1; ++i) { + for (auto i = val.m_value.array->cbegin(); + i != val.m_value.array->cend() - 1; ++i) { o->write_characters(indent_string.c_str(), new_indent); dump(*i, true, ensure_ascii, indent_step, new_indent); o->write_characters(",\n", 2); @@ -13706,8 +13712,8 @@ class serializer { o->write_character('['); // first n-1 elements - for(auto i = val.m_value.array->cbegin(); - i != val.m_value.array->cend() - 1; ++i) { + for (auto i = val.m_value.array->cbegin(); + i != val.m_value.array->cend() - 1; ++i) { dump(*i, false, ensure_ascii, indent_step, current_indent); o->write_character(','); @@ -13732,7 +13738,7 @@ class serializer { } case value_t::boolean: { - if(val.m_value.boolean) { + if (val.m_value.boolean) { o->write_characters("true", 4); } else { o->write_characters("false", 5); @@ -13794,13 +13800,13 @@ class serializer { std::size_t bytes_after_last_accept = 0; std::size_t undumped_chars = 0; - for(std::size_t i = 0; i < s.size(); ++i) { + for (std::size_t i = 0; i < s.size(); ++i) { const auto byte = static_cast(s[i]); - switch(decode(state, codepoint, byte)) { + switch (decode(state, codepoint, byte)) { case UTF8_ACCEPT: // decode found a new code point { - switch(codepoint) { + switch (codepoint) { case 0x08: // backspace { string_buffer[bytes++] = '\\'; @@ -13854,9 +13860,9 @@ 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 <= 0xFFFF) { + if ((codepoint <= 0x1F) or + (ensure_ascii and (codepoint >= 0x7F))) { + if (codepoint <= 0xFFFF) { (std::snprintf)( string_buffer.data() + bytes, 7, "\\u%04x", @@ -13884,7 +13890,7 @@ class serializer { // write buffer and reset index; there must be 13 bytes // left, as this is the maximal number of bytes to be // written ("\uxxxx\uxxxx\0") for one code point - if(string_buffer.size() - bytes < 13) { + if (string_buffer.size() - bytes < 13) { o->write_characters(string_buffer.data(), bytes); bytes = 0; } @@ -13897,7 +13903,7 @@ class serializer { case UTF8_REJECT: // decode found invalid UTF-8 byte { - switch(error_handler) { + switch (error_handler) { case error_handler_t::strict: { std::string sn(3, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); @@ -13912,7 +13918,7 @@ class serializer { // would like to read it again, because the byte // may be OK for itself, but just not OK for the // previous sequence - if(undumped_chars > 0) { + if (undumped_chars > 0) { --i; } @@ -13920,9 +13926,9 @@ class serializer { // thus removing/ignoring the invalid characters bytes = bytes_after_last_accept; - if(error_handler == error_handler_t::replace) { + if (error_handler == error_handler_t::replace) { // add a replacement character - if(ensure_ascii) { + if (ensure_ascii) { string_buffer[bytes++] = '\\'; string_buffer[bytes++] = 'u'; string_buffer[bytes++] = 'f'; @@ -13948,7 +13954,7 @@ class serializer { // 13 bytes left, as this is the maximal number // of bytes to be written ("\uxxxx\uxxxx\0") for // one code point - if(string_buffer.size() - bytes < 13) { + if (string_buffer.size() - bytes < 13) { o->write_characters(string_buffer.data(), bytes); bytes = 0; @@ -13972,7 +13978,7 @@ class serializer { default: // decode found yet incomplete multi-byte code point { - if(not ensure_ascii) { + if (not ensure_ascii) { // code point will not be escaped - copy byte to buffer string_buffer[bytes++] = s[i]; } @@ -13983,14 +13989,14 @@ class serializer { } // we finished processing the string - if(JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT)) { + if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT)) { // write buffer - if(bytes > 0) { + if (bytes > 0) { o->write_characters(string_buffer.data(), bytes); } } else { // we finish reading, but do not accept: string was incomplete - switch(error_handler) { + switch (error_handler) { case error_handler_t::strict: { std::string sn(3, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", @@ -14011,7 +14017,7 @@ class serializer { o->write_characters(string_buffer.data(), bytes_after_last_accept); // add a replacement character - if(ensure_ascii) { + if (ensure_ascii) { o->write_characters("\\ufffd", 6); } else { o->write_characters("\xEF\xBF\xBD", 3); @@ -14035,17 +14041,17 @@ class serializer { */ inline unsigned int count_digits(number_unsigned_t x) noexcept { unsigned int n_digits = 1; - for(;;) { - if(x < 10) { + for (;;) { + if (x < 10) { return n_digits; } - if(x < 100) { + if (x < 100) { return n_digits + 1; } - if(x < 1000) { + if (x < 1000) { return n_digits + 2; } - if(x < 10000) { + if (x < 10000) { return n_digits + 3; } x = x / 10000u; @@ -14097,7 +14103,7 @@ class serializer { }}; // special case for "0" - if(x == 0) { + if (x == 0) { o->write_character('0'); return; } @@ -14112,7 +14118,7 @@ class serializer { unsigned int n_chars; - if(is_negative) { + if (is_negative) { *buffer_ptr = '-'; abs_value = remove_sign(x); @@ -14132,14 +14138,14 @@ class serializer { // Fast int2ascii implementation inspired by "Fastware" talk by Andrei // Alexandrescu See: https://www.youtube.com/watch?v=o4-CwDo2zpg - while(abs_value >= 100) { + while (abs_value >= 100) { const auto digits_index = static_cast((abs_value % 100)); abs_value /= 100; *(--buffer_ptr) = digits_to_99[digits_index][1]; *(--buffer_ptr) = digits_to_99[digits_index][0]; } - if(abs_value >= 10) { + if (abs_value >= 10) { const auto digits_index = static_cast(abs_value); *(--buffer_ptr) = digits_to_99[digits_index][1]; *(--buffer_ptr) = digits_to_99[digits_index][0]; @@ -14160,7 +14166,7 @@ class serializer { */ void dump_float(number_float_t x) { // NaN / inf - if(not std::isfinite(x)) { + if (not std::isfinite(x)) { o->write_characters("null", 4); return; } @@ -14206,7 +14212,7 @@ class serializer { assert(static_cast(len) < number_buffer.size()); // erase thousands separator - if(thousands_sep != '\0') { + if (thousands_sep != '\0') { const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep); @@ -14216,10 +14222,10 @@ class serializer { } // convert decimal point to '.' - if(decimal_point != '\0' and decimal_point != '.') { + if (decimal_point != '\0' and decimal_point != '.') { const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point); - if(dec_pos != number_buffer.end()) { + if (dec_pos != number_buffer.end()) { *dec_pos = '.'; } } @@ -14232,7 +14238,7 @@ class serializer { std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) { return c == '.' or c == 'e'; }); - if(value_is_int_like) { + if (value_is_int_like) { o->write_characters(".0", 2); } } @@ -15212,7 +15218,7 @@ class basic_json { json_value(number_float_t v) noexcept : number_float(v) {} /// constructor for empty values of a given type json_value(value_t t) { - switch(t) { + switch (t) { case value_t::object: { object = create(); break; @@ -15255,7 +15261,7 @@ class basic_json { default: { object = nullptr; // silence warning, see #821 - if(JSON_HEDLEY_UNLIKELY(t == value_t::null)) { + if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { JSON_THROW(other_error::create( 500, "961c151d2e87f2686a955a9be24d316f1362b" "f21 3.7.3")); // LCOV_EXCL_LINE @@ -15300,32 +15306,32 @@ class basic_json { std::vector stack; // move the top-level items to stack - if(t == value_t::array) { + if (t == value_t::array) { stack.reserve(array->size()); std::move(array->begin(), array->end(), std::back_inserter(stack)); - } else if(t == value_t::object) { + } else if (t == value_t::object) { stack.reserve(object->size()); - for(auto&& it: *object) { + for (auto&& it: *object) { stack.push_back(std::move(it.second)); } } - while(not stack.empty()) { + while (not stack.empty()) { // move the last item to local variable to be processed basic_json current_item(std::move(stack.back())); stack.pop_back(); // if current_item is array/object, move // its children to the stack to be processed later - if(current_item.is_array()) { + if (current_item.is_array()) { std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack)); current_item.m_value.array->clear(); - } else if(current_item.is_object()) { - for(auto&& it: *current_item.m_value.object) { + } else if (current_item.is_object()) { + for (auto&& it: *current_item.m_value.object) { stack.push_back(std::move(it.second)); } @@ -15336,7 +15342,7 @@ class basic_json { // since it doesn't have any children } - switch(t) { + switch (t) { case value_t::object: { AllocatorType alloc; std::allocator_traits::destroy(alloc, @@ -15641,7 +15647,7 @@ class basic_json { using other_object_t = typename BasicJsonType::object_t; using other_array_t = typename BasicJsonType::array_t; - switch(val.type()) { + switch (val.type()) { case value_t::boolean: JSONSerializer::to_json( *this, val.template get()); @@ -15765,21 +15771,21 @@ class basic_json { }); // adjust type if type deduction is not wanted - if(not type_deduction) { + if (not type_deduction) { // if array is wanted, do not create an object though possible - if(manual_type == value_t::array) { + if (manual_type == value_t::array) { is_an_object = false; } // if object is wanted but impossible, throw an exception - if(JSON_HEDLEY_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")); } } - if(is_an_object) { + if (is_an_object) { // the initializer list is a list of pairs -> create object m_type = value_t::object; m_value = value_t::object; @@ -15981,7 +15987,7 @@ class basic_json { assert(last.m_object != nullptr); // make sure iterator fits the current value - if(JSON_HEDLEY_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")); } @@ -15990,15 +15996,15 @@ class basic_json { m_type = first.m_object->m_type; // check if iterator range is complete for primitive values - switch(m_type) { + switch (m_type) { case value_t::boolean: case value_t::number_float: case value_t::number_integer: case value_t::number_unsigned: case value_t::string: { - if(JSON_HEDLEY_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")); } @@ -16008,7 +16014,7 @@ class basic_json { default: break; } - switch(m_type) { + switch (m_type) { case value_t::number_integer: { m_value.number_integer = first.m_object->m_value.number_integer; break; @@ -16093,7 +16099,7 @@ class basic_json { // check of passed value is valid other.assert_invariant(); - switch(m_type) { + switch (m_type) { case value_t::object: { m_value = *other.m_value.object; break; @@ -16294,7 +16300,7 @@ class basic_json { serializer s(detail::output_adapter(result), indent_char, error_handler); - if(indent >= 0) { + if (indent >= 0) { s.dump(*this, true, ensure_ascii, static_cast(indent)); } else { @@ -16672,7 +16678,7 @@ class basic_json { /// get a boolean (explicit) boolean_t get_impl(boolean_t* /*unused*/) const { - if(JSON_HEDLEY_LIKELY(is_boolean())) { + if (JSON_HEDLEY_LIKELY(is_boolean())) { return m_value.boolean; } @@ -16774,7 +16780,7 @@ class basic_json { auto ptr = obj.template get_ptr< typename std::add_pointer::type>(); - if(JSON_HEDLEY_LIKELY(ptr != nullptr)) { + if (JSON_HEDLEY_LIKELY(ptr != nullptr)) { return *ptr; } @@ -17259,7 +17265,7 @@ class basic_json { */ reference at(size_type idx) { // at only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_LIKELY(is_array())) { JSON_TRY { return m_value.array->at(idx); } @@ -17303,7 +17309,7 @@ class basic_json { */ const_reference at(size_type idx) const { // at only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_LIKELY(is_array())) { JSON_TRY { return m_value.array->at(idx); } @@ -17351,7 +17357,7 @@ class basic_json { */ reference at(const typename object_t::key_type& key) { // at only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { JSON_TRY { return m_value.object->at(key); } @@ -17398,7 +17404,7 @@ class basic_json { */ const_reference at(const typename object_t::key_type& key) const { // at only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { JSON_TRY { return m_value.object->at(key); } @@ -17440,16 +17446,16 @@ class basic_json { */ reference operator[](size_type idx) { // implicitly convert null value to an empty array - if(is_null()) { + if (is_null()) { m_type = value_t::array; m_value.array = create(); assert_invariant(); } // operator[] only works for arrays - if(JSON_HEDLEY_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()) { + if (idx >= m_value.array->size()) { m_value.array->insert(m_value.array->end(), idx - m_value.array->size() + 1, basic_json()); @@ -17484,7 +17490,7 @@ class basic_json { */ const_reference operator[](size_type idx) const { // const operator[] only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_LIKELY(is_array())) { return m_value.array->operator[](idx); } @@ -17522,14 +17528,14 @@ class basic_json { */ reference operator[](const typename object_t::key_type& key) { // implicitly convert null value to an empty object - if(is_null()) { + if (is_null()) { m_type = value_t::object; m_value.object = create(); assert_invariant(); } // operator[] only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { return m_value.object->operator[](key); } @@ -17570,7 +17576,7 @@ class basic_json { */ const_reference operator[](const typename object_t::key_type& key) const { // const operator[] only works for objects - if(JSON_HEDLEY_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; } @@ -17611,14 +17617,14 @@ class basic_json { JSON_HEDLEY_NON_NULL(2) reference operator[](T* key) { // implicitly convert null to object - if(is_null()) { + if (is_null()) { m_type = value_t::object; m_value = value_t::object; assert_invariant(); } // at only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { return m_value.object->operator[](key); } @@ -17661,7 +17667,7 @@ class basic_json { JSON_HEDLEY_NON_NULL(2) const_reference operator[](T* key) const { // at only works for objects - if(JSON_HEDLEY_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; } @@ -17728,10 +17734,10 @@ class basic_json { ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const { // at only works for objects - if(JSON_HEDLEY_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); - if(it != end()) { + if (it != end()) { return *it; } @@ -17802,7 +17808,7 @@ class basic_json { ValueType value(const json_pointer& ptr, const ValueType& default_value) const { // at only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { // if pointer resolves a value, return it or use default value JSON_TRY { return ptr.get_checked(this); @@ -17963,26 +17969,26 @@ class basic_json { int>::type = 0> IteratorType erase(IteratorType pos) { // make sure iterator fits the current value - if(JSON_HEDLEY_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")); } IteratorType result = end(); - switch(m_type) { + switch (m_type) { case value_t::boolean: case value_t::number_float: case value_t::number_integer: case value_t::number_unsigned: case value_t::string: { - if(JSON_HEDLEY_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")); } - if(is_string()) { + if (is_string()) { AllocatorType alloc; std::allocator_traits::destroy( alloc, m_value.string); @@ -18073,28 +18079,28 @@ class basic_json { int>::type = 0> IteratorType erase(IteratorType first, IteratorType last) { // make sure iterator fits the current value - if(JSON_HEDLEY_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")); } IteratorType result = end(); - switch(m_type) { + switch (m_type) { case value_t::boolean: case value_t::number_float: case value_t::number_integer: case value_t::number_unsigned: case value_t::string: { - if(JSON_HEDLEY_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")); } - if(is_string()) { + if (is_string()) { AllocatorType alloc; std::allocator_traits::destroy( alloc, m_value.string); @@ -18160,7 +18166,7 @@ class basic_json { */ size_type erase(const typename object_t::key_type& key) { // this erase only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { return m_value.object->erase(key); } @@ -18194,8 +18200,8 @@ class basic_json { */ void erase(const size_type idx) { // this erase only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { - if(JSON_HEDLEY_UNLIKELY(idx >= size())) { + if (JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_UNLIKELY(idx >= size())) { JSON_THROW(out_of_range::create( 401, "array index " + std::to_string(idx) + " is out of range")); @@ -18246,7 +18252,7 @@ class basic_json { iterator find(KeyT&& key) { auto result = end(); - if(is_object()) { + if (is_object()) { result.m_it.object_iterator = m_value.object->find(std::forward(key)); } @@ -18262,7 +18268,7 @@ class basic_json { const_iterator find(KeyT&& key) const { auto result = cend(); - if(is_object()) { + if (is_object()) { result.m_it.object_iterator = m_value.object->find(std::forward(key)); } @@ -18834,7 +18840,7 @@ class basic_json { @since version 1.0.0 */ bool empty() const noexcept { - switch(m_type) { + switch (m_type) { case value_t::null: { // null values are empty return true; @@ -18900,7 +18906,7 @@ class basic_json { @since version 1.0.0 */ size_type size() const noexcept { - switch(m_type) { + switch (m_type) { case value_t::null: { // null values are empty return 0; @@ -18964,7 +18970,7 @@ class basic_json { @since version 1.0.0 */ size_type max_size() const noexcept { - switch(m_type) { + switch (m_type) { case value_t::array: { // delegate call to array_t::max_size() return m_value.array->max_size(); @@ -19028,7 +19034,7 @@ class basic_json { @since version 1.0.0 */ void clear() noexcept { - switch(m_type) { + switch (m_type) { case value_t::number_integer: { m_value.number_integer = 0; break; @@ -19090,13 +19096,13 @@ class basic_json { */ void push_back(basic_json&& val) { // push_back only works for null objects or arrays - if(JSON_HEDLEY_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()))); } // transform null object into an array - if(is_null()) { + if (is_null()) { m_type = value_t::array; m_value = value_t::array; assert_invariant(); @@ -19124,13 +19130,13 @@ class basic_json { */ void push_back(const basic_json& val) { // push_back only works for null objects or arrays - if(JSON_HEDLEY_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()))); } // transform null object into an array - if(is_null()) { + if (is_null()) { m_type = value_t::array; m_value = value_t::array; assert_invariant(); @@ -19171,13 +19177,13 @@ class basic_json { */ void push_back(const typename object_t::value_type& val) { // push_back only works for null objects or objects - if(JSON_HEDLEY_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()))); } // transform null object into an object - if(is_null()) { + if (is_null()) { m_type = value_t::object; m_value = value_t::object; assert_invariant(); @@ -19222,7 +19228,7 @@ class basic_json { objects when possible.,push_back__initializer_list} */ void push_back(initializer_list_t init) { - if(is_object() and init.size() == 2 and (*init.begin())->is_string()) { + if (is_object() and init.size() == 2 and (*init.begin())->is_string()) { basic_json&& key = init.begin()->moved_or_copied(); push_back(typename object_t::value_type( std::move(key.get_ref()), @@ -19267,14 +19273,14 @@ class basic_json { template reference emplace_back(Args&&... args) { // emplace_back only works for null objects or arrays - if(JSON_HEDLEY_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()))); } // transform null object into an array - if(is_null()) { + if (is_null()) { m_type = value_t::array; m_value = value_t::array; assert_invariant(); @@ -19319,13 +19325,13 @@ class basic_json { template std::pair emplace(Args&&... args) { // emplace only works for null objects or arrays - if(JSON_HEDLEY_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()))); } // transform null object into an object - if(is_null()) { + if (is_null()) { m_type = value_t::object; m_value = value_t::object; assert_invariant(); @@ -19388,9 +19394,9 @@ class basic_json { */ iterator insert(const_iterator pos, const basic_json& val) { // insert only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_LIKELY(is_array())) { // check if iterator pos fits to this JSON value - if(JSON_HEDLEY_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")); } @@ -19437,9 +19443,9 @@ class basic_json { */ iterator insert(const_iterator pos, size_type cnt, const basic_json& val) { // insert only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_LIKELY(is_array())) { // check if iterator pos fits to this JSON value - if(JSON_HEDLEY_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")); } @@ -19486,23 +19492,23 @@ class basic_json { const_iterator first, const_iterator last) { // insert only works for arrays - if(JSON_HEDLEY_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_HEDLEY_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_HEDLEY_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_HEDLEY_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")); } @@ -19538,13 +19544,13 @@ class basic_json { */ iterator insert(const_iterator pos, initializer_list_t ilist) { // insert only works for arrays - if(JSON_HEDLEY_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_HEDLEY_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")); } @@ -19578,18 +19584,18 @@ class basic_json { */ void insert(const_iterator first, const_iterator last) { // insert only works for objects - if(JSON_HEDLEY_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_HEDLEY_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_HEDLEY_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")); } @@ -19619,22 +19625,22 @@ class basic_json { */ void update(const_reference j) { // implicitly convert null value to an empty object - if(is_null()) { + if (is_null()) { m_type = value_t::object; m_value.object = create(); assert_invariant(); } - if(JSON_HEDLEY_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_HEDLEY_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()))); } - for(auto it = j.cbegin(); it != j.cend(); ++it) { + for (auto it = j.cbegin(); it != j.cend(); ++it) { m_value.object->operator[](it.key()) = it.value(); } } @@ -19667,30 +19673,30 @@ class basic_json { */ void update(const_iterator first, const_iterator last) { // implicitly convert null value to an empty object - if(is_null()) { + if (is_null()) { m_type = value_t::object; m_value.object = create(); assert_invariant(); } - if(JSON_HEDLEY_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_HEDLEY_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_HEDLEY_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")); } - for(auto it = first; it != last; ++it) { + for (auto it = first; it != last; ++it) { m_value.object->operator[](it.key()) = it.value(); } } @@ -19744,7 +19750,7 @@ class basic_json { */ void swap(array_t& other) { // swap only works for arrays - if(JSON_HEDLEY_LIKELY(is_array())) { + if (JSON_HEDLEY_LIKELY(is_array())) { std::swap(*(m_value.array), other); } else { JSON_THROW(type_error::create( @@ -19774,7 +19780,7 @@ class basic_json { */ void swap(object_t& other) { // swap only works for objects - if(JSON_HEDLEY_LIKELY(is_object())) { + if (JSON_HEDLEY_LIKELY(is_object())) { std::swap(*(m_value.object), other); } else { JSON_THROW(type_error::create( @@ -19804,7 +19810,7 @@ class basic_json { */ void swap(string_t& other) { // swap only works for strings - if(JSON_HEDLEY_LIKELY(is_string())) { + if (JSON_HEDLEY_LIKELY(is_string())) { std::swap(*(m_value.string), other); } else { JSON_THROW(type_error::create( @@ -19867,8 +19873,8 @@ class basic_json { const auto lhs_type = lhs.type(); const auto rhs_type = rhs.type(); - if(lhs_type == rhs_type) { - switch(lhs_type) { + if (lhs_type == rhs_type) { + switch (lhs_type) { case value_t::array: return *lhs.m_value.array == *rhs.m_value.array; @@ -19896,28 +19902,28 @@ class basic_json { default: return false; } - } else if(lhs_type == value_t::number_integer and - rhs_type == value_t::number_float) { + } else if (lhs_type == value_t::number_integer and + rhs_type == value_t::number_float) { return static_cast(lhs.m_value.number_integer) == rhs.m_value.number_float; - } else if(lhs_type == value_t::number_float and - rhs_type == value_t::number_integer) { + } else if (lhs_type == value_t::number_float and + rhs_type == value_t::number_integer) { return lhs.m_value.number_float == static_cast(rhs.m_value.number_integer); - } else if(lhs_type == value_t::number_unsigned and - rhs_type == value_t::number_float) { + } else if (lhs_type == value_t::number_unsigned and + rhs_type == value_t::number_float) { return static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_float; - } else if(lhs_type == value_t::number_float and - rhs_type == value_t::number_unsigned) { + } else if (lhs_type == value_t::number_float and + rhs_type == value_t::number_unsigned) { return lhs.m_value.number_float == static_cast(rhs.m_value.number_unsigned); - } else if(lhs_type == value_t::number_unsigned and - rhs_type == value_t::number_integer) { + } else if (lhs_type == value_t::number_unsigned and + rhs_type == value_t::number_integer) { return static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_integer; - } else if(lhs_type == value_t::number_integer and - rhs_type == value_t::number_unsigned) { + } else if (lhs_type == value_t::number_integer and + rhs_type == value_t::number_unsigned) { return lhs.m_value.number_integer == static_cast(rhs.m_value.number_unsigned); } @@ -20021,8 +20027,8 @@ class basic_json { const auto lhs_type = lhs.type(); const auto rhs_type = rhs.type(); - if(lhs_type == rhs_type) { - switch(lhs_type) { + if (lhs_type == rhs_type) { + switch (lhs_type) { case value_t::array: // note parentheses are necessary, see // https://github.com/nlohmann/json/issues/1530 @@ -20053,28 +20059,28 @@ class basic_json { default: return false; } - } else if(lhs_type == value_t::number_integer and - rhs_type == value_t::number_float) { + } else if (lhs_type == value_t::number_integer and + rhs_type == value_t::number_float) { return static_cast(lhs.m_value.number_integer) < rhs.m_value.number_float; - } else if(lhs_type == value_t::number_float and - rhs_type == value_t::number_integer) { + } else if (lhs_type == value_t::number_float and + rhs_type == value_t::number_integer) { return lhs.m_value.number_float < static_cast(rhs.m_value.number_integer); - } else if(lhs_type == value_t::number_unsigned and - rhs_type == value_t::number_float) { + } else if (lhs_type == value_t::number_unsigned and + rhs_type == value_t::number_float) { return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_float; - } else if(lhs_type == value_t::number_float and - rhs_type == value_t::number_unsigned) { + } else if (lhs_type == value_t::number_float and + rhs_type == value_t::number_unsigned) { return lhs.m_value.number_float < static_cast(rhs.m_value.number_unsigned); - } else if(lhs_type == value_t::number_integer and - rhs_type == value_t::number_unsigned) { + } else if (lhs_type == value_t::number_integer and + rhs_type == value_t::number_unsigned) { return lhs.m_value.number_integer < static_cast(rhs.m_value.number_unsigned); - } else if(lhs_type == value_t::number_unsigned and - rhs_type == value_t::number_integer) { + } else if (lhs_type == value_t::number_unsigned and + rhs_type == value_t::number_integer) { return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_integer; } @@ -20629,7 +20635,7 @@ class basic_json { JSON_HEDLEY_RETURNS_NON_NULL const char* type_name() const noexcept { { - switch(m_type) { + switch (m_type) { case value_t::null: return "null"; case value_t::object: return "object"; case value_t::array: return "array"; @@ -21776,22 +21782,22 @@ class basic_json { }; const auto get_op = [](const std::string& op) { - if(op == "add") { + if (op == "add") { return patch_operations::add; } - if(op == "remove") { + if (op == "remove") { return patch_operations::remove; } - if(op == "replace") { + if (op == "replace") { return patch_operations::replace; } - if(op == "move") { + if (op == "move") { return patch_operations::move; } - if(op == "copy") { + if (op == "copy") { return patch_operations::copy; } - if(op == "test") { + if (op == "test") { return patch_operations::test; } @@ -21802,14 +21808,14 @@ class basic_json { const auto operation_add = [&result](json_pointer& ptr, basic_json val) { // adding to the root of the target document means replacing it - if(ptr.empty()) { + if (ptr.empty()) { result = val; return; } // make sure the top element of the pointer exists json_pointer top_pointer = ptr.top(); - if(top_pointer != ptr) { + if (top_pointer != ptr) { result.at(top_pointer); } @@ -21818,7 +21824,7 @@ class basic_json { ptr.pop_back(); basic_json& parent = result[ptr]; - switch(parent.m_type) { + switch (parent.m_type) { case value_t::null: case value_t::object: { // use operator[] to add value @@ -21827,13 +21833,13 @@ class basic_json { } case value_t::array: { - if(last_path == "-") { + if (last_path == "-") { // special case: append to back parent.push_back(val); } else { const auto idx = json_pointer::array_index(last_path); - if(JSON_HEDLEY_UNLIKELY(static_cast(idx) > - parent.size())) { + if (JSON_HEDLEY_UNLIKELY(static_cast(idx) > + parent.size())) { // avoid undefined behavior JSON_THROW(out_of_range::create( 401, "array index " + std::to_string(idx) + @@ -21862,16 +21868,16 @@ class basic_json { basic_json& parent = result.at(ptr); // remove child - if(parent.is_object()) { + if (parent.is_object()) { // perform range check auto it = parent.find(last_path); - if(JSON_HEDLEY_LIKELY(it != parent.end())) { + if (JSON_HEDLEY_LIKELY(it != parent.end())) { parent.erase(it); } else { JSON_THROW(out_of_range::create( 403, "key '" + last_path + "' not found")); } - } else if(parent.is_array()) { + } else if (parent.is_array()) { // note erase performs range check parent.erase(static_cast( json_pointer::array_index(last_path))); @@ -21879,13 +21885,13 @@ class basic_json { }; // type check: top level value must be an array - if(JSON_HEDLEY_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")); } // iterate and apply the operations - for(const auto& val: json_patch) { + for (const auto& val: json_patch) { // wrapper to get a value for an operation const auto get_value = [&val](const std::string& op, const std::string& member, @@ -21898,15 +21904,15 @@ class basic_json { (op == "op") ? "operation" : "operation '" + op + "'"; // check if desired value is present - if(JSON_HEDLEY_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_HEDLEY_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 + @@ -21918,7 +21924,7 @@ class basic_json { }; // type check: every element of the array must be an object - if(JSON_HEDLEY_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")); } @@ -21928,7 +21934,7 @@ class basic_json { const std::string path = get_value(op, "path", true); json_pointer ptr(path); - switch(get_op(op)) { + switch (get_op(op)) { case patch_operations::add: { operation_add(ptr, get_value("add", "value", false)); break; @@ -21990,7 +21996,7 @@ class basic_json { } // throw an exception if test fails - if(JSON_HEDLEY_UNLIKELY(not success)) { + if (JSON_HEDLEY_UNLIKELY(not success)) { JSON_THROW(other_error::create( 501, "unsuccessful: " + val.dump())); } @@ -22051,22 +22057,22 @@ class basic_json { basic_json result(value_t::array); // if the values are the same, return empty patch - if(source == target) { + if (source == target) { return result; } - if(source.type() != target.type()) { + if (source.type() != target.type()) { // different types: replace value result.push_back( {{"op", "replace"}, {"path", path}, {"value", target}}); return result; } - switch(source.type()) { + switch (source.type()) { case value_t::array: { // first pass: traverse common elements std::size_t i = 0; - while(i < source.size() and i < target.size()) { + while (i < source.size() and i < target.size()) { // recursive call to compare array values at index i auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i)); @@ -22081,7 +22087,7 @@ class basic_json { // remove my remaining elements const auto end_index = static_cast(result.size()); - while(i < source.size()) { + while (i < source.size()) { // add operations in reverse order to avoid invalid // indices result.insert( @@ -22092,7 +22098,7 @@ class basic_json { } // add other remaining elements - while(i < target.size()) { + while (i < target.size()) { result.push_back({{"op", "add"}, {"path", path + "/" + std::to_string(i)}, {"value", target[i]}}); @@ -22104,11 +22110,11 @@ class basic_json { case value_t::object: { // first pass: traverse this object's elements - for(auto it = source.cbegin(); it != source.cend(); ++it) { + for (auto it = source.cbegin(); it != source.cend(); ++it) { // escape the key name to be used in a JSON patch const auto key = json_pointer::escape(it.key()); - if(target.find(it.key()) != target.end()) { + if (target.find(it.key()) != target.end()) { // recursive call to compare object values at key it auto temp_diff = diff(it.value(), target[it.key()], path + "/" + key); @@ -22122,8 +22128,8 @@ class basic_json { } // second pass: traverse other object's elements - for(auto it = target.cbegin(); it != target.cend(); ++it) { - if(source.find(it.key()) == source.end()) { + for (auto it = target.cbegin(); it != target.cend(); ++it) { + if (source.find(it.key()) == source.end()) { // found a key that is not in this -> add it const auto key = json_pointer::escape(it.key()); result.push_back({{"op", "add"}, @@ -22198,12 +22204,12 @@ class basic_json { @since version 3.0.0 */ void merge_patch(const basic_json& apply_patch) { - if(apply_patch.is_object()) { - if(not is_object()) { + if (apply_patch.is_object()) { + if (not is_object()) { *this = object(); } - for(auto it = apply_patch.begin(); it != apply_patch.end(); ++it) { - if(it.value().is_null()) { + for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it) { + if (it.value().is_null()) { erase(it.key()); } else { operator[](it.key()).merge_patch(it.value());