| 1 |
// Copyright 2016 Glyn Matthews. |
| 2 |
// Distributed under the Boost Software License, Version 1.0. |
| 3 |
// (See accompanying file LICENSE_1_0.txt of copy at |
| 4 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
|
| 6 |
#ifndef TEST_URI_INC |
| 7 |
#define TEST_URI_INC |
| 8 |
|
| 9 |
#include <iterator> |
| 10 |
#include <network/uri/detail/uri_parts.hpp> |
| 11 |
#include "../src/detail/uri_parse.hpp" |
| 12 |
|
| 13 |
using network::detail::parse; |
| 14 |
using network::detail::uri_part; |
| 15 |
using network::detail::uri_parts; |
| 16 |
|
| 17 |
namespace test { |
| 18 |
struct uri { |
| 19 |
|
| 20 |
explicit uri(const std::string &uri) |
| 21 |
: uri_(uri), view(uri_) { |
| 22 |
it = std::begin(view); |
| 23 |
last = std::end(view); |
| 24 |
} |
| 25 |
|
| 26 |
bool parse_uri() { |
| 27 |
return parse(it, last, parts); |
| 28 |
} |
| 29 |
|
| 30 |
std::string parsed_till() const { |
| 31 |
return std::string(std::begin(view), it); |
| 32 |
} |
| 33 |
|
| 34 |
bool has_scheme() const { |
| 35 |
return static_cast<bool>(parts.scheme); |
| 36 |
} |
| 37 |
|
| 38 |
std::string scheme() const { |
| 39 |
return (*parts.scheme).to_string(); |
| 40 |
} |
| 41 |
|
| 42 |
bool has_user_info() const { |
| 43 |
return static_cast<bool>(parts.hier_part.user_info); |
| 44 |
} |
| 45 |
|
| 46 |
std::string user_info() const { |
| 47 |
return (*parts.hier_part.user_info).to_string(); |
| 48 |
} |
| 49 |
|
| 50 |
bool has_host() const { |
| 51 |
return static_cast<bool>(parts.hier_part.host); |
| 52 |
} |
| 53 |
|
| 54 |
std::string host() const { |
| 55 |
return (*parts.hier_part.host).to_string(); |
| 56 |
} |
| 57 |
|
| 58 |
bool has_port() const { |
| 59 |
return static_cast<bool>(parts.hier_part.port); |
| 60 |
} |
| 61 |
|
| 62 |
std::string port() const { |
| 63 |
return (*parts.hier_part.port).to_string(); |
| 64 |
} |
| 65 |
|
| 66 |
bool has_path() const { |
| 67 |
return static_cast<bool>(parts.hier_part.path); |
| 68 |
} |
| 69 |
|
| 70 |
std::string path() const { |
| 71 |
return (*parts.hier_part.path).to_string(); |
| 72 |
} |
| 73 |
|
| 74 |
bool has_query() const { |
| 75 |
return static_cast<bool>(parts.query); |
| 76 |
} |
| 77 |
|
| 78 |
std::string query() const { |
| 79 |
return (*parts.query).to_string(); |
| 80 |
} |
| 81 |
|
| 82 |
bool has_fragment() const { |
| 83 |
return static_cast<bool>(parts.fragment); |
| 84 |
} |
| 85 |
|
| 86 |
std::string fragment() const { |
| 87 |
return (*parts.fragment).to_string(); |
| 88 |
} |
| 89 |
|
| 90 |
std::string uri_; |
| 91 |
network::string_view view; |
| 92 |
network::string_view::const_iterator it, last; |
| 93 |
|
| 94 |
uri_parts parts; |
| 95 |
|
| 96 |
}; |
| 97 |
} // namespace test |
| 98 |
|
| 99 |
#endif // TEST_URI_INC |