include/boost/url/impl/segments_ref.hpp

100.0% Lines (71/71) 100.0% List of functions (21/21)
segments_ref.hpp
f(x) Functions (21)
Function Calls Lines Blocks
void boost::urls::segments_ref::assign<boost::core::basic_string_view<char> const*>(boost::core::basic_string_view<char> const*, boost::core::basic_string_view<char> const*) :31 32x 100.0% 58.0% void boost::urls::segments_ref::assign<boost::urls::segments_base::iterator>(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator) :31 2x 100.0% 58.0% boost::urls::segments_base::iterator boost::urls::segments_ref::insert<boost::core::basic_string_view<char> const*>(boost::urls::segments_base::iterator, boost::core::basic_string_view<char> const*, boost::core::basic_string_view<char> const*) :55 31x 100.0% 100.0% boost::urls::segments_base::iterator boost::urls::segments_ref::replace<boost::core::basic_string_view<char> const*>(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator, boost::core::basic_string_view<char> const*, boost::core::basic_string_view<char> const*) :84 14x 100.0% 70.0% boost::urls::segments_base::iterator boost::urls::segments_ref::insert<boost::core::basic_string_view<char> const*>(boost::urls::segments_base::iterator, boost::core::basic_string_view<char> const*, boost::core::basic_string_view<char> const*, std::forward_iterator_tag) :115 31x 100.0% 70.0% boost::urls::segments_ref::segments_ref(boost::urls::url_base&) :137 1146x 100.0% 100.0% boost::urls::segments_ref::operator boost::urls::segments_view() const :147 1x 100.0% 100.0% boost::urls::segments_ref::operator=(boost::urls::segments_ref const&) :156 1x 100.0% 100.0% boost::urls::segments_ref::operator=(boost::urls::segments_view const&) :166 1x 100.0% 100.0% boost::urls::segments_ref::operator=(std::initializer_list<boost::core::basic_string_view<char> >) :175 17x 100.0% 100.0% boost::urls::segments_ref::clear() :191 507x 100.0% 100.0% boost::urls::segments_ref::assign(std::initializer_list<boost::core::basic_string_view<char> >) :199 8x 100.0% 100.0% boost::urls::segments_ref::insert(boost::urls::segments_base::iterator, boost::core::basic_string_view<char>) :208 799x 100.0% 70.0% boost::urls::segments_ref::insert(boost::urls::segments_base::iterator, std::initializer_list<boost::core::basic_string_view<char> >) :222 16x 100.0% 100.0% boost::urls::segments_ref::erase(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator) :237 861x 100.0% 100.0% boost::urls::segments_ref::replace(boost::urls::segments_base::iterator, boost::core::basic_string_view<char>) :253 108x 100.0% 76.0% boost::urls::segments_ref::replace(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator, boost::core::basic_string_view<char>) :267 13x 100.0% 70.0% boost::urls::segments_ref::replace(boost::urls::segments_base::iterator, boost::urls::segments_base::iterator, std::initializer_list<boost::core::basic_string_view<char> >) :282 7x 100.0% 100.0% boost::urls::segments_ref::erase(boost::urls::segments_base::iterator) :299 347x 100.0% 100.0% boost::urls::segments_ref::push_back(boost::core::basic_string_view<char>) :309 587x 100.0% 100.0% boost::urls::segments_ref::pop_back() :318 183x 100.0% 100.0%
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/boostorg/url
9 //
10
11 #ifndef BOOST_URL_IMPL_SEGMENTS_REF_HPP
12 #define BOOST_URL_IMPL_SEGMENTS_REF_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/detail/any_segments_iter.hpp>
16 #include <boost/url/detail/segments_iter_impl.hpp>
17 #include <boost/url/detail/path.hpp>
18 #include <type_traits>
19
20 namespace boost {
21 namespace urls {
22
23 //------------------------------------------------
24 //
25 // Modifiers
26 //
27 //------------------------------------------------
28
29 template<class FwdIt>
30 void
31 34x segments_ref::
32 assign(FwdIt first, FwdIt last)
33 {
34 /* If you get a compile error here, it
35 means that the iterators you passed
36 do not meet the requirements stated
37 in the documentation.
38 */
39 static_assert(
40 std::is_convertible<
41 typename std::iterator_traits<
42 FwdIt>::reference,
43 core::string_view>::value,
44 "Type requirements not met");
45
46 68x u_->edit_segments(
47 34x begin().it_,
48 68x end().it_,
49 detail::make_segments_iter(
50 first, last));
51 34x }
52
53 template<class FwdIt>
54 auto
55 31x segments_ref::
56 insert(
57 iterator before,
58 FwdIt first,
59 FwdIt last) ->
60 iterator
61 {
62 /* If you get a compile error here, it
63 means that the iterators you passed
64 do not meet the requirements stated
65 in the documentation.
66 */
67 static_assert(
68 std::is_convertible<
69 typename std::iterator_traits<
70 FwdIt>::reference,
71 core::string_view>::value,
72 "Type requirements not met");
73
74 62x return insert(
75 before,
76 first,
77 last,
78 typename std::iterator_traits<
79 62x FwdIt>::iterator_category{});
80 }
81
82 template<class FwdIt>
83 auto
84 14x segments_ref::
85 replace(
86 iterator from,
87 iterator to,
88 FwdIt first,
89 FwdIt last) ->
90 iterator
91 {
92 /* If you get a compile error here, it
93 means that the iterators you passed
94 do not meet the requirements stated
95 in the documentation.
96 */
97 static_assert(
98 std::is_convertible<
99 typename std::iterator_traits<
100 FwdIt>::reference,
101 core::string_view>::value,
102 "Type requirements not met");
103
104 28x return u_->edit_segments(
105 from.it_,
106 to.it_,
107 detail::make_segments_iter(
108 28x first, last));
109 }
110
111 //------------------------------------------------
112
113 template<class FwdIt>
114 auto
115 31x segments_ref::
116 insert(
117 iterator before,
118 FwdIt first,
119 FwdIt last,
120 std::forward_iterator_tag) ->
121 iterator
122 {
123 62x return u_->edit_segments(
124 before.it_,
125 before.it_,
126 detail::make_segments_iter(
127 62x first, last));
128 }
129
130 //------------------------------------------------
131 //
132 // Special Members
133 //
134 //------------------------------------------------
135
136 inline
137 1146x segments_ref::
138 segments_ref(
139 1146x url_base& u) noexcept
140 : segments_base(
141 2292x detail::path_ref(u.impl_))
142 1146x , u_(&u)
143 {
144 1146x }
145
146 inline
147 1x segments_ref::
148 operator
149 segments_view() const noexcept
150 {
151 1x return segments_view(ref_);
152 }
153
154 inline
155 segments_ref&
156 1x segments_ref::
157 operator=(segments_ref const& other)
158 {
159 1x if (!ref_.alias_of(other.ref_))
160 1x assign(other.begin(), other.end());
161 1x return *this;
162 }
163
164 inline
165 segments_ref&
166 1x segments_ref::
167 operator=(segments_view const& other)
168 {
169 1x assign(other.begin(), other.end());
170 1x return *this;
171 }
172
173 inline
174 segments_ref&
175 17x segments_ref::
176 operator=(std::initializer_list<
177 core::string_view> init)
178 {
179 17x assign(init.begin(), init.end());
180 17x return *this;
181 }
182
183 //------------------------------------------------
184 //
185 // Modifiers
186 //
187 //------------------------------------------------
188
189 inline
190 void
191 507x segments_ref::
192 clear() noexcept
193 {
194 507x erase(begin(), end());
195 507x }
196
197 inline
198 void
199 8x segments_ref::
200 assign(std::initializer_list<
201 core::string_view> init)
202 {
203 8x assign(init.begin(), init.end());
204 8x }
205
206 inline
207 auto
208 799x segments_ref::
209 insert(
210 iterator before,
211 core::string_view s) ->
212 iterator
213 {
214 799x return u_->edit_segments(
215 before.it_,
216 before.it_,
217 1598x detail::segment_iter(s));
218 }
219
220 inline
221 auto
222 16x segments_ref::
223 insert(
224 iterator before,
225 std::initializer_list<
226 core::string_view> init) ->
227 iterator
228 {
229 16x return insert(
230 before,
231 init.begin(),
232 16x init.end());
233 }
234
235 inline
236 auto
237 861x segments_ref::
238 erase(
239 iterator first,
240 iterator last) noexcept ->
241 iterator
242 {
243 861x core::string_view s;
244 861x return u_->edit_segments(
245 first.it_,
246 last.it_,
247 1722x detail::make_segments_encoded_iter(
248 861x &s, &s));
249 }
250
251 inline
252 auto
253 108x segments_ref::
254 replace(
255 iterator pos,
256 core::string_view s) ->
257 iterator
258 {
259 324x return u_->edit_segments(
260 pos.it_,
261 108x std::next(pos).it_,
262 216x detail::segment_iter(s));
263 }
264
265 inline
266 auto
267 13x segments_ref::
268 replace(
269 iterator from,
270 iterator to,
271 core::string_view s) ->
272 iterator
273 {
274 13x return u_->edit_segments(
275 from.it_,
276 to.it_,
277 26x detail::segment_iter(s));
278 }
279
280 inline
281 auto
282 7x segments_ref::
283 replace(
284 iterator from,
285 iterator to,
286 std::initializer_list<
287 core::string_view> init) ->
288 iterator
289 {
290 7x return replace(
291 from,
292 to,
293 init.begin(),
294 7x init.end());
295 }
296
297 inline
298 auto
299 347x segments_ref::
300 erase(
301 iterator pos) noexcept ->
302 iterator
303 {
304 347x return erase(pos, std::next(pos));
305 }
306
307 inline
308 void
309 587x segments_ref::
310 push_back(
311 core::string_view s)
312 {
313 587x insert(end(), s);
314 587x }
315
316 inline
317 void
318 183x segments_ref::
319 pop_back() noexcept
320 {
321 366x erase(std::prev(end()));
322 183x }
323
324 } // urls
325 } // boost
326
327 #endif
328