include/boost/url/impl/segments_encoded_base.hpp
100.0% Lines (58/58)
100.0% Functions (21/21)
| 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_ENCODED_BASE_HPP | ||
| 12 | #define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/segments_iter_impl.hpp> | ||
| 15 | #include <boost/assert.hpp> | ||
| 16 | #include <ostream> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace urls { | ||
| 20 | namespace detail { | ||
| 21 | struct segments_iter_access; | ||
| 22 | } | ||
| 23 | |||
| 24 | class segments_encoded_base::iterator | ||
| 25 | { | ||
| 26 | detail::segments_iter_impl it_; | ||
| 27 | |||
| 28 | friend class url_base; | ||
| 29 | friend class segments_encoded_base; | ||
| 30 | friend class segments_encoded_ref; | ||
| 31 | friend struct detail::segments_iter_access; | ||
| 32 | |||
| 33 | iterator(detail::path_ref const&) noexcept; | ||
| 34 | iterator(detail::path_ref const&, int) noexcept; | ||
| 35 | |||
| 36 | 387 | iterator( | |
| 37 | detail::segments_iter_impl const& it) noexcept | ||
| 38 | 387 | : it_(it) | |
| 39 | { | ||
| 40 | 387 | } | |
| 41 | |||
| 42 | public: | ||
| 43 | using value_type = | ||
| 44 | segments_encoded_base::value_type; | ||
| 45 | using reference = | ||
| 46 | segments_encoded_base::reference; | ||
| 47 | using pointer = reference; | ||
| 48 | using difference_type = std::ptrdiff_t; | ||
| 49 | using iterator_category = | ||
| 50 | std::bidirectional_iterator_tag; | ||
| 51 | |||
| 52 | iterator() = default; | ||
| 53 | iterator(iterator const&) = default; | ||
| 54 | iterator& operator=( | ||
| 55 | iterator const&) = default; | ||
| 56 | |||
| 57 | reference | ||
| 58 | 3925 | operator*() const noexcept | |
| 59 | { | ||
| 60 | 3925 | return it_.dereference(); | |
| 61 | } | ||
| 62 | |||
| 63 | pointer | ||
| 64 | 21 | operator->() const noexcept | |
| 65 | { | ||
| 66 | 21 | return it_.dereference(); | |
| 67 | } | ||
| 68 | |||
| 69 | iterator& | ||
| 70 | 2010 | operator++() noexcept | |
| 71 | { | ||
| 72 | 2010 | it_.increment(); | |
| 73 | 2010 | return *this; | |
| 74 | } | ||
| 75 | |||
| 76 | iterator& | ||
| 77 | 1512 | operator--() noexcept | |
| 78 | { | ||
| 79 | 1512 | it_.decrement(); | |
| 80 | 1512 | return *this; | |
| 81 | } | ||
| 82 | |||
| 83 | iterator | ||
| 84 | 600 | operator++(int) noexcept | |
| 85 | { | ||
| 86 | 600 | auto tmp = *this; | |
| 87 | 600 | ++*this; | |
| 88 | 600 | return tmp; | |
| 89 | } | ||
| 90 | |||
| 91 | iterator | ||
| 92 | 21 | operator--(int) noexcept | |
| 93 | { | ||
| 94 | 21 | auto tmp = *this; | |
| 95 | 21 | --*this; | |
| 96 | 21 | return tmp; | |
| 97 | } | ||
| 98 | |||
| 99 | bool | ||
| 100 | 707 | operator==( | |
| 101 | iterator const& other) const noexcept | ||
| 102 | { | ||
| 103 | 707 | return it_.equal(other.it_); | |
| 104 | } | ||
| 105 | |||
| 106 | bool | ||
| 107 | 3546 | operator!=( | |
| 108 | iterator const& other) const noexcept | ||
| 109 | { | ||
| 110 | 3546 | return ! it_.equal(other.it_); | |
| 111 | } | ||
| 112 | }; | ||
| 113 | |||
| 114 | //------------------------------------------------ | ||
| 115 | |||
| 116 | inline | ||
| 117 | 1784 | segments_encoded_base:: | |
| 118 | iterator:: | ||
| 119 | iterator( | ||
| 120 | 1784 | detail::path_ref const& ref) noexcept | |
| 121 | 1784 | : it_(ref) | |
| 122 | { | ||
| 123 | 1784 | } | |
| 124 | |||
| 125 | inline | ||
| 126 | 1471 | segments_encoded_base:: | |
| 127 | iterator:: | ||
| 128 | iterator( | ||
| 129 | detail::path_ref const& ref, | ||
| 130 | 1471 | int) noexcept | |
| 131 | 1471 | : it_(ref, 0) | |
| 132 | { | ||
| 133 | 1471 | } | |
| 134 | |||
| 135 | //------------------------------------------------ | ||
| 136 | // | ||
| 137 | // segments_encoded_base | ||
| 138 | // | ||
| 139 | //------------------------------------------------ | ||
| 140 | |||
| 141 | inline | ||
| 142 | 1369 | segments_encoded_base:: | |
| 143 | segments_encoded_base( | ||
| 144 | 1369 | detail::path_ref const& ref) noexcept | |
| 145 | 1369 | : ref_(ref) | |
| 146 | { | ||
| 147 | 1369 | } | |
| 148 | |||
| 149 | //------------------------------------------------ | ||
| 150 | // | ||
| 151 | // Observers | ||
| 152 | // | ||
| 153 | //------------------------------------------------ | ||
| 154 | |||
| 155 | inline | ||
| 156 | pct_string_view | ||
| 157 | 58 | segments_encoded_base:: | |
| 158 | buffer() const noexcept | ||
| 159 | { | ||
| 160 | 58 | return ref_.buffer(); | |
| 161 | } | ||
| 162 | |||
| 163 | inline | ||
| 164 | bool | ||
| 165 | 392 | segments_encoded_base:: | |
| 166 | is_absolute() const noexcept | ||
| 167 | { | ||
| 168 | 392 | return ref_.buffer().starts_with('/'); | |
| 169 | } | ||
| 170 | |||
| 171 | inline | ||
| 172 | bool | ||
| 173 | 599 | segments_encoded_base:: | |
| 174 | empty() const noexcept | ||
| 175 | { | ||
| 176 | 599 | return ref_.nseg() == 0; | |
| 177 | } | ||
| 178 | |||
| 179 | inline | ||
| 180 | std::size_t | ||
| 181 | 433 | segments_encoded_base:: | |
| 182 | size() const noexcept | ||
| 183 | { | ||
| 184 | 433 | return ref_.nseg(); | |
| 185 | } | ||
| 186 | |||
| 187 | inline | ||
| 188 | pct_string_view | ||
| 189 | 98 | segments_encoded_base:: | |
| 190 | front() const noexcept | ||
| 191 | { | ||
| 192 | 98 | BOOST_ASSERT(! empty()); | |
| 193 | 98 | return *begin(); | |
| 194 | } | ||
| 195 | |||
| 196 | inline | ||
| 197 | pct_string_view | ||
| 198 | 16 | segments_encoded_base:: | |
| 199 | back() const noexcept | ||
| 200 | { | ||
| 201 | 16 | BOOST_ASSERT(! empty()); | |
| 202 | 16 | return *--end(); | |
| 203 | } | ||
| 204 | |||
| 205 | inline | ||
| 206 | auto | ||
| 207 | 1784 | segments_encoded_base:: | |
| 208 | begin() const noexcept -> | ||
| 209 | iterator | ||
| 210 | { | ||
| 211 | 1784 | return iterator(ref_); | |
| 212 | } | ||
| 213 | |||
| 214 | inline | ||
| 215 | auto | ||
| 216 | 1471 | segments_encoded_base:: | |
| 217 | end() const noexcept -> | ||
| 218 | iterator | ||
| 219 | { | ||
| 220 | 1471 | return iterator(ref_, 0); | |
| 221 | } | ||
| 222 | |||
| 223 | //------------------------------------------------ | ||
| 224 | |||
| 225 | inline | ||
| 226 | std::ostream& | ||
| 227 | 15 | operator<<( | |
| 228 | std::ostream& os, | ||
| 229 | segments_encoded_base const& ps) | ||
| 230 | { | ||
| 231 | 15 | os << ps.buffer(); | |
| 232 | 15 | return os; | |
| 233 | } | ||
| 234 | |||
| 235 | } // urls | ||
| 236 | } // boost | ||
| 237 | |||
| 238 | #endif | ||
| 239 |