Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:01

0001 //
0002 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/json
0008 //
0009 
0010 #ifndef BOOST_JSON_IMPL_ERROR_IPP
0011 #define BOOST_JSON_IMPL_ERROR_IPP
0012 
0013 #include <boost/json/error.hpp>
0014 
0015 namespace boost {
0016 namespace json {
0017 namespace detail {
0018 
0019 // msvc 14.0 has a bug that warns about inability to use constexpr
0020 // construction here, even though there's no constexpr construction
0021 #if defined(_MSC_VER) && _MSC_VER <= 1900
0022 # pragma warning( push )
0023 # pragma warning( disable : 4592 )
0024 #endif
0025 BOOST_JSON_CONSTINIT
0026 error_code_category_t error_code_category;
0027 
0028 BOOST_JSON_CONSTINIT
0029 error_condition_category_t error_condition_category;
0030 #if defined(_MSC_VER) && _MSC_VER <= 1900
0031 # pragma warning( pop )
0032 #endif
0033 
0034 char const*
0035 error_code_category_t::name() const noexcept
0036 {
0037     return "boost.json";
0038 }
0039 
0040 char const*
0041 error_code_category_t::message( int ev, char*, std::size_t ) const noexcept
0042 {
0043     switch(static_cast<error>(ev))
0044     {
0045     default:
0046 case error::syntax: return "syntax error";
0047 case error::extra_data: return "extra data";
0048 case error::incomplete: return "incomplete JSON";
0049 case error::exponent_overflow: return "exponent overflow";
0050 case error::too_deep: return "too deep";
0051 case error::illegal_leading_surrogate: return "illegal leading surrogate";
0052 case error::illegal_trailing_surrogate: return "illegal trailing surrogate";
0053 case error::expected_hex_digit: return "expected hex digit";
0054 case error::expected_utf16_escape: return "expected utf16 escape";
0055 case error::object_too_large: return "object too large";
0056 case error::array_too_large: return "array too large";
0057 case error::key_too_large: return "key too large";
0058 case error::string_too_large: return "string too large";
0059 case error::number_too_large: return "number too large";
0060 case error::input_error: return "input error";
0061 
0062 case error::exception: return "got exception";
0063 case error::out_of_range: return "out of range";
0064 case error::test_failure: return "test failure";
0065 
0066 case error::missing_slash: return "missing slash character";
0067 case error::invalid_escape: return "invalid escape sequence";
0068 case error::token_not_number: return "token is not a number";
0069 case error::value_is_scalar: return "current value is scalar";
0070 case error::not_found: return "no referenced value";
0071 case error::token_overflow: return "token overflow";
0072 case error::past_the_end: return "past-the-end token not supported";
0073 
0074 case error::not_number: return "not a number";
0075 case error::not_exact: return "not exact";
0076 case error::not_null: return "value is not null";
0077 case error::not_bool: return "value is not boolean";
0078 case error::not_array: return "value is not an array";
0079 case error::not_object: return "value is not an object";
0080 case error::not_string: return "value is not a string";
0081 case error::not_int64: return "value is not a std::int64_t number";
0082 case error::not_uint64: return "value is not a std::uint64_t number";
0083 case error::not_double: return "value is not a double";
0084 case error::not_integer: return "value is not integer";
0085 case error::size_mismatch: return "source composite size does not match target size";
0086 case error::exhausted_variants: return "exhausted all variants";
0087 case error::unknown_name: return "unknown name";
0088     }
0089 }
0090 
0091 std::string
0092 error_code_category_t::message( int ev ) const
0093 {
0094     return message( ev, nullptr, 0 );
0095 }
0096 
0097 error_condition
0098 error_code_category_t::default_error_condition( int ev) const noexcept
0099 {
0100     switch(static_cast<error>(ev))
0101     {
0102     default:
0103         return {ev, *this};
0104 
0105 case error::syntax:
0106 case error::extra_data:
0107 case error::incomplete:
0108 case error::exponent_overflow:
0109 case error::too_deep:
0110 case error::illegal_leading_surrogate:
0111 case error::illegal_trailing_surrogate:
0112 case error::expected_hex_digit:
0113 case error::expected_utf16_escape:
0114 case error::object_too_large:
0115 case error::array_too_large:
0116 case error::key_too_large:
0117 case error::string_too_large:
0118 case error::number_too_large:
0119 case error::input_error:
0120     return condition::parse_error;
0121 
0122 case error::missing_slash:
0123 case error::invalid_escape:
0124     return condition::pointer_parse_error;
0125 
0126 case error::token_not_number:
0127 case error::value_is_scalar:
0128 case error::not_found:
0129 case error::token_overflow:
0130 case error::past_the_end:
0131     return condition::pointer_use_error;
0132 
0133 case error::not_number:
0134 case error::not_exact:
0135 case error::not_null:
0136 case error::not_bool:
0137 case error::not_array:
0138 case error::not_object:
0139 case error::not_string:
0140 case error::not_int64:
0141 case error::not_uint64:
0142 case error::not_double:
0143 case error::not_integer:
0144 case error::size_mismatch:
0145 case error::exhausted_variants:
0146 case error::unknown_name:
0147     return condition::conversion_error;
0148 
0149 case error::exception:
0150 case error::out_of_range:
0151     return condition::generic_error;
0152     }
0153 }
0154 
0155 char const*
0156 error_condition_category_t::name() const noexcept
0157 {
0158     return "boost.json";
0159 }
0160 
0161 char const*
0162 error_condition_category_t::message( int cv, char*, std::size_t ) const noexcept
0163 {
0164     switch(static_cast<condition>(cv))
0165     {
0166     default:
0167     case condition::parse_error:
0168         return "A JSON parse error occurred";
0169     case condition::pointer_parse_error:
0170         return "A JSON Pointer parse error occurred";
0171     case condition::pointer_use_error:
0172         return "An error occurred when JSON Pointer was used with"
0173             " a value";
0174     case condition::conversion_error:
0175         return "An error occurred during conversion";
0176     }
0177 }
0178 
0179 std::string
0180 error_condition_category_t::message( int cv ) const
0181 {
0182     return message( cv, nullptr, 0 );
0183 }
0184 
0185 } // namespace detail
0186 
0187 } // namespace json
0188 } // namespace boost
0189 
0190 #endif