100.00% Lines (58/58)
100.00% Functions (21/21)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | 3 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/url | 8 | // Official repository: https://github.com/boostorg/url | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP | 11 | #ifndef BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP | |||||
| 12 | #define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP | 12 | #define BOOST_URL_IMPL_SEGMENTS_ENCODED_BASE_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/url/detail/segments_iter_impl.hpp> | 14 | #include <boost/url/detail/segments_iter_impl.hpp> | |||||
| 15 | #include <boost/assert.hpp> | 15 | #include <boost/assert.hpp> | |||||
| 16 | #include <ostream> | 16 | #include <ostream> | |||||
| 17 | 17 | |||||||
| 18 | namespace boost { | 18 | namespace boost { | |||||
| 19 | namespace urls { | 19 | namespace urls { | |||||
| 20 | namespace detail { | 20 | namespace detail { | |||||
| 21 | struct segments_iter_access; | 21 | struct segments_iter_access; | |||||
| 22 | } | 22 | } | |||||
| 23 | 23 | |||||||
| 24 | class segments_encoded_base::iterator | 24 | class segments_encoded_base::iterator | |||||
| 25 | { | 25 | { | |||||
| 26 | detail::segments_iter_impl it_; | 26 | detail::segments_iter_impl it_; | |||||
| 27 | 27 | |||||||
| 28 | friend class url_base; | 28 | friend class url_base; | |||||
| 29 | friend class segments_encoded_base; | 29 | friend class segments_encoded_base; | |||||
| 30 | friend class segments_encoded_ref; | 30 | friend class segments_encoded_ref; | |||||
| 31 | friend struct detail::segments_iter_access; | 31 | friend struct detail::segments_iter_access; | |||||
| 32 | 32 | |||||||
| 33 | iterator(detail::path_ref const&) noexcept; | 33 | iterator(detail::path_ref const&) noexcept; | |||||
| 34 | iterator(detail::path_ref const&, int) noexcept; | 34 | iterator(detail::path_ref const&, int) noexcept; | |||||
| 35 | 35 | |||||||
| HITCBC | 36 | 435 | iterator( | 36 | 435 | iterator( | ||
| 37 | detail::segments_iter_impl const& it) noexcept | 37 | detail::segments_iter_impl const& it) noexcept | |||||
| HITCBC | 38 | 435 | : it_(it) | 38 | 435 | : it_(it) | ||
| 39 | { | 39 | { | |||||
| HITCBC | 40 | 435 | } | 40 | 435 | } | ||
| 41 | 41 | |||||||
| 42 | public: | 42 | public: | |||||
| 43 | using value_type = | 43 | using value_type = | |||||
| 44 | segments_encoded_base::value_type; | 44 | segments_encoded_base::value_type; | |||||
| 45 | using reference = | 45 | using reference = | |||||
| 46 | segments_encoded_base::reference; | 46 | segments_encoded_base::reference; | |||||
| 47 | using pointer = reference; | 47 | using pointer = reference; | |||||
| 48 | using difference_type = std::ptrdiff_t; | 48 | using difference_type = std::ptrdiff_t; | |||||
| 49 | using iterator_category = | 49 | using iterator_category = | |||||
| 50 | std::bidirectional_iterator_tag; | 50 | std::bidirectional_iterator_tag; | |||||
| 51 | 51 | |||||||
| 52 | iterator() = default; | 52 | iterator() = default; | |||||
| 53 | iterator(iterator const&) = default; | 53 | iterator(iterator const&) = default; | |||||
| 54 | iterator& operator=( | 54 | iterator& operator=( | |||||
| 55 | iterator const&) = default; | 55 | iterator const&) = default; | |||||
| 56 | 56 | |||||||
| 57 | reference | 57 | reference | |||||
| HITCBC | 58 | 4276 | operator*() const noexcept | 58 | 4276 | operator*() const noexcept | ||
| 59 | { | 59 | { | |||||
| HITCBC | 60 | 4276 | return it_.dereference(); | 60 | 4276 | return it_.dereference(); | ||
| 61 | } | 61 | } | |||||
| 62 | 62 | |||||||
| 63 | pointer | 63 | pointer | |||||
| HITCBC | 64 | 31 | operator->() const noexcept | 64 | 31 | operator->() const noexcept | ||
| 65 | { | 65 | { | |||||
| HITCBC | 66 | 31 | return it_.dereference(); | 66 | 31 | return it_.dereference(); | ||
| 67 | } | 67 | } | |||||
| 68 | 68 | |||||||
| 69 | iterator& | 69 | iterator& | |||||
| HITCBC | 70 | 2164 | operator++() noexcept | 70 | 2164 | operator++() noexcept | ||
| 71 | { | 71 | { | |||||
| HITCBC | 72 | 2164 | it_.increment(); | 72 | 2164 | it_.increment(); | ||
| HITCBC | 73 | 2164 | return *this; | 73 | 2164 | return *this; | ||
| 74 | } | 74 | } | |||||
| 75 | 75 | |||||||
| 76 | iterator& | 76 | iterator& | |||||
| HITCBC | 77 | 1729 | operator--() noexcept | 77 | 1729 | operator--() noexcept | ||
| 78 | { | 78 | { | |||||
| HITCBC | 79 | 1729 | it_.decrement(); | 79 | 1729 | it_.decrement(); | ||
| HITCBC | 80 | 1729 | return *this; | 80 | 1729 | return *this; | ||
| 81 | } | 81 | } | |||||
| 82 | 82 | |||||||
| 83 | iterator | 83 | iterator | |||||
| HITCBC | 84 | 657 | operator++(int) noexcept | 84 | 657 | operator++(int) noexcept | ||
| 85 | { | 85 | { | |||||
| HITCBC | 86 | 657 | auto tmp = *this; | 86 | 657 | auto tmp = *this; | ||
| HITCBC | 87 | 657 | ++*this; | 87 | 657 | ++*this; | ||
| HITCBC | 88 | 657 | return tmp; | 88 | 657 | return tmp; | ||
| 89 | } | 89 | } | |||||
| 90 | 90 | |||||||
| 91 | iterator | 91 | iterator | |||||
| HITCBC | 92 | 26 | operator--(int) noexcept | 92 | 26 | operator--(int) noexcept | ||
| 93 | { | 93 | { | |||||
| HITCBC | 94 | 26 | auto tmp = *this; | 94 | 26 | auto tmp = *this; | ||
| HITCBC | 95 | 26 | --*this; | 95 | 26 | --*this; | ||
| HITCBC | 96 | 26 | return tmp; | 96 | 26 | return tmp; | ||
| 97 | } | 97 | } | |||||
| 98 | 98 | |||||||
| 99 | bool | 99 | bool | |||||
| HITCBC | 100 | 801 | operator==( | 100 | 801 | operator==( | ||
| 101 | iterator const& other) const noexcept | 101 | iterator const& other) const noexcept | |||||
| 102 | { | 102 | { | |||||
| HITCBC | 103 | 801 | return it_.equal(other.it_); | 103 | 801 | return it_.equal(other.it_); | ||
| 104 | } | 104 | } | |||||
| 105 | 105 | |||||||
| 106 | bool | 106 | bool | |||||
| HITCBC | 107 | 3964 | operator!=( | 107 | 3964 | operator!=( | ||
| 108 | iterator const& other) const noexcept | 108 | iterator const& other) const noexcept | |||||
| 109 | { | 109 | { | |||||
| HITCBC | 110 | 3964 | return ! it_.equal(other.it_); | 110 | 3964 | return ! it_.equal(other.it_); | ||
| 111 | } | 111 | } | |||||
| 112 | }; | 112 | }; | |||||
| 113 | 113 | |||||||
| 114 | //------------------------------------------------ | 114 | //------------------------------------------------ | |||||
| 115 | 115 | |||||||
| 116 | inline | 116 | inline | |||||
| HITCBC | 117 | 2177 | segments_encoded_base:: | 117 | 2177 | segments_encoded_base:: | ||
| 118 | iterator:: | 118 | iterator:: | |||||
| 119 | iterator( | 119 | iterator( | |||||
| HITCBC | 120 | 2177 | detail::path_ref const& ref) noexcept | 120 | 2177 | detail::path_ref const& ref) noexcept | ||
| HITCBC | 121 | 2177 | : it_(ref) | 121 | 2177 | : it_(ref) | ||
| 122 | { | 122 | { | |||||
| HITCBC | 123 | 2177 | } | 123 | 2177 | } | ||
| 124 | 124 | |||||||
| 125 | inline | 125 | inline | |||||
| HITCBC | 126 | 1813 | segments_encoded_base:: | 126 | 1813 | segments_encoded_base:: | ||
| 127 | iterator:: | 127 | iterator:: | |||||
| 128 | iterator( | 128 | iterator( | |||||
| 129 | detail::path_ref const& ref, | 129 | detail::path_ref const& ref, | |||||
| HITCBC | 130 | 1813 | int) noexcept | 130 | 1813 | int) noexcept | ||
| HITCBC | 131 | 1813 | : it_(ref, 0) | 131 | 1813 | : it_(ref, 0) | ||
| 132 | { | 132 | { | |||||
| HITCBC | 133 | 1813 | } | 133 | 1813 | } | ||
| 134 | 134 | |||||||
| 135 | //------------------------------------------------ | 135 | //------------------------------------------------ | |||||
| 136 | // | 136 | // | |||||
| 137 | // segments_encoded_base | 137 | // segments_encoded_base | |||||
| 138 | // | 138 | // | |||||
| 139 | //------------------------------------------------ | 139 | //------------------------------------------------ | |||||
| 140 | 140 | |||||||
| 141 | inline | 141 | inline | |||||
| HITCBC | 142 | 1642 | segments_encoded_base:: | 142 | 1642 | segments_encoded_base:: | ||
| 143 | segments_encoded_base( | 143 | segments_encoded_base( | |||||
| HITCBC | 144 | 1642 | detail::path_ref const& ref) noexcept | 144 | 1642 | detail::path_ref const& ref) noexcept | ||
| HITCBC | 145 | 1642 | : ref_(ref) | 145 | 1642 | : ref_(ref) | ||
| 146 | { | 146 | { | |||||
| HITCBC | 147 | 1642 | } | 147 | 1642 | } | ||
| 148 | 148 | |||||||
| 149 | //------------------------------------------------ | 149 | //------------------------------------------------ | |||||
| 150 | // | 150 | // | |||||
| 151 | // Observers | 151 | // Observers | |||||
| 152 | // | 152 | // | |||||
| 153 | //------------------------------------------------ | 153 | //------------------------------------------------ | |||||
| 154 | 154 | |||||||
| 155 | inline | 155 | inline | |||||
| 156 | pct_string_view | 156 | pct_string_view | |||||
| HITCBC | 157 | 62 | segments_encoded_base:: | 157 | 62 | segments_encoded_base:: | ||
| 158 | buffer() const noexcept | 158 | buffer() const noexcept | |||||
| 159 | { | 159 | { | |||||
| HITCBC | 160 | 62 | return ref_.buffer(); | 160 | 62 | return ref_.buffer(); | ||
| 161 | } | 161 | } | |||||
| 162 | 162 | |||||||
| 163 | inline | 163 | inline | |||||
| 164 | bool | 164 | bool | |||||
| HITCBC | 165 | 516 | segments_encoded_base:: | 165 | 516 | segments_encoded_base:: | ||
| 166 | is_absolute() const noexcept | 166 | is_absolute() const noexcept | |||||
| 167 | { | 167 | { | |||||
| HITCBC | 168 | 516 | return ref_.buffer().starts_with('/'); | 168 | 516 | return ref_.buffer().starts_with('/'); | ||
| 169 | } | 169 | } | |||||
| 170 | 170 | |||||||
| 171 | inline | 171 | inline | |||||
| 172 | bool | 172 | bool | |||||
| HITCBC | 173 | 745 | segments_encoded_base:: | 173 | 745 | segments_encoded_base:: | ||
| 174 | empty() const noexcept | 174 | empty() const noexcept | |||||
| 175 | { | 175 | { | |||||
| HITCBC | 176 | 745 | return ref_.nseg() == 0; | 176 | 745 | return ref_.nseg() == 0; | ||
| 177 | } | 177 | } | |||||
| 178 | 178 | |||||||
| 179 | inline | 179 | inline | |||||
| 180 | std::size_t | 180 | std::size_t | |||||
| HITCBC | 181 | 466 | segments_encoded_base:: | 181 | 466 | segments_encoded_base:: | ||
| 182 | size() const noexcept | 182 | size() const noexcept | |||||
| 183 | { | 183 | { | |||||
| HITCBC | 184 | 466 | return ref_.nseg(); | 184 | 466 | return ref_.nseg(); | ||
| 185 | } | 185 | } | |||||
| 186 | 186 | |||||||
| 187 | inline | 187 | inline | |||||
| 188 | pct_string_view | 188 | pct_string_view | |||||
| HITCBC | 189 | 110 | segments_encoded_base:: | 189 | 110 | segments_encoded_base:: | ||
| 190 | front() const noexcept | 190 | front() const noexcept | |||||
| 191 | { | 191 | { | |||||
| HITCBC | 192 | 110 | BOOST_ASSERT(! empty()); | 192 | 110 | BOOST_ASSERT(! empty()); | ||
| HITCBC | 193 | 110 | return *begin(); | 193 | 110 | return *begin(); | ||
| 194 | } | 194 | } | |||||
| 195 | 195 | |||||||
| 196 | inline | 196 | inline | |||||
| 197 | pct_string_view | 197 | pct_string_view | |||||
| HITCBC | 198 | 24 | segments_encoded_base:: | 198 | 24 | segments_encoded_base:: | ||
| 199 | back() const noexcept | 199 | back() const noexcept | |||||
| 200 | { | 200 | { | |||||
| HITCBC | 201 | 24 | BOOST_ASSERT(! empty()); | 201 | 24 | BOOST_ASSERT(! empty()); | ||
| HITCBC | 202 | 24 | return *--end(); | 202 | 24 | return *--end(); | ||
| 203 | } | 203 | } | |||||
| 204 | 204 | |||||||
| 205 | inline | 205 | inline | |||||
| 206 | auto | 206 | auto | |||||
| HITCBC | 207 | 2177 | segments_encoded_base:: | 207 | 2177 | segments_encoded_base:: | ||
| 208 | begin() const noexcept -> | 208 | begin() const noexcept -> | |||||
| 209 | iterator | 209 | iterator | |||||
| 210 | { | 210 | { | |||||
| HITCBC | 211 | 2177 | return iterator(ref_); | 211 | 2177 | return iterator(ref_); | ||
| 212 | } | 212 | } | |||||
| 213 | 213 | |||||||
| 214 | inline | 214 | inline | |||||
| 215 | auto | 215 | auto | |||||
| HITCBC | 216 | 1813 | segments_encoded_base:: | 216 | 1813 | segments_encoded_base:: | ||
| 217 | end() const noexcept -> | 217 | end() const noexcept -> | |||||
| 218 | iterator | 218 | iterator | |||||
| 219 | { | 219 | { | |||||
| HITCBC | 220 | 1813 | return iterator(ref_, 0); | 220 | 1813 | return iterator(ref_, 0); | ||
| 221 | } | 221 | } | |||||
| 222 | 222 | |||||||
| 223 | //------------------------------------------------ | 223 | //------------------------------------------------ | |||||
| 224 | 224 | |||||||
| 225 | inline | 225 | inline | |||||
| 226 | std::ostream& | 226 | std::ostream& | |||||
| HITCBC | 227 | 17 | operator<<( | 227 | 17 | operator<<( | ||
| 228 | std::ostream& os, | 228 | std::ostream& os, | |||||
| 229 | segments_encoded_base const& ps) | 229 | segments_encoded_base const& ps) | |||||
| 230 | { | 230 | { | |||||
| HITCBC | 231 | 17 | os << ps.buffer(); | 231 | 17 | os << ps.buffer(); | ||
| HITCBC | 232 | 17 | return os; | 232 | 17 | return os; | ||
| 233 | } | 233 | } | |||||
| 234 | 234 | |||||||
| 235 | } // urls | 235 | } // urls | |||||
| 236 | } // boost | 236 | } // boost | |||||
| 237 | 237 | |||||||
| 238 | #endif | 238 | #endif | |||||