include/boost/url/detail/impl/any_params_iter.hpp
97.7% Lines (43/44)
100.0% Functions (5/5)
88.9% Branches (16/18)
include/boost/url/detail/impl/any_params_iter.hpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2023 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_DETAIL_IMPL_ANY_PARAMS_ITER_HPP | ||
| 12 | #define BOOST_URL_DETAIL_IMPL_ANY_PARAMS_ITER_HPP | ||
| 13 | |||
| 14 | #include <boost/url/encode.hpp> | ||
| 15 | #include <boost/url/rfc/detail/charsets.hpp> | ||
| 16 | #include <boost/assert.hpp> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace urls { | ||
| 20 | namespace detail { | ||
| 21 | |||
| 22 | //------------------------------------------------ | ||
| 23 | // | ||
| 24 | // query_string_iter | ||
| 25 | // | ||
| 26 | //------------------------------------------------ | ||
| 27 | |||
| 28 | inline | ||
| 29 | 33 | query_string_iter:: | |
| 30 | query_string_iter( | ||
| 31 | core::string_view s, | ||
| 32 | 33 | bool ne) noexcept | |
| 33 | : any_params_iter( | ||
| 34 |
4/4✓ Branch 2 taken 25 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 3 times.
|
33 | s.empty() && ! ne, s) |
| 35 | { | ||
| 36 | 33 | rewind(); | |
| 37 | 33 | } | |
| 38 | |||
| 39 | inline | ||
| 40 | void | ||
| 41 | 44 | query_string_iter:: | |
| 42 | rewind() noexcept | ||
| 43 | { | ||
| 44 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 22 times.
|
44 | if(empty) |
| 45 | { | ||
| 46 | 22 | at_end_ = true; | |
| 47 | 22 | return; | |
| 48 | } | ||
| 49 | 22 | p_ = s0.begin(); | |
| 50 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 6 times.
|
22 | if(! s0.empty()) |
| 51 | { | ||
| 52 | auto pos = | ||
| 53 | 16 | s0.find_first_of('&'); | |
| 54 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
|
16 | if(pos != core::string_view::npos) |
| 55 | 4 | n_ = pos; | |
| 56 | else | ||
| 57 | 12 | n_ = s0.size(); | |
| 58 | } | ||
| 59 | else | ||
| 60 | { | ||
| 61 | 6 | n_ = 0; | |
| 62 | } | ||
| 63 | 22 | at_end_ = false; | |
| 64 | } | ||
| 65 | |||
| 66 | inline | ||
| 67 | bool | ||
| 68 | 46 | query_string_iter:: | |
| 69 | measure( | ||
| 70 | std::size_t& n) noexcept | ||
| 71 | { | ||
| 72 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
|
46 | if(at_end_) |
| 73 | 33 | return false; | |
| 74 | // When interacting with the query as | ||
| 75 | // an intact string, we do not treat | ||
| 76 | // the plus sign as an encoded space. | ||
| 77 | 13 | encoding_opts opt; | |
| 78 | 13 | opt.space_as_plus = false; | |
| 79 | 13 | n += encoded_size( | |
| 80 | core::string_view(p_, n_), | ||
| 81 | query_chars, | ||
| 82 | opt); | ||
| 83 | 13 | increment(); | |
| 84 | 13 | return true; | |
| 85 | } | ||
| 86 | |||
| 87 | inline | ||
| 88 | void | ||
| 89 | 13 | query_string_iter:: | |
| 90 | copy( | ||
| 91 | char*& dest, | ||
| 92 | char const* end) noexcept | ||
| 93 | { | ||
| 94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | BOOST_ASSERT(! at_end_); |
| 95 | // When interacting with the query as | ||
| 96 | // an intact string, we do not treat | ||
| 97 | // the plus sign as an encoded space. | ||
| 98 | 13 | encoding_opts opt; | |
| 99 | 13 | opt.space_as_plus = false; | |
| 100 | 13 | dest += encode_unsafe( | |
| 101 | dest, | ||
| 102 | 13 | end - dest, | |
| 103 | core::string_view(p_, n_), | ||
| 104 | query_chars, | ||
| 105 | opt); | ||
| 106 | 13 | increment(); | |
| 107 | 13 | } | |
| 108 | |||
| 109 | inline | ||
| 110 | void | ||
| 111 | 26 | query_string_iter:: | |
| 112 | increment() noexcept | ||
| 113 | { | ||
| 114 | 26 | p_ += n_; | |
| 115 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 2 taken 4 times.
|
26 | if(p_ == s0.end()) |
| 116 | { | ||
| 117 | 22 | at_end_ = true; | |
| 118 | 22 | return; | |
| 119 | } | ||
| 120 | 4 | ++p_; | |
| 121 | 4 | core::string_view s(p_, s0.end() - p_); | |
| 122 | 4 | auto pos = s.find_first_of('&'); | |
| 123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if(pos != core::string_view::npos) |
| 124 | ✗ | n_ = pos; | |
| 125 | else | ||
| 126 | 4 | n_ = s.size(); | |
| 127 | } | ||
| 128 | |||
| 129 | } // detail | ||
| 130 | } // urls | ||
| 131 | } // boost | ||
| 132 | |||
| 133 | #endif | ||
| 134 |