blob: 17a69687fe468a359831d582b6e88ad8bcdb9539 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright 2016 Glyn Matthews.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef NETWORK_DETAIL_URI_PARTS_INC
#define NETWORK_DETAIL_URI_PARTS_INC
#include <string>
#include <utility>
#include <iterator>
#include <network/optional.hpp>
#include <network/string_view.hpp>
namespace network {
namespace detail {
class uri_part {
public:
typedef string_view::value_type value_type;
typedef string_view::iterator iterator;
typedef string_view::const_iterator const_iterator;
typedef string_view::const_pointer const_pointer;
typedef string_view::size_type size_type;
typedef string_view::difference_type difference_type;
uri_part() noexcept = default;
uri_part(const_iterator first, const_iterator last) noexcept
: first(first), last(last) {}
const_iterator begin() const noexcept { return first; }
const_iterator end() const noexcept { return last; }
bool empty() const noexcept { return first == last; }
std::string to_string() const { return std::string(first, last); }
const_pointer ptr() const noexcept {
assert(first != last);
return first;
}
difference_type length() const noexcept {
return last - first;
}
string_view to_string_view() const noexcept { return string_view(ptr(), length()); }
private:
const_iterator first, last;
};
struct hierarchical_part {
hierarchical_part() = default;
optional<uri_part> user_info;
optional<uri_part> host;
optional<uri_part> port;
optional<uri_part> path;
void clear() {
user_info = nullopt;
host = nullopt;
port = nullopt;
path = nullopt;
}
};
struct uri_parts {
uri_parts() = default;
optional<uri_part> scheme;
hierarchical_part hier_part;
optional<uri_part> query;
optional<uri_part> fragment;
void clear() {
scheme = nullopt;
hier_part.clear();
query = nullopt;
fragment = nullopt;
}
};
} // namespace detail
} // namespace network
#endif // NETWORK_DETAIL_URI_PARTS_INC
|