Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2022 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 | |||
10 | #ifndef BOOST_URL_DETAIL_URL_IMPL_HPP | ||
11 | #define BOOST_URL_DETAIL_URL_IMPL_HPP | ||
12 | |||
13 | #include <boost/url/host_type.hpp> | ||
14 | #include <boost/url/pct_string_view.hpp> | ||
15 | #include <boost/url/scheme.hpp> | ||
16 | #include <boost/core/detail/string_view.hpp> | ||
17 | #include <boost/url/detail/parts_base.hpp> | ||
18 | #include <boost/assert.hpp> | ||
19 | #include <cstdint> | ||
20 | |||
21 | namespace boost { | ||
22 | namespace urls { | ||
23 | |||
24 | class url_view; | ||
25 | class authority_view; | ||
26 | |||
27 | namespace detail { | ||
28 | |||
29 | constexpr char const* const empty_c_str_ = ""; | ||
30 | |||
31 | // This is the private 'guts' of a | ||
32 | // url_view, exposed so different parts | ||
33 | // of the implementation can work on it. | ||
34 | struct BOOST_URL_DECL url_impl : parts_base | ||
35 | { | ||
36 | static | ||
37 | constexpr | ||
38 | std::size_t const zero_ = 0; | ||
39 | |||
40 | // never nullptr | ||
41 | char const* cs_ = empty_c_str_; | ||
42 | |||
43 | std::size_t offset_[id_end + 1] = {}; | ||
44 | std::size_t decoded_[id_end] = {}; | ||
45 | std::size_t nseg_ = 0; | ||
46 | std::size_t nparam_ = 0; | ||
47 | unsigned char ip_addr_[16] = {}; | ||
48 | // VFALCO don't we need a bool? | ||
49 | std::uint16_t port_number_ = 0; | ||
50 | host_type host_type_ = | ||
51 | urls::host_type::none; | ||
52 | scheme scheme_ = | ||
53 | urls::scheme::none; | ||
54 | |||
55 | from from_ = from::string; | ||
56 | |||
57 | 16526 | url_impl( | |
58 | from b) noexcept | ||
59 | 16526 | : from_(b) | |
60 | { | ||
61 | 16526 | } | |
62 | |||
63 | // in url_view.ipp | ||
64 | url_view construct() const noexcept; | ||
65 | |||
66 | // in authority_view.ipp | ||
67 | authority_view | ||
68 | construct_authority() const noexcept; | ||
69 | |||
70 | std::size_t len(int, int) const noexcept; | ||
71 | std::size_t len(int) const noexcept; | ||
72 | std::size_t offset(int) const noexcept; | ||
73 | core::string_view get(int) const noexcept; | ||
74 | core::string_view get(int, int) const noexcept; | ||
75 | pct_string_view pct_get(int) const noexcept; | ||
76 | pct_string_view pct_get(int, int) const noexcept; | ||
77 | void set_size(int, std::size_t) noexcept; | ||
78 | void split(int, std::size_t) noexcept; | ||
79 | void adjust(int, int, std::size_t) noexcept; | ||
80 | void collapse(int, int, std::size_t) noexcept; | ||
81 | |||
82 | void apply_scheme(core::string_view) noexcept; | ||
83 | void apply_userinfo(pct_string_view const&, | ||
84 | pct_string_view const*) noexcept; | ||
85 | void apply_host(host_type, pct_string_view, | ||
86 | unsigned char const*) noexcept; | ||
87 | void apply_port(core::string_view, unsigned short) noexcept; | ||
88 | void apply_authority(authority_view const&) noexcept; | ||
89 | void apply_path(pct_string_view, std::size_t) noexcept; | ||
90 | void apply_query(pct_string_view, std::size_t) noexcept; | ||
91 | void apply_frag(pct_string_view) noexcept; | ||
92 | }; | ||
93 | |||
94 | //------------------------------------------------ | ||
95 | |||
96 | // this allows a path to come from a | ||
97 | // url_impl or a separate core::string_view | ||
98 | class path_ref | ||
99 | : private parts_base | ||
100 | { | ||
101 | url_impl const* impl_ = nullptr; | ||
102 | char const* data_ = nullptr; | ||
103 | std::size_t size_ = 0; | ||
104 | std::size_t nseg_ = 0; | ||
105 | std::size_t dn_ = 0; | ||
106 | |||
107 | public: | ||
108 | path_ref() = default; | ||
109 | path_ref(url_impl const& impl) noexcept; | ||
110 | path_ref(core::string_view, | ||
111 | std::size_t, std::size_t) noexcept; | ||
112 | pct_string_view buffer() const noexcept; | ||
113 | std::size_t size() const noexcept; | ||
114 | char const* data() const noexcept; | ||
115 | char const* end() const noexcept; | ||
116 | std::size_t nseg() const noexcept; | ||
117 | |||
118 | bool | ||
119 | 1130 | alias_of( | |
120 | url_impl const& impl) const noexcept | ||
121 | { | ||
122 | 1130 | return impl_ == &impl; | |
123 | } | ||
124 | |||
125 | bool | ||
126 | 4944 | alias_of( | |
127 | path_ref const& ref) const noexcept | ||
128 | { | ||
129 |
2/2✓ Branch 0 taken 2457 times.
✓ Branch 1 taken 2487 times.
|
4944 | if(impl_) |
130 | 2457 | return impl_ == ref.impl_; | |
131 |
4/8✓ Branch 0 taken 2487 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2487 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2487 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2487 times.
✗ Branch 7 not taken.
|
2487 | BOOST_ASSERT(data_ != ref.data_ || ( |
132 | size_ == ref.size_ && | ||
133 | nseg_ == ref.nseg_ && | ||
134 | dn_ == ref.dn_)); | ||
135 | 2487 | return data_ == ref.data_; | |
136 | } | ||
137 | }; | ||
138 | |||
139 | //------------------------------------------------ | ||
140 | |||
141 | // this allows a params to come from a | ||
142 | // url_impl or a separate core::string_view | ||
143 | class BOOST_URL_DECL query_ref | ||
144 | : private parts_base | ||
145 | { | ||
146 | url_impl const* impl_ = nullptr; | ||
147 | char const* data_ = nullptr; | ||
148 | std::size_t size_ = 0; | ||
149 | std::size_t nparam_ = 0; | ||
150 | std::size_t dn_ = 0; | ||
151 | bool question_mark_ = false; | ||
152 | |||
153 | public: | ||
154 | query_ref( | ||
155 | core::string_view s, // buffer, no '?' | ||
156 | std::size_t dn, // decoded size | ||
157 | std::size_t nparam | ||
158 | ) noexcept; | ||
159 | 9 | query_ref() = default; | |
160 | query_ref(url_impl const& impl) noexcept; | ||
161 | pct_string_view buffer() const noexcept; | ||
162 | std::size_t size() const noexcept; // with '?' | ||
163 | char const* begin() const noexcept; // no '?' | ||
164 | char const* end() const noexcept; | ||
165 | std::size_t nparam() const noexcept; | ||
166 | |||
167 | bool | ||
168 | 276 | alias_of( | |
169 | url_impl const& impl) const noexcept | ||
170 | { | ||
171 | 276 | return impl_ == &impl; | |
172 | } | ||
173 | |||
174 | bool | ||
175 | 2449 | alias_of( | |
176 | query_ref const& ref) const noexcept | ||
177 | { | ||
178 |
2/2✓ Branch 0 taken 718 times.
✓ Branch 1 taken 1731 times.
|
2449 | if(impl_) |
179 | 718 | return impl_ == ref.impl_; | |
180 |
4/8✓ Branch 0 taken 1731 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1731 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1731 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1731 times.
✗ Branch 7 not taken.
|
1731 | BOOST_ASSERT(data_ != ref.data_ || ( |
181 | size_ == ref.size_ && | ||
182 | nparam_ == ref.nparam_ && | ||
183 | dn_ == ref.dn_)); | ||
184 | 1731 | return data_ == ref.data_; | |
185 | } | ||
186 | }; | ||
187 | |||
188 | } // detail | ||
189 | |||
190 | } // urls | ||
191 | } // boost | ||
192 | |||
193 | #endif | ||
194 |