error.ipp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/url
  8. //
  9. #ifndef BOOST_URL_IMPL_ERROR_IPP
  10. #define BOOST_URL_IMPL_ERROR_IPP
  11. #include <boost/url/error.hpp>
  12. namespace boost {
  13. namespace urls {
  14. namespace detail {
  15. const char*
  16. error_cat_type::
  17. name() const noexcept
  18. {
  19. return "boost.url";
  20. }
  21. std::string
  22. error_cat_type::
  23. message(int code) const
  24. {
  25. return message(code, nullptr, 0);
  26. }
  27. char const*
  28. error_cat_type::
  29. message(
  30. int code,
  31. char*,
  32. std::size_t) const noexcept
  33. {
  34. switch(static_cast<error>(code))
  35. {
  36. case error::success: return "success";
  37. case error::illegal_null: return "illegal null";
  38. case error::illegal_reserved_char: return "illegal reserved char";
  39. case error::non_canonical: return "non canonical";
  40. case error::bad_pct_hexdig: return "bad hexdig in pct-encoding";
  41. case error::incomplete_encoding: return "incomplete pct-encoding";
  42. case error::missing_pct_hexdig: return "missing hexdig in pct-encoding";
  43. case error::no_space: return "no space";
  44. case error::not_a_base: return "not a base";
  45. }
  46. return "";
  47. }
  48. error_condition
  49. error_cat_type::
  50. default_error_condition(
  51. int ev) const noexcept
  52. {
  53. switch(static_cast<error>(ev))
  54. {
  55. default:
  56. return {ev, *this};
  57. case error::bad_pct_hexdig:
  58. case error::incomplete_encoding:
  59. case error::missing_pct_hexdig:
  60. return grammar::condition::fatal;
  61. }
  62. }
  63. //-----------------------------------------------
  64. // msvc 14.0 has a bug that warns about inability
  65. // to use constexpr construction here, even though
  66. // there's no constexpr construction
  67. #if defined(_MSC_VER) && _MSC_VER <= 1900
  68. # pragma warning( push )
  69. # pragma warning( disable : 4592 )
  70. #endif
  71. #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
  72. constinit error_cat_type error_cat;
  73. #else
  74. error_cat_type error_cat;
  75. #endif
  76. #if defined(_MSC_VER) && _MSC_VER <= 1900
  77. # pragma warning( pop )
  78. #endif
  79. } // detail
  80. } // urls
  81. } // boost
  82. #endif