100.00% Lines (94/94) 100.00% Functions (29/29)
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_URL_VIEW_BASE_HPP 11   #ifndef BOOST_URL_URL_VIEW_BASE_HPP
12   #define BOOST_URL_URL_VIEW_BASE_HPP 12   #define BOOST_URL_URL_VIEW_BASE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/authority_view.hpp> 15   #include <boost/url/authority_view.hpp>
16   #include <boost/url/host_type.hpp> 16   #include <boost/url/host_type.hpp>
17   #include <boost/url/ipv4_address.hpp> 17   #include <boost/url/ipv4_address.hpp>
18   #include <boost/url/ipv6_address.hpp> 18   #include <boost/url/ipv6_address.hpp>
19   #include <boost/url/params_view.hpp> 19   #include <boost/url/params_view.hpp>
20   #include <boost/url/params_encoded_view.hpp> 20   #include <boost/url/params_encoded_view.hpp>
21   #include <boost/url/pct_string_view.hpp> 21   #include <boost/url/pct_string_view.hpp>
22   #include <boost/url/scheme.hpp> 22   #include <boost/url/scheme.hpp>
23   #include <boost/url/segments_encoded_view.hpp> 23   #include <boost/url/segments_encoded_view.hpp>
24   #include <boost/url/segments_view.hpp> 24   #include <boost/url/segments_view.hpp>
25   #include <boost/url/detail/url_impl.hpp> 25   #include <boost/url/detail/url_impl.hpp>
26   #include <boost/url/grammar/string_token.hpp> 26   #include <boost/url/grammar/string_token.hpp>
27   #include <boost/assert.hpp> 27   #include <boost/assert.hpp>
28   #include <cstddef> 28   #include <cstddef>
29   #include <cstdint> 29   #include <cstdint>
30   #include <iosfwd> 30   #include <iosfwd>
31   #include <memory> 31   #include <memory>
32   #include <string> 32   #include <string>
33   #include <utility> 33   #include <utility>
34   34  
35   namespace boost { 35   namespace boost {
36   namespace urls { 36   namespace urls {
37   37  
38   #ifndef BOOST_URL_DOCS 38   #ifndef BOOST_URL_DOCS
39   namespace detail { 39   namespace detail {
40   struct pattern; 40   struct pattern;
41   } 41   }
42   #endif 42   #endif
43   43  
44   44  
45   /** Common functionality for containers 45   /** Common functionality for containers
46   46  
47   This base class is used by the library 47   This base class is used by the library
48   to provide common member functions for 48   to provide common member functions for
49   containers. This cannot be instantiated 49   containers. This cannot be instantiated
50   directly; Instead, use one of the 50   directly; Instead, use one of the
51   containers or functions: 51   containers or functions:
52   52  
53   @par Containers 53   @par Containers
54   @li @ref url 54   @li @ref url
55   @li @ref url_view 55   @li @ref url_view
56   @li @ref static_url 56   @li @ref static_url
57   57  
58   @par Functions 58   @par Functions
59   @li @ref parse_absolute_uri 59   @li @ref parse_absolute_uri
60   @li @ref parse_origin_form 60   @li @ref parse_origin_form
61   @li @ref parse_relative_ref 61   @li @ref parse_relative_ref
62   @li @ref parse_uri 62   @li @ref parse_uri
63   @li @ref parse_uri_reference 63   @li @ref parse_uri_reference
64   */ 64   */
65   class BOOST_SYMBOL_VISIBLE url_view_base 65   class BOOST_SYMBOL_VISIBLE url_view_base
66   : private detail::parts_base 66   : private detail::parts_base
67   { 67   {
68   detail::url_impl impl_; 68   detail::url_impl impl_;
69   detail::url_impl const* external_impl_; 69   detail::url_impl const* external_impl_;
70   70  
71   friend class url; 71   friend class url;
72   friend class url_base; 72   friend class url_base;
73   friend class url_view; 73   friend class url_view;
74   friend class static_url_base; 74   friend class static_url_base;
75   friend class params_base; 75   friend class params_base;
76   friend class params_encoded_base; 76   friend class params_encoded_base;
77   friend class params_encoded_ref; 77   friend class params_encoded_ref;
78   friend class params_encoded_view; 78   friend class params_encoded_view;
79   friend class params_ref; 79   friend class params_ref;
80   friend class params_view; 80   friend class params_view;
81   friend class segments_base; 81   friend class segments_base;
82   friend class segments_encoded_base; 82   friend class segments_encoded_base;
83   friend class segments_encoded_ref; 83   friend class segments_encoded_ref;
84   friend class segments_encoded_view; 84   friend class segments_encoded_view;
85   friend class segments_ref; 85   friend class segments_ref;
86   friend class segments_view; 86   friend class segments_view;
87   friend struct detail::pattern; 87   friend struct detail::pattern;
88   88  
89   struct shared_impl; 89   struct shared_impl;
90   90  
91   // Returns reference to the active implementation. 91   // Returns reference to the active implementation.
92   // Uses external_impl_ if set, otherwise local impl_. 92   // Uses external_impl_ if set, otherwise local impl_.
93   BOOST_URL_CXX14_CONSTEXPR 93   BOOST_URL_CXX14_CONSTEXPR
94   detail::url_impl const& 94   detail::url_impl const&
HITCBC 95   248843 impl() const noexcept 95   250424 impl() const noexcept
96   { 96   {
HITCBC 97   248843 return external_impl_ ? *external_impl_ : impl_; 97   250424 return external_impl_ ? *external_impl_ : impl_;
98   } 98   }
99   99  
100   BOOST_URL_CXX14_CONSTEXPR 100   BOOST_URL_CXX14_CONSTEXPR
HITCBC 101   5686 url_view_base() noexcept 101   5691 url_view_base() noexcept
HITCBC 102   5686 : impl_(detail::url_impl::from::url) 102   5691 : impl_(detail::url_impl::from::url)
HITCBC 103   5686 , external_impl_(nullptr) 103   5691 , external_impl_(nullptr)
104   { 104   {
HITCBC 105   5686 } 105   5691 }
106   106  
107   BOOST_URL_CXX14_CONSTEXPR 107   BOOST_URL_CXX14_CONSTEXPR
HITCBC 108   21626 explicit url_view_base( 108   21630 explicit url_view_base(
109   detail::url_impl const& impl) noexcept 109   detail::url_impl const& impl) noexcept
HITCBC 110   21626 : impl_(impl) 110   21630 : impl_(impl)
HITCBC 111   21626 , external_impl_(nullptr) 111   21630 , external_impl_(nullptr)
112   { 112   {
HITCBC 113   21626 } 113   21630 }
114   114  
115   ~url_view_base() = default; 115   ~url_view_base() = default;
116   116  
117   BOOST_URL_CXX14_CONSTEXPR 117   BOOST_URL_CXX14_CONSTEXPR
118   url_view_base( 118   url_view_base(
119   url_view_base const& o) noexcept = default; 119   url_view_base const& o) noexcept = default;
120   120  
121   BOOST_URL_CXX14_CONSTEXPR 121   BOOST_URL_CXX14_CONSTEXPR
122   url_view_base( 122   url_view_base(
123   url_view_base&& o) noexcept = default; 123   url_view_base&& o) noexcept = default;
124   124  
125   url_view_base& operator=( 125   url_view_base& operator=(
126   url_view_base const&) = delete; 126   url_view_base const&) = delete;
127   127  
128   protected: 128   protected:
129   /** Calculate a hash of the url 129   /** Calculate a hash of the url
130   130  
131   This function calculates a hash of the 131   This function calculates a hash of the
132   url as if it were always normalized. 132   url as if it were always normalized.
133   133  
134   @par Complexity 134   @par Complexity
135   Linear in `this->size()`. 135   Linear in `this->size()`.
136   136  
137   @par Exception Safety 137   @par Exception Safety
138   Throws nothing. 138   Throws nothing.
139   139  
140   @param salt An initial value to add to 140   @param salt An initial value to add to
141   the hash 141   the hash
142   142  
143   @return A hash value suitable for use 143   @return A hash value suitable for use
144   in hash-based containers. 144   in hash-based containers.
145   */ 145   */
146   std::size_t 146   std::size_t
147   digest(std::size_t salt = 0) const noexcept; 147   digest(std::size_t salt = 0) const noexcept;
148   148  
149   public: 149   public:
150   //-------------------------------------------- 150   //--------------------------------------------
151   // 151   //
152   // Observers 152   // Observers
153   // 153   //
154   //-------------------------------------------- 154   //--------------------------------------------
155   155  
156   /** Return the maximum number of characters possible 156   /** Return the maximum number of characters possible
157   157  
158   This represents the largest number 158   This represents the largest number
159   of characters that are theoretically 159   of characters that are theoretically
160   possible to represent in a url, 160   possible to represent in a url,
161   not including any null terminator. 161   not including any null terminator.
162   In practice the actual possible size 162   In practice the actual possible size
163   may be lower than this number. 163   may be lower than this number.
164   164  
165   @par Complexity 165   @par Complexity
166   Constant. 166   Constant.
167   167  
168   @par Exception Safety 168   @par Exception Safety
169   Throws nothing. 169   Throws nothing.
170   170  
171   @return The maximum number of characters. 171   @return The maximum number of characters.
172   */ 172   */
173   static 173   static
174   constexpr 174   constexpr
175   std::size_t 175   std::size_t
HITCBC 176   22462 max_size() noexcept 176   22479 max_size() noexcept
177   { 177   {
HITCBC 178   22462 return BOOST_URL_MAX_SIZE; 178   22479 return BOOST_URL_MAX_SIZE;
179   } 179   }
180   180  
181   /** Return the number of characters in the url 181   /** Return the number of characters in the url
182   182  
183   This function returns the number of 183   This function returns the number of
184   characters in the url's encoded string, 184   characters in the url's encoded string,
185   not including any null terminator, 185   not including any null terminator,
186   if present. 186   if present.
187   187  
188   @par Example 188   @par Example
189   @code 189   @code
190   assert( url_view( "file:///Program%20Files" ).size() == 23 ); 190   assert( url_view( "file:///Program%20Files" ).size() == 23 );
191   @endcode 191   @endcode
192   192  
193   @par Complexity 193   @par Complexity
194   Constant. 194   Constant.
195   195  
196   @par Exception Safety 196   @par Exception Safety
197   Throws nothing. 197   Throws nothing.
198   198  
199   @return The number of characters in the url. 199   @return The number of characters in the url.
200   */ 200   */
201   std::size_t 201   std::size_t
HITCBC 202   115437 size() const noexcept 202   115498 size() const noexcept
203   { 203   {
HITCBC 204   115437 return impl().offset(id_end); 204   115498 return impl().offset(id_end);
205   } 205   }
206   206  
207   /** Return true if the url is empty 207   /** Return true if the url is empty
208   208  
209   The empty string matches the 209   The empty string matches the
210   <em>relative-ref</em> grammar. 210   <em>relative-ref</em> grammar.
211   211  
212   @par Example 212   @par Example
213   @code 213   @code
214   assert( url_view( "" ).empty() ); 214   assert( url_view( "" ).empty() );
215   @endcode 215   @endcode
216   216  
217   @par Complexity 217   @par Complexity
218   Constant. 218   Constant.
219   219  
220   @par Exception Safety 220   @par Exception Safety
221   Throws nothing. 221   Throws nothing.
222   222  
223   @par BNF 223   @par BNF
224   @code 224   @code
225   relative-ref = relative-part [ "?" query ] [ "#" fragment ] 225   relative-ref = relative-part [ "?" query ] [ "#" fragment ]
226   226  
227   relative-part = "//" authority path-abempty 227   relative-part = "//" authority path-abempty
228   / path-absolute 228   / path-absolute
229   / path-noscheme 229   / path-noscheme
230   / path-empty 230   / path-empty
231   @endcode 231   @endcode
232   232  
233   @par Specification 233   @par Specification
234   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-4.2">4.2. Relative Reference (rfc3986)</a> 234   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-4.2">4.2. Relative Reference (rfc3986)</a>
235   235  
236   @return `true` if the url is empty. 236   @return `true` if the url is empty.
237   */ 237   */
238   bool 238   bool
HITCBC 239   15 empty() const noexcept 239   15 empty() const noexcept
240   { 240   {
HITCBC 241   15 return impl().offset(id_end) == 0; 241   15 return impl().offset(id_end) == 0;
242   } 242   }
243   243  
244   /** Return a pointer to the url's character buffer 244   /** Return a pointer to the url's character buffer
245   245  
246   This function returns a pointer to 246   This function returns a pointer to
247   the first character of the url, which 247   the first character of the url, which
248   is not guaranteed to be null-terminated. 248   is not guaranteed to be null-terminated.
249   249  
250   @par Complexity 250   @par Complexity
251   Constant. 251   Constant.
252   252  
253   @par Exception Safety 253   @par Exception Safety
254   Throws nothing. 254   Throws nothing.
255   255  
256   @return A pointer to the first character. 256   @return A pointer to the first character.
257   */ 257   */
258   char const* 258   char const*
HITCBC 259   17827 data() const noexcept 259   17831 data() const noexcept
260   { 260   {
HITCBC 261   17827 return impl().cs_; 261   17831 return impl().cs_;
262   } 262   }
263   263  
264   /** Return the url string 264   /** Return the url string
265   265  
266   This function returns the entire url, 266   This function returns the entire url,
267   which may contain percent escapes. 267   which may contain percent escapes.
268   268  
269   @par Example 269   @par Example
270   @code 270   @code
271   assert( url_view( "http://www.example.com" ).buffer() == "http://www.example.com" ); 271   assert( url_view( "http://www.example.com" ).buffer() == "http://www.example.com" );
272   @endcode 272   @endcode
273   273  
274   @par Complexity 274   @par Complexity
275   Constant. 275   Constant.
276   276  
277   @par Exception Safety 277   @par Exception Safety
278   Throws nothing. 278   Throws nothing.
279   279  
280   @return The url as a string. 280   @return The url as a string.
281   */ 281   */
282   core::string_view 282   core::string_view
HITCBC 283   12725 buffer() const noexcept 283   12725 buffer() const noexcept
284   { 284   {
HITCBC 285   12725 return core::string_view( 285   12725 return core::string_view(
HITCBC 286   12725 data(), size()); 286   12725 data(), size());
287   } 287   }
288   288  
289   /** Return the URL as a core::string_view 289   /** Return the URL as a core::string_view
290   290  
291   @par Complexity 291   @par Complexity
292   Constant. 292   Constant.
293   293  
294   @par Exception Safety 294   @par Exception Safety
295   Throws nothing. 295   Throws nothing.
296   296  
297   @return A string view of the URL. 297   @return A string view of the URL.
298   */ 298   */
HITCBC 299   250 operator core::string_view() const noexcept 299   250 operator core::string_view() const noexcept
300   { 300   {
HITCBC 301   250 return buffer(); 301   250 return buffer();
302   } 302   }
303   303  
304   /** Return a shared, persistent copy of the url 304   /** Return a shared, persistent copy of the url
305   305  
306   This function returns a read-only copy of 306   This function returns a read-only copy of
307   the url, with shared lifetime. The returned 307   the url, with shared lifetime. The returned
308   value owns (persists) the underlying string. 308   value owns (persists) the underlying string.
309   The algorithm used to create the value 309   The algorithm used to create the value
310   minimizes the number of individual memory 310   minimizes the number of individual memory
311   allocations, making it more efficient than 311   allocations, making it more efficient than
312   when using direct standard library functions. 312   when using direct standard library functions.
313   313  
314   @par Example 314   @par Example
315   @code 315   @code
316   std::shared_ptr< url_view const > sp; 316   std::shared_ptr< url_view const > sp;
317   { 317   {
318   std::string s( "http://example.com" ); 318   std::string s( "http://example.com" );
319   url_view u( s ); // u references characters in s 319   url_view u( s ); // u references characters in s
320   320  
321   assert( u.data() == s.data() ); // same buffer 321   assert( u.data() == s.data() ); // same buffer
322   322  
323   sp = u.persist(); 323   sp = u.persist();
324   324  
325   assert( sp->data() != s.data() ); // different buffer 325   assert( sp->data() != s.data() ); // different buffer
326   assert( sp->buffer() == s); // same contents 326   assert( sp->buffer() == s); // same contents
327   327  
328   // s is destroyed and thus u 328   // s is destroyed and thus u
329   // becomes invalid, but sp remains valid. 329   // becomes invalid, but sp remains valid.
330   } 330   }
331   @endcode 331   @endcode
332   332  
333   @par Complexity 333   @par Complexity
334   Linear in `this->size()`. 334   Linear in `this->size()`.
335   335  
336   @par Exception Safety 336   @par Exception Safety
337   Calls to allocate may throw. 337   Calls to allocate may throw.
338   338  
339   @return A shared pointer to a read-only url_view. 339   @return A shared pointer to a read-only url_view.
340   */ 340   */
341   std::shared_ptr< 341   std::shared_ptr<
342   url_view const> persist() const; 342   url_view const> persist() const;
343   343  
344   //-------------------------------------------- 344   //--------------------------------------------
345   // 345   //
346   // Scheme 346   // Scheme
347   // 347   //
348   //-------------------------------------------- 348   //--------------------------------------------
349   349  
350   /** Return true a scheme is present 350   /** Return true a scheme is present
351   351  
352   This function returns true if this 352   This function returns true if this
353   contains a scheme. 353   contains a scheme.
354   354  
355   @par Example 355   @par Example
356   @code 356   @code
357   assert( url_view( "http://www.example.com" ).has_scheme() ); 357   assert( url_view( "http://www.example.com" ).has_scheme() );
358   @endcode 358   @endcode
359   359  
360   @par Complexity 360   @par Complexity
361   Constant. 361   Constant.
362   362  
363   @par Exception Safety 363   @par Exception Safety
364   Throws nothing. 364   Throws nothing.
365   365  
366   @par BNF 366   @par BNF
367   @code 367   @code
368   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 368   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
369   369  
370   absolute-URI = scheme ":" hier-part [ "?" query ] 370   absolute-URI = scheme ":" hier-part [ "?" query ]
371   371  
372   scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) 372   scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
373   @endcode 373   @endcode
374   374  
375   @par Specification 375   @par Specification
376   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">3.1. Scheme (rfc3986)</a> 376   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">3.1. Scheme (rfc3986)</a>
377   377  
378   @see 378   @see
379   @ref scheme, 379   @ref scheme,
380   @ref scheme_id. 380   @ref scheme_id.
381   381  
382   @return `true` if the url contains a scheme. 382   @return `true` if the url contains a scheme.
383   */ 383   */
384   bool 384   bool
385   has_scheme() const noexcept; 385   has_scheme() const noexcept;
386   386  
387   /** Return the scheme 387   /** Return the scheme
388   388  
389   This function returns the scheme if it 389   This function returns the scheme if it
390   exists, without a trailing colon (':'). 390   exists, without a trailing colon (':').
391   Otherwise it returns an empty string. 391   Otherwise it returns an empty string.
392   Note that schemes are case-insensitive, 392   Note that schemes are case-insensitive,
393   and the canonical form is lowercased. 393   and the canonical form is lowercased.
394   394  
395   @par Example 395   @par Example
396   @code 396   @code
397   assert( url_view( "http://www.example.com" ).scheme() == "http" ); 397   assert( url_view( "http://www.example.com" ).scheme() == "http" );
398   @endcode 398   @endcode
399   399  
400   @par Exception Safety 400   @par Exception Safety
401   Throws nothing. 401   Throws nothing.
402   402  
403   @par BNF 403   @par BNF
404   @code 404   @code
405   scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) 405   scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
406   406  
407   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 407   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
408   408  
409   absolute-URI = scheme ":" hier-part [ "?" query ] 409   absolute-URI = scheme ":" hier-part [ "?" query ]
410   @endcode 410   @endcode
411   411  
412   @par Specification 412   @par Specification
413   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">3.1. Scheme (rfc3986)</a> 413   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">3.1. Scheme (rfc3986)</a>
414   414  
415   @see 415   @see
416   @ref has_scheme, 416   @ref has_scheme,
417   @ref scheme_id. 417   @ref scheme_id.
418   418  
419   @return The scheme as a string. 419   @return The scheme as a string.
420   */ 420   */
421   core::string_view 421   core::string_view
422   scheme() const noexcept; 422   scheme() const noexcept;
423   423  
424   /** Return the scheme 424   /** Return the scheme
425   425  
426   This function returns a value which 426   This function returns a value which
427   depends on the scheme in the url: 427   depends on the scheme in the url:
428   428  
429   @li If the scheme is a well-known 429   @li If the scheme is a well-known
430   scheme, corresponding value from 430   scheme, corresponding value from
431   the enumeration @ref urls::scheme 431   the enumeration @ref urls::scheme
432   is returned. 432   is returned.
433   433  
434   @li If a scheme is present but is not 434   @li If a scheme is present but is not
435   a well-known scheme, the value 435   a well-known scheme, the value
436   returned is @ref urls::scheme::unknown. 436   returned is @ref urls::scheme::unknown.
437   437  
438   @li Otherwise, if the scheme is absent 438   @li Otherwise, if the scheme is absent
439   the value returned is 439   the value returned is
440   @ref urls::scheme::none. 440   @ref urls::scheme::none.
441   441  
442   @par Example 442   @par Example
443   @code 443   @code
444   assert( url_view( "wss://www.example.com/crypto.cgi" ).scheme_id() == scheme::wss ); 444   assert( url_view( "wss://www.example.com/crypto.cgi" ).scheme_id() == scheme::wss );
445   @endcode 445   @endcode
446   446  
447   @par Complexity 447   @par Complexity
448   Constant. 448   Constant.
449   449  
450   @par Exception Safety 450   @par Exception Safety
451   Throws nothing. 451   Throws nothing.
452   452  
453   @par BNF 453   @par BNF
454   @code 454   @code
455   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 455   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
456   456  
457   absolute-URI = scheme ":" hier-part [ "?" query ] 457   absolute-URI = scheme ":" hier-part [ "?" query ]
458   458  
459   scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) 459   scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
460   @endcode 460   @endcode
461   461  
462   @par Specification 462   @par Specification
463   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">3.1. Scheme (rfc3986)</a> 463   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">3.1. Scheme (rfc3986)</a>
464   464  
465   @see 465   @see
466   @ref has_scheme, 466   @ref has_scheme,
467   @ref scheme. 467   @ref scheme.
468   468  
469   @return The scheme as an enumeration value. 469   @return The scheme as an enumeration value.
470   */ 470   */
471   urls::scheme 471   urls::scheme
472   scheme_id() const noexcept; 472   scheme_id() const noexcept;
473   473  
474   //-------------------------------------------- 474   //--------------------------------------------
475   // 475   //
476   // Authority 476   // Authority
477   // 477   //
478   //-------------------------------------------- 478   //--------------------------------------------
479   479  
480   /** Return true if an authority is present 480   /** Return true if an authority is present
481   481  
482   This function returns true if the url 482   This function returns true if the url
483   contains an authority. The presence of 483   contains an authority. The presence of
484   an authority is denoted by a double 484   an authority is denoted by a double
485   slash ("//") at the beginning or after 485   slash ("//") at the beginning or after
486   the scheme. 486   the scheme.
487   487  
488   @par Example 488   @par Example
489   @code 489   @code
490   assert( url_view( "http://www.example.com/index.htm" ).has_authority() ); 490   assert( url_view( "http://www.example.com/index.htm" ).has_authority() );
491   @endcode 491   @endcode
492   492  
493   @par Complexity 493   @par Complexity
494   Constant. 494   Constant.
495   495  
496   @par Exception Safety 496   @par Exception Safety
497   Throws nothing. 497   Throws nothing.
498   498  
499   @par BNF 499   @par BNF
500   @code 500   @code
501   authority = [ userinfo "@" ] host [ ":" port ] 501   authority = [ userinfo "@" ] host [ ":" port ]
502   502  
503   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 503   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
504   504  
505   absolute-URI = scheme ":" hier-part [ "?" query ] 505   absolute-URI = scheme ":" hier-part [ "?" query ]
506   506  
507   URI-reference = URI / relative-ref 507   URI-reference = URI / relative-ref
508   508  
509   relative-ref = relative-part [ "?" query ] [ "#" fragment ] 509   relative-ref = relative-part [ "?" query ] [ "#" fragment ]
510   510  
511   hier-part = "//" authority path-abempty 511   hier-part = "//" authority path-abempty
512   ; (more...) 512   ; (more...)
513   513  
514   relative-part = "//" authority path-abempty 514   relative-part = "//" authority path-abempty
515   ; (more...) 515   ; (more...)
516   516  
517   @endcode 517   @endcode
518   518  
519   @par Specification 519   @par Specification
520   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">3.2. Authority (rfc3986)</a> 520   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">3.2. Authority (rfc3986)</a>
521   521  
522   @see 522   @see
523   @ref authority, 523   @ref authority,
524   @ref encoded_authority. 524   @ref encoded_authority.
525   525  
526   @return `true` if the url contains an authority. 526   @return `true` if the url contains an authority.
527   */ 527   */
528   bool 528   bool
HITCBC 529   9286 has_authority() const noexcept 529   9286 has_authority() const noexcept
530   { 530   {
HITCBC 531   9286 return impl().len(id_user) > 0; 531   9286 return impl().len(id_user) > 0;
532   } 532   }
533   533  
534   /** Return the authority 534   /** Return the authority
535   535  
536   This function returns the authority as 536   This function returns the authority as
537   an @ref authority_view. 537   an @ref authority_view.
538   538  
539   @par Example 539   @par Example
540   @code 540   @code
541   authority_view a = url_view( "https://www.example.com:8080/index.htm" ).authority(); 541   authority_view a = url_view( "https://www.example.com:8080/index.htm" ).authority();
542   @endcode 542   @endcode
543   543  
544   @par Complexity 544   @par Complexity
545   Constant. 545   Constant.
546   546  
547   @par Exception Safety 547   @par Exception Safety
548   Throws nothing. 548   Throws nothing.
549   549  
550   @par BNF 550   @par BNF
551   @code 551   @code
552   authority = [ userinfo "@" ] host [ ":" port ] 552   authority = [ userinfo "@" ] host [ ":" port ]
553   @endcode 553   @endcode
554   554  
555   @par Specification 555   @par Specification
556   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">3.2. Authority (rfc3986)</a> 556   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">3.2. Authority (rfc3986)</a>
557   557  
558   @see 558   @see
559   @ref encoded_authority, 559   @ref encoded_authority,
560   @ref has_authority. 560   @ref has_authority.
561   561  
562   @return An authority_view representing the authority. 562   @return An authority_view representing the authority.
563   */ 563   */
564   authority_view 564   authority_view
565   authority() const noexcept; 565   authority() const noexcept;
566   566  
567   /** Return the authority. 567   /** Return the authority.
568   568  
569   If present, this function returns a 569   If present, this function returns a
570   string representing the authority (which 570   string representing the authority (which
571   may be empty). 571   may be empty).
572   Otherwise it returns an empty string. 572   Otherwise it returns an empty string.
573   The returned string may contain 573   The returned string may contain
574   percent escapes. 574   percent escapes.
575   575  
576   @par Example 576   @par Example
577   @code 577   @code
578   assert( url_view( "file://Network%20Drive/My%2DFiles" ).encoded_authority() == "Network%20Drive" ); 578   assert( url_view( "file://Network%20Drive/My%2DFiles" ).encoded_authority() == "Network%20Drive" );
579   @endcode 579   @endcode
580   580  
581   @par Complexity 581   @par Complexity
582   Constant. 582   Constant.
583   583  
584   @par Exception Safety 584   @par Exception Safety
585   Throws nothing. 585   Throws nothing.
586   586  
587   @par BNF 587   @par BNF
588   @code 588   @code
589   authority = [ userinfo "@" ] host [ ":" port ] 589   authority = [ userinfo "@" ] host [ ":" port ]
590   @endcode 590   @endcode
591   591  
592   @par Specification 592   @par Specification
593   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">3.2. Authority (rfc3986)</a> 593   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">3.2. Authority (rfc3986)</a>
594   594  
595   @see 595   @see
596   @ref authority, 596   @ref authority,
597   @ref has_authority. 597   @ref has_authority.
598   598  
599   @return The authority as a string. 599   @return The authority as a string.
600   */ 600   */
601   pct_string_view 601   pct_string_view
602   encoded_authority() const noexcept; 602   encoded_authority() const noexcept;
603   603  
604   //-------------------------------------------- 604   //--------------------------------------------
605   // 605   //
606   // Userinfo 606   // Userinfo
607   // 607   //
608   //-------------------------------------------- 608   //--------------------------------------------
609   609  
610   /** Return true if a userinfo is present 610   /** Return true if a userinfo is present
611   611  
612   This function returns true if this 612   This function returns true if this
613   contains a userinfo. 613   contains a userinfo.
614   614  
615   @par Example 615   @par Example
616   @code 616   @code
617   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() ); 617   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() );
618   @endcode 618   @endcode
619   619  
620   @par Complexity 620   @par Complexity
621   Constant. 621   Constant.
622   622  
623   @par Exception Safety 623   @par Exception Safety
624   Throws nothing. 624   Throws nothing.
625   625  
626   @par BNF 626   @par BNF
627   @code 627   @code
628   userinfo = user [ ":" [ password ] ] 628   userinfo = user [ ":" [ password ] ]
629   629  
630   authority = [ userinfo "@" ] host [ ":" port ] 630   authority = [ userinfo "@" ] host [ ":" port ]
631   @endcode 631   @endcode
632   632  
633   @par Specification 633   @par Specification
634   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 634   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
635   635  
636   @see 636   @see
637   @ref has_password, 637   @ref has_password,
638   @ref encoded_password, 638   @ref encoded_password,
639   @ref encoded_user, 639   @ref encoded_user,
640   @ref encoded_userinfo, 640   @ref encoded_userinfo,
641   @ref password, 641   @ref password,
642   @ref user, 642   @ref user,
643   @ref userinfo. 643   @ref userinfo.
644   644  
645   @return `true` if the userinfo is present. 645   @return `true` if the userinfo is present.
646   */ 646   */
647   bool 647   bool
648   has_userinfo() const noexcept; 648   has_userinfo() const noexcept;
649   649  
650   /** Return true if a password is present 650   /** Return true if a password is present
651   651  
652   This function returns true if the 652   This function returns true if the
653   userinfo is present and contains 653   userinfo is present and contains
654   a password. 654   a password.
655   655  
656   @par Example 656   @par Example
657   @code 657   @code
658   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() ); 658   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() );
659   @endcode 659   @endcode
660   660  
661   @par Complexity 661   @par Complexity
662   Constant. 662   Constant.
663   663  
664   @par Exception Safety 664   @par Exception Safety
665   Throws nothing. 665   Throws nothing.
666   666  
667   @par BNF 667   @par BNF
668   @code 668   @code
669   userinfo = user [ ":" [ password ] ] 669   userinfo = user [ ":" [ password ] ]
670   670  
671   user = *( unreserved / pct-encoded / sub-delims ) 671   user = *( unreserved / pct-encoded / sub-delims )
672   password = *( unreserved / pct-encoded / sub-delims / ":" ) 672   password = *( unreserved / pct-encoded / sub-delims / ":" )
673   @endcode 673   @endcode
674   674  
675   @par Specification 675   @par Specification
676   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 676   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
677   677  
678   @see 678   @see
679   @ref has_userinfo, 679   @ref has_userinfo,
680   @ref encoded_password, 680   @ref encoded_password,
681   @ref encoded_user, 681   @ref encoded_user,
682   @ref encoded_userinfo, 682   @ref encoded_userinfo,
683   @ref password, 683   @ref password,
684   @ref user, 684   @ref user,
685   @ref userinfo. 685   @ref userinfo.
686   686  
687   @return `true` if the userinfo contains a password. 687   @return `true` if the userinfo contains a password.
688   */ 688   */
689   bool 689   bool
690   has_password() const noexcept; 690   has_password() const noexcept;
691   691  
692   /** Return the userinfo 692   /** Return the userinfo
693   693  
694   If present, this function returns a 694   If present, this function returns a
695   string representing the userinfo (which 695   string representing the userinfo (which
696   may be empty). 696   may be empty).
697   Otherwise it returns an empty string. 697   Otherwise it returns an empty string.
698   Any percent-escapes in the string are 698   Any percent-escapes in the string are
699   decoded first. 699   decoded first.
700   700  
701   @note 701   @note
702   This function uses the string token 702   This function uses the string token
703   return type customization. Depending on 703   return type customization. Depending on
704   the token passed, the return type and 704   the token passed, the return type and
705   behavior of the function can be different. 705   behavior of the function can be different.
706   See @ref string_token::return_string 706   See @ref string_token::return_string
707   for more information. 707   for more information.
708   708  
709   @par Example 709   @par Example
710   @code 710   @code
711   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" ); 711   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" );
712   @endcode 712   @endcode
713   713  
714   @par Complexity 714   @par Complexity
715   Linear in `this->userinfo().size()`. 715   Linear in `this->userinfo().size()`.
716   716  
717   @par Exception Safety 717   @par Exception Safety
718   Calls to allocate may throw. 718   Calls to allocate may throw.
719   719  
720   @return When called with no arguments, 720   @return When called with no arguments,
721   a value of type `std::string` is 721   a value of type `std::string` is
722   returned. Otherwise, the return type 722   returned. Otherwise, the return type
723   and meaning depends on the string token 723   and meaning depends on the string token
724   passed to the function. 724   passed to the function.
725   725  
726   @par BNF 726   @par BNF
727   @code 727   @code
728   userinfo = user [ ":" [ password ] ] 728   userinfo = user [ ":" [ password ] ]
729   729  
730   authority = [ userinfo "@" ] host [ ":" port ] 730   authority = [ userinfo "@" ] host [ ":" port ]
731   @endcode 731   @endcode
732   732  
733   @par Specification 733   @par Specification
734   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 734   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
735   735  
736   @see 736   @see
737   @ref has_password, 737   @ref has_password,
738   @ref has_userinfo, 738   @ref has_userinfo,
739   @ref encoded_password, 739   @ref encoded_password,
740   @ref encoded_user, 740   @ref encoded_user,
741   @ref encoded_userinfo, 741   @ref encoded_userinfo,
742   @ref password, 742   @ref password,
743   @ref user. 743   @ref user.
744   744  
745   @param token The string token to use. 745   @param token The string token to use.
746   @return The userinfo as a string. 746   @return The userinfo as a string.
747   */ 747   */
748   template<BOOST_URL_STRTOK_TPARAM> 748   template<BOOST_URL_STRTOK_TPARAM>
749   BOOST_URL_STRTOK_RETURN 749   BOOST_URL_STRTOK_RETURN
HITCBC 750   40 userinfo( 750   40 userinfo(
751   StringToken&& token = {}) const 751   StringToken&& token = {}) const
752   { 752   {
HITCBC 753   40 encoding_opts opt; 753   40 encoding_opts opt;
HITCBC 754   40 opt.space_as_plus = false; 754   40 opt.space_as_plus = false;
HITCBC 755   80 return encoded_userinfo().decode( 755   80 return encoded_userinfo().decode(
HITCBC 756   80 opt, std::forward<StringToken>(token)); 756   80 opt, std::forward<StringToken>(token));
757   } 757   }
758   758  
759   /** Return the userinfo 759   /** Return the userinfo
760   760  
761   If present, this function returns a 761   If present, this function returns a
762   string representing the userinfo (which 762   string representing the userinfo (which
763   may be empty). 763   may be empty).
764   Otherwise it returns an empty string. 764   Otherwise it returns an empty string.
765   The returned string may contain 765   The returned string may contain
766   percent escapes. 766   percent escapes.
767   767  
768   @par Example 768   @par Example
769   @code 769   @code
770   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" ); 770   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" );
771   @endcode 771   @endcode
772   772  
773   @par Complexity 773   @par Complexity
774   Constant. 774   Constant.
775   775  
776   @par Exception Safety 776   @par Exception Safety
777   Throws nothing 777   Throws nothing
778   778  
779   @par BNF 779   @par BNF
780   @code 780   @code
781   userinfo = user [ ":" [ password ] ] 781   userinfo = user [ ":" [ password ] ]
782   782  
783   authority = [ userinfo "@" ] host [ ":" port ] 783   authority = [ userinfo "@" ] host [ ":" port ]
784   @endcode 784   @endcode
785   785  
786   @par Specification 786   @par Specification
787   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 787   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
788   788  
789   @see 789   @see
790   @ref has_password, 790   @ref has_password,
791   @ref has_userinfo, 791   @ref has_userinfo,
792   @ref encoded_password, 792   @ref encoded_password,
793   @ref encoded_user, 793   @ref encoded_user,
794   @ref password, 794   @ref password,
795   @ref user, 795   @ref user,
796   @ref userinfo. 796   @ref userinfo.
797   797  
798   @return The userinfo as a string. 798   @return The userinfo as a string.
799   */ 799   */
800   pct_string_view 800   pct_string_view
801   encoded_userinfo() const noexcept; 801   encoded_userinfo() const noexcept;
802   802  
803   //-------------------------------------------- 803   //--------------------------------------------
804   804  
805   /** Return the user 805   /** Return the user
806   806  
807   If present, this function returns a 807   If present, this function returns a
808   string representing the user (which 808   string representing the user (which
809   may be empty). 809   may be empty).
810   Otherwise it returns an empty string. 810   Otherwise it returns an empty string.
811   Any percent-escapes in the string are 811   Any percent-escapes in the string are
812   decoded first. 812   decoded first.
813   813  
814   @par Example 814   @par Example
815   @code 815   @code
816   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" ); 816   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" );
817   @endcode 817   @endcode
818   818  
819   @par Complexity 819   @par Complexity
820   Linear in `this->user().size()`. 820   Linear in `this->user().size()`.
821   821  
822   @par Exception Safety 822   @par Exception Safety
823   Calls to allocate may throw. 823   Calls to allocate may throw.
824   824  
825   @par BNF 825   @par BNF
826   @code 826   @code
827   userinfo = user [ ":" [ password ] ] 827   userinfo = user [ ":" [ password ] ]
828   828  
829   user = *( unreserved / pct-encoded / sub-delims ) 829   user = *( unreserved / pct-encoded / sub-delims )
830   password = *( unreserved / pct-encoded / sub-delims / ":" ) 830   password = *( unreserved / pct-encoded / sub-delims / ":" )
831   @endcode 831   @endcode
832   832  
833   @par Specification 833   @par Specification
834   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 834   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
835   835  
836   @see 836   @see
837   @ref has_password, 837   @ref has_password,
838   @ref has_userinfo, 838   @ref has_userinfo,
839   @ref encoded_password, 839   @ref encoded_password,
840   @ref encoded_user, 840   @ref encoded_user,
841   @ref encoded_userinfo, 841   @ref encoded_userinfo,
842   @ref password, 842   @ref password,
843   @ref userinfo. 843   @ref userinfo.
844   844  
845   @param token The string token to use. 845   @param token The string token to use.
846   @return The user as a string. 846   @return The user as a string.
847   */ 847   */
848   template<BOOST_URL_STRTOK_TPARAM> 848   template<BOOST_URL_STRTOK_TPARAM>
849   BOOST_URL_STRTOK_RETURN 849   BOOST_URL_STRTOK_RETURN
HITCBC 850   66 user( 850   66 user(
851   StringToken&& token = {}) const 851   StringToken&& token = {}) const
852   { 852   {
HITCBC 853   66 encoding_opts opt; 853   66 encoding_opts opt;
HITCBC 854   66 opt.space_as_plus = false; 854   66 opt.space_as_plus = false;
HITCBC 855   132 return encoded_user().decode( 855   132 return encoded_user().decode(
HITCBC 856   132 opt, std::forward<StringToken>(token)); 856   132 opt, std::forward<StringToken>(token));
857   } 857   }
858   858  
859   /** Return the user 859   /** Return the user
860   860  
861   If present, this function returns a 861   If present, this function returns a
862   string representing the user (which 862   string representing the user (which
863   may be empty). 863   may be empty).
864   Otherwise it returns an empty string. 864   Otherwise it returns an empty string.
865   The returned string may contain 865   The returned string may contain
866   percent escapes. 866   percent escapes.
867   867  
868   @par Example 868   @par Example
869   @code 869   @code
870   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" ); 870   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" );
871   @endcode 871   @endcode
872   872  
873   @par Complexity 873   @par Complexity
874   Constant. 874   Constant.
875   875  
876   @par Exception Safety 876   @par Exception Safety
877   Throws nothing. 877   Throws nothing.
878   878  
879   @par BNF 879   @par BNF
880   @code 880   @code
881   userinfo = user [ ":" [ password ] ] 881   userinfo = user [ ":" [ password ] ]
882   882  
883   user = *( unreserved / pct-encoded / sub-delims ) 883   user = *( unreserved / pct-encoded / sub-delims )
884   password = *( unreserved / pct-encoded / sub-delims / ":" ) 884   password = *( unreserved / pct-encoded / sub-delims / ":" )
885   @endcode 885   @endcode
886   886  
887   @par Specification 887   @par Specification
888   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 888   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
889   889  
890   @see 890   @see
891   @ref has_password, 891   @ref has_password,
892   @ref has_userinfo, 892   @ref has_userinfo,
893   @ref encoded_password, 893   @ref encoded_password,
894   @ref encoded_userinfo, 894   @ref encoded_userinfo,
895   @ref password, 895   @ref password,
896   @ref user, 896   @ref user,
897   @ref userinfo. 897   @ref userinfo.
898   898  
899   @return The user as a string. 899   @return The user as a string.
900   */ 900   */
901   pct_string_view 901   pct_string_view
902   encoded_user() const noexcept; 902   encoded_user() const noexcept;
903   903  
904   /** Return the password 904   /** Return the password
905   905  
906   If present, this function returns a 906   If present, this function returns a
907   string representing the password (which 907   string representing the password (which
908   may be an empty string). 908   may be an empty string).
909   Otherwise it returns an empty string. 909   Otherwise it returns an empty string.
910   Any percent-escapes in the string are 910   Any percent-escapes in the string are
911   decoded first. 911   decoded first.
912   912  
913   @par Example 913   @par Example
914   @code 914   @code
915   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" ); 915   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" );
916   @endcode 916   @endcode
917   917  
918   @par Complexity 918   @par Complexity
919   Linear in `this->password().size()`. 919   Linear in `this->password().size()`.
920   920  
921   @par Exception Safety 921   @par Exception Safety
922   Calls to allocate may throw. 922   Calls to allocate may throw.
923   923  
924   @par BNF 924   @par BNF
925   @code 925   @code
926   userinfo = user [ ":" [ password ] ] 926   userinfo = user [ ":" [ password ] ]
927   927  
928   user = *( unreserved / pct-encoded / sub-delims ) 928   user = *( unreserved / pct-encoded / sub-delims )
929   password = *( unreserved / pct-encoded / sub-delims / ":" ) 929   password = *( unreserved / pct-encoded / sub-delims / ":" )
930   @endcode 930   @endcode
931   931  
932   @par Specification 932   @par Specification
933   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 933   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
934   934  
935   @see 935   @see
936   @ref has_password, 936   @ref has_password,
937   @ref has_userinfo, 937   @ref has_userinfo,
938   @ref encoded_password, 938   @ref encoded_password,
939   @ref encoded_user, 939   @ref encoded_user,
940   @ref encoded_userinfo, 940   @ref encoded_userinfo,
941   @ref user, 941   @ref user,
942   @ref userinfo. 942   @ref userinfo.
943   943  
944   @param token The string token to use. 944   @param token The string token to use.
945   @return The password as a string. 945   @return The password as a string.
946   */ 946   */
947   template<BOOST_URL_STRTOK_TPARAM> 947   template<BOOST_URL_STRTOK_TPARAM>
948   BOOST_URL_STRTOK_RETURN 948   BOOST_URL_STRTOK_RETURN
HITCBC 949   33 password( 949   33 password(
950   StringToken&& token = {}) const 950   StringToken&& token = {}) const
951   { 951   {
HITCBC 952   33 encoding_opts opt; 952   33 encoding_opts opt;
HITCBC 953   33 opt.space_as_plus = false; 953   33 opt.space_as_plus = false;
HITCBC 954   66 return encoded_password().decode( 954   66 return encoded_password().decode(
HITCBC 955   66 opt, std::forward<StringToken>(token)); 955   66 opt, std::forward<StringToken>(token));
956   } 956   }
957   957  
958   /** Return the password 958   /** Return the password
959   959  
960   This function returns the password portion 960   This function returns the password portion
961   of the userinfo as a percent-encoded string. 961   of the userinfo as a percent-encoded string.
962   962  
963   @par Example 963   @par Example
964   @code 964   @code
965   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" ); 965   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" );
966   @endcode 966   @endcode
967   967  
968   @par Complexity 968   @par Complexity
969   Constant. 969   Constant.
970   970  
971   @par Exception Safety 971   @par Exception Safety
972   Throws nothing. 972   Throws nothing.
973   973  
974   @par BNF 974   @par BNF
975   @code 975   @code
976   userinfo = user [ ":" [ password ] ] 976   userinfo = user [ ":" [ password ] ]
977   977  
978   user = *( unreserved / pct-encoded / sub-delims ) 978   user = *( unreserved / pct-encoded / sub-delims )
979   password = *( unreserved / pct-encoded / sub-delims / ":" ) 979   password = *( unreserved / pct-encoded / sub-delims / ":" )
980   @endcode 980   @endcode
981   981  
982   @par Specification 982   @par Specification
983   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a> 983   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">3.2.1. User Information (rfc3986)</a>
984   984  
985   @see 985   @see
986   @ref has_password, 986   @ref has_password,
987   @ref has_userinfo, 987   @ref has_userinfo,
988   @ref encoded_user, 988   @ref encoded_user,
989   @ref encoded_userinfo, 989   @ref encoded_userinfo,
990   @ref password, 990   @ref password,
991   @ref user, 991   @ref user,
992   @ref userinfo. 992   @ref userinfo.
993   993  
994   @return The password as a string. 994   @return The password as a string.
995   */ 995   */
996   pct_string_view 996   pct_string_view
997   encoded_password() const noexcept; 997   encoded_password() const noexcept;
998   998  
999   //-------------------------------------------- 999   //--------------------------------------------
1000   // 1000   //
1001   // Host 1001   // Host
1002   // 1002   //
1003   //-------------------------------------------- 1003   //--------------------------------------------
1004   1004  
1005   /** Return the host type 1005   /** Return the host type
1006   1006  
1007   This function returns one of the 1007   This function returns one of the
1008   following constants representing the 1008   following constants representing the
1009   type of host present. 1009   type of host present.
1010   1010  
1011   @li @ref host_type::ipv4 1011   @li @ref host_type::ipv4
1012   @li @ref host_type::ipv6 1012   @li @ref host_type::ipv6
1013   @li @ref host_type::ipvfuture 1013   @li @ref host_type::ipvfuture
1014   @li @ref host_type::name 1014   @li @ref host_type::name
1015   @li @ref host_type::none 1015   @li @ref host_type::none
1016   1016  
1017   When @ref has_authority is false, the 1017   When @ref has_authority is false, the
1018   host type is @ref host_type::none. 1018   host type is @ref host_type::none.
1019   1019  
1020   @par Example 1020   @par Example
1021   @code 1021   @code
1022   assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 ); 1022   assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 );
1023   @endcode 1023   @endcode
1024   1024  
1025   @par Complexity 1025   @par Complexity
1026   Constant. 1026   Constant.
1027   1027  
1028   @par Exception Safety 1028   @par Exception Safety
1029   Throws nothing. 1029   Throws nothing.
1030   1030  
1031   @par Specification 1031   @par Specification
1032   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1032   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1033   1033  
1034   @return The type of host present. 1034   @return The type of host present.
1035   */ 1035   */
1036   urls::host_type 1036   urls::host_type
HITCBC 1037   845 host_type() const noexcept 1037   845 host_type() const noexcept
1038   { 1038   {
HITCBC 1039   845 return impl().host_type_; 1039   845 return impl().host_type_;
1040   } 1040   }
1041   1041  
1042   /** Return the host 1042   /** Return the host
1043   1043  
1044   This function returns the host portion 1044   This function returns the host portion
1045   of the authority as a string, or the 1045   of the authority as a string, or the
1046   empty string if there is no authority. 1046   empty string if there is no authority.
1047   Any percent-escapes in the string are 1047   Any percent-escapes in the string are
1048   decoded first. 1048   decoded first.
1049   1049  
1050   @par Example 1050   @par Example
1051   @code 1051   @code
1052   assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" ); 1052   assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" );
1053   @endcode 1053   @endcode
1054   1054  
1055   @par Complexity 1055   @par Complexity
1056   Linear in `this->host().size()`. 1056   Linear in `this->host().size()`.
1057   1057  
1058   @par Exception Safety 1058   @par Exception Safety
1059   Calls to allocate may throw. 1059   Calls to allocate may throw.
1060   1060  
1061   @par BNF 1061   @par BNF
1062   @code 1062   @code
1063   host = IP-literal / IPv4address / reg-name 1063   host = IP-literal / IPv4address / reg-name
1064   1064  
1065   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1065   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1066   1066  
1067   reg-name = *( unreserved / pct-encoded / "-" / ".") 1067   reg-name = *( unreserved / pct-encoded / "-" / ".")
1068   @endcode 1068   @endcode
1069   1069  
1070   @par Specification 1070   @par Specification
1071   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1071   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1072   1072  
1073   @param token A string token customization 1073   @param token A string token customization
1074   @return The host address as a string. 1074   @return The host address as a string.
1075   */ 1075   */
1076   template<BOOST_URL_STRTOK_TPARAM> 1076   template<BOOST_URL_STRTOK_TPARAM>
1077   BOOST_URL_STRTOK_RETURN 1077   BOOST_URL_STRTOK_RETURN
HITCBC 1078   97 host( 1078   97 host(
1079   StringToken&& token = {}) const 1079   StringToken&& token = {}) const
1080   { 1080   {
HITCBC 1081   97 encoding_opts opt; 1081   97 encoding_opts opt;
HITCBC 1082   97 opt.space_as_plus = false; 1082   97 opt.space_as_plus = false;
HITCBC 1083   194 return encoded_host().decode( 1083   194 return encoded_host().decode(
HITCBC 1084   194 opt, std::forward<StringToken>(token)); 1084   194 opt, std::forward<StringToken>(token));
1085   } 1085   }
1086   1086  
1087   /** Return the host 1087   /** Return the host
1088   1088  
1089   This function returns the host portion 1089   This function returns the host portion
1090   of the authority as a string, or the 1090   of the authority as a string, or the
1091   empty string if there is no authority. 1091   empty string if there is no authority.
1092   The returned string may contain 1092   The returned string may contain
1093   percent escapes. 1093   percent escapes.
1094   1094  
1095   @par Example 1095   @par Example
1096   @code 1096   @code
1097   assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" ); 1097   assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" );
1098   @endcode 1098   @endcode
1099   1099  
1100   @par Complexity 1100   @par Complexity
1101   Constant. 1101   Constant.
1102   1102  
1103   @par Exception Safety 1103   @par Exception Safety
1104   Throws nothing. 1104   Throws nothing.
1105   1105  
1106   @par BNF 1106   @par BNF
1107   @code 1107   @code
1108   host = IP-literal / IPv4address / reg-name 1108   host = IP-literal / IPv4address / reg-name
1109   1109  
1110   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1110   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1111   1111  
1112   reg-name = *( unreserved / pct-encoded / "-" / ".") 1112   reg-name = *( unreserved / pct-encoded / "-" / ".")
1113   @endcode 1113   @endcode
1114   1114  
1115   @par Specification 1115   @par Specification
1116   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1116   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1117   1117  
1118   @return The host address as a string. 1118   @return The host address as a string.
1119   */ 1119   */
1120   pct_string_view 1120   pct_string_view
1121   encoded_host() const noexcept; 1121   encoded_host() const noexcept;
1122   1122  
1123   /** Return the host 1123   /** Return the host
1124   1124  
1125   The value returned by this function 1125   The value returned by this function
1126   depends on the type of host returned 1126   depends on the type of host returned
1127   from the function @ref host_type. 1127   from the function @ref host_type.
1128   1128  
1129   @li If the type is @ref host_type::ipv4, 1129   @li If the type is @ref host_type::ipv4,
1130   then the IPv4 address string is returned. 1130   then the IPv4 address string is returned.
1131   1131  
1132   @li If the type is @ref host_type::ipv6, 1132   @li If the type is @ref host_type::ipv6,
1133   then the IPv6 address string is returned, 1133   then the IPv6 address string is returned,
1134   without any enclosing brackets. 1134   without any enclosing brackets.
1135   1135  
1136   @li If the type is @ref host_type::ipvfuture, 1136   @li If the type is @ref host_type::ipvfuture,
1137   then the IPvFuture address string is returned, 1137   then the IPvFuture address string is returned,
1138   without any enclosing brackets. 1138   without any enclosing brackets.
1139   1139  
1140   @li If the type is @ref host_type::name, 1140   @li If the type is @ref host_type::name,
1141   then the host name string is returned. 1141   then the host name string is returned.
1142   Any percent-escapes in the string are 1142   Any percent-escapes in the string are
1143   decoded first. 1143   decoded first.
1144   1144  
1145   @li If the type is @ref host_type::none, 1145   @li If the type is @ref host_type::none,
1146   then an empty string is returned. 1146   then an empty string is returned.
1147   1147  
1148   @par Example 1148   @par Example
1149   @code 1149   @code
1150   assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" ); 1150   assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" );
1151   @endcode 1151   @endcode
1152   1152  
1153   @par Complexity 1153   @par Complexity
1154   Linear in `this->host_address().size()`. 1154   Linear in `this->host_address().size()`.
1155   1155  
1156   @par Exception Safety 1156   @par Exception Safety
1157   Calls to allocate may throw. 1157   Calls to allocate may throw.
1158   1158  
1159   @par BNF 1159   @par BNF
1160   @code 1160   @code
1161   host = IP-literal / IPv4address / reg-name 1161   host = IP-literal / IPv4address / reg-name
1162   1162  
1163   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1163   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1164   1164  
1165   reg-name = *( unreserved / pct-encoded / "-" / ".") 1165   reg-name = *( unreserved / pct-encoded / "-" / ".")
1166   @endcode 1166   @endcode
1167   1167  
1168   @par Specification 1168   @par Specification
1169   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1169   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1170   1170  
1171   @param token A string token customization 1171   @param token A string token customization
1172   @return The host address as a string. 1172   @return The host address as a string.
1173   */ 1173   */
1174   template<BOOST_URL_STRTOK_TPARAM> 1174   template<BOOST_URL_STRTOK_TPARAM>
1175   BOOST_URL_STRTOK_RETURN 1175   BOOST_URL_STRTOK_RETURN
HITCBC 1176   99 host_address( 1176   99 host_address(
1177   StringToken&& token = {}) const 1177   StringToken&& token = {}) const
1178   { 1178   {
HITCBC 1179   99 encoding_opts opt; 1179   99 encoding_opts opt;
HITCBC 1180   99 opt.space_as_plus = false; 1180   99 opt.space_as_plus = false;
HITCBC 1181   198 return encoded_host_address().decode( 1181   198 return encoded_host_address().decode(
HITCBC 1182   198 opt, std::forward<StringToken>(token)); 1182   198 opt, std::forward<StringToken>(token));
1183   } 1183   }
1184   1184  
1185   /** Return the host 1185   /** Return the host
1186   1186  
1187   The value returned by this function 1187   The value returned by this function
1188   depends on the type of host returned 1188   depends on the type of host returned
1189   from the function @ref host_type. 1189   from the function @ref host_type.
1190   1190  
1191   @li If the type is @ref host_type::ipv4, 1191   @li If the type is @ref host_type::ipv4,
1192   then the IPv4 address string is returned. 1192   then the IPv4 address string is returned.
1193   1193  
1194   @li If the type is @ref host_type::ipv6, 1194   @li If the type is @ref host_type::ipv6,
1195   then the IPv6 address string is returned, 1195   then the IPv6 address string is returned,
1196   without any enclosing brackets. 1196   without any enclosing brackets.
1197   1197  
1198   @li If the type is @ref host_type::ipvfuture, 1198   @li If the type is @ref host_type::ipvfuture,
1199   then the IPvFuture address string is returned, 1199   then the IPvFuture address string is returned,
1200   without any enclosing brackets. 1200   without any enclosing brackets.
1201   1201  
1202   @li If the type is @ref host_type::name, 1202   @li If the type is @ref host_type::name,
1203   then the host name string is returned. 1203   then the host name string is returned.
1204   Any percent-escapes in the string are 1204   Any percent-escapes in the string are
1205   decoded first. 1205   decoded first.
1206   1206  
1207   @li If the type is @ref host_type::none, 1207   @li If the type is @ref host_type::none,
1208   then an empty string is returned. 1208   then an empty string is returned.
1209   The returned string may contain 1209   The returned string may contain
1210   percent escapes. 1210   percent escapes.
1211   1211  
1212   @par Example 1212   @par Example
1213   @code 1213   @code
1214   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" ); 1214   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" );
1215   @endcode 1215   @endcode
1216   1216  
1217   @par Complexity 1217   @par Complexity
1218   Constant. 1218   Constant.
1219   1219  
1220   @par Exception Safety 1220   @par Exception Safety
1221   Throws nothing. 1221   Throws nothing.
1222   1222  
1223   @par BNF 1223   @par BNF
1224   @code 1224   @code
1225   host = IP-literal / IPv4address / reg-name 1225   host = IP-literal / IPv4address / reg-name
1226   1226  
1227   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1227   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1228   1228  
1229   reg-name = *( unreserved / pct-encoded / "-" / ".") 1229   reg-name = *( unreserved / pct-encoded / "-" / ".")
1230   @endcode 1230   @endcode
1231   1231  
1232   @par Specification 1232   @par Specification
1233   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1233   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1234   1234  
1235   @return The host address as a string. 1235   @return The host address as a string.
1236   */ 1236   */
1237   pct_string_view 1237   pct_string_view
1238   encoded_host_address() const noexcept; 1238   encoded_host_address() const noexcept;
1239   1239  
1240   /** Return the host IPv4 address 1240   /** Return the host IPv4 address
1241   1241  
1242   If the host type is @ref host_type::ipv4, 1242   If the host type is @ref host_type::ipv4,
1243   this function returns the address as 1243   this function returns the address as
1244   a value of type @ref ipv4_address. 1244   a value of type @ref ipv4_address.
1245   Otherwise, if the host type is not an IPv4 1245   Otherwise, if the host type is not an IPv4
1246   address, it returns a default-constructed 1246   address, it returns a default-constructed
1247   value which is equal to the unspecified 1247   value which is equal to the unspecified
1248   address "0.0.0.0". 1248   address "0.0.0.0".
1249   1249  
1250   @par Example 1250   @par Example
1251   @code 1251   @code
1252   assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) ); 1252   assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) );
1253   @endcode 1253   @endcode
1254   1254  
1255   @par Complexity 1255   @par Complexity
1256   Constant. 1256   Constant.
1257   1257  
1258   @par Exception Safety 1258   @par Exception Safety
1259   Throws nothing. 1259   Throws nothing.
1260   1260  
1261   @par BNF 1261   @par BNF
1262   @code 1262   @code
1263   IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet 1263   IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
1264   1264  
1265   dec-octet = DIGIT ; 0-9 1265   dec-octet = DIGIT ; 0-9
1266   / %x31-39 DIGIT ; 10-99 1266   / %x31-39 DIGIT ; 10-99
1267   / "1" 2DIGIT ; 100-199 1267   / "1" 2DIGIT ; 100-199
1268   / "2" %x30-34 DIGIT ; 200-249 1268   / "2" %x30-34 DIGIT ; 200-249
1269   / "25" %x30-35 ; 250-255 1269   / "25" %x30-35 ; 250-255
1270   @endcode 1270   @endcode
1271   1271  
1272   @par Specification 1272   @par Specification
1273   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1273   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1274   1274  
1275   @return The IPv4 address as a value of type @ref ipv4_address. 1275   @return The IPv4 address as a value of type @ref ipv4_address.
1276   */ 1276   */
1277   ipv4_address 1277   ipv4_address
1278   host_ipv4_address() const noexcept; 1278   host_ipv4_address() const noexcept;
1279   1279  
1280   /** Return the host IPv6 address 1280   /** Return the host IPv6 address
1281   1281  
1282   If the host type is @ref host_type::ipv6, 1282   If the host type is @ref host_type::ipv6,
1283   this function returns the address as 1283   this function returns the address as
1284   a value of type @ref ipv6_address. 1284   a value of type @ref ipv6_address.
1285   Otherwise, if the host type is not an IPv6 1285   Otherwise, if the host type is not an IPv6
1286   address, it returns a default-constructed 1286   address, it returns a default-constructed
1287   value which is equal to the unspecified 1287   value which is equal to the unspecified
1288   address "0:0:0:0:0:0:0:0". 1288   address "0:0:0:0:0:0:0:0".
1289   1289  
1290   @par Example 1290   @par Example
1291   @code 1291   @code
1292   assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) ); 1292   assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) );
1293   @endcode 1293   @endcode
1294   1294  
1295   @par Complexity 1295   @par Complexity
1296   Constant. 1296   Constant.
1297   1297  
1298   @par Exception Safety 1298   @par Exception Safety
1299   Throws nothing. 1299   Throws nothing.
1300   1300  
1301   @par BNF 1301   @par BNF
1302   @code 1302   @code
1303   IPv6address = 6( h16 ":" ) ls32 1303   IPv6address = 6( h16 ":" ) ls32
1304   / "::" 5( h16 ":" ) ls32 1304   / "::" 5( h16 ":" ) ls32
1305   / [ h16 ] "::" 4( h16 ":" ) ls32 1305   / [ h16 ] "::" 4( h16 ":" ) ls32
1306   / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 1306   / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1307   / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 1307   / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1308   / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 1308   / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1309   / [ *4( h16 ":" ) h16 ] "::" ls32 1309   / [ *4( h16 ":" ) h16 ] "::" ls32
1310   / [ *5( h16 ":" ) h16 ] "::" h16 1310   / [ *5( h16 ":" ) h16 ] "::" h16
1311   / [ *6( h16 ":" ) h16 ] "::" 1311   / [ *6( h16 ":" ) h16 ] "::"
1312   1312  
1313   ls32 = ( h16 ":" h16 ) / IPv4address 1313   ls32 = ( h16 ":" h16 ) / IPv4address
1314   ; least-significant 32 bits of address 1314   ; least-significant 32 bits of address
1315   1315  
1316   h16 = 1*4HEXDIG 1316   h16 = 1*4HEXDIG
1317   ; 16 bits of address represented in hexadecimal 1317   ; 16 bits of address represented in hexadecimal
1318   @endcode 1318   @endcode
1319   1319  
1320   @par Specification 1320   @par Specification
1321   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1321   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1322   1322  
1323   @return The IPv6 address as a value of type @ref ipv6_address. 1323   @return The IPv6 address as a value of type @ref ipv6_address.
1324   */ 1324   */
1325   ipv6_address 1325   ipv6_address
1326   host_ipv6_address() const noexcept; 1326   host_ipv6_address() const noexcept;
1327   1327  
1328   /** Return the host IPvFuture address 1328   /** Return the host IPvFuture address
1329   1329  
1330   If the host type is @ref host_type::ipvfuture, 1330   If the host type is @ref host_type::ipvfuture,
1331   this function returns the address as 1331   this function returns the address as
1332   a string. 1332   a string.
1333   Otherwise, if the host type is not an 1333   Otherwise, if the host type is not an
1334   IPvFuture address, it returns an 1334   IPvFuture address, it returns an
1335   empty string. 1335   empty string.
1336   1336  
1337   @par Example 1337   @par Example
1338   @code 1338   @code
1339   assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" ); 1339   assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" );
1340   @endcode 1340   @endcode
1341   1341  
1342   @par Complexity 1342   @par Complexity
1343   Constant. 1343   Constant.
1344   1344  
1345   @par Exception Safety 1345   @par Exception Safety
1346   Throws nothing. 1346   Throws nothing.
1347   1347  
1348   @par BNF 1348   @par BNF
1349   @code 1349   @code
1350   IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) 1350   IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1351   @endcode 1351   @endcode
1352   1352  
1353   @par Specification 1353   @par Specification
1354   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1354   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1355   1355  
1356   @return The IPvFuture address as a string. 1356   @return The IPvFuture address as a string.
1357   */ 1357   */
1358   core::string_view 1358   core::string_view
1359   host_ipvfuture() const noexcept; 1359   host_ipvfuture() const noexcept;
1360   1360  
1361   /** Return the host name 1361   /** Return the host name
1362   1362  
1363   If the host type is @ref host_type::name, 1363   If the host type is @ref host_type::name,
1364   this function returns the name as 1364   this function returns the name as
1365   a string. Otherwise an empty string is returned. 1365   a string. Otherwise an empty string is returned.
1366   Any percent-escapes in the string are 1366   Any percent-escapes in the string are
1367   decoded first. 1367   decoded first.
1368   1368  
1369   @par Example 1369   @par Example
1370   @code 1370   @code
1371   assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" ); 1371   assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" );
1372   @endcode 1372   @endcode
1373   1373  
1374   @par Complexity 1374   @par Complexity
1375   Linear in `this->host_name().size()`. 1375   Linear in `this->host_name().size()`.
1376   1376  
1377   @par Exception Safety 1377   @par Exception Safety
1378   Calls to allocate may throw. 1378   Calls to allocate may throw.
1379   1379  
1380   @par BNF 1380   @par BNF
1381   @code 1381   @code
1382   host = IP-literal / IPv4address / reg-name 1382   host = IP-literal / IPv4address / reg-name
1383   1383  
1384   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1384   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1385   1385  
1386   reg-name = *( unreserved / pct-encoded / "-" / ".") 1386   reg-name = *( unreserved / pct-encoded / "-" / ".")
1387   @endcode 1387   @endcode
1388   1388  
1389   @par Specification 1389   @par Specification
1390   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1390   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1391   1391  
1392   @param token A string token customization. 1392   @param token A string token customization.
1393   @return The host name as a string. 1393   @return The host name as a string.
1394   */ 1394   */
1395   template<BOOST_URL_STRTOK_TPARAM> 1395   template<BOOST_URL_STRTOK_TPARAM>
1396   BOOST_URL_STRTOK_RETURN 1396   BOOST_URL_STRTOK_RETURN
HITCBC 1397   93 host_name( 1397   93 host_name(
1398   StringToken&& token = {}) const 1398   StringToken&& token = {}) const
1399   { 1399   {
HITCBC 1400   93 encoding_opts opt; 1400   93 encoding_opts opt;
HITCBC 1401   93 opt.space_as_plus = false; 1401   93 opt.space_as_plus = false;
HITCBC 1402   186 return encoded_host_name().decode( 1402   186 return encoded_host_name().decode(
HITCBC 1403   186 opt, std::forward<StringToken>(token)); 1403   186 opt, std::forward<StringToken>(token));
1404   } 1404   }
1405   1405  
1406   /** Return the host name 1406   /** Return the host name
1407   1407  
1408   If the host type is @ref host_type::name, 1408   If the host type is @ref host_type::name,
1409   this function returns the name as 1409   this function returns the name as
1410   a string. 1410   a string.
1411   Otherwise, if the host type is not an 1411   Otherwise, if the host type is not an
1412   name, it returns an empty string. 1412   name, it returns an empty string.
1413   The returned string may contain 1413   The returned string may contain
1414   percent escapes. 1414   percent escapes.
1415   1415  
1416   @par Example 1416   @par Example
1417   @code 1417   @code
1418   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" ); 1418   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" );
1419   @endcode 1419   @endcode
1420   1420  
1421   @par Complexity 1421   @par Complexity
1422   Constant. 1422   Constant.
1423   1423  
1424   @par Exception Safety 1424   @par Exception Safety
1425   Throws nothing. 1425   Throws nothing.
1426   1426  
1427   @par BNF 1427   @par BNF
1428   @code 1428   @code
1429   host = IP-literal / IPv4address / reg-name 1429   host = IP-literal / IPv4address / reg-name
1430   1430  
1431   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1431   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1432   1432  
1433   reg-name = *( unreserved / pct-encoded / "-" / ".") 1433   reg-name = *( unreserved / pct-encoded / "-" / ".")
1434   @endcode 1434   @endcode
1435   1435  
1436   @par Specification 1436   @par Specification
1437   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 1437   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
1438   1438  
1439   @return The host name as a percent-encoded string. 1439   @return The host name as a percent-encoded string.
1440   */ 1440   */
1441   pct_string_view 1441   pct_string_view
1442   encoded_host_name() const noexcept; 1442   encoded_host_name() const noexcept;
1443   1443  
1444   /** Return the IPv6 Zone ID 1444   /** Return the IPv6 Zone ID
1445   1445  
1446   If the host type is @ref host_type::ipv6, 1446   If the host type is @ref host_type::ipv6,
1447   this function returns the Zone ID as 1447   this function returns the Zone ID as
1448   a string. Otherwise an empty string is returned. 1448   a string. Otherwise an empty string is returned.
1449   Any percent-escapes in the string are 1449   Any percent-escapes in the string are
1450   decoded first. 1450   decoded first.
1451   1451  
1452   @par Example 1452   @par Example
1453   @code 1453   @code
1454   assert( url_view( "http://[fe80::1%25eth0]/" ).zone_id() == "eth0" ); 1454   assert( url_view( "http://[fe80::1%25eth0]/" ).zone_id() == "eth0" );
1455   @endcode 1455   @endcode
1456   1456  
1457   @par Complexity 1457   @par Complexity
1458   Linear in `this->encoded_zone_id().size()`. 1458   Linear in `this->encoded_zone_id().size()`.
1459   1459  
1460   @par Exception Safety 1460   @par Exception Safety
1461   Calls to allocate may throw. 1461   Calls to allocate may throw.
1462   1462  
1463   @par BNF 1463   @par BNF
1464   @code 1464   @code
1465   host = IP-literal / IPv4address / reg-name 1465   host = IP-literal / IPv4address / reg-name
1466   1466  
1467   IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]" 1467   IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]"
1468   1468  
1469   ZoneID = 1*( unreserved / pct-encoded ) 1469   ZoneID = 1*( unreserved / pct-encoded )
1470   1470  
1471   IPv6addrz = IPv6address "%25" ZoneID 1471   IPv6addrz = IPv6address "%25" ZoneID
1472   @endcode 1472   @endcode
1473   1473  
1474   @par Specification 1474   @par Specification
1475   @li <a href="https://datatracker.ietf.org/doc/html/rfc6874">Representing IPv6 Zone Identifiers in Address Literals and Uniform Resource Identifiers</a> 1475   @li <a href="https://datatracker.ietf.org/doc/html/rfc6874">Representing IPv6 Zone Identifiers in Address Literals and Uniform Resource Identifiers</a>
1476   1476  
1477   @param token A string token customization. 1477   @param token A string token customization.
1478   @return The Zone ID as a string. 1478   @return The Zone ID as a string.
1479   */ 1479   */
1480   template<BOOST_URL_STRTOK_TPARAM> 1480   template<BOOST_URL_STRTOK_TPARAM>
1481   BOOST_URL_STRTOK_RETURN 1481   BOOST_URL_STRTOK_RETURN
HITCBC 1482   10 zone_id( 1482   10 zone_id(
1483   StringToken&& token = {}) const 1483   StringToken&& token = {}) const
1484   { 1484   {
HITCBC 1485   10 encoding_opts opt; 1485   10 encoding_opts opt;
HITCBC 1486   10 opt.space_as_plus = false; 1486   10 opt.space_as_plus = false;
HITCBC 1487   20 return encoded_zone_id().decode( 1487   20 return encoded_zone_id().decode(
HITCBC 1488   20 opt, std::forward<StringToken>(token)); 1488   20 opt, std::forward<StringToken>(token));
1489   } 1489   }
1490   1490  
1491   /** Return the IPv6 Zone ID 1491   /** Return the IPv6 Zone ID
1492   1492  
1493   If the host type is @ref host_type::ipv6, 1493   If the host type is @ref host_type::ipv6,
1494   this function returns the Zone ID as 1494   this function returns the Zone ID as
1495   a string. Otherwise an empty string is returned. 1495   a string. Otherwise an empty string is returned.
1496   The returned string may contain 1496   The returned string may contain
1497   percent escapes. 1497   percent escapes.
1498   1498  
1499   @par Example 1499   @par Example
1500   @code 1500   @code
1501   assert( url_view( "http://[fe80::1%25eth0]/" ).encoded_zone_id() == "eth0" ); 1501   assert( url_view( "http://[fe80::1%25eth0]/" ).encoded_zone_id() == "eth0" );
1502   @endcode 1502   @endcode
1503   1503  
1504   @par Complexity 1504   @par Complexity
1505   Constant. 1505   Constant.
1506   1506  
1507   @par Exception Safety 1507   @par Exception Safety
1508   Throws nothing. 1508   Throws nothing.
1509   1509  
1510   @par BNF 1510   @par BNF
1511   @code 1511   @code
1512   host = IP-literal / IPv4address / reg-name 1512   host = IP-literal / IPv4address / reg-name
1513   1513  
1514   IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]" 1514   IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]"
1515   1515  
1516   ZoneID = 1*( unreserved / pct-encoded ) 1516   ZoneID = 1*( unreserved / pct-encoded )
1517   1517  
1518   IPv6addrz = IPv6address "%25" ZoneID 1518   IPv6addrz = IPv6address "%25" ZoneID
1519   @endcode 1519   @endcode
1520   1520  
1521   @par Specification 1521   @par Specification
1522   @li <a href="https://datatracker.ietf.org/doc/html/rfc6874">Representing IPv6 Zone Identifiers in Address Literals and Uniform Resource Identifiers</a> 1522   @li <a href="https://datatracker.ietf.org/doc/html/rfc6874">Representing IPv6 Zone Identifiers in Address Literals and Uniform Resource Identifiers</a>
1523   1523  
1524   @return The Zone ID as a percent-encoded string. 1524   @return The Zone ID as a percent-encoded string.
1525   */ 1525   */
1526   pct_string_view 1526   pct_string_view
1527   encoded_zone_id() const noexcept; 1527   encoded_zone_id() const noexcept;
1528   1528  
1529   //-------------------------------------------- 1529   //--------------------------------------------
1530   // 1530   //
1531   // Port 1531   // Port
1532   // 1532   //
1533   //-------------------------------------------- 1533   //--------------------------------------------
1534   1534  
1535   /** Return true if a port is present 1535   /** Return true if a port is present
1536   1536  
1537   This function returns true if an 1537   This function returns true if an
1538   authority is present and contains a port. 1538   authority is present and contains a port.
1539   1539  
1540   @par Example 1540   @par Example
1541   @code 1541   @code
1542   assert( url_view( "wss://www.example.com:443" ).has_port() ); 1542   assert( url_view( "wss://www.example.com:443" ).has_port() );
1543   @endcode 1543   @endcode
1544   1544  
1545   @par Complexity 1545   @par Complexity
1546   Constant. 1546   Constant.
1547   1547  
1548   @par Exception Safety 1548   @par Exception Safety
1549   Throws nothing. 1549   Throws nothing.
1550   1550  
1551   @par BNF 1551   @par BNF
1552   @code 1552   @code
1553   authority = [ userinfo "@" ] host [ ":" port ] 1553   authority = [ userinfo "@" ] host [ ":" port ]
1554   1554  
1555   port = *DIGIT 1555   port = *DIGIT
1556   @endcode 1556   @endcode
1557   1557  
1558   @par Specification 1558   @par Specification
1559   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a> 1559   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a>
1560   1560  
1561   @see 1561   @see
1562   @ref encoded_host_and_port, 1562   @ref encoded_host_and_port,
1563   @ref port, 1563   @ref port,
1564   @ref port_number. 1564   @ref port_number.
1565   1565  
1566   @return `true` if a port is present, `false` otherwise. 1566   @return `true` if a port is present, `false` otherwise.
1567   */ 1567   */
1568   bool 1568   bool
1569   has_port() const noexcept; 1569   has_port() const noexcept;
1570   1570  
1571   /** Return the port 1571   /** Return the port
1572   1572  
1573   If present, this function returns a 1573   If present, this function returns a
1574   string representing the port (which 1574   string representing the port (which
1575   may be empty). 1575   may be empty).
1576   Otherwise it returns an empty string. 1576   Otherwise it returns an empty string.
1577   1577  
1578   @par Example 1578   @par Example
1579   @code 1579   @code
1580   assert( url_view( "http://localhost.com:8080" ).port() == "8080" ); 1580   assert( url_view( "http://localhost.com:8080" ).port() == "8080" );
1581   @endcode 1581   @endcode
1582   1582  
1583   @par Complexity 1583   @par Complexity
1584   Constant. 1584   Constant.
1585   1585  
1586   @par Exception Safety 1586   @par Exception Safety
1587   Throws nothing. 1587   Throws nothing.
1588   1588  
1589   @par BNF 1589   @par BNF
1590   @code 1590   @code
1591   port = *DIGIT 1591   port = *DIGIT
1592   @endcode 1592   @endcode
1593   1593  
1594   @par Specification 1594   @par Specification
1595   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a> 1595   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a>
1596   1596  
1597   @see 1597   @see
1598   @ref encoded_host_and_port, 1598   @ref encoded_host_and_port,
1599   @ref has_port, 1599   @ref has_port,
1600   @ref port_number. 1600   @ref port_number.
1601   1601  
1602   @return The port as a string. 1602   @return The port as a string.
1603   */ 1603   */
1604   core::string_view 1604   core::string_view
1605   port() const noexcept; 1605   port() const noexcept;
1606   1606  
1607   /** Return the port 1607   /** Return the port
1608   1608  
1609   If a port is present and the numerical 1609   If a port is present and the numerical
1610   value is representable, it is returned 1610   value is representable, it is returned
1611   as an unsigned integer. Otherwise, the 1611   as an unsigned integer. Otherwise, the
1612   number zero is returned. 1612   number zero is returned.
1613   1613  
1614   @par Example 1614   @par Example
1615   @code 1615   @code
1616   assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 ); 1616   assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 );
1617   @endcode 1617   @endcode
1618   1618  
1619   @par Complexity 1619   @par Complexity
1620   Constant. 1620   Constant.
1621   1621  
1622   @par Exception Safety 1622   @par Exception Safety
1623   Throws nothing. 1623   Throws nothing.
1624   1624  
1625   @par BNF 1625   @par BNF
1626   @code 1626   @code
1627   port = *DIGIT 1627   port = *DIGIT
1628   @endcode 1628   @endcode
1629   1629  
1630   @par Specification 1630   @par Specification
1631   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a> 1631   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a>
1632   1632  
1633   @see 1633   @see
1634   @ref encoded_host_and_port, 1634   @ref encoded_host_and_port,
1635   @ref has_port, 1635   @ref has_port,
1636   @ref port. 1636   @ref port.
1637   1637  
1638   @return The port number as an unsigned integer. 1638   @return The port number as an unsigned integer.
1639   */ 1639   */
1640   std::uint16_t 1640   std::uint16_t
1641   port_number() const noexcept; 1641   port_number() const noexcept;
1642   1642  
1643   //-------------------------------------------- 1643   //--------------------------------------------
1644   // 1644   //
1645   // Path 1645   // Path
1646   // 1646   //
1647   //-------------------------------------------- 1647   //--------------------------------------------
1648   1648  
1649   /** Return true if the path is absolute 1649   /** Return true if the path is absolute
1650   1650  
1651   This function returns true if the path 1651   This function returns true if the path
1652   begins with a forward slash ('/'). 1652   begins with a forward slash ('/').
1653   1653  
1654   @par Example 1654   @par Example
1655   @code 1655   @code
1656   assert( url_view( "/path/to/file.txt" ).is_path_absolute() ); 1656   assert( url_view( "/path/to/file.txt" ).is_path_absolute() );
1657   @endcode 1657   @endcode
1658   1658  
1659   @par Complexity 1659   @par Complexity
1660   Constant. 1660   Constant.
1661   1661  
1662   @par Exception Safety 1662   @par Exception Safety
1663   Throws nothing. 1663   Throws nothing.
1664   1664  
1665   @par BNF 1665   @par BNF
1666   @code 1666   @code
1667   path = path-abempty ; begins with "/" or is empty 1667   path = path-abempty ; begins with "/" or is empty
1668   / path-absolute ; begins with "/" but not "//" 1668   / path-absolute ; begins with "/" but not "//"
1669   / path-noscheme ; begins with a non-colon segment 1669   / path-noscheme ; begins with a non-colon segment
1670   / path-rootless ; begins with a segment 1670   / path-rootless ; begins with a segment
1671   / path-empty ; zero characters 1671   / path-empty ; zero characters
1672   1672  
1673   path-abempty = *( "/" segment ) 1673   path-abempty = *( "/" segment )
1674   path-absolute = "/" [ segment-nz *( "/" segment ) ] 1674   path-absolute = "/" [ segment-nz *( "/" segment ) ]
1675   path-noscheme = segment-nz-nc *( "/" segment ) 1675   path-noscheme = segment-nz-nc *( "/" segment )
1676   path-rootless = segment-nz *( "/" segment ) 1676   path-rootless = segment-nz *( "/" segment )
1677   path-empty = 0<pchar> 1677   path-empty = 0<pchar>
1678   @endcode 1678   @endcode
1679   1679  
1680   @par Specification 1680   @par Specification
1681   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 1681   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
1682   1682  
1683   @see 1683   @see
1684   @ref encoded_path, 1684   @ref encoded_path,
1685   @ref encoded_segments. 1685   @ref encoded_segments.
1686   @ref path, 1686   @ref path,
1687   @ref segments. 1687   @ref segments.
1688   1688  
1689   @return `true` if the path is absolute, `false` otherwise. 1689   @return `true` if the path is absolute, `false` otherwise.
1690   */ 1690   */
1691   bool 1691   bool
HITCBC 1692   5000 is_path_absolute() const noexcept 1692   5000 is_path_absolute() const noexcept
1693   { 1693   {
1694   return 1694   return
HITCBC 1695   8824 impl().len(id_path) > 0 && 1695   8824 impl().len(id_path) > 0 &&
HITCBC 1696   8824 impl().cs_[impl().offset(id_path)] == '/'; 1696   8824 impl().cs_[impl().offset(id_path)] == '/';
1697   } 1697   }
1698   1698  
1699   /** Return the path 1699   /** Return the path
1700   1700  
1701   This function returns the path as a 1701   This function returns the path as a
1702   string. The path may be empty. 1702   string. The path may be empty.
1703   Any percent-escapes in the string are 1703   Any percent-escapes in the string are
1704   decoded first. 1704   decoded first.
1705   1705  
1706   @par Example 1706   @par Example
1707   @code 1707   @code
1708   assert( url_view( "file:///Program%20Files/Games/config.ini" ).path() == "/Program Files/Games/config.ini" ); 1708   assert( url_view( "file:///Program%20Files/Games/config.ini" ).path() == "/Program Files/Games/config.ini" );
1709   @endcode 1709   @endcode
1710   1710  
1711   @par Complexity 1711   @par Complexity
1712   Linear in `this->path().size()`. 1712   Linear in `this->path().size()`.
1713   1713  
1714   @par Exception Safety 1714   @par Exception Safety
1715   Calls to allocate may throw. 1715   Calls to allocate may throw.
1716   1716  
1717   @par BNF 1717   @par BNF
1718   @code 1718   @code
1719   path = path-abempty ; begins with "/" or is empty 1719   path = path-abempty ; begins with "/" or is empty
1720   / path-absolute ; begins with "/" but not "//" 1720   / path-absolute ; begins with "/" but not "//"
1721   / path-noscheme ; begins with a non-colon segment 1721   / path-noscheme ; begins with a non-colon segment
1722   / path-rootless ; begins with a segment 1722   / path-rootless ; begins with a segment
1723   / path-empty ; zero characters 1723   / path-empty ; zero characters
1724   1724  
1725   path-abempty = *( "/" segment ) 1725   path-abempty = *( "/" segment )
1726   path-absolute = "/" [ segment-nz *( "/" segment ) ] 1726   path-absolute = "/" [ segment-nz *( "/" segment ) ]
1727   path-noscheme = segment-nz-nc *( "/" segment ) 1727   path-noscheme = segment-nz-nc *( "/" segment )
1728   path-rootless = segment-nz *( "/" segment ) 1728   path-rootless = segment-nz *( "/" segment )
1729   path-empty = 0<pchar> 1729   path-empty = 0<pchar>
1730   @endcode 1730   @endcode
1731   1731  
1732   @par Specification 1732   @par Specification
1733   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 1733   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
1734   1734  
1735   @see 1735   @see
1736   @ref is_path_absolute, 1736   @ref is_path_absolute,
1737   @ref encoded_path, 1737   @ref encoded_path,
1738   @ref encoded_segments. 1738   @ref encoded_segments.
1739   @ref segments. 1739   @ref segments.
1740   1740  
1741   @param token A string token to use for the result. 1741   @param token A string token to use for the result.
1742   @return The path as a string. 1742   @return The path as a string.
1743   */ 1743   */
1744   template<BOOST_URL_STRTOK_TPARAM> 1744   template<BOOST_URL_STRTOK_TPARAM>
1745   BOOST_URL_STRTOK_RETURN 1745   BOOST_URL_STRTOK_RETURN
HITCBC 1746   74 path( 1746   74 path(
1747   StringToken&& token = {}) const 1747   StringToken&& token = {}) const
1748   { 1748   {
HITCBC 1749   74 encoding_opts opt; 1749   74 encoding_opts opt;
HITCBC 1750   74 opt.space_as_plus = false; 1750   74 opt.space_as_plus = false;
HITCBC 1751   148 return encoded_path().decode( 1751   148 return encoded_path().decode(
HITCBC 1752   148 opt, std::forward<StringToken>(token)); 1752   148 opt, std::forward<StringToken>(token));
1753   } 1753   }
1754   1754  
1755   /** Return the path 1755   /** Return the path
1756   1756  
1757   This function returns the path as a 1757   This function returns the path as a
1758   string. The path may be empty. 1758   string. The path may be empty.
1759   Any percent-escapes in the string are 1759   Any percent-escapes in the string are
1760   decoded first. 1760   decoded first.
1761   1761  
1762   @par Example 1762   @par Example
1763   @code 1763   @code
1764   assert( url_view( "file:///Program%20Files/Games/config.ini" ).encoded_path() == "/Program%20Files/Games/config.ini" ); 1764   assert( url_view( "file:///Program%20Files/Games/config.ini" ).encoded_path() == "/Program%20Files/Games/config.ini" );
1765   @endcode 1765   @endcode
1766   1766  
1767   @par Complexity 1767   @par Complexity
1768   Constant. 1768   Constant.
1769   1769  
1770   @par Exception Safety 1770   @par Exception Safety
1771   Throws nothing. 1771   Throws nothing.
1772   1772  
1773   @par BNF 1773   @par BNF
1774   @code 1774   @code
1775   path = path-abempty ; begins with "/" or is empty 1775   path = path-abempty ; begins with "/" or is empty
1776   / path-absolute ; begins with "/" but not "//" 1776   / path-absolute ; begins with "/" but not "//"
1777   / path-noscheme ; begins with a non-colon segment 1777   / path-noscheme ; begins with a non-colon segment
1778   / path-rootless ; begins with a segment 1778   / path-rootless ; begins with a segment
1779   / path-empty ; zero characters 1779   / path-empty ; zero characters
1780   1780  
1781   path-abempty = *( "/" segment ) 1781   path-abempty = *( "/" segment )
1782   path-absolute = "/" [ segment-nz *( "/" segment ) ] 1782   path-absolute = "/" [ segment-nz *( "/" segment ) ]
1783   path-noscheme = segment-nz-nc *( "/" segment ) 1783   path-noscheme = segment-nz-nc *( "/" segment )
1784   path-rootless = segment-nz *( "/" segment ) 1784   path-rootless = segment-nz *( "/" segment )
1785   path-empty = 0<pchar> 1785   path-empty = 0<pchar>
1786   @endcode 1786   @endcode
1787   1787  
1788   @par Specification 1788   @par Specification
1789   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 1789   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
1790   1790  
1791   @see 1791   @see
1792   @ref is_path_absolute, 1792   @ref is_path_absolute,
1793   @ref encoded_segments. 1793   @ref encoded_segments.
1794   @ref path, 1794   @ref path,
1795   @ref segments. 1795   @ref segments.
1796   1796  
1797   @return The path as a string. 1797   @return The path as a string.
1798   */ 1798   */
1799   pct_string_view 1799   pct_string_view
1800   encoded_path() const noexcept; 1800   encoded_path() const noexcept;
1801   1801  
1802   /** Return the path as a container of segments 1802   /** Return the path as a container of segments
1803   1803  
1804   This function returns a bidirectional 1804   This function returns a bidirectional
1805   view of strings over the path. 1805   view of strings over the path.
1806   The returned view references the same 1806   The returned view references the same
1807   underlying character buffer; ownership 1807   underlying character buffer; ownership
1808   is not transferred. 1808   is not transferred.
1809   Any percent-escapes in strings returned 1809   Any percent-escapes in strings returned
1810   when iterating the view are decoded first. 1810   when iterating the view are decoded first.
1811   1811  
1812   @par Example 1812   @par Example
1813   @code 1813   @code
1814   segments_view sv = url_view( "/path/to/file.txt" ).segments(); 1814   segments_view sv = url_view( "/path/to/file.txt" ).segments();
1815   @endcode 1815   @endcode
1816   1816  
1817   @par Complexity 1817   @par Complexity
1818   Constant. 1818   Constant.
1819   1819  
1820   @par Exception Safety 1820   @par Exception Safety
1821   Throws nothing. 1821   Throws nothing.
1822   1822  
1823   @par BNF 1823   @par BNF
1824   @code 1824   @code
1825   path = [ "/" ] segment *( "/" segment ) 1825   path = [ "/" ] segment *( "/" segment )
1826   @endcode 1826   @endcode
1827   1827  
1828   @par Specification 1828   @par Specification
1829   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 1829   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
1830   1830  
1831   @see 1831   @see
1832   @ref is_path_absolute, 1832   @ref is_path_absolute,
1833   @ref encoded_path, 1833   @ref encoded_path,
1834   @ref encoded_segments. 1834   @ref encoded_segments.
1835   @ref path, 1835   @ref path,
1836   @ref segments_view. 1836   @ref segments_view.
1837   1837  
1838   @return A bidirectional view of segments. 1838   @return A bidirectional view of segments.
1839   */ 1839   */
1840   segments_view 1840   segments_view
1841   segments() const noexcept; 1841   segments() const noexcept;
1842   1842  
1843   /** Return the path as a container of segments 1843   /** Return the path as a container of segments
1844   1844  
1845   This function returns a bidirectional 1845   This function returns a bidirectional
1846   view of strings over the path. 1846   view of strings over the path.
1847   The returned view references the same 1847   The returned view references the same
1848   underlying character buffer; ownership 1848   underlying character buffer; ownership
1849   is not transferred. 1849   is not transferred.
1850   Strings returned when iterating the 1850   Strings returned when iterating the
1851   range may contain percent escapes. 1851   range may contain percent escapes.
1852   1852  
1853   @par Example 1853   @par Example
1854   @code 1854   @code
1855   segments_encoded_view sv = url_view( "/path/to/file.txt" ).encoded_segments(); 1855   segments_encoded_view sv = url_view( "/path/to/file.txt" ).encoded_segments();
1856   @endcode 1856   @endcode
1857   1857  
1858   @par Complexity 1858   @par Complexity
1859   Constant. 1859   Constant.
1860   1860  
1861   @par Exception Safety 1861   @par Exception Safety
1862   Throws nothing. 1862   Throws nothing.
1863   1863  
1864   @par BNF 1864   @par BNF
1865   @code 1865   @code
1866   path = path-abempty ; begins with "/" or is empty 1866   path = path-abempty ; begins with "/" or is empty
1867   / path-absolute ; begins with "/" but not "//" 1867   / path-absolute ; begins with "/" but not "//"
1868   / path-noscheme ; begins with a non-colon segment 1868   / path-noscheme ; begins with a non-colon segment
1869   / path-rootless ; begins with a segment 1869   / path-rootless ; begins with a segment
1870   / path-empty ; zero characters 1870   / path-empty ; zero characters
1871   1871  
1872   path-abempty = *( "/" segment ) 1872   path-abempty = *( "/" segment )
1873   path-absolute = "/" [ segment-nz *( "/" segment ) ] 1873   path-absolute = "/" [ segment-nz *( "/" segment ) ]
1874   path-noscheme = segment-nz-nc *( "/" segment ) 1874   path-noscheme = segment-nz-nc *( "/" segment )
1875   path-rootless = segment-nz *( "/" segment ) 1875   path-rootless = segment-nz *( "/" segment )
1876   path-empty = 0<pchar> 1876   path-empty = 0<pchar>
1877   @endcode 1877   @endcode
1878   1878  
1879   @par Specification 1879   @par Specification
1880   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 1880   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
1881   1881  
1882   @see 1882   @see
1883   @ref is_path_absolute, 1883   @ref is_path_absolute,
1884   @ref encoded_path, 1884   @ref encoded_path,
1885   @ref path, 1885   @ref path,
1886   @ref segments, 1886   @ref segments,
1887   @ref segments_encoded_view. 1887   @ref segments_encoded_view.
1888   1888  
1889   @return A bidirectional view of encoded segments. 1889   @return A bidirectional view of encoded segments.
1890   */ 1890   */
1891   segments_encoded_view 1891   segments_encoded_view
1892   encoded_segments() const noexcept; 1892   encoded_segments() const noexcept;
1893   1893  
1894   //-------------------------------------------- 1894   //--------------------------------------------
1895   // 1895   //
1896   // Query 1896   // Query
1897   // 1897   //
1898   //-------------------------------------------- 1898   //--------------------------------------------
1899   1899  
1900   /** Return true if a query is present 1900   /** Return true if a query is present
1901   1901  
1902   This function returns true if this 1902   This function returns true if this
1903   contains a query. An empty query is 1903   contains a query. An empty query is
1904   distinct from having no query. 1904   distinct from having no query.
1905   1905  
1906   @par Example 1906   @par Example
1907   @code 1907   @code
1908   assert( url_view( "/sql?id=42&col=name&page-size=20" ).has_query() ); 1908   assert( url_view( "/sql?id=42&col=name&page-size=20" ).has_query() );
1909   @endcode 1909   @endcode
1910   1910  
1911   @par Complexity 1911   @par Complexity
1912   Constant. 1912   Constant.
1913   1913  
1914   @par Exception Safety 1914   @par Exception Safety
1915   Throws nothing. 1915   Throws nothing.
1916   1916  
1917   @par BNF 1917   @par BNF
1918   @code 1918   @code
1919   query = *( pchar / "/" / "?" ) 1919   query = *( pchar / "/" / "?" )
1920   1920  
1921   query-param = key [ "=" value ] 1921   query-param = key [ "=" value ]
1922   query-params = [ query-param ] *( "&" query-param ) 1922   query-params = [ query-param ] *( "&" query-param )
1923   @endcode 1923   @endcode
1924   1924  
1925   @par Specification 1925   @par Specification
1926   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 1926   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
1927   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a> 1927   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a>
1928   1928  
1929   @see 1929   @see
1930   @ref encoded_params, 1930   @ref encoded_params,
1931   @ref encoded_query, 1931   @ref encoded_query,
1932   @ref params, 1932   @ref params,
1933   @ref query. 1933   @ref query.
1934   1934  
1935   @return `true` if a query is present. 1935   @return `true` if a query is present.
1936   */ 1936   */
1937   bool 1937   bool
1938   has_query() const noexcept; 1938   has_query() const noexcept;
1939   1939  
1940   /** Return the query 1940   /** Return the query
1941   1941  
1942   If this contains a query, it is returned 1942   If this contains a query, it is returned
1943   as a string (which may be empty). 1943   as a string (which may be empty).
1944   Otherwise, an empty string is returned. 1944   Otherwise, an empty string is returned.
1945   Any percent-escapes in the string are 1945   Any percent-escapes in the string are
1946   decoded first. 1946   decoded first.
1947   <br> 1947   <br>
1948   1948  
1949   Literal plus signs remain unchanged by 1949   Literal plus signs remain unchanged by
1950   default to match RFC 3986. To treat '+' 1950   default to match RFC 3986. To treat '+'
1951   as a space, supply decoding options with 1951   as a space, supply decoding options with
1952   `space_as_plus = true` when calling this 1952   `space_as_plus = true` when calling this
1953   function. 1953   function.
1954   1954  
1955   @par Example 1955   @par Example
1956   @code 1956   @code
1957   assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).query() == "id=42&name=jane-doe&page size=20" ); 1957   assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).query() == "id=42&name=jane-doe&page size=20" );
1958   @endcode 1958   @endcode
1959   1959  
1960   @par Complexity 1960   @par Complexity
1961   Linear in `this->query().size()`. 1961   Linear in `this->query().size()`.
1962   1962  
1963   @par Exception Safety 1963   @par Exception Safety
1964   Calls to allocate may throw. 1964   Calls to allocate may throw.
1965   1965  
1966   @par BNF 1966   @par BNF
1967   @code 1967   @code
1968   query = *( pchar / "/" / "?" ) 1968   query = *( pchar / "/" / "?" )
1969   1969  
1970   query-param = key [ "=" value ] 1970   query-param = key [ "=" value ]
1971   query-params = [ query-param ] *( "&" query-param ) 1971   query-params = [ query-param ] *( "&" query-param )
1972   @endcode 1972   @endcode
1973   1973  
1974   @par Specification 1974   @par Specification
1975   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 1975   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
1976   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a> 1976   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a>
1977   1977  
1978   @see 1978   @see
1979   @ref encoded_params, 1979   @ref encoded_params,
1980   @ref encoded_query, 1980   @ref encoded_query,
1981   @ref has_query, 1981   @ref has_query,
1982   @ref params. 1982   @ref params.
1983   1983  
1984   @param token A token to use for the returned string. 1984   @param token A token to use for the returned string.
1985   @return The query as a string. 1985   @return The query as a string.
1986   */ 1986   */
1987   template<BOOST_URL_STRTOK_TPARAM> 1987   template<BOOST_URL_STRTOK_TPARAM>
1988   BOOST_URL_STRTOK_RETURN 1988   BOOST_URL_STRTOK_RETURN
HITCBC 1989   50 query( 1989   50 query(
1990   StringToken&& token = {}) const 1990   StringToken&& token = {}) const
1991   { 1991   {
1992   // When interacting with the query as 1992   // When interacting with the query as
1993   // an intact string, we do not treat 1993   // an intact string, we do not treat
1994   // the plus sign as an encoded space. 1994   // the plus sign as an encoded space.
HITCBC 1995   50 encoding_opts opt; 1995   50 encoding_opts opt;
HITCBC 1996   50 opt.space_as_plus = false; 1996   50 opt.space_as_plus = false;
HITCBC 1997   100 return encoded_query().decode( 1997   100 return encoded_query().decode(
HITCBC 1998   100 opt, std::forward<StringToken>(token)); 1998   100 opt, std::forward<StringToken>(token));
1999   } 1999   }
2000   2000  
2001   /** Return the query 2001   /** Return the query
2002   2002  
2003   If this contains a query, it is returned 2003   If this contains a query, it is returned
2004   as a string (which may be empty). 2004   as a string (which may be empty).
2005   Otherwise, an empty string is returned. 2005   Otherwise, an empty string is returned.
2006   The returned string may contain 2006   The returned string may contain
2007   percent escapes. 2007   percent escapes.
2008   2008  
2009   @par Example 2009   @par Example
2010   @code 2010   @code
2011   assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_query() == "id=42&name=jane%2Ddoe&page+size=20" ); 2011   assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_query() == "id=42&name=jane%2Ddoe&page+size=20" );
2012   @endcode 2012   @endcode
2013   2013  
2014   @par Complexity 2014   @par Complexity
2015   Constant. 2015   Constant.
2016   2016  
2017   @par Exception Safety 2017   @par Exception Safety
2018   Throws nothing. 2018   Throws nothing.
2019   2019  
2020   @par BNF 2020   @par BNF
2021   @code 2021   @code
2022   query = *( pchar / "/" / "?" ) 2022   query = *( pchar / "/" / "?" )
2023   2023  
2024   query-param = key [ "=" value ] 2024   query-param = key [ "=" value ]
2025   query-params = [ query-param ] *( "&" query-param ) 2025   query-params = [ query-param ] *( "&" query-param )
2026   @endcode 2026   @endcode
2027   2027  
2028   @par Specification 2028   @par Specification
2029   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 2029   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
2030   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a> 2030   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a>
2031   2031  
2032   @see 2032   @see
2033   @ref encoded_params, 2033   @ref encoded_params,
2034   @ref has_query, 2034   @ref has_query,
2035   @ref params, 2035   @ref params,
2036   @ref query. 2036   @ref query.
2037   2037  
2038   @return The query as a string. 2038   @return The query as a string.
2039   */ 2039   */
2040   pct_string_view 2040   pct_string_view
2041   encoded_query() const noexcept; 2041   encoded_query() const noexcept;
2042   2042  
2043   /** Return the query as a container of parameters 2043   /** Return the query as a container of parameters
2044   2044  
2045   This function returns a bidirectional 2045   This function returns a bidirectional
2046   view of key/value pairs over the query. 2046   view of key/value pairs over the query.
2047   The returned view references the same 2047   The returned view references the same
2048   underlying character buffer; ownership 2048   underlying character buffer; ownership
2049   is not transferred. 2049   is not transferred.
2050   Any percent-escapes in strings returned 2050   Any percent-escapes in strings returned
2051   when iterating the view are decoded first. 2051   when iterating the view are decoded first.
2052   2052  
2053   @par Example 2053   @par Example
2054   @code 2054   @code
2055   params_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).params(); 2055   params_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).params();
2056   @endcode 2056   @endcode
2057   2057  
2058   @par Complexity 2058   @par Complexity
2059   Constant. 2059   Constant.
2060   2060  
2061   @par Exception Safety 2061   @par Exception Safety
2062   Throws nothing. 2062   Throws nothing.
2063   2063  
2064   @par BNF 2064   @par BNF
2065   @code 2065   @code
2066   query = *( pchar / "/" / "?" ) 2066   query = *( pchar / "/" / "?" )
2067   2067  
2068   query-param = key [ "=" value ] 2068   query-param = key [ "=" value ]
2069   query-params = [ query-param ] *( "&" query-param ) 2069   query-params = [ query-param ] *( "&" query-param )
2070   @endcode 2070   @endcode
2071   2071  
2072   @par Specification 2072   @par Specification
2073   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 2073   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
2074   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a> 2074   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a>
2075   2075  
2076   @see 2076   @see
2077   @ref encoded_params, 2077   @ref encoded_params,
2078   @ref encoded_query, 2078   @ref encoded_query,
2079   @ref has_query, 2079   @ref has_query,
2080   @ref query. 2080   @ref query.
2081   2081  
2082   @return A bidirectional view of key/value pairs. 2082   @return A bidirectional view of key/value pairs.
2083   */ 2083   */
2084   params_view 2084   params_view
2085   params() const noexcept; 2085   params() const noexcept;
2086   2086  
2087   params_view 2087   params_view
2088   params(encoding_opts opt) const noexcept; 2088   params(encoding_opts opt) const noexcept;
2089   2089  
2090   /** Return the query as a container of parameters 2090   /** Return the query as a container of parameters
2091   2091  
2092   This function returns a bidirectional 2092   This function returns a bidirectional
2093   view of key/value pairs over the query. 2093   view of key/value pairs over the query.
2094   The returned view references the same 2094   The returned view references the same
2095   underlying character buffer; ownership 2095   underlying character buffer; ownership
2096   is not transferred. 2096   is not transferred.
2097   Strings returned when iterating the 2097   Strings returned when iterating the
2098   range may contain percent escapes. 2098   range may contain percent escapes.
2099   2099  
2100   @par Example 2100   @par Example
2101   @code 2101   @code
2102   params_encoded_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_params(); 2102   params_encoded_view pv = url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_params();
2103   @endcode 2103   @endcode
2104   2104  
2105   @par Complexity 2105   @par Complexity
2106   Constant. 2106   Constant.
2107   2107  
2108   @par Exception Safety 2108   @par Exception Safety
2109   Throws nothing. 2109   Throws nothing.
2110   2110  
2111   @par BNF 2111   @par BNF
2112   @code 2112   @code
2113   query = *( pchar / "/" / "?" ) 2113   query = *( pchar / "/" / "?" )
2114   query-param = key [ "=" value ] 2114   query-param = key [ "=" value ]
2115   query-params = [ query-param ] *( "&" query-param ) 2115   query-params = [ query-param ] *( "&" query-param )
2116   @endcode 2116   @endcode
2117   2117  
2118   @par Specification 2118   @par Specification
2119   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 2119   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
2120   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a> 2120   @li <a href="https://en.wikipedia.org/wiki/Query_string">Query string (Wikipedia)</a>
2121   2121  
2122   @see 2122   @see
2123   @ref encoded_query, 2123   @ref encoded_query,
2124   @ref has_query, 2124   @ref has_query,
2125   @ref params, 2125   @ref params,
2126   @ref query. 2126   @ref query.
2127   2127  
2128   @return A bidirectional view of key/value pairs. 2128   @return A bidirectional view of key/value pairs.
2129   */ 2129   */
2130   params_encoded_view 2130   params_encoded_view
2131   encoded_params() const noexcept; 2131   encoded_params() const noexcept;
2132   2132  
2133   //-------------------------------------------- 2133   //--------------------------------------------
2134   // 2134   //
2135   // Fragment 2135   // Fragment
2136   // 2136   //
2137   //-------------------------------------------- 2137   //--------------------------------------------
2138   2138  
2139   /** Return true if a fragment is present 2139   /** Return true if a fragment is present
2140   2140  
2141   This function returns true if the url 2141   This function returns true if the url
2142   contains a fragment. 2142   contains a fragment.
2143   An empty fragment is distinct from 2143   An empty fragment is distinct from
2144   no fragment. 2144   no fragment.
2145   2145  
2146   @par Example 2146   @par Example
2147   @code 2147   @code
2148   assert( url_view( "http://www.example.com/index.htm#anchor" ).has_fragment() ); 2148   assert( url_view( "http://www.example.com/index.htm#anchor" ).has_fragment() );
2149   @endcode 2149   @endcode
2150   2150  
2151   @par Complexity 2151   @par Complexity
2152   Constant. 2152   Constant.
2153   2153  
2154   @par Exception Safety 2154   @par Exception Safety
2155   Throws nothing. 2155   Throws nothing.
2156   2156  
2157   @par BNF 2157   @par BNF
2158   @code 2158   @code
2159   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 2159   URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
2160   2160  
2161   relative-ref = relative-part [ "?" query ] [ "#" fragment ] 2161   relative-ref = relative-part [ "?" query ] [ "#" fragment ]
2162   @endcode 2162   @endcode
2163   2163  
2164   @par Specification 2164   @par Specification
2165   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5">3.5. Fragment (rfc3986)</a> 2165   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5">3.5. Fragment (rfc3986)</a>
2166   2166  
2167   @see 2167   @see
2168   @ref encoded_fragment, 2168   @ref encoded_fragment,
2169   @ref fragment. 2169   @ref fragment.
2170   2170  
2171   @return `true` if the url contains a fragment. 2171   @return `true` if the url contains a fragment.
2172   */ 2172   */
2173   bool 2173   bool
2174   has_fragment() const noexcept; 2174   has_fragment() const noexcept;
2175   2175  
2176   /** Return the fragment 2176   /** Return the fragment
2177   2177  
2178   This function calculates the fragment 2178   This function calculates the fragment
2179   of the url, with percent escapes decoded 2179   of the url, with percent escapes decoded
2180   and without the leading pound sign ('#') 2180   and without the leading pound sign ('#')
2181   whose presence indicates that the url 2181   whose presence indicates that the url
2182   contains a fragment. 2182   contains a fragment.
2183   2183  
2184   <br> 2184   <br>
2185   2185  
2186   This function accepts an optional 2186   This function accepts an optional
2187   <em>StringToken</em> parameter which 2187   <em>StringToken</em> parameter which
2188   controls the return type and behavior 2188   controls the return type and behavior
2189   of the function: 2189   of the function:
2190   2190  
2191   @li When called with no arguments, 2191   @li When called with no arguments,
2192   the return type of the function is 2192   the return type of the function is
2193   `std::string`. Otherwise 2193   `std::string`. Otherwise
2194   2194  
2195   @li When called with a string token, 2195   @li When called with a string token,
2196   the behavior and return type of the 2196   the behavior and return type of the
2197   function depends on the type of string 2197   function depends on the type of string
2198   token being passed. 2198   token being passed.
2199   2199  
2200   @par Example 2200   @par Example
2201   @code 2201   @code
2202   assert( url_view( "http://www.example.com/index.htm#a%2D1" ).fragment() == "a-1" ); 2202   assert( url_view( "http://www.example.com/index.htm#a%2D1" ).fragment() == "a-1" );
2203   @endcode 2203   @endcode
2204   2204  
2205   @par Complexity 2205   @par Complexity
2206   Linear in `this->fragment().size()`. 2206   Linear in `this->fragment().size()`.
2207   2207  
2208   @par Exception Safety 2208   @par Exception Safety
2209   Calls to allocate may throw. 2209   Calls to allocate may throw.
2210   String tokens may throw exceptions. 2210   String tokens may throw exceptions.
2211   2211  
2212   @param token An optional string token to 2212   @param token An optional string token to
2213   use. If this parameter is omitted, the 2213   use. If this parameter is omitted, the
2214   function returns a new `std::string`. 2214   function returns a new `std::string`.
2215   2215  
2216   @return The fragment portion of the url. 2216   @return The fragment portion of the url.
2217   2217  
2218   @par BNF 2218   @par BNF
2219   @code 2219   @code
2220   fragment = *( pchar / "/" / "?" ) 2220   fragment = *( pchar / "/" / "?" )
2221   2221  
2222   fragment-part = [ "#" fragment ] 2222   fragment-part = [ "#" fragment ]
2223   @endcode 2223   @endcode
2224   2224  
2225   @par Specification 2225   @par Specification
2226   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5">3.5. Fragment (rfc3986)</a> 2226   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5">3.5. Fragment (rfc3986)</a>
2227   2227  
2228   @see 2228   @see
2229   @ref encoded_fragment, 2229   @ref encoded_fragment,
2230   @ref has_fragment. 2230   @ref has_fragment.
2231   2231  
2232   */ 2232   */
2233   template<BOOST_URL_STRTOK_TPARAM> 2233   template<BOOST_URL_STRTOK_TPARAM>
2234   BOOST_URL_STRTOK_RETURN 2234   BOOST_URL_STRTOK_RETURN
HITCBC 2235   40 fragment( 2235   40 fragment(
2236   StringToken&& token = {}) const 2236   StringToken&& token = {}) const
2237   { 2237   {
HITCBC 2238   40 encoding_opts opt; 2238   40 encoding_opts opt;
HITCBC 2239   40 opt.space_as_plus = false; 2239   40 opt.space_as_plus = false;
HITCBC 2240   80 return encoded_fragment().decode( 2240   80 return encoded_fragment().decode(
HITCBC 2241   80 opt, std::forward<StringToken>(token)); 2241   80 opt, std::forward<StringToken>(token));
2242   } 2242   }
2243   2243  
2244   /** Return the fragment 2244   /** Return the fragment
2245   2245  
2246   This function returns the fragment as a 2246   This function returns the fragment as a
2247   string with percent-escapes. 2247   string with percent-escapes.
2248   Ownership is not transferred; the 2248   Ownership is not transferred; the
2249   string returned references the underlying 2249   string returned references the underlying
2250   character buffer, which must remain valid 2250   character buffer, which must remain valid
2251   or else undefined behavior occurs. 2251   or else undefined behavior occurs.
2252   2252  
2253   @par Example 2253   @par Example
2254   @code 2254   @code
2255   assert( url_view( "http://www.example.com/index.htm#a%2D1" ).encoded_fragment() == "a%2D1" ); 2255   assert( url_view( "http://www.example.com/index.htm#a%2D1" ).encoded_fragment() == "a%2D1" );
2256   @endcode 2256   @endcode
2257   2257  
2258   @par Complexity 2258   @par Complexity
2259   Constant. 2259   Constant.
2260   2260  
2261   @par Exception Safety 2261   @par Exception Safety
2262   Throws nothing. 2262   Throws nothing.
2263   2263  
2264   @par BNF 2264   @par BNF
2265   @code 2265   @code
2266   fragment = *( pchar / "/" / "?" ) 2266   fragment = *( pchar / "/" / "?" )
2267   2267  
2268   pchar = unreserved / pct-encoded / sub-delims / ":" / "@" 2268   pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
2269   @endcode 2269   @endcode
2270   2270  
2271   @par Specification 2271   @par Specification
2272   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5">3.5. Fragment (rfc3986)</a> 2272   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5">3.5. Fragment (rfc3986)</a>
2273   2273  
2274   @see 2274   @see
2275   @ref fragment, 2275   @ref fragment,
2276   @ref has_fragment. 2276   @ref has_fragment.
2277   2277  
2278   @return The fragment portion of the url. 2278   @return The fragment portion of the url.
2279   */ 2279   */
2280   pct_string_view 2280   pct_string_view
2281   encoded_fragment() const noexcept; 2281   encoded_fragment() const noexcept;
2282   2282  
2283   //-------------------------------------------- 2283   //--------------------------------------------
2284   // 2284   //
2285   // Compound Fields 2285   // Compound Fields
2286   // 2286   //
2287   //-------------------------------------------- 2287   //--------------------------------------------
2288   2288  
2289   /** Return the host and port 2289   /** Return the host and port
2290   2290  
2291   If an authority is present, this 2291   If an authority is present, this
2292   function returns the host and optional 2292   function returns the host and optional
2293   port as a string, which may be empty. 2293   port as a string, which may be empty.
2294   Otherwise it returns an empty string. 2294   Otherwise it returns an empty string.
2295   The returned string may contain 2295   The returned string may contain
2296   percent escapes. 2296   percent escapes.
2297   2297  
2298   @par Example 2298   @par Example
2299   @code 2299   @code
2300   assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" ); 2300   assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
2301   @endcode 2301   @endcode
2302   2302  
2303   @par Complexity 2303   @par Complexity
2304   Constant. 2304   Constant.
2305   2305  
2306   @par Exception Safety 2306   @par Exception Safety
2307   Throws nothing. 2307   Throws nothing.
2308   2308  
2309   @par BNF 2309   @par BNF
2310   @code 2310   @code
2311   authority = [ userinfo "@" ] host [ ":" port ] 2311   authority = [ userinfo "@" ] host [ ":" port ]
2312   @endcode 2312   @endcode
2313   2313  
2314   @par Specification 2314   @par Specification
2315   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a> 2315   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">3.2.2. Host (rfc3986)</a>
2316   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a> 2316   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">3.2.3. Port (rfc3986)</a>
2317   2317  
2318   @see 2318   @see
2319   @ref has_port, 2319   @ref has_port,
2320   @ref port, 2320   @ref port,
2321   @ref port_number. 2321   @ref port_number.
2322   2322  
2323   @return The host and port portion of the url. 2323   @return The host and port portion of the url.
2324   */ 2324   */
2325   pct_string_view 2325   pct_string_view
2326   encoded_host_and_port() const noexcept; 2326   encoded_host_and_port() const noexcept;
2327   2327  
2328   /** Return the origin 2328   /** Return the origin
2329   2329  
2330   If an authority is present, this 2330   If an authority is present, this
2331   function returns the scheme and 2331   function returns the scheme and
2332   authority portion of the url. 2332   authority portion of the url.
2333   Otherwise, an empty string is 2333   Otherwise, an empty string is
2334   returned. 2334   returned.
2335   The returned string may contain 2335   The returned string may contain
2336   percent escapes. 2336   percent escapes.
2337   2337  
2338   @par Example 2338   @par Example
2339   @code 2339   @code
2340   assert( url_view( "http://www.example.com:8080/index.htm?text=none#h1" ).encoded_origin() == "http://www.example.com:8080" ); 2340   assert( url_view( "http://www.example.com:8080/index.htm?text=none#h1" ).encoded_origin() == "http://www.example.com:8080" );
2341   @endcode 2341   @endcode
2342   2342  
2343   @par Complexity 2343   @par Complexity
2344   Constant. 2344   Constant.
2345   2345  
2346   @par Exception Safety 2346   @par Exception Safety
2347   Throws nothing. 2347   Throws nothing.
2348   2348  
2349   @see 2349   @see
2350   @ref encoded_resource, 2350   @ref encoded_resource,
2351   @ref encoded_target. 2351   @ref encoded_target.
2352   2352  
2353   @return The origin portion of the url. 2353   @return The origin portion of the url.
2354   */ 2354   */
2355   pct_string_view 2355   pct_string_view
2356   encoded_origin() const noexcept; 2356   encoded_origin() const noexcept;
2357   2357  
2358   /** Return the resource 2358   /** Return the resource
2359   2359  
2360   This function returns the resource, which 2360   This function returns the resource, which
2361   is the portion of the url that includes 2361   is the portion of the url that includes
2362   only the path, query, and fragment. 2362   only the path, query, and fragment.
2363   The returned string may contain 2363   The returned string may contain
2364   percent escapes. 2364   percent escapes.
2365   2365  
2366   @par Example 2366   @par Example
2367   @code 2367   @code
2368   assert( url_view( "http://www.example.com/index.html?query#frag" ).encoded_resource() == "/index.html?query#frag" ); 2368   assert( url_view( "http://www.example.com/index.html?query#frag" ).encoded_resource() == "/index.html?query#frag" );
2369   @endcode 2369   @endcode
2370   2370  
2371   @par Complexity 2371   @par Complexity
2372   Constant. 2372   Constant.
2373   2373  
2374   @par Exception Safety 2374   @par Exception Safety
2375   Throws nothing. 2375   Throws nothing.
2376   2376  
2377   @par Specification 2377   @par Specification
2378   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 2378   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
2379   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 2379   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
2380   2380  
2381   @see 2381   @see
2382   @ref encoded_origin, 2382   @ref encoded_origin,
2383   @ref encoded_target. 2383   @ref encoded_target.
2384   2384  
2385   @return The resource portion of the url. 2385   @return The resource portion of the url.
2386   */ 2386   */
2387   pct_string_view 2387   pct_string_view
2388   encoded_resource() const noexcept; 2388   encoded_resource() const noexcept;
2389   2389  
2390   /** Return the target 2390   /** Return the target
2391   2391  
2392   This function returns the target, which 2392   This function returns the target, which
2393   is the portion of the url that includes 2393   is the portion of the url that includes
2394   only the path and query. 2394   only the path and query.
2395   The returned string may contain 2395   The returned string may contain
2396   percent escapes. 2396   percent escapes.
2397   2397  
2398   @par Example 2398   @par Example
2399   @code 2399   @code
2400   assert( url_view( "http://www.example.com/index.html?query#frag" ).encoded_target() == "/index.html?query" ); 2400   assert( url_view( "http://www.example.com/index.html?query#frag" ).encoded_target() == "/index.html?query" );
2401   @endcode 2401   @endcode
2402   2402  
2403   @par Complexity 2403   @par Complexity
2404   Constant. 2404   Constant.
2405   2405  
2406   @par Exception Safety 2406   @par Exception Safety
2407   Throws nothing. 2407   Throws nothing.
2408   2408  
2409   @par Specification 2409   @par Specification
2410   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a> 2410   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">3.3. Path (rfc3986)</a>
2411   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a> 2411   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4">3.4. Query (rfc3986)</a>
2412   2412  
2413   @see 2413   @see
2414   @ref encoded_origin, 2414   @ref encoded_origin,
2415   @ref encoded_resource. 2415   @ref encoded_resource.
2416   2416  
2417   @return The target portion of the url. 2417   @return The target portion of the url.
2418   */ 2418   */
2419   pct_string_view 2419   pct_string_view
2420   encoded_target() const noexcept; 2420   encoded_target() const noexcept;
2421   2421  
2422   //-------------------------------------------- 2422   //--------------------------------------------
2423   // 2423   //
2424   // Comparison 2424   // Comparison
2425   // 2425   //
2426   //-------------------------------------------- 2426   //--------------------------------------------
2427   2427  
2428   /** Return the result of comparing this with another url 2428   /** Return the result of comparing this with another url
2429   2429  
2430   This function compares two URLs 2430   This function compares two URLs
2431   according to Syntax-Based comparison 2431   according to Syntax-Based comparison
2432   algorithm. 2432   algorithm.
2433   2433  
2434   @par Complexity 2434   @par Complexity
2435   Linear in `min( u0.size(), u1.size() )` 2435   Linear in `min( u0.size(), u1.size() )`
2436   2436  
2437   @par Exception Safety 2437   @par Exception Safety
2438   Throws nothing. 2438   Throws nothing.
2439   2439  
2440   @par Specification 2440   @par Specification
2441   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2441   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2442   2442  
2443   @param other The url to compare 2443   @param other The url to compare
2444   @return -1 if `*this < other`, 0 if `this == other`, and 1 if `this > other`. 2444   @return -1 if `*this < other`, 0 if `this == other`, and 1 if `this > other`.
2445   */ 2445   */
2446   int 2446   int
2447   compare(url_view_base const& other) const noexcept; 2447   compare(url_view_base const& other) const noexcept;
2448   2448  
2449   /** Return the result of comparing two URLs 2449   /** Return the result of comparing two URLs
2450   2450  
2451   The URLs are compared component by 2451   The URLs are compared component by
2452   component as if they were first 2452   component as if they were first
2453   normalized. 2453   normalized.
2454   2454  
2455   @par Example 2455   @par Example
2456   @code 2456   @code
2457   url_view u0( "http://www.a.com/index.htm" ); 2457   url_view u0( "http://www.a.com/index.htm" );
2458   url_view u1( "http://www.a.com/index.htm" ); 2458   url_view u1( "http://www.a.com/index.htm" );
2459   assert( u0 == u1 ); 2459   assert( u0 == u1 );
2460   @endcode 2460   @endcode
2461   2461  
2462   @par Effects 2462   @par Effects
2463   @code 2463   @code
2464   url a(u0); 2464   url a(u0);
2465   a.normalize(); 2465   a.normalize();
2466   url b(u1); 2466   url b(u1);
2467   b.normalize(); 2467   b.normalize();
2468   return a.buffer() == b.buffer(); 2468   return a.buffer() == b.buffer();
2469   @endcode 2469   @endcode
2470   2470  
2471   @par Complexity 2471   @par Complexity
2472   Linear in `min( u0.size(), u1.size() )` 2472   Linear in `min( u0.size(), u1.size() )`
2473   2473  
2474   @par Exception Safety 2474   @par Exception Safety
2475   Throws nothing 2475   Throws nothing
2476   2476  
2477   @param u0 The first url to compare 2477   @param u0 The first url to compare
2478   @param u1 The second url to compare 2478   @param u1 The second url to compare
2479   @return `true` if `u0 == u1` 2479   @return `true` if `u0 == u1`
2480   2480  
2481   @par Specification 2481   @par Specification
2482   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2482   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2483   */ 2483   */
2484   friend 2484   friend
2485   bool 2485   bool
HITCBC 2486   133 operator==( 2486   133 operator==(
2487   url_view_base const& u0, 2487   url_view_base const& u0,
2488   url_view_base const& u1) noexcept 2488   url_view_base const& u1) noexcept
2489   { 2489   {
HITCBC 2490   133 return u0.compare(u1) == 0; 2490   133 return u0.compare(u1) == 0;
2491   } 2491   }
2492   2492  
2493   /** Return the result of comparing two URLs 2493   /** Return the result of comparing two URLs
2494   2494  
2495   The URLs are compared component by 2495   The URLs are compared component by
2496   component as if they were first 2496   component as if they were first
2497   normalized. 2497   normalized.
2498   2498  
2499   @par Example 2499   @par Example
2500   @code 2500   @code
2501   url_view u0( "http://www.a.com/index.htm" ); 2501   url_view u0( "http://www.a.com/index.htm" );
2502   url_view u1( "http://www.b.com/index.htm" ); 2502   url_view u1( "http://www.b.com/index.htm" );
2503   assert( u0 != u1 ); 2503   assert( u0 != u1 );
2504   @endcode 2504   @endcode
2505   2505  
2506   @par Effects 2506   @par Effects
2507   @code 2507   @code
2508   url a(u0); 2508   url a(u0);
2509   a.normalize(); 2509   a.normalize();
2510   url b(u1); 2510   url b(u1);
2511   b.normalize(); 2511   b.normalize();
2512   return a.buffer() != b.buffer(); 2512   return a.buffer() != b.buffer();
2513   @endcode 2513   @endcode
2514   2514  
2515   @par Complexity 2515   @par Complexity
2516   Linear in `min( u0.size(), u1.size() )` 2516   Linear in `min( u0.size(), u1.size() )`
2517   2517  
2518   @par Exception Safety 2518   @par Exception Safety
2519   Throws nothing 2519   Throws nothing
2520   2520  
2521   @param u0 The first url to compare 2521   @param u0 The first url to compare
2522   @param u1 The second url to compare 2522   @param u1 The second url to compare
2523   @return `true` if `u0 != u1` 2523   @return `true` if `u0 != u1`
2524   2524  
2525   @par Specification 2525   @par Specification
2526   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2526   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2527   */ 2527   */
2528   friend 2528   friend
2529   bool 2529   bool
HITCBC 2530   40 operator!=( 2530   40 operator!=(
2531   url_view_base const& u0, 2531   url_view_base const& u0,
2532   url_view_base const& u1) noexcept 2532   url_view_base const& u1) noexcept
2533   { 2533   {
HITCBC 2534   40 return ! (u0 == u1); 2534   40 return ! (u0 == u1);
2535   } 2535   }
2536   2536  
2537   /** Return the result of comparing two URLs 2537   /** Return the result of comparing two URLs
2538   2538  
2539   The URLs are compared component by 2539   The URLs are compared component by
2540   component as if they were first 2540   component as if they were first
2541   normalized. 2541   normalized.
2542   2542  
2543   @par Example 2543   @par Example
2544   @code 2544   @code
2545   url_view u0( "http://www.a.com/index.htm" ); 2545   url_view u0( "http://www.a.com/index.htm" );
2546   url_view u1( "http://www.b.com/index.htm" ); 2546   url_view u1( "http://www.b.com/index.htm" );
2547   assert( u0 < u1 ); 2547   assert( u0 < u1 );
2548   @endcode 2548   @endcode
2549   2549  
2550   @par Effects 2550   @par Effects
2551   @code 2551   @code
2552   url a(u0); 2552   url a(u0);
2553   a.normalize(); 2553   a.normalize();
2554   url b(u1); 2554   url b(u1);
2555   b.normalize(); 2555   b.normalize();
2556   return a.buffer() < b.buffer(); 2556   return a.buffer() < b.buffer();
2557   @endcode 2557   @endcode
2558   2558  
2559   @par Complexity 2559   @par Complexity
2560   Linear in `min( u0.size(), u1.size() )` 2560   Linear in `min( u0.size(), u1.size() )`
2561   2561  
2562   @par Exception Safety 2562   @par Exception Safety
2563   Throws nothing 2563   Throws nothing
2564   2564  
2565   @param u0 The first url to compare 2565   @param u0 The first url to compare
2566   @param u1 The second url to compare 2566   @param u1 The second url to compare
2567   @return `true` if `u0 < u1` 2567   @return `true` if `u0 < u1`
2568   2568  
2569   @par Specification 2569   @par Specification
2570   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2570   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2571   */ 2571   */
2572   friend 2572   friend
2573   bool 2573   bool
HITCBC 2574   32 operator<( 2574   32 operator<(
2575   url_view_base const& u0, 2575   url_view_base const& u0,
2576   url_view_base const& u1) noexcept 2576   url_view_base const& u1) noexcept
2577   { 2577   {
HITCBC 2578   32 return u0.compare(u1) < 0; 2578   32 return u0.compare(u1) < 0;
2579   } 2579   }
2580   2580  
2581   /** Return the result of comparing two URLs 2581   /** Return the result of comparing two URLs
2582   2582  
2583   The URLs are compared component by 2583   The URLs are compared component by
2584   component as if they were first 2584   component as if they were first
2585   normalized. 2585   normalized.
2586   2586  
2587   @par Example 2587   @par Example
2588   @code 2588   @code
2589   url_view u0( "http://www.b.com/index.htm" ); 2589   url_view u0( "http://www.b.com/index.htm" );
2590   url_view u1( "http://www.b.com/index.htm" ); 2590   url_view u1( "http://www.b.com/index.htm" );
2591   assert( u0 <= u1 ); 2591   assert( u0 <= u1 );
2592   @endcode 2592   @endcode
2593   2593  
2594   @par Effects 2594   @par Effects
2595   @code 2595   @code
2596   url a(u0); 2596   url a(u0);
2597   a.normalize(); 2597   a.normalize();
2598   url b(u1); 2598   url b(u1);
2599   b.normalize(); 2599   b.normalize();
2600   return a.buffer() <= b.buffer(); 2600   return a.buffer() <= b.buffer();
2601   @endcode 2601   @endcode
2602   2602  
2603   @par Complexity 2603   @par Complexity
2604   Linear in `min( u0.size(), u1.size() )` 2604   Linear in `min( u0.size(), u1.size() )`
2605   2605  
2606   @par Exception Safety 2606   @par Exception Safety
2607   Throws nothing 2607   Throws nothing
2608   2608  
2609   @param u0 The first url to compare 2609   @param u0 The first url to compare
2610   @param u1 The second url to compare 2610   @param u1 The second url to compare
2611   @return `true` if `u0 <= u1` 2611   @return `true` if `u0 <= u1`
2612   2612  
2613   @par Specification 2613   @par Specification
2614   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2614   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2615   */ 2615   */
2616   friend 2616   friend
2617   bool 2617   bool
HITCBC 2618   23 operator<=( 2618   23 operator<=(
2619   url_view_base const& u0, 2619   url_view_base const& u0,
2620   url_view_base const& u1) noexcept 2620   url_view_base const& u1) noexcept
2621   { 2621   {
HITCBC 2622   23 return u0.compare(u1) <= 0; 2622   23 return u0.compare(u1) <= 0;
2623   } 2623   }
2624   2624  
2625   /** Return the result of comparing two URLs 2625   /** Return the result of comparing two URLs
2626   2626  
2627   The URLs are compared component by 2627   The URLs are compared component by
2628   component as if they were first 2628   component as if they were first
2629   normalized. 2629   normalized.
2630   2630  
2631   @par Example 2631   @par Example
2632   @code 2632   @code
2633   url_view u0( "http://www.b.com/index.htm" ); 2633   url_view u0( "http://www.b.com/index.htm" );
2634   url_view u1( "http://www.a.com/index.htm" ); 2634   url_view u1( "http://www.a.com/index.htm" );
2635   assert( u0 > u1 ); 2635   assert( u0 > u1 );
2636   @endcode 2636   @endcode
2637   2637  
2638   @par Effects 2638   @par Effects
2639   @code 2639   @code
2640   url a(u0); 2640   url a(u0);
2641   a.normalize(); 2641   a.normalize();
2642   url b(u1); 2642   url b(u1);
2643   b.normalize(); 2643   b.normalize();
2644   return a.buffer() > b.buffer(); 2644   return a.buffer() > b.buffer();
2645   @endcode 2645   @endcode
2646   2646  
2647   @par Complexity 2647   @par Complexity
2648   Linear in `min( u0.size(), u1.size() )` 2648   Linear in `min( u0.size(), u1.size() )`
2649   2649  
2650   @par Exception Safety 2650   @par Exception Safety
2651   Throws nothing 2651   Throws nothing
2652   2652  
2653   @param u0 The first url to compare 2653   @param u0 The first url to compare
2654   @param u1 The second url to compare 2654   @param u1 The second url to compare
2655   @return `true` if `u0 > u1` 2655   @return `true` if `u0 > u1`
2656   2656  
2657   @par Specification 2657   @par Specification
2658   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2658   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2659   */ 2659   */
2660   friend 2660   friend
2661   bool 2661   bool
HITCBC 2662   23 operator>( 2662   23 operator>(
2663   url_view_base const& u0, 2663   url_view_base const& u0,
2664   url_view_base const& u1) noexcept 2664   url_view_base const& u1) noexcept
2665   { 2665   {
HITCBC 2666   23 return u0.compare(u1) > 0; 2666   23 return u0.compare(u1) > 0;
2667   } 2667   }
2668   2668  
2669   /** Return the result of comparing two URLs 2669   /** Return the result of comparing two URLs
2670   2670  
2671   The URLs are compared component by 2671   The URLs are compared component by
2672   component as if they were first 2672   component as if they were first
2673   normalized. 2673   normalized.
2674   2674  
2675   @par Example 2675   @par Example
2676   @code 2676   @code
2677   url_view u0( "http://www.a.com/index.htm" ); 2677   url_view u0( "http://www.a.com/index.htm" );
2678   url_view u1( "http://www.a.com/index.htm" ); 2678   url_view u1( "http://www.a.com/index.htm" );
2679   assert( u0 >= u1 ); 2679   assert( u0 >= u1 );
2680   @endcode 2680   @endcode
2681   2681  
2682   @par Effects 2682   @par Effects
2683   @code 2683   @code
2684   url a(u0); 2684   url a(u0);
2685   a.normalize(); 2685   a.normalize();
2686   url b(u1); 2686   url b(u1);
2687   b.normalize(); 2687   b.normalize();
2688   return a.buffer() >= b.buffer(); 2688   return a.buffer() >= b.buffer();
2689   @endcode 2689   @endcode
2690   2690  
2691   @par Complexity 2691   @par Complexity
2692   Linear in `min( u0.size(), u1.size() )` 2692   Linear in `min( u0.size(), u1.size() )`
2693   2693  
2694   @par Exception Safety 2694   @par Exception Safety
2695   Throws nothing 2695   Throws nothing
2696   2696  
2697   @param u0 The first url to compare 2697   @param u0 The first url to compare
2698   @param u1 The second url to compare 2698   @param u1 The second url to compare
2699   @return `true` if `u0 >= u1` 2699   @return `true` if `u0 >= u1`
2700   2700  
2701   @par Specification 2701   @par Specification
2702   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a> 2702   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2">6.2.2 Syntax-Based Normalization (rfc3986)</a>
2703   */ 2703   */
2704   friend 2704   friend
2705   bool 2705   bool
HITCBC 2706   23 operator>=( 2706   23 operator>=(
2707   url_view_base const& u0, 2707   url_view_base const& u0,
2708   url_view_base const& u1) noexcept 2708   url_view_base const& u1) noexcept
2709   { 2709   {
HITCBC 2710   23 return u0.compare(u1) >= 0; 2710   23 return u0.compare(u1) >= 0;
2711   } 2711   }
2712   2712  
2713   /** Format the url to the output stream 2713   /** Format the url to the output stream
2714   2714  
2715   This function serializes the url to 2715   This function serializes the url to
2716   the specified output stream. Any 2716   the specified output stream. Any
2717   percent-escapes are emitted as-is; 2717   percent-escapes are emitted as-is;
2718   no decoding is performed. 2718   no decoding is performed.
2719   2719  
2720   @par Example 2720   @par Example
2721   @code 2721   @code
2722   url_view u( "http://www.example.com/index.htm" ); 2722   url_view u( "http://www.example.com/index.htm" );
2723   std::stringstream ss; 2723   std::stringstream ss;
2724   ss << u; 2724   ss << u;
2725   assert( ss.str() == "http://www.example.com/index.htm" ); 2725   assert( ss.str() == "http://www.example.com/index.htm" );
2726   @endcode 2726   @endcode
2727   2727  
2728   @par Effects 2728   @par Effects
2729   @code 2729   @code
2730   return os << u.buffer(); 2730   return os << u.buffer();
2731   @endcode 2731   @endcode
2732   2732  
2733   @par Complexity 2733   @par Complexity
2734   Linear in `u.buffer().size()` 2734   Linear in `u.buffer().size()`
2735   2735  
2736   @par Exception Safety 2736   @par Exception Safety
2737   Basic guarantee. 2737   Basic guarantee.
2738   2738  
2739   @return A reference to the output stream, for chaining 2739   @return A reference to the output stream, for chaining
2740   2740  
2741   @param os The output stream to write to. 2741   @param os The output stream to write to.
2742   2742  
2743   @param u The url to write. 2743   @param u The url to write.
2744   */ 2744   */
2745   friend 2745   friend
2746   std::ostream& 2746   std::ostream&
HITCBC 2747   31 operator<<( 2747   31 operator<<(
2748   std::ostream& os, 2748   std::ostream& os,
2749   url_view_base const& u) 2749   url_view_base const& u)
2750   { 2750   {
HITCBC 2751   31 return os << u.buffer(); 2751   31 return os << u.buffer();
2752   } 2752   }
2753   2753  
2754   private: 2754   private:
2755   //-------------------------------------------- 2755   //--------------------------------------------
2756   // 2756   //
2757   // implementation 2757   // implementation
2758   // 2758   //
2759   //-------------------------------------------- 2759   //--------------------------------------------
2760   static 2760   static
2761   int 2761   int
2762   segments_compare( 2762   segments_compare(
2763   segments_encoded_view seg0, 2763   segments_encoded_view seg0,
2764   segments_encoded_view seg1) noexcept; 2764   segments_encoded_view seg1) noexcept;
2765   }; 2765   };
2766   2766  
2767   //------------------------------------------------ 2767   //------------------------------------------------
2768   2768  
2769   /** Format the url to the output stream 2769   /** Format the url to the output stream
2770   2770  
2771   This function serializes the url to 2771   This function serializes the url to
2772   the specified output stream. Any 2772   the specified output stream. Any
2773   percent-escapes are emitted as-is; 2773   percent-escapes are emitted as-is;
2774   no decoding is performed. 2774   no decoding is performed.
2775   2775  
2776   @par Example 2776   @par Example
2777   @code 2777   @code
2778   url_view u( "http://www.example.com/index.htm" ); 2778   url_view u( "http://www.example.com/index.htm" );
2779   std::stringstream ss; 2779   std::stringstream ss;
2780   ss << u; 2780   ss << u;
2781   assert( ss.str() == "http://www.example.com/index.htm" ); 2781   assert( ss.str() == "http://www.example.com/index.htm" );
2782   @endcode 2782   @endcode
2783   2783  
2784   @par Effects 2784   @par Effects
2785   @code 2785   @code
2786   return os << u.buffer(); 2786   return os << u.buffer();
2787   @endcode 2787   @endcode
2788   2788  
2789   @par Complexity 2789   @par Complexity
2790   Linear in `u.buffer().size()` 2790   Linear in `u.buffer().size()`
2791   2791  
2792   @par Exception Safety 2792   @par Exception Safety
2793   Basic guarantee. 2793   Basic guarantee.
2794   2794  
2795   @return A reference to the output stream, for chaining 2795   @return A reference to the output stream, for chaining
2796   2796  
2797   @param os The output stream to write to. 2797   @param os The output stream to write to.
2798   2798  
2799   @param u The url to write. 2799   @param u The url to write.
2800   */ 2800   */
2801   std::ostream& 2801   std::ostream&
2802   operator<<( 2802   operator<<(
2803   std::ostream& os, 2803   std::ostream& os,
2804   url_view_base const& u); 2804   url_view_base const& u);
2805   2805  
2806   } // urls 2806   } // urls
2807   } // boost 2807   } // boost
2808   2808  
2809   #include <boost/url/impl/url_view_base.hpp> 2809   #include <boost/url/impl/url_view_base.hpp>
2810   2810  
2811   #endif 2811   #endif