aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2022-08-13 15:53:36 +0300
committerrobot-contrib <robot-contrib@yandex-team.com>2022-08-13 15:53:36 +0300
commit63727ce4a70378db0021af1d58d675ed4100939a (patch)
tree43d7186c2a145870276b344f7d65c6a33ae5e2c6 /contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp
parent05c17382d5a2fcbb4b947f1a856e0ac62e02aeb7 (diff)
downloadydb-63727ce4a70378db0021af1d58d675ed4100939a.tar.gz
Update contrib/restricted/nlohmann_json to 3.11.2
Diffstat (limited to 'contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp')
-rw-r--r--contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp85
1 files changed, 52 insertions, 33 deletions
diff --git a/contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp b/contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp
index b4b1804963..96d7e01040 100644
--- a/contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp
+++ b/contrib/restricted/nlohmann_json/include/nlohmann/detail/exceptions.hpp
@@ -1,5 +1,14 @@
+// __ _____ _____ _____
+// __| | __| | | | JSON for Modern C++
+// | | |__ | | | | | | version 3.11.2
+// |_____|_____|_____|_|___| https://github.com/nlohmann/json
+//
+// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
+// SPDX-License-Identifier: MIT
+
#pragma once
+#include <cstddef> // nullptr_t
#include <exception> // exception
#include <stdexcept> // runtime_error
#include <string> // to_string
@@ -9,11 +18,15 @@
#include <nlohmann/detail/string_escape.hpp>
#include <nlohmann/detail/input/position_t.hpp>
#include <nlohmann/detail/macro_scope.hpp>
+#include <nlohmann/detail/meta/cpp_future.hpp>
+#include <nlohmann/detail/meta/type_traits.hpp>
+#include <nlohmann/detail/string_concat.hpp>
-namespace nlohmann
-{
+
+NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
+
////////////////
// exceptions //
////////////////
@@ -38,15 +51,20 @@ class exception : public std::exception
static std::string name(const std::string& ename, int id_)
{
- return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
+ return concat("[json.exception.", ename, '.', std::to_string(id_), "] ");
+ }
+
+ static std::string diagnostics(std::nullptr_t /*leaf_element*/)
+ {
+ return "";
}
template<typename BasicJsonType>
- static std::string diagnostics(const BasicJsonType& leaf_element)
+ static std::string diagnostics(const BasicJsonType* leaf_element)
{
#if JSON_DIAGNOSTICS
std::vector<std::string> tokens;
- for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent)
+ for (const auto* current = leaf_element; current != nullptr && current->m_parent != nullptr; current = current->m_parent)
{
switch (current->m_parent->type())
{
@@ -94,11 +112,12 @@ class exception : public std::exception
return "";
}
- return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
- [](const std::string & a, const std::string & b)
+ auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
+ [](const std::string & a, const std::string & b)
{
- return a + "/" + detail::escape(b);
- }) + ") ";
+ return concat(a, '/', detail::escape(b));
+ });
+ return concat('(', str, ") ");
#else
static_cast<void>(leaf_element);
return "";
@@ -124,20 +143,20 @@ class parse_error : public exception
@param[in] what_arg the explanatory string
@return parse_error object
*/
- template<typename BasicJsonType>
- static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
+ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
+ static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
{
- std::string w = exception::name("parse_error", id_) + "parse error" +
- position_string(pos) + ": " + exception::diagnostics(context) + what_arg;
+ std::string w = concat(exception::name("parse_error", id_), "parse error",
+ position_string(pos), ": ", exception::diagnostics(context), what_arg);
return {id_, pos.chars_read_total, w.c_str()};
}
- template<typename BasicJsonType>
- static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context)
+ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
+ static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context)
{
- std::string w = exception::name("parse_error", id_) + "parse error" +
- (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
- ": " + exception::diagnostics(context) + what_arg;
+ std::string w = concat(exception::name("parse_error", id_), "parse error",
+ (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""),
+ ": ", exception::diagnostics(context), what_arg);
return {id_, byte_, w.c_str()};
}
@@ -158,8 +177,8 @@ class parse_error : public exception
static std::string position_string(const position_t& pos)
{
- return " at line " + std::to_string(pos.lines_read + 1) +
- ", column " + std::to_string(pos.chars_read_current_line);
+ return concat(" at line ", std::to_string(pos.lines_read + 1),
+ ", column ", std::to_string(pos.chars_read_current_line));
}
};
@@ -168,10 +187,10 @@ class parse_error : public exception
class invalid_iterator : public exception
{
public:
- template<typename BasicJsonType>
- static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context)
+ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
+ static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
{
- std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
+ std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
}
@@ -186,10 +205,10 @@ class invalid_iterator : public exception
class type_error : public exception
{
public:
- template<typename BasicJsonType>
- static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
+ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
+ static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
- std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg;
+ std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
}
@@ -203,10 +222,10 @@ class type_error : public exception
class out_of_range : public exception
{
public:
- template<typename BasicJsonType>
- static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
+ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
+ static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
{
- std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg;
+ std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
}
@@ -220,10 +239,10 @@ class out_of_range : public exception
class other_error : public exception
{
public:
- template<typename BasicJsonType>
- static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
+ template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
+ static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
- std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg;
+ std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
}
@@ -233,4 +252,4 @@ class other_error : public exception
};
} // namespace detail
-} // namespace nlohmann
+NLOHMANN_JSON_NAMESPACE_END