include/boost/url/impl/params_encoded_ref.hpp

98.4% Lines (126/128) 100.0% List of functions (31/31)
params_encoded_ref.hpp
f(x) Functions (31)
Function Calls Lines Blocks
boost::urls::params_encoded_ref::params_encoded_ref(boost::urls::url_base&) :31 77x 100.0% 100.0% boost::urls::params_encoded_ref::operator=(boost::urls::params_encoded_ref const&) :41 1x 100.0% 100.0% boost::urls::params_encoded_ref::operator=(std::initializer_list<boost::urls::param_pct_view>) :52 2x 100.0% 100.0% boost::urls::params_encoded_ref::operator boost::urls::params_encoded_view() const :61 58x 100.0% 100.0% boost::urls::params_encoded_ref::assign(std::initializer_list<boost::urls::param_pct_view>) :76 3x 100.0% 100.0% boost::urls::params_encoded_ref::clear() :86 3x 100.0% 100.0% void boost::urls::params_encoded_ref::assign<boost::urls::param_pct_view const*>(boost::urls::param_pct_view const*, boost::urls::param_pct_view const*) :94 5x 100.0% 100.0% void boost::urls::params_encoded_ref::assign<boost::urls::param_view const*>(boost::urls::param_view const*, boost::urls::param_view const*) :94 1x 100.0% 100.0% void boost::urls::params_encoded_ref::assign<boost::urls::params_encoded_base::iterator>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator) :94 1x 100.0% 100.0% boost::urls::params_encoded_ref::append(boost::urls::param_pct_view const&) :116 4x 100.0% 100.0% boost::urls::params_encoded_ref::append(std::initializer_list<boost::urls::param_pct_view>) :126 4x 100.0% 100.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::append<boost::urls::param_view const*>(boost::urls::param_view const*, boost::urls::param_view const*) :137 6x 100.0% 100.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::insert<boost::urls::param_pct_view const*>(boost::urls::params_encoded_base::iterator, boost::urls::param_pct_view const*, boost::urls::param_pct_view const*) :160 12x 100.0% 100.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::insert<boost::urls::param_view const*>(boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*) :160 7x 100.0% 100.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::replace<boost::urls::param_pct_view const*>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_pct_view const*, boost::urls::param_pct_view const*) :189 1x 100.0% 70.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::replace<boost::urls::param_view const*>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*) :189 2x 100.0% 100.0% void boost::urls::params_encoded_ref::assign<boost::urls::param_pct_view const*>(boost::urls::param_pct_view const*, boost::urls::param_pct_view const*, std::forward_iterator_tag) :223 5x 100.0% 58.0% void boost::urls::params_encoded_ref::assign<boost::urls::param_view const*>(boost::urls::param_view const*, boost::urls::param_view const*, std::forward_iterator_tag) :223 1x 100.0% 58.0% void boost::urls::params_encoded_ref::assign<boost::urls::params_encoded_base::iterator>(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, std::forward_iterator_tag) :223 1x 100.0% 58.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::insert<boost::urls::param_pct_view const*>(boost::urls::params_encoded_base::iterator, boost::urls::param_pct_view const*, boost::urls::param_pct_view const*, std::forward_iterator_tag) :236 12x 100.0% 70.0% boost::urls::params_encoded_base::iterator boost::urls::params_encoded_ref::insert<boost::urls::param_view const*>(boost::urls::params_encoded_base::iterator, boost::urls::param_view const*, boost::urls::param_view const*, std::forward_iterator_tag) :236 7x 100.0% 100.0% boost::urls::params_encoded_ref::insert(boost::urls::params_encoded_base::iterator, boost::urls::param_pct_view const&) :253 7x 100.0% 70.0% boost::urls::params_encoded_ref::insert(boost::urls::params_encoded_base::iterator, std::initializer_list<boost::urls::param_pct_view>) :267 12x 100.0% 100.0% boost::urls::params_encoded_ref::erase(boost::urls::pct_string_view, boost::urls::ignore_case_param) :282 2x 93.8% 95.0% boost::urls::params_encoded_ref::replace(boost::urls::params_encoded_base::iterator, boost::urls::param_pct_view const&) :314 5x 100.0% 76.0% boost::urls::params_encoded_ref::replace(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator, std::initializer_list<boost::urls::param_pct_view>) :328 1x 100.0% 100.0% boost::urls::params_encoded_ref::unset(boost::urls::params_encoded_base::iterator) :345 4x 100.0% 89.0% boost::urls::params_encoded_ref::set(boost::urls::params_encoded_base::iterator, boost::urls::pct_string_view) :360 4x 100.0% 64.0% boost::urls::params_encoded_ref::set(boost::urls::pct_string_view, boost::urls::pct_string_view, boost::urls::ignore_case_param) :376 1x 90.0% 75.0% boost::urls::params_encoded_ref::erase(boost::urls::params_encoded_base::iterator) :402 9x 100.0% 100.0% boost::urls::params_encoded_ref::erase(boost::urls::params_encoded_base::iterator, boost::urls::params_encoded_base::iterator) :414 11x 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_PARAMS_ENCODED_REF_HPP
12 #define BOOST_URL_IMPL_PARAMS_ENCODED_REF_HPP
13
14 #include <boost/url/params_encoded_view.hpp>
15 #include <boost/url/url_base.hpp>
16 #include <boost/url/detail/except.hpp>
17 #include <boost/url/grammar/ci_string.hpp>
18 #include <boost/assert.hpp>
19 #include <utility>
20
21 namespace boost {
22 namespace urls {
23
24 //------------------------------------------------
25 //
26 // Special Members
27 //
28 //------------------------------------------------
29
30 inline
31 77x params_encoded_ref::
32 params_encoded_ref(
33 77x url_base& u) noexcept
34 77x : params_encoded_base(u.impl_)
35 77x , u_(&u)
36 {
37 77x }
38
39 inline
40 params_encoded_ref&
41 1x params_encoded_ref::
42 operator=(
43 params_encoded_ref const& other)
44 {
45 1x if (!ref_.alias_of( other.ref_ ))
46 1x assign(other.begin(), other.end());
47 1x return *this;
48 }
49
50 inline
51 params_encoded_ref&
52 2x params_encoded_ref::
53 operator=(std::initializer_list<
54 param_pct_view> init)
55 {
56 2x assign(init.begin(), init.end());
57 2x return *this;
58 }
59
60 inline
61 58x params_encoded_ref::
62 operator
63 params_encoded_view() const noexcept
64 {
65 58x return {ref_};
66 }
67
68 //------------------------------------------------
69 //
70 // Modifiers
71 //
72 //------------------------------------------------
73
74 inline
75 void
76 3x params_encoded_ref::
77 assign(
78 std::initializer_list<
79 param_pct_view> init)
80 {
81 3x assign(init.begin(), init.end());
82 3x }
83
84 inline
85 void
86 3x params_encoded_ref::
87 clear() noexcept
88 {
89 3x u_->remove_query();
90 3x }
91
92 template<class FwdIt>
93 void
94 7x params_encoded_ref::
95 assign(FwdIt first, FwdIt last)
96 {
97 /* If you get a compile error here, it
98 means that the iterators you passed
99 do not meet the requirements stated
100 in the documentation.
101 */
102 static_assert(
103 std::is_convertible<
104 typename std::iterator_traits<
105 FwdIt>::reference,
106 param_view>::value,
107 "Type requirements not met");
108
109 7x assign(first, last,
110 typename std::iterator_traits<
111 FwdIt>::iterator_category{});
112 7x }
113
114 inline
115 auto
116 4x params_encoded_ref::
117 append(
118 param_pct_view const& p) ->
119 iterator
120 {
121 4x return insert(end(), p);
122 }
123
124 inline
125 auto
126 4x params_encoded_ref::
127 append(
128 std::initializer_list<
129 param_pct_view> init) ->
130 iterator
131 {
132 4x return insert(end(), init);
133 }
134
135 template<class FwdIt>
136 auto
137 6x params_encoded_ref::
138 append(
139 FwdIt first, FwdIt last) ->
140 iterator
141 {
142 /* If you get a compile error here, it
143 means that the iterators you passed
144 do not meet the requirements stated
145 in the documentation.
146 */
147 static_assert(
148 std::is_convertible<
149 typename std::iterator_traits<
150 FwdIt>::reference,
151 param_view>::value,
152 "Type requirements not met");
153
154 6x return insert(
155 3x end(), first, last);
156 }
157
158 template<class FwdIt>
159 auto
160 19x params_encoded_ref::
161 insert(
162 iterator before,
163 FwdIt first,
164 FwdIt last) ->
165 iterator
166 {
167 /* If you get a compile error here, it
168 means that the iterators you passed
169 do not meet the requirements stated
170 in the documentation.
171 */
172 static_assert(
173 std::is_convertible<
174 typename std::iterator_traits<
175 FwdIt>::reference,
176 param_view>::value,
177 "Type requirements not met");
178
179 34x return insert(
180 before,
181 first,
182 last,
183 typename std::iterator_traits<
184 30x FwdIt>::iterator_category{});
185 }
186
187 template<class FwdIt>
188 auto
189 3x params_encoded_ref::
190 replace(
191 iterator from,
192 iterator to,
193 FwdIt first,
194 FwdIt last) ->
195 iterator
196 {
197 /* If you get a compile error here, it
198 means that the iterators you passed
199 do not meet the requirements stated
200 in the documentation.
201 */
202 static_assert(
203 std::is_convertible<
204 typename std::iterator_traits<
205 FwdIt>::reference,
206 param_view>::value,
207 "Type requirements not met");
208
209 6x return u_->edit_params(
210 from.it_, to.it_,
211 detail::make_params_encoded_iter(
212 4x first, last));
213 }
214
215 //------------------------------------------------
216 //
217 // implementation
218 //
219 //------------------------------------------------
220
221 template<class FwdIt>
222 void
223 7x params_encoded_ref::
224 assign(FwdIt first, FwdIt last,
225 std::forward_iterator_tag)
226 {
227 14x u_->edit_params(
228 7x begin().it_,
229 14x end().it_,
230 detail::make_params_encoded_iter(
231 first, last));
232 7x }
233
234 template<class FwdIt>
235 auto
236 19x params_encoded_ref::
237 insert(
238 iterator before,
239 FwdIt first,
240 FwdIt last,
241 std::forward_iterator_tag) ->
242 iterator
243 {
244 38x return u_->edit_params(
245 before.it_,
246 before.it_,
247 detail::make_params_encoded_iter(
248 30x first, last));
249 }
250
251 inline
252 auto
253 7x params_encoded_ref::
254 insert(
255 iterator before,
256 param_pct_view const& p) ->
257 iterator
258 {
259 7x return u_->edit_params(
260 before.it_,
261 before.it_,
262 14x detail::param_encoded_iter(p));
263 }
264
265 inline
266 auto
267 12x params_encoded_ref::
268 insert(
269 iterator before,
270 std::initializer_list<
271 param_pct_view> init) ->
272 iterator
273 {
274 12x return insert(
275 before,
276 init.begin(),
277 12x init.end());
278 }
279
280 inline
281 std::size_t
282 2x params_encoded_ref::
283 erase(
284 pct_string_view key,
285 ignore_case_param ic) noexcept
286 {
287 // end() can't be fully cached,
288 // since erase invalidates it.
289 2x iterator it;
290 {
291 2x auto const end_ = end();
292 2x it = find_last(end_, key, ic);
293 2x if(it == end_)
294 return 0;
295 }
296 2x std::size_t n = 0;
297 for(;;)
298 {
299 5x ++n;
300 // Use it->key instead of key,
301 // to handle self-intersection
302 5x auto prev = find_last(it, it->key, ic);
303 5x if(prev == end())
304 2x break;
305 3x erase(it);
306 3x it = prev;
307 3x }
308 2x erase(it);
309 2x return n;
310 }
311
312 inline
313 auto
314 5x params_encoded_ref::
315 replace(
316 iterator pos,
317 param_pct_view const& p) ->
318 iterator
319 {
320 15x return u_->edit_params(
321 pos.it_,
322 5x std::next(pos).it_,
323 10x detail::param_encoded_iter(p));
324 }
325
326 inline
327 auto
328 1x params_encoded_ref::
329 replace(
330 iterator from,
331 iterator to,
332 std::initializer_list<
333 param_pct_view> init) ->
334 iterator
335 {
336 1x return replace(
337 from,
338 to,
339 init.begin(),
340 1x init.end());
341 }
342
343 inline
344 auto
345 4x params_encoded_ref::
346 unset(
347 iterator pos) noexcept ->
348 iterator
349 {
350 4x BOOST_ASSERT(pos.it_.nk > 0);
351 4x pct_string_view s;
352 4x return u_->edit_params(
353 4x pos.it_, pos.it_.next(),
354 4x detail::param_encoded_value_iter(
355 8x pos.it_.nk - 1, s, false));
356 }
357
358 inline
359 auto
360 4x params_encoded_ref::
361 set(
362 iterator pos,
363 pct_string_view value) ->
364 iterator
365 {
366 4x BOOST_ASSERT(pos.it_.nk > 0);
367 4x return u_->edit_params(
368 pos.it_,
369 4x pos.it_.next(),
370 4x detail::param_encoded_value_iter(
371 12x pos.it_.nk - 1, value, true));
372 }
373
374 inline
375 auto
376 1x params_encoded_ref::
377 set(
378 pct_string_view key,
379 pct_string_view value,
380 ignore_case_param ic) ->
381 iterator
382 {
383 // VFALCO we can't cache end() here
384 // because it is invalidated
385 // every time we set or erase.
386 1x auto it0 = find(key, ic);
387 1x if(it0 == end())
388 return append({key, value});
389 1x it0 = set(it0, value);
390 1x auto it = end();
391 for(;;)
392 {
393 2x it = find_last(it, key, ic);
394 2x if(it == it0)
395 1x return it0;
396 1x it = erase(it);
397 }
398 }
399
400 inline
401 auto
402 9x params_encoded_ref::
403 erase(
404 iterator pos) noexcept ->
405 iterator
406 {
407 9x return erase(
408 pos,
409 9x std::next(pos));
410 }
411
412 inline
413 auto
414 11x params_encoded_ref::
415 erase(
416 iterator first,
417 iterator last) noexcept ->
418 iterator
419 {
420 11x core::string_view s("", 0);
421 11x return u_->edit_params(
422 first.it_,
423 last.it_,
424 22x detail::query_string_iter(s));
425 }
426
427 } // urls
428 } // boost
429
430 #endif
431