include/boost/url/detail/impl/any_segments_iter.hpp
100.0% Lines (62/62)
100.0% Functions (12/12)
| Line | TLA | 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_SEGMENTS_ITER_HPP | ||
| 12 | #define BOOST_URL_DETAIL_IMPL_ANY_SEGMENTS_ITER_HPP | ||
| 13 | |||
| 14 | #include <boost/url/encode.hpp> | ||
| 15 | #include <boost/url/rfc/pchars.hpp> | ||
| 16 | #include <boost/url/rfc/detail/charsets.hpp> | ||
| 17 | #include <boost/url/detail/encode.hpp> | ||
| 18 | |||
| 19 | namespace boost { | ||
| 20 | namespace urls { | ||
| 21 | namespace detail { | ||
| 22 | |||
| 23 | //------------------------------------------------ | ||
| 24 | // | ||
| 25 | // segment_iter | ||
| 26 | // | ||
| 27 | //------------------------------------------------ | ||
| 28 | |||
| 29 | inline | ||
| 30 | 75 | segment_iter:: | |
| 31 | segment_iter( | ||
| 32 | 75 | core::string_view s_) noexcept | |
| 33 | 75 | : any_segments_iter(s_) | |
| 34 | { | ||
| 35 | 75 | front = s; | |
| 36 | 75 | fast_nseg = 1; | |
| 37 | 75 | } | |
| 38 | |||
| 39 | inline | ||
| 40 | void | ||
| 41 | 75 | segment_iter:: | |
| 42 | rewind() noexcept | ||
| 43 | { | ||
| 44 | 75 | at_end_ = false; | |
| 45 | 75 | } | |
| 46 | |||
| 47 | inline | ||
| 48 | bool | ||
| 49 | 150 | segment_iter:: | |
| 50 | measure( | ||
| 51 | std::size_t& n) noexcept | ||
| 52 | { | ||
| 53 | 150 | if(at_end_) | |
| 54 | 75 | return false; | |
| 55 | 75 | encoding_opts opt; | |
| 56 | 75 | opt.space_as_plus = false; | |
| 57 | 75 | n += encoded_size( | |
| 58 | s, | ||
| 59 | 75 | encode_colons ? | |
| 60 | nocolon_pchars : | ||
| 61 | pchars, | ||
| 62 | opt); | ||
| 63 | 75 | at_end_ = true; | |
| 64 | 75 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 | inline | ||
| 68 | void | ||
| 69 | 75 | segment_iter:: | |
| 70 | copy( | ||
| 71 | char*& dest, | ||
| 72 | char const* end) noexcept | ||
| 73 | { | ||
| 74 | 75 | encoding_opts opt; | |
| 75 | 75 | opt.space_as_plus = false; | |
| 76 | 75 | dest += encode( | |
| 77 | dest, | ||
| 78 | 75 | end - dest, | |
| 79 | s, | ||
| 80 | 75 | encode_colons ? | |
| 81 | nocolon_pchars : | ||
| 82 | pchars, | ||
| 83 | opt); | ||
| 84 | 75 | } | |
| 85 | |||
| 86 | //------------------------------------------------ | ||
| 87 | // | ||
| 88 | // segments_iter_base | ||
| 89 | // | ||
| 90 | //------------------------------------------------ | ||
| 91 | |||
| 92 | inline | ||
| 93 | void | ||
| 94 | 188 | segments_iter_base:: | |
| 95 | measure_impl( | ||
| 96 | std::size_t& n, | ||
| 97 | core::string_view s, | ||
| 98 | bool encode_colons) noexcept | ||
| 99 | { | ||
| 100 | 188 | encoding_opts opt; | |
| 101 | 188 | opt.space_as_plus = false; | |
| 102 | 188 | n += encoded_size( | |
| 103 | s, | ||
| 104 | encode_colons ? | ||
| 105 | nocolon_pchars : | ||
| 106 | pchars, | ||
| 107 | opt); | ||
| 108 | 188 | } | |
| 109 | |||
| 110 | inline | ||
| 111 | void | ||
| 112 | 188 | segments_iter_base:: | |
| 113 | copy_impl( | ||
| 114 | char*& dest, | ||
| 115 | char const* end, | ||
| 116 | core::string_view s, | ||
| 117 | bool encode_colons) noexcept | ||
| 118 | { | ||
| 119 | 188 | encoding_opts opt; | |
| 120 | 188 | opt.space_as_plus = false; | |
| 121 | 188 | dest += encode( | |
| 122 | dest, | ||
| 123 | 188 | end - dest, | |
| 124 | s, | ||
| 125 | encode_colons ? | ||
| 126 | nocolon_pchars : | ||
| 127 | pchars, | ||
| 128 | opt); | ||
| 129 | 188 | } | |
| 130 | |||
| 131 | //------------------------------------------------ | ||
| 132 | // | ||
| 133 | // segment_encoded_iter | ||
| 134 | // | ||
| 135 | //------------------------------------------------ | ||
| 136 | |||
| 137 | inline | ||
| 138 | 72 | segment_encoded_iter:: | |
| 139 | segment_encoded_iter( | ||
| 140 | 72 | pct_string_view const& s_) noexcept | |
| 141 | 72 | : any_segments_iter(s_) | |
| 142 | { | ||
| 143 | 72 | front = s; | |
| 144 | 72 | fast_nseg = 1; | |
| 145 | 72 | } | |
| 146 | |||
| 147 | inline | ||
| 148 | void | ||
| 149 | 72 | segment_encoded_iter:: | |
| 150 | rewind() noexcept | ||
| 151 | { | ||
| 152 | 72 | at_end_ = false; | |
| 153 | 72 | } | |
| 154 | |||
| 155 | inline | ||
| 156 | bool | ||
| 157 | 144 | segment_encoded_iter:: | |
| 158 | measure( | ||
| 159 | std::size_t& n) noexcept | ||
| 160 | { | ||
| 161 | 144 | if(at_end_) | |
| 162 | 72 | return false; | |
| 163 | 72 | n += detail::re_encoded_size_unsafe( | |
| 164 | s, | ||
| 165 | 72 | encode_colons ? | |
| 166 | nocolon_pchars : | ||
| 167 | pchars); | ||
| 168 | 72 | at_end_ = true; | |
| 169 | 72 | return true; | |
| 170 | } | ||
| 171 | |||
| 172 | inline | ||
| 173 | void | ||
| 174 | 72 | segment_encoded_iter:: | |
| 175 | copy( | ||
| 176 | char*& dest, | ||
| 177 | char const* end) noexcept | ||
| 178 | { | ||
| 179 | 72 | detail::re_encode_unsafe( | |
| 180 | dest, | ||
| 181 | end, | ||
| 182 | s, | ||
| 183 | 72 | encode_colons ? | |
| 184 | nocolon_pchars : | ||
| 185 | pchars); | ||
| 186 | 72 | } | |
| 187 | |||
| 188 | //------------------------------------------------ | ||
| 189 | // | ||
| 190 | // segments_encoded_iter_base | ||
| 191 | // | ||
| 192 | //------------------------------------------------ | ||
| 193 | |||
| 194 | inline | ||
| 195 | void | ||
| 196 | 399 | segments_encoded_iter_base:: | |
| 197 | measure_impl( | ||
| 198 | std::size_t& n, | ||
| 199 | core::string_view s, | ||
| 200 | bool encode_colons) noexcept | ||
| 201 | { | ||
| 202 | 399 | n += detail::re_encoded_size_unsafe( | |
| 203 | s, | ||
| 204 | encode_colons ? | ||
| 205 | nocolon_pchars : | ||
| 206 | pchars); | ||
| 207 | 399 | } | |
| 208 | |||
| 209 | inline | ||
| 210 | void | ||
| 211 | 397 | segments_encoded_iter_base:: | |
| 212 | copy_impl( | ||
| 213 | char*& dest, | ||
| 214 | char const* end, | ||
| 215 | core::string_view s, | ||
| 216 | bool encode_colons) noexcept | ||
| 217 | { | ||
| 218 | 397 | detail::re_encode_unsafe( | |
| 219 | dest, | ||
| 220 | end, | ||
| 221 | s, | ||
| 222 | encode_colons ? | ||
| 223 | nocolon_pchars : | ||
| 224 | pchars); | ||
| 225 | 397 | } | |
| 226 | |||
| 227 | } // detail | ||
| 228 | } // urls | ||
| 229 | } // boost | ||
| 230 | |||
| 231 | #endif | ||
| 232 |