include/boost/url/impl/error.hpp
100.0% Lines (27 / 27)
100.0% Functions (6 / 6)
Functions (6)
Function
Calls
Lines
Blocks
boost::urls::detail::error_cat_type::name() const
:38
246x
100.0%
100.0%
boost::urls::detail::error_cat_type::message[abi:cxx11](int) const
:44
247x
100.0%
80.0%
boost::urls::detail::error_cat_type::message(int, char*, unsigned long) const
:51
247x
100.0%
100.0%
boost::urls::detail::error_cat_type::error_cat_type()
:76
78x
100.0%
100.0%
boost::urls::make_error_code(boost::urls::error)
:97
264x
100.0%
100.0%
boost::urls::detail::error_cat_type::default_error_condition(int) const
:108
9x
100.0%
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/boostorg/url | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_URL_IMPL_ERROR_HPP | ||
| 12 | #define BOOST_URL_IMPL_ERROR_HPP | ||
| 13 | |||
| 14 | #include <boost/url/grammar/error.hpp> | ||
| 15 | #include <type_traits> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | |||
| 19 | //----------------------------------------------- | ||
| 20 | namespace system { | ||
| 21 | template<> | ||
| 22 | struct is_error_code_enum<::boost::urls::error> | ||
| 23 | { | ||
| 24 | static bool const value = true; | ||
| 25 | }; | ||
| 26 | } // system | ||
| 27 | //----------------------------------------------- | ||
| 28 | |||
| 29 | namespace urls { | ||
| 30 | |||
| 31 | namespace detail { | ||
| 32 | |||
| 33 | struct BOOST_SYMBOL_VISIBLE | ||
| 34 | error_cat_type | ||
| 35 | : system::error_category | ||
| 36 | { | ||
| 37 | BOOST_URL_CXX20_CONSTEXPR | ||
| 38 | 246x | const char* name( | |
| 39 | ) const noexcept override | ||
| 40 | { | ||
| 41 | 246x | return "boost.url"; | |
| 42 | } | ||
| 43 | |||
| 44 | 247x | std::string message( | |
| 45 | int code) const override | ||
| 46 | { | ||
| 47 | 494x | return message(code, nullptr, 0); | |
| 48 | } | ||
| 49 | |||
| 50 | BOOST_URL_CXX20_CONSTEXPR | ||
| 51 | 247x | char const* message( | |
| 52 | int code, | ||
| 53 | char*, | ||
| 54 | std::size_t) const noexcept override | ||
| 55 | { | ||
| 56 | 247x | switch(static_cast<error>(code)) | |
| 57 | { | ||
| 58 | 1x | case error::success: return "success"; | |
| 59 | 1x | case error::illegal_null: return "illegal null"; | |
| 60 | 1x | case error::illegal_reserved_char: return "illegal reserved char"; | |
| 61 | 1x | case error::non_canonical: return "non canonical"; | |
| 62 | 98x | case error::bad_pct_hexdig: return "bad hexdig in pct-encoding"; | |
| 63 | 141x | case error::incomplete_encoding: return "incomplete pct-encoding"; | |
| 64 | 1x | case error::missing_pct_hexdig: return "missing hexdig in pct-encoding"; | |
| 65 | 1x | case error::no_space: return "no space"; | |
| 66 | 1x | case error::not_a_base: return "not a base"; | |
| 67 | } | ||
| 68 | 1x | return ""; | |
| 69 | } | ||
| 70 | |||
| 71 | BOOST_URL_CXX20_CONSTEXPR | ||
| 72 | system::error_condition | ||
| 73 | default_error_condition( | ||
| 74 | int ev) const noexcept override; | ||
| 75 | |||
| 76 | 78x | BOOST_SYSTEM_CONSTEXPR error_cat_type() noexcept | |
| 77 | 78x | : error_category(0xbc15399d7a4ce829) | |
| 78 | { | ||
| 79 | 78x | } | |
| 80 | }; | ||
| 81 | |||
| 82 | #if defined(BOOST_URL_HAS_CXX20_CONSTEXPR) | ||
| 83 | // Visible so a shared library built as C++20 | ||
| 84 | // still exports the symbol that consumers built | ||
| 85 | // as C++17 reference through the extern below | ||
| 86 | BOOST_SYMBOL_VISIBLE | ||
| 87 | inline constexpr error_cat_type error_cat{}; | ||
| 88 | #else | ||
| 89 | BOOST_URL_DECL extern error_cat_type error_cat; | ||
| 90 | #endif | ||
| 91 | |||
| 92 | } // detail | ||
| 93 | |||
| 94 | inline | ||
| 95 | BOOST_SYSTEM_CONSTEXPR | ||
| 96 | system::error_code | ||
| 97 | 264x | make_error_code( | |
| 98 | error ev) noexcept | ||
| 99 | { | ||
| 100 | return system::error_code{ | ||
| 101 | static_cast<std::underlying_type< | ||
| 102 | error>::type>(ev), | ||
| 103 | 264x | detail::error_cat}; | |
| 104 | } | ||
| 105 | |||
| 106 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | ||
| 107 | system::error_condition | ||
| 108 | 9x | detail::error_cat_type:: | |
| 109 | default_error_condition( | ||
| 110 | int ev) const noexcept | ||
| 111 | { | ||
| 112 | 9x | switch(static_cast<error>(ev)) | |
| 113 | { | ||
| 114 | 6x | default: | |
| 115 | 6x | return {ev, *this}; | |
| 116 | 3x | case error::bad_pct_hexdig: | |
| 117 | case error::incomplete_encoding: | ||
| 118 | case error::missing_pct_hexdig: | ||
| 119 | 3x | return grammar::condition::fatal; | |
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | } // urls | ||
| 124 | } // boost | ||
| 125 | |||
| 126 | #endif | ||
| 127 |