include/boost/url/impl/segments_ref.hpp
100.0% Lines (66/66)
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_REF_HPP | ||
| 12 | #define BOOST_URL_IMPL_SEGMENTS_REF_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | #include <boost/url/detail/any_segments_iter.hpp> | ||
| 16 | #include <boost/url/detail/segments_iter_impl.hpp> | ||
| 17 | #include <boost/url/detail/path.hpp> | ||
| 18 | #include <type_traits> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace urls { | ||
| 22 | |||
| 23 | //------------------------------------------------ | ||
| 24 | // | ||
| 25 | // Modifiers | ||
| 26 | // | ||
| 27 | //------------------------------------------------ | ||
| 28 | |||
| 29 | template<class FwdIt> | ||
| 30 | void | ||
| 31 | 34 | segments_ref:: | |
| 32 | assign(FwdIt first, FwdIt last) | ||
| 33 | { | ||
| 34 | /* If you get a compile error here, it | ||
| 35 | means that the iterators you passed | ||
| 36 | do not meet the requirements stated | ||
| 37 | in the documentation. | ||
| 38 | */ | ||
| 39 | static_assert( | ||
| 40 | std::is_convertible< | ||
| 41 | typename std::iterator_traits< | ||
| 42 | FwdIt>::reference, | ||
| 43 | core::string_view>::value, | ||
| 44 | "Type requirements not met"); | ||
| 45 | |||
| 46 | 68 | u_->edit_segments( | |
| 47 | 34 | begin().it_, | |
| 48 | 68 | end().it_, | |
| 49 | detail::make_segments_iter( | ||
| 50 | first, last)); | ||
| 51 | 34 | } | |
| 52 | |||
| 53 | template<class FwdIt> | ||
| 54 | auto | ||
| 55 | 31 | segments_ref:: | |
| 56 | insert( | ||
| 57 | iterator before, | ||
| 58 | FwdIt first, | ||
| 59 | FwdIt last) -> | ||
| 60 | iterator | ||
| 61 | { | ||
| 62 | /* If you get a compile error here, it | ||
| 63 | means that the iterators you passed | ||
| 64 | do not meet the requirements stated | ||
| 65 | in the documentation. | ||
| 66 | */ | ||
| 67 | static_assert( | ||
| 68 | std::is_convertible< | ||
| 69 | typename std::iterator_traits< | ||
| 70 | FwdIt>::reference, | ||
| 71 | core::string_view>::value, | ||
| 72 | "Type requirements not met"); | ||
| 73 | |||
| 74 | 62 | return insert( | |
| 75 | before, | ||
| 76 | first, | ||
| 77 | last, | ||
| 78 | typename std::iterator_traits< | ||
| 79 | 62 | FwdIt>::iterator_category{}); | |
| 80 | } | ||
| 81 | |||
| 82 | template<class FwdIt> | ||
| 83 | auto | ||
| 84 | 14 | segments_ref:: | |
| 85 | replace( | ||
| 86 | iterator from, | ||
| 87 | iterator to, | ||
| 88 | FwdIt first, | ||
| 89 | FwdIt last) -> | ||
| 90 | iterator | ||
| 91 | { | ||
| 92 | /* If you get a compile error here, it | ||
| 93 | means that the iterators you passed | ||
| 94 | do not meet the requirements stated | ||
| 95 | in the documentation. | ||
| 96 | */ | ||
| 97 | static_assert( | ||
| 98 | std::is_convertible< | ||
| 99 | typename std::iterator_traits< | ||
| 100 | FwdIt>::reference, | ||
| 101 | core::string_view>::value, | ||
| 102 | "Type requirements not met"); | ||
| 103 | |||
| 104 | 28 | return u_->edit_segments( | |
| 105 | from.it_, | ||
| 106 | to.it_, | ||
| 107 | detail::make_segments_iter( | ||
| 108 | 28 | first, last)); | |
| 109 | } | ||
| 110 | |||
| 111 | //------------------------------------------------ | ||
| 112 | |||
| 113 | template<class FwdIt> | ||
| 114 | auto | ||
| 115 | 31 | segments_ref:: | |
| 116 | insert( | ||
| 117 | iterator before, | ||
| 118 | FwdIt first, | ||
| 119 | FwdIt last, | ||
| 120 | std::forward_iterator_tag) -> | ||
| 121 | iterator | ||
| 122 | { | ||
| 123 | 62 | return u_->edit_segments( | |
| 124 | before.it_, | ||
| 125 | before.it_, | ||
| 126 | detail::make_segments_iter( | ||
| 127 | 62 | first, last)); | |
| 128 | } | ||
| 129 | |||
| 130 | //------------------------------------------------ | ||
| 131 | // | ||
| 132 | // Special Members | ||
| 133 | // | ||
| 134 | //------------------------------------------------ | ||
| 135 | |||
| 136 | inline | ||
| 137 | 267 | segments_ref:: | |
| 138 | segments_ref( | ||
| 139 | 267 | url_base& u) noexcept | |
| 140 | : segments_base( | ||
| 141 | 534 | detail::path_ref(u.impl_)) | |
| 142 | 267 | , u_(&u) | |
| 143 | { | ||
| 144 | 267 | } | |
| 145 | |||
| 146 | inline | ||
| 147 | 1 | segments_ref:: | |
| 148 | operator | ||
| 149 | segments_view() const noexcept | ||
| 150 | { | ||
| 151 | 1 | return segments_view(ref_); | |
| 152 | } | ||
| 153 | |||
| 154 | inline | ||
| 155 | segments_ref& | ||
| 156 | 1 | segments_ref:: | |
| 157 | operator=(segments_ref const& other) | ||
| 158 | { | ||
| 159 | 1 | if (!ref_.alias_of(other.ref_)) | |
| 160 | 1 | assign(other.begin(), other.end()); | |
| 161 | 1 | return *this; | |
| 162 | } | ||
| 163 | |||
| 164 | inline | ||
| 165 | segments_ref& | ||
| 166 | 1 | segments_ref:: | |
| 167 | operator=(segments_view const& other) | ||
| 168 | { | ||
| 169 | 1 | assign(other.begin(), other.end()); | |
| 170 | 1 | return *this; | |
| 171 | } | ||
| 172 | |||
| 173 | inline | ||
| 174 | segments_ref& | ||
| 175 | 17 | segments_ref:: | |
| 176 | operator=(std::initializer_list< | ||
| 177 | core::string_view> init) | ||
| 178 | { | ||
| 179 | 17 | assign(init.begin(), init.end()); | |
| 180 | 17 | return *this; | |
| 181 | } | ||
| 182 | |||
| 183 | //------------------------------------------------ | ||
| 184 | // | ||
| 185 | // Modifiers | ||
| 186 | // | ||
| 187 | //------------------------------------------------ | ||
| 188 | |||
| 189 | inline | ||
| 190 | void | ||
| 191 | 9 | segments_ref:: | |
| 192 | clear() noexcept | ||
| 193 | { | ||
| 194 | 9 | erase(begin(), end()); | |
| 195 | 9 | } | |
| 196 | |||
| 197 | inline | ||
| 198 | void | ||
| 199 | 8 | segments_ref:: | |
| 200 | assign(std::initializer_list< | ||
| 201 | core::string_view> init) | ||
| 202 | { | ||
| 203 | 8 | assign(init.begin(), init.end()); | |
| 204 | 8 | } | |
| 205 | |||
| 206 | inline | ||
| 207 | auto | ||
| 208 | 46 | segments_ref:: | |
| 209 | insert( | ||
| 210 | iterator before, | ||
| 211 | core::string_view s) -> | ||
| 212 | iterator | ||
| 213 | { | ||
| 214 | 46 | return u_->edit_segments( | |
| 215 | before.it_, | ||
| 216 | before.it_, | ||
| 217 | 92 | detail::segment_iter(s)); | |
| 218 | } | ||
| 219 | |||
| 220 | inline | ||
| 221 | auto | ||
| 222 | 16 | segments_ref:: | |
| 223 | insert( | ||
| 224 | iterator before, | ||
| 225 | std::initializer_list< | ||
| 226 | core::string_view> init) -> | ||
| 227 | iterator | ||
| 228 | { | ||
| 229 | 16 | return insert( | |
| 230 | before, | ||
| 231 | init.begin(), | ||
| 232 | 16 | init.end()); | |
| 233 | } | ||
| 234 | |||
| 235 | inline | ||
| 236 | auto | ||
| 237 | 37 | segments_ref:: | |
| 238 | erase( | ||
| 239 | iterator first, | ||
| 240 | iterator last) noexcept -> | ||
| 241 | iterator | ||
| 242 | { | ||
| 243 | 37 | core::string_view s; | |
| 244 | 37 | return u_->edit_segments( | |
| 245 | first.it_, | ||
| 246 | last.it_, | ||
| 247 | 74 | detail::make_segments_encoded_iter( | |
| 248 | 37 | &s, &s)); | |
| 249 | } | ||
| 250 | |||
| 251 | inline | ||
| 252 | auto | ||
| 253 | 16 | segments_ref:: | |
| 254 | replace( | ||
| 255 | iterator pos, | ||
| 256 | core::string_view s) -> | ||
| 257 | iterator | ||
| 258 | { | ||
| 259 | 48 | return u_->edit_segments( | |
| 260 | pos.it_, | ||
| 261 | 16 | std::next(pos).it_, | |
| 262 | 32 | detail::segment_iter(s)); | |
| 263 | } | ||
| 264 | |||
| 265 | inline | ||
| 266 | auto | ||
| 267 | 13 | segments_ref:: | |
| 268 | replace( | ||
| 269 | iterator from, | ||
| 270 | iterator to, | ||
| 271 | core::string_view s) -> | ||
| 272 | iterator | ||
| 273 | { | ||
| 274 | 13 | return u_->edit_segments( | |
| 275 | from.it_, | ||
| 276 | to.it_, | ||
| 277 | 26 | detail::segment_iter(s)); | |
| 278 | } | ||
| 279 | |||
| 280 | inline | ||
| 281 | auto | ||
| 282 | 7 | segments_ref:: | |
| 283 | replace( | ||
| 284 | iterator from, | ||
| 285 | iterator to, | ||
| 286 | std::initializer_list< | ||
| 287 | core::string_view> init) -> | ||
| 288 | iterator | ||
| 289 | { | ||
| 290 | 7 | return replace( | |
| 291 | from, | ||
| 292 | to, | ||
| 293 | init.begin(), | ||
| 294 | 7 | init.end()); | |
| 295 | } | ||
| 296 | |||
| 297 | inline | ||
| 298 | auto | ||
| 299 | 22 | segments_ref:: | |
| 300 | erase( | ||
| 301 | iterator pos) noexcept -> | ||
| 302 | iterator | ||
| 303 | { | ||
| 304 | 22 | return erase(pos, std::next(pos)); | |
| 305 | } | ||
| 306 | |||
| 307 | inline | ||
| 308 | void | ||
| 309 | 14 | segments_ref:: | |
| 310 | push_back( | ||
| 311 | core::string_view s) | ||
| 312 | { | ||
| 313 | 14 | insert(end(), s); | |
| 314 | 14 | } | |
| 315 | |||
| 316 | inline | ||
| 317 | void | ||
| 318 | 7 | segments_ref:: | |
| 319 | pop_back() noexcept | ||
| 320 | { | ||
| 321 | 14 | erase(std::prev(end())); | |
| 322 | 7 | } | |
| 323 | |||
| 324 | } // urls | ||
| 325 | } // boost | ||
| 326 | |||
| 327 | #endif | ||
| 328 |