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