| 1 |
// Copyright 2013-2016 Glyn Matthews. |
| 2 |
// Distributed under the Boost Software License, Version 1.0. |
| 3 |
// (See accompanying file LICENSE_1_0.txt or copy at |
| 4 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
|
| 6 |
#include <string> |
| 7 |
#include <network/uri/uri_errors.hpp> |
| 8 |
|
| 9 |
namespace network { |
| 10 |
|
| 11 |
class uri_category_impl : public std::error_category { |
| 12 |
public: |
| 13 |
uri_category_impl() = default; |
| 14 |
|
| 15 |
virtual ~uri_category_impl() noexcept; |
| 16 |
|
| 17 |
virtual const char *name() const noexcept; |
| 18 |
|
| 19 |
virtual std::string message(int ev) const; |
| 20 |
}; |
| 21 |
|
| 22 |
uri_category_impl::~uri_category_impl() noexcept {} |
| 23 |
|
| 24 |
const char *uri_category_impl::name() const noexcept { |
| 25 |
static const char name[] = "uri_error"; |
| 26 |
return name; |
| 27 |
} |
| 28 |
|
| 29 |
std::string uri_category_impl::message(int ev) const { |
| 30 |
switch (uri_error(ev)) { |
| 31 |
case uri_error::invalid_syntax: |
| 32 |
return "Unable to parse URI string."; |
| 33 |
case uri_error::not_enough_input: |
| 34 |
return "Percent decoding: Not enough input."; |
| 35 |
case uri_error::non_hex_input: |
| 36 |
return "Percent decoding: Non-hex input."; |
| 37 |
case uri_error::conversion_failed: |
| 38 |
return "Percent decoding: Conversion failed."; |
| 39 |
default: |
| 40 |
break; |
| 41 |
} |
| 42 |
return "Unknown URI error."; |
| 43 |
} |
| 44 |
|
| 45 |
const std::error_category &uri_category() { |
| 46 |
static uri_category_impl uri_category; |
| 47 |
return uri_category; |
| 48 |
} |
| 49 |
|
| 50 |
std::error_code make_error_code(uri_error e) { |
| 51 |
return std::error_code(static_cast<int>(e), uri_category()); |
| 52 |
} |
| 53 |
|
| 54 |
uri_syntax_error::uri_syntax_error() |
| 55 |
: std::system_error(make_error_code(uri_error::invalid_syntax)) {} |
| 56 |
|
| 57 |
uri_syntax_error::~uri_syntax_error() noexcept {} |
| 58 |
|
| 59 |
uri_builder_error::uri_builder_error() |
| 60 |
: std::system_error(make_error_code(uri_error::invalid_uri)) {} |
| 61 |
|
| 62 |
uri_builder_error::~uri_builder_error() noexcept {} |
| 63 |
|
| 64 |
percent_decoding_error::percent_decoding_error(uri_error error) |
| 65 |
: std::system_error(make_error_code(error)) {} |
| 66 |
|
| 67 |
percent_decoding_error::~percent_decoding_error() noexcept {} |
| 68 |
|
| 69 |
} // namespace network |