| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@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_IMPL_PCT_ENCODED_VIEW_HPP | ||
| 11 | #define BOOST_URL_IMPL_PCT_ENCODED_VIEW_HPP | ||
| 12 | |||
| 13 | #include <boost/url/grammar/type_traits.hpp> | ||
| 14 | #include <boost/static_assert.hpp> | ||
| 15 | |||
| 16 | namespace boost { | ||
| 17 | namespace urls { | ||
| 18 | |||
| 19 | class decode_view::iterator | ||
| 20 | { | ||
| 21 | char const* begin_ = nullptr; | ||
| 22 | char const* pos_ = nullptr; | ||
| 23 | bool space_as_plus_ = true; | ||
| 24 | |||
| 25 | friend decode_view; | ||
| 26 | |||
| 27 | 6356 | iterator( | |
| 28 | char const* str, | ||
| 29 | bool space_as_plus) noexcept | ||
| 30 | 6356 | : begin_(str) | |
| 31 | , pos_(str) | ||
| 32 | , space_as_plus_( | ||
| 33 | 6356 | space_as_plus) | |
| 34 | { | ||
| 35 | 6356 | } | |
| 36 | |||
| 37 | // end ctor | ||
| 38 | 885 | iterator( | |
| 39 | char const* str, | ||
| 40 | size_type n, | ||
| 41 | bool space_as_plus) noexcept | ||
| 42 | 885 | : begin_(str) | |
| 43 | 885 | , pos_(str + n) | |
| 44 | 885 | , space_as_plus_(space_as_plus) | |
| 45 | { | ||
| 46 | 885 | } | |
| 47 | |||
| 48 | public: | ||
| 49 | using value_type = char; | ||
| 50 | using reference = char; | ||
| 51 | using pointer = void const*; | ||
| 52 | using const_reference = char; | ||
| 53 | using size_type = std::size_t; | ||
| 54 | using difference_type = std::ptrdiff_t; | ||
| 55 | using iterator_category = | ||
| 56 | std::bidirectional_iterator_tag; | ||
| 57 | |||
| 58 | 2 | iterator() = default; | |
| 59 | |||
| 60 | iterator(iterator const&) = default; | ||
| 61 | |||
| 62 | iterator& | ||
| 63 | operator=(iterator const&) = default; | ||
| 64 | |||
| 65 | BOOST_URL_DECL | ||
| 66 | reference | ||
| 67 | operator*() const noexcept; | ||
| 68 | |||
| 69 | iterator& | ||
| 70 | 4835 | operator++() noexcept | |
| 71 | { | ||
| 72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4835 times.
|
4835 | BOOST_ASSERT(pos_ != nullptr); |
| 73 |
2/2✓ Branch 0 taken 4538 times.
✓ Branch 1 taken 297 times.
|
4835 | if (*pos_ != '%') |
| 74 | 4538 | ++pos_; | |
| 75 | else | ||
| 76 | 297 | pos_ += 3; | |
| 77 | 4835 | return *this; | |
| 78 | } | ||
| 79 | |||
| 80 | iterator& | ||
| 81 | 1182 | operator--() noexcept | |
| 82 | { | ||
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1182 times.
|
1182 | BOOST_ASSERT(pos_ != begin_); |
| 84 |
2/2✓ Branch 0 taken 679 times.
✓ Branch 1 taken 503 times.
|
1182 | if (pos_ - begin_ < 3 || |
| 85 |
2/2✓ Branch 0 taken 627 times.
✓ Branch 1 taken 52 times.
|
679 | pos_[-3] != '%') |
| 86 | 1130 | --pos_; | |
| 87 | else | ||
| 88 | 52 | pos_ -= 3; | |
| 89 | 1182 | return *this; | |
| 90 | } | ||
| 91 | |||
| 92 | iterator | ||
| 93 | 4668 | operator++(int) noexcept | |
| 94 | { | ||
| 95 | 4668 | auto tmp = *this; | |
| 96 | 4668 | ++*this; | |
| 97 | 4668 | return tmp; | |
| 98 | } | ||
| 99 | |||
| 100 | iterator | ||
| 101 | operator--(int) noexcept | ||
| 102 | { | ||
| 103 | auto tmp = *this; | ||
| 104 | --*this; | ||
| 105 | return tmp; | ||
| 106 | } | ||
| 107 | |||
| 108 | char const* | ||
| 109 | 7 | base() | |
| 110 | { | ||
| 111 | 7 | return pos_; | |
| 112 | } | ||
| 113 | |||
| 114 | bool | ||
| 115 | 2992 | operator==( | |
| 116 | iterator const& other) const noexcept | ||
| 117 | { | ||
| 118 | 2992 | return pos_ == other.pos_; | |
| 119 | } | ||
| 120 | |||
| 121 | bool | ||
| 122 | 1962 | operator!=( | |
| 123 | iterator const& other) const noexcept | ||
| 124 | { | ||
| 125 | 1962 | return !(*this == other); | |
| 126 | } | ||
| 127 | }; | ||
| 128 | |||
| 129 | //------------------------------------------------ | ||
| 130 | |||
| 131 | inline | ||
| 132 | auto | ||
| 133 | 6356 | decode_view:: | |
| 134 | begin() const noexcept -> | ||
| 135 | const_iterator | ||
| 136 | { | ||
| 137 | 6356 | return {p_, space_as_plus_}; | |
| 138 | } | ||
| 139 | |||
| 140 | inline | ||
| 141 | auto | ||
| 142 | 885 | decode_view:: | |
| 143 | end() const noexcept -> | ||
| 144 | const_iterator | ||
| 145 | { | ||
| 146 | 885 | return {p_, n_, space_as_plus_}; | |
| 147 | } | ||
| 148 | |||
| 149 | inline | ||
| 150 | auto | ||
| 151 | 3 | decode_view:: | |
| 152 | front() const noexcept -> | ||
| 153 | const_reference | ||
| 154 | { | ||
| 155 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | BOOST_ASSERT( !empty() ); |
| 156 | 3 | return *begin(); | |
| 157 | } | ||
| 158 | |||
| 159 | inline | ||
| 160 | auto | ||
| 161 | 3 | decode_view:: | |
| 162 | back() const noexcept -> | ||
| 163 | const_reference | ||
| 164 | { | ||
| 165 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | BOOST_ASSERT( !empty() ); |
| 166 | 3 | return *--end(); | |
| 167 | } | ||
| 168 | |||
| 169 | } // urls | ||
| 170 | } // boost | ||
| 171 | |||
| 172 | #endif | ||
| 173 |