100.00% Lines (43/43) 100.00% Functions (15/15)
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_AUTHORITY_VIEW_HPP 11   #ifndef BOOST_URL_AUTHORITY_VIEW_HPP
12   #define BOOST_URL_AUTHORITY_VIEW_HPP 12   #define BOOST_URL_AUTHORITY_VIEW_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/host_type.hpp> 15   #include <boost/url/host_type.hpp>
16   #include <boost/url/ipv4_address.hpp> 16   #include <boost/url/ipv4_address.hpp>
17   #include <boost/url/ipv6_address.hpp> 17   #include <boost/url/ipv6_address.hpp>
18   #include <boost/url/pct_string_view.hpp> 18   #include <boost/url/pct_string_view.hpp>
19   #include <boost/url/detail/except.hpp> 19   #include <boost/url/detail/except.hpp>
20   #include <boost/url/detail/url_impl.hpp> 20   #include <boost/url/detail/url_impl.hpp>
21   #include <boost/assert.hpp> 21   #include <boost/assert.hpp>
22   #include <cstddef> 22   #include <cstddef>
23   #include <iosfwd> 23   #include <iosfwd>
24   #include <utility> 24   #include <utility>
25   25  
26   namespace boost { 26   namespace boost {
27   namespace urls { 27   namespace urls {
28   28  
29   class url_base; 29   class url_base;
30   30  
31   namespace implementation_defined { 31   namespace implementation_defined {
32   struct authority_rule_t; 32   struct authority_rule_t;
33   struct uri_rule_t; 33   struct uri_rule_t;
34   struct relative_ref_rule_t; 34   struct relative_ref_rule_t;
35   struct absolute_uri_rule_t; 35   struct absolute_uri_rule_t;
36   } // implementation_defined 36   } // implementation_defined
37   37  
38   /** A non-owning reference to a valid authority 38   /** A non-owning reference to a valid authority
39   39  
40   Objects of this type represent valid authority 40   Objects of this type represent valid authority
41   strings constructed from a parsed, external 41   strings constructed from a parsed, external
42   character buffer whose storage is managed 42   character buffer whose storage is managed
43   by the caller. That is, it acts like a 43   by the caller. That is, it acts like a
44   `core::string_view` in terms of ownership. 44   `core::string_view` in terms of ownership.
45   The caller is responsible for ensuring 45   The caller is responsible for ensuring
46   that the lifetime of the underlying 46   that the lifetime of the underlying
47   character buffer extends until it is no 47   character buffer extends until it is no
48   longer referenced. 48   longer referenced.
49   49  
50   @par Example 1 50   @par Example 1
51   Construction from a string parses the input 51   Construction from a string parses the input
52   as an <em>authority</em> and throws an 52   as an <em>authority</em> and throws an
53   exception on error. Upon success, the 53   exception on error. Upon success, the
54   constructed object points to the passed 54   constructed object points to the passed
55   character buffer; ownership is not 55   character buffer; ownership is not
56   transferred. 56   transferred.
57   @code 57   @code
58   authority_view a( "user:pass@www.example.com:8080" ); 58   authority_view a( "user:pass@www.example.com:8080" );
59   @endcode 59   @endcode
60   60  
61   @par Example 2 61   @par Example 2
62   The parsing function @ref parse_authority returns 62   The parsing function @ref parse_authority returns
63   a `boost::system::result` containing either a valid 63   a `boost::system::result` containing either a valid
64   @ref authority_view upon success, otherwise it 64   @ref authority_view upon success, otherwise it
65   contains an error. The error can be converted to 65   contains an error. The error can be converted to
66   an exception by the caller if desired: 66   an exception by the caller if desired:
67   @code 67   @code
68   system::result< authority_view > rv = parse_authority( "user:pass@www.example.com:8080" ); 68   system::result< authority_view > rv = parse_authority( "user:pass@www.example.com:8080" );
69   @endcode 69   @endcode
70   70  
71   @par BNF 71   @par BNF
72   @code 72   @code
73   authority = [ userinfo "@" ] host [ ":" port ] 73   authority = [ userinfo "@" ] host [ ":" port ]
74   74  
75   userinfo = user [ ":" [ password ] ] 75   userinfo = user [ ":" [ password ] ]
76   76  
77   user = *( unreserved / pct-encoded / sub-delims ) 77   user = *( unreserved / pct-encoded / sub-delims )
78   password = *( unreserved / pct-encoded / sub-delims / ":" ) 78   password = *( unreserved / pct-encoded / sub-delims / ":" )
79   79  
80   host = IP-literal / IPv4address / reg-name 80   host = IP-literal / IPv4address / reg-name
81   81  
82   port = *DIGIT 82   port = *DIGIT
83   @endcode 83   @endcode
84   84  
85   @par Specification 85   @par Specification
86   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2" 86   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
87   >3.2. Authority (rfc3986)</a> 87   >3.2. Authority (rfc3986)</a>
88   88  
89   @see 89   @see
90   @ref parse_authority. 90   @ref parse_authority.
91   */ 91   */
92   class BOOST_SYMBOL_VISIBLE 92   class BOOST_SYMBOL_VISIBLE
93   authority_view 93   authority_view
94   : private detail::parts_base 94   : private detail::parts_base
95   { 95   {
96   detail::url_impl u_; 96   detail::url_impl u_;
97   97  
98   friend struct detail::url_impl; 98   friend struct detail::url_impl;
99   friend struct implementation_defined::authority_rule_t; 99   friend struct implementation_defined::authority_rule_t;
100   friend struct implementation_defined::uri_rule_t; 100   friend struct implementation_defined::uri_rule_t;
101   friend struct implementation_defined::relative_ref_rule_t; 101   friend struct implementation_defined::relative_ref_rule_t;
102   friend struct implementation_defined::absolute_uri_rule_t; 102   friend struct implementation_defined::absolute_uri_rule_t;
103   friend class url_view_base; 103   friend class url_view_base;
104   friend class url_base; 104   friend class url_base;
105   105  
106   BOOST_URL_CXX14_CONSTEXPR 106   BOOST_URL_CXX14_CONSTEXPR
107   explicit 107   explicit
HITCBC 108   7209 authority_view( 108   7209 authority_view(
109   detail::url_impl const& u) noexcept 109   detail::url_impl const& u) noexcept
HITCBC 110   7209 : u_(u) 110   7209 : u_(u)
111   { 111   {
HITCBC 112   7209 } 112   7209 }
113   113  
114   public: 114   public:
115   //-------------------------------------------- 115   //--------------------------------------------
116   // 116   //
117   // Special Members 117   // Special Members
118   // 118   //
119   //-------------------------------------------- 119   //--------------------------------------------
120   120  
121   /** Destructor 121   /** Destructor
122   */ 122   */
123   BOOST_URL_CXX20_CONSTEXPR 123   BOOST_URL_CXX20_CONSTEXPR
124   virtual 124   virtual
HITCBC 125   54319 ~authority_view() 125   54327 ~authority_view()
HITCBC 126   54319 { 126   54327 {
127   // Empty body instead of = default because 127   // Empty body instead of = default because
128   // some GCC versions reject a defaulted 128   // some GCC versions reject a defaulted
129   // virtual constexpr destructor in constexpr 129   // virtual constexpr destructor in constexpr
130   // evaluation ("used before its definition"). 130   // evaluation ("used before its definition").
HITCBC 131   54319 } 131   54327 }
132   132  
133   /** Constructor 133   /** Constructor
134   134  
135   Default constructed authorities 135   Default constructed authorities
136   refer to a string with zero length, 136   refer to a string with zero length,
137   which is always valid. This matches 137   which is always valid. This matches
138   the grammar for a zero-length host. 138   the grammar for a zero-length host.
139   139  
140   @par Exception Safety 140   @par Exception Safety
141   Throws nothing. 141   Throws nothing.
142   142  
143   @par Specification 143   @par Specification
144   */ 144   */
145   BOOST_URL_CXX14_CONSTEXPR 145   BOOST_URL_CXX14_CONSTEXPR
HITCBC 146   20370 authority_view() noexcept 146   20374 authority_view() noexcept
HITCBC 147   20370 : u_(from::authority) 147   20374 : u_(from::authority)
148   { 148   {
HITCBC 149   20370 } 149   20374 }
150   150  
151   /** Construct from a string. 151   /** Construct from a string.
152   152  
153   This function attempts to construct 153   This function attempts to construct
154   an authority from the string `s`, 154   an authority from the string `s`,
155   which must be a valid authority or 155   which must be a valid authority or
156   else an exception is thrown. Upon 156   else an exception is thrown. Upon
157   successful construction, the view 157   successful construction, the view
158   refers to the characters in the 158   refers to the characters in the
159   buffer pointed to by `s`. 159   buffer pointed to by `s`.
160   Ownership is not transferred; the 160   Ownership is not transferred; the
161   caller is responsible for ensuring 161   caller is responsible for ensuring
162   that the lifetime of the buffer 162   that the lifetime of the buffer
163   extends until the view is destroyed. 163   extends until the view is destroyed.
164   164  
165   @param s The string to parse 165   @param s The string to parse
166   166  
167   @par BNF 167   @par BNF
168   @code 168   @code
169   authority = [ userinfo "@" ] host [ ":" port ] 169   authority = [ userinfo "@" ] host [ ":" port ]
170   170  
171   userinfo = user [ ":" [ password ] ] 171   userinfo = user [ ":" [ password ] ]
172   172  
173   user = *( unreserved / pct-encoded / sub-delims ) 173   user = *( unreserved / pct-encoded / sub-delims )
174   password = *( unreserved / pct-encoded / sub-delims / ":" ) 174   password = *( unreserved / pct-encoded / sub-delims / ":" )
175   175  
176   host = IP-literal / IPv4address / reg-name 176   host = IP-literal / IPv4address / reg-name
177   177  
178   port = *DIGIT 178   port = *DIGIT
179   @endcode 179   @endcode
180   180  
181   @par Specification 181   @par Specification
182   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2" 182   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
183   >3.2. Authority (rfc3986)</a> 183   >3.2. Authority (rfc3986)</a>
184   184  
185   @see 185   @see
186   @ref parse_authority. 186   @ref parse_authority.
187   */ 187   */
188   BOOST_URL_CXX20_CONSTEXPR 188   BOOST_URL_CXX20_CONSTEXPR
189   explicit 189   explicit
190   authority_view(core::string_view s); 190   authority_view(core::string_view s);
191   191  
192   /** Constructor 192   /** Constructor
193   */ 193   */
194   BOOST_URL_CXX14_CONSTEXPR 194   BOOST_URL_CXX14_CONSTEXPR
HITCBC 195   26740 authority_view( 195   26744 authority_view(
196   authority_view const&) noexcept = default; 196   authority_view const&) noexcept = default;
197   197  
198   /** Assignment 198   /** Assignment
199   199  
200   This function assigns the contents of 200   This function assigns the contents of
201   `other` to this object. 201   `other` to this object.
202   202  
203   @param other The object to assign 203   @param other The object to assign
204   @return A reference to this object 204   @return A reference to this object
205   205  
206   @par Exception Safety 206   @par Exception Safety
207   Throws nothing. 207   Throws nothing.
208   */ 208   */
209   BOOST_URL_CXX20_CONSTEXPR 209   BOOST_URL_CXX20_CONSTEXPR
210   authority_view& 210   authority_view&
HITCBC 211   6436 operator=( 211   6436 operator=(
212   authority_view const& other) noexcept = default; 212   authority_view const& other) noexcept = default;
213   213  
214   //-------------------------------------------- 214   //--------------------------------------------
215   // 215   //
216   // Observers 216   // Observers
217   // 217   //
218   //-------------------------------------------- 218   //--------------------------------------------
219   219  
220   /** Return the number of characters in the authority 220   /** Return the number of characters in the authority
221   221  
222   This function returns the number of 222   This function returns the number of
223   characters in the authority. 223   characters in the authority.
224   224  
225   @return The number of characters in the authority 225   @return The number of characters in the authority
226   226  
227   @par Example 227   @par Example
228   @code 228   @code
229   assert( authority_view( "user:pass@www.example.com:8080" ).size() == 30 ); 229   assert( authority_view( "user:pass@www.example.com:8080" ).size() == 30 );
230   @endcode 230   @endcode
231   231  
232   @par Exception Safety 232   @par Exception Safety
233   Throws nothing. 233   Throws nothing.
234   */ 234   */
235   std::size_t 235   std::size_t
HITCBC 236   155 size() const noexcept 236   155 size() const noexcept
237   { 237   {
HITCBC 238   155 return u_.offset(id_end); 238   155 return u_.offset(id_end);
239   } 239   }
240   240  
241   /** Return true if the authority is empty 241   /** Return true if the authority is empty
242   242  
243   An empty authority has an empty host, 243   An empty authority has an empty host,
244   no userinfo, and no port. 244   no userinfo, and no port.
245   245  
246   @return `true` if the authority is empty 246   @return `true` if the authority is empty
247   247  
248   @par Example 248   @par Example
249   @code 249   @code
250   assert( authority_view( "" ).empty() ); 250   assert( authority_view( "" ).empty() );
251   @endcode 251   @endcode
252   252  
253   @par Exception Safety 253   @par Exception Safety
254   Throws nothing. 254   Throws nothing.
255   */ 255   */
256   bool 256   bool
HITCBC 257   3 empty() const noexcept 257   3 empty() const noexcept
258   { 258   {
HITCBC 259   3 return size() == 0; 259   3 return size() == 0;
260   } 260   }
261   261  
262   /** Return a pointer to the first character 262   /** Return a pointer to the first character
263   263  
264   This function returns a pointer to the 264   This function returns a pointer to the
265   beginning of the view, which is not 265   beginning of the view, which is not
266   guaranteed to be null-terminated. 266   guaranteed to be null-terminated.
267   267  
268   @return A pointer to the first character 268   @return A pointer to the first character
269   269  
270   @par Exception Safety 270   @par Exception Safety
271   Throws nothing. 271   Throws nothing.
272   */ 272   */
273   char const* 273   char const*
HITCBC 274   94 data() const noexcept 274   94 data() const noexcept
275   { 275   {
HITCBC 276   94 return u_.cs_; 276   94 return u_.cs_;
277   } 277   }
278   278  
279   /** Return the complete authority 279   /** Return the complete authority
280   280  
281   This function returns the authority 281   This function returns the authority
282   as a percent-encoded string. 282   as a percent-encoded string.
283   283  
284   @return The complete authority 284   @return The complete authority
285   285  
286   @par Example 286   @par Example
287   @code 287   @code
288   assert( parse_authority( "www.example.com" ).value().buffer() == "www.example.com" ); 288   assert( parse_authority( "www.example.com" ).value().buffer() == "www.example.com" );
289   @endcode 289   @endcode
290   290  
291   @par BNF 291   @par BNF
292   @code 292   @code
293   authority = [ userinfo "@" ] host [ ":" port ] 293   authority = [ userinfo "@" ] host [ ":" port ]
294   @endcode 294   @endcode
295   295  
296   @par Exception Safety 296   @par Exception Safety
297   Throws nothing. 297   Throws nothing.
298   298  
299   @par Specification 299   @par Specification
300   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2" 300   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
301   >3.2. Authority (rfc3986)</a> 301   >3.2. Authority (rfc3986)</a>
302   */ 302   */
303   core::string_view 303   core::string_view
HITCBC 304   92 buffer() const noexcept 304   92 buffer() const noexcept
305   { 305   {
HITCBC 306   92 return core::string_view(data(), size()); 306   92 return core::string_view(data(), size());
307   } 307   }
308   308  
309   //-------------------------------------------- 309   //--------------------------------------------
310   // 310   //
311   // Userinfo 311   // Userinfo
312   // 312   //
313   //-------------------------------------------- 313   //--------------------------------------------
314   314  
315   /** Return true if a userinfo is present 315   /** Return true if a userinfo is present
316   316  
317   This function returns true if this 317   This function returns true if this
318   contains a userinfo. 318   contains a userinfo.
319   319  
320   @return `true` if a userinfo is present 320   @return `true` if a userinfo is present
321   321  
322   @par Example 322   @par Example
323   @code 323   @code
324   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() ); 324   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() );
325   @endcode 325   @endcode
326   326  
327   @par Complexity 327   @par Complexity
328   Constant. 328   Constant.
329   329  
330   @par Exception Safety 330   @par Exception Safety
331   Throws nothing. 331   Throws nothing.
332   332  
333   @par BNF 333   @par BNF
334   @code 334   @code
335   userinfo = user [ ":" [ password ] ] 335   userinfo = user [ ":" [ password ] ]
336   336  
337   authority = [ userinfo "@" ] host [ ":" port ] 337   authority = [ userinfo "@" ] host [ ":" port ]
338   @endcode 338   @endcode
339   339  
340   @par Specification 340   @par Specification
341   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 341   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
342   >3.2.1. User Information (rfc3986)</a> 342   >3.2.1. User Information (rfc3986)</a>
343   343  
344   @see 344   @see
345   @ref has_password, 345   @ref has_password,
346   @ref encoded_password, 346   @ref encoded_password,
347   @ref encoded_user, 347   @ref encoded_user,
348   @ref encoded_userinfo, 348   @ref encoded_userinfo,
349   @ref password, 349   @ref password,
350   @ref user, 350   @ref user,
351   @ref userinfo. 351   @ref userinfo.
352   352  
353   */ 353   */
354   BOOST_URL_CXX20_CONSTEXPR 354   BOOST_URL_CXX20_CONSTEXPR
355   bool 355   bool
356   has_userinfo() const noexcept; 356   has_userinfo() const noexcept;
357   357  
358   /** Return the userinfo 358   /** Return the userinfo
359   359  
360   If present, this function returns a 360   If present, this function returns a
361   string representing the userinfo (which 361   string representing the userinfo (which
362   may be empty). 362   may be empty).
363   Otherwise it returns an empty string. 363   Otherwise it returns an empty string.
364   Any percent-escapes in the string are 364   Any percent-escapes in the string are
365   decoded first. 365   decoded first.
366   366  
367   @param token A string token to receive the result. 367   @param token A string token to receive the result.
368   @return The userinfo 368   @return The userinfo
369   369  
370   @par Example 370   @par Example
371   @code 371   @code
372   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" ); 372   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" );
373   @endcode 373   @endcode
374   374  
375   @par Complexity 375   @par Complexity
376   Linear in `this->userinfo().size()`. 376   Linear in `this->userinfo().size()`.
377   377  
378   @par Exception Safety 378   @par Exception Safety
379   Calls to allocate may throw. 379   Calls to allocate may throw.
380   380  
381   @par BNF 381   @par BNF
382   @code 382   @code
383   userinfo = user [ ":" [ password ] ] 383   userinfo = user [ ":" [ password ] ]
384   384  
385   authority = [ userinfo "@" ] host [ ":" port ] 385   authority = [ userinfo "@" ] host [ ":" port ]
386   @endcode 386   @endcode
387   387  
388   @par Specification 388   @par Specification
389   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 389   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
390   >3.2.1. User Information (rfc3986)</a> 390   >3.2.1. User Information (rfc3986)</a>
391   391  
392   @see 392   @see
393   @ref has_password, 393   @ref has_password,
394   @ref has_userinfo, 394   @ref has_userinfo,
395   @ref encoded_password, 395   @ref encoded_password,
396   @ref encoded_user, 396   @ref encoded_user,
397   @ref encoded_userinfo, 397   @ref encoded_userinfo,
398   @ref password, 398   @ref password,
399   @ref user. 399   @ref user.
400   */ 400   */
401   template<BOOST_URL_STRTOK_TPARAM> 401   template<BOOST_URL_STRTOK_TPARAM>
402   BOOST_URL_STRTOK_RETURN 402   BOOST_URL_STRTOK_RETURN
HITCBC 403   24 userinfo( 403   24 userinfo(
404   BOOST_URL_STRTOK_ARG(token)) const 404   BOOST_URL_STRTOK_ARG(token)) const
405   { 405   {
HITCBC 406   24 encoding_opts opt; 406   24 encoding_opts opt;
HITCBC 407   24 opt.space_as_plus = false; 407   24 opt.space_as_plus = false;
HITCBC 408   48 return encoded_userinfo().decode( 408   48 return encoded_userinfo().decode(
HITCBC 409   48 opt, std::move(token)); 409   48 opt, std::move(token));
410   } 410   }
411   411  
412   /** Return the userinfo 412   /** Return the userinfo
413   413  
414   If present, this function returns a 414   If present, this function returns a
415   string representing the userinfo (which 415   string representing the userinfo (which
416   may be empty). 416   may be empty).
417   Otherwise it returns an empty string. 417   Otherwise it returns an empty string.
418   The returned string may contain 418   The returned string may contain
419   percent escapes. 419   percent escapes.
420   420  
421   @return The userinfo 421   @return The userinfo
422   422  
423   @par Example 423   @par Example
424   @code 424   @code
425   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" ); 425   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" );
426   @endcode 426   @endcode
427   427  
428   @par Complexity 428   @par Complexity
429   Constant. 429   Constant.
430   430  
431   @par Exception Safety 431   @par Exception Safety
432   Throws nothing 432   Throws nothing
433   433  
434   @par BNF 434   @par BNF
435   @code 435   @code
436   userinfo = user [ ":" [ password ] ] 436   userinfo = user [ ":" [ password ] ]
437   437  
438   authority = [ userinfo "@" ] host [ ":" port ] 438   authority = [ userinfo "@" ] host [ ":" port ]
439   @endcode 439   @endcode
440   440  
441   @par Specification 441   @par Specification
442   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 442   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
443   >3.2.1. User Information (rfc3986)</a> 443   >3.2.1. User Information (rfc3986)</a>
444   444  
445   @see 445   @see
446   @ref has_password, 446   @ref has_password,
447   @ref has_userinfo, 447   @ref has_userinfo,
448   @ref encoded_password, 448   @ref encoded_password,
449   @ref encoded_user, 449   @ref encoded_user,
450   @ref password, 450   @ref password,
451   @ref user, 451   @ref user,
452   @ref userinfo. 452   @ref userinfo.
453   */ 453   */
454   BOOST_URL_CXX20_CONSTEXPR 454   BOOST_URL_CXX20_CONSTEXPR
455   pct_string_view 455   pct_string_view
456   encoded_userinfo() const noexcept; 456   encoded_userinfo() const noexcept;
457   457  
458   //-------------------------------------------- 458   //--------------------------------------------
459   459  
460   /** Return the user 460   /** Return the user
461   461  
462   If present, this function returns a 462   If present, this function returns a
463   string representing the user (which 463   string representing the user (which
464   may be empty). 464   may be empty).
465   Otherwise it returns an empty string. 465   Otherwise it returns an empty string.
466   Any percent-escapes in the string are 466   Any percent-escapes in the string are
467   decoded first. 467   decoded first.
468   468  
469   @param token A string token to receive the result. 469   @param token A string token to receive the result.
470   @return The user 470   @return The user
471   471  
472   @par Example 472   @par Example
473   @code 473   @code
474   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" ); 474   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" );
475   @endcode 475   @endcode
476   476  
477   @par Complexity 477   @par Complexity
478   Linear in `this->user().size()`. 478   Linear in `this->user().size()`.
479   479  
480   @par Exception Safety 480   @par Exception Safety
481   Calls to allocate may throw. 481   Calls to allocate may throw.
482   482  
483   @par BNF 483   @par BNF
484   @code 484   @code
485   userinfo = user [ ":" [ password ] ] 485   userinfo = user [ ":" [ password ] ]
486   486  
487   user = *( unreserved / pct-encoded / sub-delims ) 487   user = *( unreserved / pct-encoded / sub-delims )
488   password = *( unreserved / pct-encoded / sub-delims / ":" ) 488   password = *( unreserved / pct-encoded / sub-delims / ":" )
489   @endcode 489   @endcode
490   490  
491   @par Specification 491   @par Specification
492   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 492   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
493   >3.2.1. User Information (rfc3986)</a> 493   >3.2.1. User Information (rfc3986)</a>
494   494  
495   @see 495   @see
496   @ref has_password, 496   @ref has_password,
497   @ref has_userinfo, 497   @ref has_userinfo,
498   @ref encoded_password, 498   @ref encoded_password,
499   @ref encoded_user, 499   @ref encoded_user,
500   @ref encoded_userinfo, 500   @ref encoded_userinfo,
501   @ref password, 501   @ref password,
502   @ref userinfo. 502   @ref userinfo.
503   */ 503   */
504   template<BOOST_URL_STRTOK_TPARAM> 504   template<BOOST_URL_STRTOK_TPARAM>
505   BOOST_URL_STRTOK_RETURN 505   BOOST_URL_STRTOK_RETURN
HITCBC 506   14 user( 506   14 user(
507   BOOST_URL_STRTOK_ARG(token)) const 507   BOOST_URL_STRTOK_ARG(token)) const
508   { 508   {
HITCBC 509   14 encoding_opts opt; 509   14 encoding_opts opt;
HITCBC 510   14 opt.space_as_plus = false; 510   14 opt.space_as_plus = false;
HITCBC 511   28 return encoded_user().decode( 511   28 return encoded_user().decode(
HITCBC 512   28 opt, std::move(token)); 512   28 opt, std::move(token));
513   } 513   }
514   514  
515   /** Return the user 515   /** Return the user
516   516  
517   If present, this function returns a 517   If present, this function returns a
518   string representing the user (which 518   string representing the user (which
519   may be empty). 519   may be empty).
520   Otherwise it returns an empty string. 520   Otherwise it returns an empty string.
521   The returned string may contain 521   The returned string may contain
522   percent escapes. 522   percent escapes.
523   523  
524   @return The user 524   @return The user
525   525  
526   @par Example 526   @par Example
527   @code 527   @code
528   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" ); 528   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" );
529   @endcode 529   @endcode
530   530  
531   @par Complexity 531   @par Complexity
532   Constant. 532   Constant.
533   533  
534   @par Exception Safety 534   @par Exception Safety
535   Throws nothing. 535   Throws nothing.
536   536  
537   @par BNF 537   @par BNF
538   @code 538   @code
539   userinfo = user [ ":" [ password ] ] 539   userinfo = user [ ":" [ password ] ]
540   540  
541   user = *( unreserved / pct-encoded / sub-delims ) 541   user = *( unreserved / pct-encoded / sub-delims )
542   password = *( unreserved / pct-encoded / sub-delims / ":" ) 542   password = *( unreserved / pct-encoded / sub-delims / ":" )
543   @endcode 543   @endcode
544   544  
545   @par Specification 545   @par Specification
546   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 546   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
547   >3.2.1. User Information (rfc3986)</a> 547   >3.2.1. User Information (rfc3986)</a>
548   548  
549   @see 549   @see
550   @ref has_password, 550   @ref has_password,
551   @ref has_userinfo, 551   @ref has_userinfo,
552   @ref encoded_password, 552   @ref encoded_password,
553   @ref encoded_userinfo, 553   @ref encoded_userinfo,
554   @ref password, 554   @ref password,
555   @ref user, 555   @ref user,
556   @ref userinfo. 556   @ref userinfo.
557   */ 557   */
558   BOOST_URL_CXX20_CONSTEXPR 558   BOOST_URL_CXX20_CONSTEXPR
559   pct_string_view 559   pct_string_view
560   encoded_user() const noexcept; 560   encoded_user() const noexcept;
561   561  
562   /** Return true if a password is present 562   /** Return true if a password is present
563   563  
564   This function returns true if the 564   This function returns true if the
565   userinfo is present and contains 565   userinfo is present and contains
566   a password. 566   a password.
567   567  
568   @return `true` if a password is present 568   @return `true` if a password is present
569   569  
570   @par Example 570   @par Example
571   @code 571   @code
572   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() ); 572   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() );
573   @endcode 573   @endcode
574   574  
575   @par Complexity 575   @par Complexity
576   Constant. 576   Constant.
577   577  
578   @par Exception Safety 578   @par Exception Safety
579   Throws nothing. 579   Throws nothing.
580   580  
581   @par BNF 581   @par BNF
582   @code 582   @code
583   userinfo = user [ ":" [ password ] ] 583   userinfo = user [ ":" [ password ] ]
584   584  
585   user = *( unreserved / pct-encoded / sub-delims ) 585   user = *( unreserved / pct-encoded / sub-delims )
586   password = *( unreserved / pct-encoded / sub-delims / ":" ) 586   password = *( unreserved / pct-encoded / sub-delims / ":" )
587   @endcode 587   @endcode
588   588  
589   @par Specification 589   @par Specification
590   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 590   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
591   >3.2.1. User Information (rfc3986)</a> 591   >3.2.1. User Information (rfc3986)</a>
592   592  
593   @see 593   @see
594   @ref has_userinfo, 594   @ref has_userinfo,
595   @ref encoded_password, 595   @ref encoded_password,
596   @ref encoded_user, 596   @ref encoded_user,
597   @ref encoded_userinfo, 597   @ref encoded_userinfo,
598   @ref password, 598   @ref password,
599   @ref user, 599   @ref user,
600   @ref userinfo. 600   @ref userinfo.
601   */ 601   */
602   BOOST_URL_CXX20_CONSTEXPR 602   BOOST_URL_CXX20_CONSTEXPR
603   bool 603   bool
604   has_password() const noexcept; 604   has_password() const noexcept;
605   605  
606   /** Return the password 606   /** Return the password
607   607  
608   If present, this function returns a 608   If present, this function returns a
609   string representing the password (which 609   string representing the password (which
610   may be an empty string). 610   may be an empty string).
611   Otherwise it returns an empty string. 611   Otherwise it returns an empty string.
612   Any percent-escapes in the string are 612   Any percent-escapes in the string are
613   decoded first. 613   decoded first.
614   614  
615   @param token A string token to receive the result. 615   @param token A string token to receive the result.
616   @return The password 616   @return The password
617   617  
618   @par Example 618   @par Example
619   @code 619   @code
620   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" ); 620   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" );
621   @endcode 621   @endcode
622   622  
623   @par Complexity 623   @par Complexity
624   Linear in `this->password().size()`. 624   Linear in `this->password().size()`.
625   625  
626   @par Exception Safety 626   @par Exception Safety
627   Calls to allocate may throw. 627   Calls to allocate may throw.
628   628  
629   @par BNF 629   @par BNF
630   @code 630   @code
631   userinfo = user [ ":" [ password ] ] 631   userinfo = user [ ":" [ password ] ]
632   632  
633   user = *( unreserved / pct-encoded / sub-delims ) 633   user = *( unreserved / pct-encoded / sub-delims )
634   password = *( unreserved / pct-encoded / sub-delims / ":" ) 634   password = *( unreserved / pct-encoded / sub-delims / ":" )
635   @endcode 635   @endcode
636   636  
637   @par Specification 637   @par Specification
638   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 638   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
639   >3.2.1. User Information (rfc3986)</a> 639   >3.2.1. User Information (rfc3986)</a>
640   640  
641   @see 641   @see
642   @ref has_password, 642   @ref has_password,
643   @ref has_userinfo, 643   @ref has_userinfo,
644   @ref encoded_password, 644   @ref encoded_password,
645   @ref encoded_user, 645   @ref encoded_user,
646   @ref encoded_userinfo, 646   @ref encoded_userinfo,
647   @ref user, 647   @ref user,
648   @ref userinfo. 648   @ref userinfo.
649   */ 649   */
650   template<BOOST_URL_STRTOK_TPARAM> 650   template<BOOST_URL_STRTOK_TPARAM>
651   BOOST_URL_STRTOK_RETURN 651   BOOST_URL_STRTOK_RETURN
HITCBC 652   14 password( 652   14 password(
653   BOOST_URL_STRTOK_ARG(token)) const 653   BOOST_URL_STRTOK_ARG(token)) const
654   { 654   {
HITCBC 655   14 encoding_opts opt; 655   14 encoding_opts opt;
HITCBC 656   14 opt.space_as_plus = false; 656   14 opt.space_as_plus = false;
HITCBC 657   28 return encoded_password().decode( 657   28 return encoded_password().decode(
HITCBC 658   28 opt, std::move(token)); 658   28 opt, std::move(token));
659   } 659   }
660   660  
661   /** Return the password 661   /** Return the password
662   662  
663   This function returns the password portion 663   This function returns the password portion
664   of the userinfo as a percent-encoded string. 664   of the userinfo as a percent-encoded string.
665   665  
666   @return The password 666   @return The password
667   667  
668   @par Example 668   @par Example
669   @code 669   @code
670   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" ); 670   assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" );
671   @endcode 671   @endcode
672   672  
673   @par Complexity 673   @par Complexity
674   Constant. 674   Constant.
675   675  
676   @par Exception Safety 676   @par Exception Safety
677   Throws nothing. 677   Throws nothing.
678   678  
679   @par BNF 679   @par BNF
680   @code 680   @code
681   userinfo = user [ ":" [ password ] ] 681   userinfo = user [ ":" [ password ] ]
682   682  
683   user = *( unreserved / pct-encoded / sub-delims ) 683   user = *( unreserved / pct-encoded / sub-delims )
684   password = *( unreserved / pct-encoded / sub-delims / ":" ) 684   password = *( unreserved / pct-encoded / sub-delims / ":" )
685   @endcode 685   @endcode
686   686  
687   @par Specification 687   @par Specification
688   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1" 688   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
689   >3.2.1. User Information (rfc3986)</a> 689   >3.2.1. User Information (rfc3986)</a>
690   690  
691   @see 691   @see
692   @ref has_password, 692   @ref has_password,
693   @ref has_userinfo, 693   @ref has_userinfo,
694   @ref encoded_user, 694   @ref encoded_user,
695   @ref encoded_userinfo, 695   @ref encoded_userinfo,
696   @ref password, 696   @ref password,
697   @ref user, 697   @ref user,
698   @ref userinfo. 698   @ref userinfo.
699   */ 699   */
700   BOOST_URL_CXX20_CONSTEXPR 700   BOOST_URL_CXX20_CONSTEXPR
701   pct_string_view 701   pct_string_view
702   encoded_password() const noexcept; 702   encoded_password() const noexcept;
703   703  
704   //-------------------------------------------- 704   //--------------------------------------------
705   // 705   //
706   // Host 706   // Host
707   // 707   //
708   //-------------------------------------------- 708   //--------------------------------------------
709   709  
710   /** Return the host type 710   /** Return the host type
711   711  
712   This function returns one of the 712   This function returns one of the
713   following constants representing the 713   following constants representing the
714   type of host present. 714   type of host present.
715   715  
716   @li @ref host_type::ipv4 716   @li @ref host_type::ipv4
717   @li @ref host_type::ipv6 717   @li @ref host_type::ipv6
718   @li @ref host_type::ipvfuture 718   @li @ref host_type::ipvfuture
719   @li @ref host_type::name 719   @li @ref host_type::name
720   720  
721   @return The host type 721   @return The host type
722   722  
723   @par Example 723   @par Example
724   @code 724   @code
725   assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 ); 725   assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 );
726   @endcode 726   @endcode
727   727  
728   @par Complexity 728   @par Complexity
729   Constant. 729   Constant.
730   730  
731   @par Exception Safety 731   @par Exception Safety
732   Throws nothing. 732   Throws nothing.
733   733  
734   @par Specification 734   @par Specification
735   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 735   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
736   >3.2.2. Host (rfc3986)</a> 736   >3.2.2. Host (rfc3986)</a>
737   */ 737   */
738   urls::host_type 738   urls::host_type
HITCBC 739   8 host_type() const noexcept 739   8 host_type() const noexcept
740   { 740   {
HITCBC 741   8 return u_.host_type_; 741   8 return u_.host_type_;
742   } 742   }
743   743  
744   /** Return the host 744   /** Return the host
745   745  
746   This function returns the host portion 746   This function returns the host portion
747   of the authority as a string, or the 747   of the authority as a string, or the
748   empty string if there is no authority. 748   empty string if there is no authority.
749   Any percent-escapes in the string are 749   Any percent-escapes in the string are
750   decoded first. 750   decoded first.
751   751  
752   @param token A string token to receive the result. 752   @param token A string token to receive the result.
753   @return The host 753   @return The host
754   754  
755   @par Example 755   @par Example
756   @code 756   @code
757   assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" ); 757   assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" );
758   @endcode 758   @endcode
759   759  
760   @par Complexity 760   @par Complexity
761   Linear in `this->host().size()`. 761   Linear in `this->host().size()`.
762   762  
763   @par Exception Safety 763   @par Exception Safety
764   Calls to allocate may throw. 764   Calls to allocate may throw.
765   765  
766   @par BNF 766   @par BNF
767   @code 767   @code
768   host = IP-literal / IPv4address / reg-name 768   host = IP-literal / IPv4address / reg-name
769   769  
770   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 770   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
771   771  
772   reg-name = *( unreserved / pct-encoded / "-" / ".") 772   reg-name = *( unreserved / pct-encoded / "-" / ".")
773   @endcode 773   @endcode
774   774  
775   @par Specification 775   @par Specification
776   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 776   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
777   >3.2.2. Host (rfc3986)</a> 777   >3.2.2. Host (rfc3986)</a>
778   */ 778   */
779   template<BOOST_URL_STRTOK_TPARAM> 779   template<BOOST_URL_STRTOK_TPARAM>
780   BOOST_URL_STRTOK_RETURN 780   BOOST_URL_STRTOK_RETURN
HITCBC 781   8 host( 781   8 host(
782   BOOST_URL_STRTOK_ARG(token)) const 782   BOOST_URL_STRTOK_ARG(token)) const
783   { 783   {
HITCBC 784   8 encoding_opts opt; 784   8 encoding_opts opt;
HITCBC 785   8 opt.space_as_plus = false; 785   8 opt.space_as_plus = false;
HITCBC 786   16 return encoded_host().decode( 786   16 return encoded_host().decode(
HITCBC 787   16 opt, std::move(token)); 787   16 opt, std::move(token));
788   } 788   }
789   789  
790   /** Return the host 790   /** Return the host
791   791  
792   This function returns the host portion 792   This function returns the host portion
793   of the authority as a string, or the 793   of the authority as a string, or the
794   empty string if there is no authority. 794   empty string if there is no authority.
795   The returned string may contain 795   The returned string may contain
796   percent escapes. 796   percent escapes.
797   797  
798   @return The host 798   @return The host
799   799  
800   @par Example 800   @par Example
801   @code 801   @code
802   assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" ); 802   assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" );
803   @endcode 803   @endcode
804   804  
805   @par Complexity 805   @par Complexity
806   Constant. 806   Constant.
807   807  
808   @par Exception Safety 808   @par Exception Safety
809   Throws nothing. 809   Throws nothing.
810   810  
811   @par BNF 811   @par BNF
812   @code 812   @code
813   host = IP-literal / IPv4address / reg-name 813   host = IP-literal / IPv4address / reg-name
814   814  
815   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 815   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
816   816  
817   reg-name = *( unreserved / pct-encoded / "-" / ".") 817   reg-name = *( unreserved / pct-encoded / "-" / ".")
818   @endcode 818   @endcode
819   819  
820   @par Specification 820   @par Specification
821   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 821   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
822   >3.2.2. Host (rfc3986)</a> 822   >3.2.2. Host (rfc3986)</a>
823   */ 823   */
824   BOOST_URL_CXX20_CONSTEXPR 824   BOOST_URL_CXX20_CONSTEXPR
825   pct_string_view 825   pct_string_view
826   encoded_host() const noexcept; 826   encoded_host() const noexcept;
827   827  
828   /** Return the host 828   /** Return the host
829   829  
830   The value returned by this function 830   The value returned by this function
831   depends on the type of host returned 831   depends on the type of host returned
832   from the function @ref host_type. 832   from the function @ref host_type.
833   833  
834   @li If the type is @ref host_type::ipv4, 834   @li If the type is @ref host_type::ipv4,
835   then the IPv4 address string is returned. 835   then the IPv4 address string is returned.
836   836  
837   @li If the type is @ref host_type::ipv6, 837   @li If the type is @ref host_type::ipv6,
838   then the IPv6 address string is returned, 838   then the IPv6 address string is returned,
839   without any enclosing brackets. 839   without any enclosing brackets.
840   840  
841   @li If the type is @ref host_type::ipvfuture, 841   @li If the type is @ref host_type::ipvfuture,
842   then the IPvFuture address string is returned, 842   then the IPvFuture address string is returned,
843   without any enclosing brackets. 843   without any enclosing brackets.
844   844  
845   @li If the type is @ref host_type::name, 845   @li If the type is @ref host_type::name,
846   then the host name string is returned. 846   then the host name string is returned.
847   Any percent-escapes in the string are 847   Any percent-escapes in the string are
848   decoded first. 848   decoded first.
849   849  
850   @li If the type is @ref host_type::none, 850   @li If the type is @ref host_type::none,
851   then an empty string is returned. 851   then an empty string is returned.
852   852  
853   @param token A string token to receive the result. 853   @param token A string token to receive the result.
854   @return The host address 854   @return The host address
855   855  
856   @par Example 856   @par Example
857   @code 857   @code
858   assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" ); 858   assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" );
859   @endcode 859   @endcode
860   860  
861   @par Complexity 861   @par Complexity
862   Linear in `this->host_address().size()`. 862   Linear in `this->host_address().size()`.
863   863  
864   @par Exception Safety 864   @par Exception Safety
865   Calls to allocate may throw. 865   Calls to allocate may throw.
866   866  
867   @par BNF 867   @par BNF
868   @code 868   @code
869   host = IP-literal / IPv4address / reg-name 869   host = IP-literal / IPv4address / reg-name
870   870  
871   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 871   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
872   872  
873   reg-name = *( unreserved / pct-encoded / "-" / ".") 873   reg-name = *( unreserved / pct-encoded / "-" / ".")
874   @endcode 874   @endcode
875   875  
876   @par Specification 876   @par Specification
877   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 877   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
878   >3.2.2. Host (rfc3986)</a> 878   >3.2.2. Host (rfc3986)</a>
879   */ 879   */
880   template<BOOST_URL_STRTOK_TPARAM> 880   template<BOOST_URL_STRTOK_TPARAM>
881   BOOST_URL_STRTOK_RETURN 881   BOOST_URL_STRTOK_RETURN
882   host_address( 882   host_address(
883   BOOST_URL_STRTOK_ARG(token)) const 883   BOOST_URL_STRTOK_ARG(token)) const
884   { 884   {
885   encoding_opts opt; 885   encoding_opts opt;
886   opt.space_as_plus = false; 886   opt.space_as_plus = false;
887   return encoded_host_address().decode( 887   return encoded_host_address().decode(
888   opt, std::move(token)); 888   opt, std::move(token));
889   } 889   }
890   890  
891   /** Return the host 891   /** Return the host
892   892  
893   The value returned by this function 893   The value returned by this function
894   depends on the type of host returned 894   depends on the type of host returned
895   from the function @ref host_type. 895   from the function @ref host_type.
896   896  
897   @li If the type is @ref host_type::ipv4, 897   @li If the type is @ref host_type::ipv4,
898   then the IPv4 address string is returned. 898   then the IPv4 address string is returned.
899   899  
900   @li If the type is @ref host_type::ipv6, 900   @li If the type is @ref host_type::ipv6,
901   then the IPv6 address string is returned, 901   then the IPv6 address string is returned,
902   without any enclosing brackets. 902   without any enclosing brackets.
903   903  
904   @li If the type is @ref host_type::ipvfuture, 904   @li If the type is @ref host_type::ipvfuture,
905   then the IPvFuture address string is returned, 905   then the IPvFuture address string is returned,
906   without any enclosing brackets. 906   without any enclosing brackets.
907   907  
908   @li If the type is @ref host_type::name, 908   @li If the type is @ref host_type::name,
909   then the host name string is returned. 909   then the host name string is returned.
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   @li If the type is @ref host_type::none, 913   @li If the type is @ref host_type::none,
914   then an empty string is returned. 914   then an empty string is returned.
915   The returned string may contain 915   The returned string may contain
916   percent escapes. 916   percent escapes.
917   917  
918   @return The host address 918   @return The host address
919   919  
920   @par Example 920   @par Example
921   @code 921   @code
922   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" ); 922   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" );
923   @endcode 923   @endcode
924   924  
925   @par Complexity 925   @par Complexity
926   Constant. 926   Constant.
927   927  
928   @par Exception Safety 928   @par Exception Safety
929   Throws nothing. 929   Throws nothing.
930   930  
931   @par BNF 931   @par BNF
932   @code 932   @code
933   host = IP-literal / IPv4address / reg-name 933   host = IP-literal / IPv4address / reg-name
934   934  
935   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 935   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
936   936  
937   reg-name = *( unreserved / pct-encoded / "-" / ".") 937   reg-name = *( unreserved / pct-encoded / "-" / ".")
938   @endcode 938   @endcode
939   939  
940   @par Specification 940   @par Specification
941   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 941   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
942   >3.2.2. Host (rfc3986)</a> 942   >3.2.2. Host (rfc3986)</a>
943   */ 943   */
944   BOOST_URL_CXX20_CONSTEXPR 944   BOOST_URL_CXX20_CONSTEXPR
945   pct_string_view 945   pct_string_view
946   encoded_host_address() const noexcept; 946   encoded_host_address() const noexcept;
947   947  
948   /** Return the host IPv4 address 948   /** Return the host IPv4 address
949   949  
950   If the host type is @ref host_type::ipv4, 950   If the host type is @ref host_type::ipv4,
951   this function returns the address as 951   this function returns the address as
952   a value of type @ref ipv4_address. 952   a value of type @ref ipv4_address.
953   Otherwise, if the host type is not an IPv4 953   Otherwise, if the host type is not an IPv4
954   address, it returns a default-constructed 954   address, it returns a default-constructed
955   value which is equal to the unspecified 955   value which is equal to the unspecified
956   address "0.0.0.0". 956   address "0.0.0.0".
957   957  
958   @return The host IPv4 address 958   @return The host IPv4 address
959   959  
960   @par Example 960   @par Example
961   @code 961   @code
962   assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) ); 962   assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) );
963   @endcode 963   @endcode
964   964  
965   @par Complexity 965   @par Complexity
966   Constant. 966   Constant.
967   967  
968   @par Exception Safety 968   @par Exception Safety
969   Throws nothing. 969   Throws nothing.
970   970  
971   @par BNF 971   @par BNF
972   @code 972   @code
973   IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet 973   IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
974   974  
975   dec-octet = DIGIT ; 0-9 975   dec-octet = DIGIT ; 0-9
976   / %x31-39 DIGIT ; 10-99 976   / %x31-39 DIGIT ; 10-99
977   / "1" 2DIGIT ; 100-199 977   / "1" 2DIGIT ; 100-199
978   / "2" %x30-34 DIGIT ; 200-249 978   / "2" %x30-34 DIGIT ; 200-249
979   / "25" %x30-35 ; 250-255 979   / "25" %x30-35 ; 250-255
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.2" 983   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
984   >3.2.2. Host (rfc3986)</a> 984   >3.2.2. Host (rfc3986)</a>
985   */ 985   */
986   BOOST_URL_CXX20_CONSTEXPR 986   BOOST_URL_CXX20_CONSTEXPR
987   ipv4_address 987   ipv4_address
988   host_ipv4_address() const noexcept; 988   host_ipv4_address() const noexcept;
989   989  
990   /** Return the host IPv6 address 990   /** Return the host IPv6 address
991   991  
992   If the host type is @ref host_type::ipv6, 992   If the host type is @ref host_type::ipv6,
993   this function returns the address as 993   this function returns the address as
994   a value of type @ref ipv6_address. 994   a value of type @ref ipv6_address.
995   Otherwise, if the host type is not an IPv6 995   Otherwise, if the host type is not an IPv6
996   address, it returns a default-constructed 996   address, it returns a default-constructed
997   value which is equal to the unspecified 997   value which is equal to the unspecified
998   address "0:0:0:0:0:0:0:0". 998   address "0:0:0:0:0:0:0:0".
999   999  
1000   @return The host IPv6 address 1000   @return The host IPv6 address
1001   1001  
1002   @par Example 1002   @par Example
1003   @code 1003   @code
1004   assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) ); 1004   assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) );
1005   @endcode 1005   @endcode
1006   1006  
1007   @par Complexity 1007   @par Complexity
1008   Constant. 1008   Constant.
1009   1009  
1010   @par Exception Safety 1010   @par Exception Safety
1011   Throws nothing. 1011   Throws nothing.
1012   1012  
1013   @par BNF 1013   @par BNF
1014   @code 1014   @code
1015   IPv6address = 6( h16 ":" ) ls32 1015   IPv6address = 6( h16 ":" ) ls32
1016   / "::" 5( h16 ":" ) ls32 1016   / "::" 5( h16 ":" ) ls32
1017   / [ h16 ] "::" 4( h16 ":" ) ls32 1017   / [ h16 ] "::" 4( h16 ":" ) ls32
1018   / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 1018   / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1019   / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 1019   / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1020   / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 1020   / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1021   / [ *4( h16 ":" ) h16 ] "::" ls32 1021   / [ *4( h16 ":" ) h16 ] "::" ls32
1022   / [ *5( h16 ":" ) h16 ] "::" h16 1022   / [ *5( h16 ":" ) h16 ] "::" h16
1023   / [ *6( h16 ":" ) h16 ] "::" 1023   / [ *6( h16 ":" ) h16 ] "::"
1024   1024  
1025   ls32 = ( h16 ":" h16 ) / IPv4address 1025   ls32 = ( h16 ":" h16 ) / IPv4address
1026   ; least-significant 32 bits of address 1026   ; least-significant 32 bits of address
1027   1027  
1028   h16 = 1*4HEXDIG 1028   h16 = 1*4HEXDIG
1029   ; 16 bits of address represented in hexadecimal 1029   ; 16 bits of address represented in hexadecimal
1030   @endcode 1030   @endcode
1031   1031  
1032   @par Specification 1032   @par Specification
1033   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 1033   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1034   >3.2.2. Host (rfc3986)</a> 1034   >3.2.2. Host (rfc3986)</a>
1035   */ 1035   */
1036   BOOST_URL_CXX20_CONSTEXPR 1036   BOOST_URL_CXX20_CONSTEXPR
1037   ipv6_address 1037   ipv6_address
1038   host_ipv6_address() const noexcept; 1038   host_ipv6_address() const noexcept;
1039   1039  
1040   /** Return the host IPvFuture address 1040   /** Return the host IPvFuture address
1041   1041  
1042   If the host type is @ref host_type::ipvfuture, 1042   If the host type is @ref host_type::ipvfuture,
1043   this function returns the address as 1043   this function returns the address as
1044   a string. 1044   a string.
1045   Otherwise, if the host type is not an 1045   Otherwise, if the host type is not an
1046   IPvFuture address, it returns an 1046   IPvFuture address, it returns an
1047   empty string. 1047   empty string.
1048   1048  
1049   @return The host IPvFuture address 1049   @return The host IPvFuture address
1050   1050  
1051   @par Example 1051   @par Example
1052   @code 1052   @code
1053   assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" ); 1053   assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" );
1054   @endcode 1054   @endcode
1055   1055  
1056   @par Complexity 1056   @par Complexity
1057   Constant. 1057   Constant.
1058   1058  
1059   @par Exception Safety 1059   @par Exception Safety
1060   Throws nothing. 1060   Throws nothing.
1061   1061  
1062   @par BNF 1062   @par BNF
1063   @code 1063   @code
1064   IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) 1064   IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1065   @endcode 1065   @endcode
1066   1066  
1067   @par Specification 1067   @par Specification
1068   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 1068   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1069   >3.2.2. Host (rfc3986)</a> 1069   >3.2.2. Host (rfc3986)</a>
1070   */ 1070   */
1071   BOOST_URL_CXX20_CONSTEXPR 1071   BOOST_URL_CXX20_CONSTEXPR
1072   core::string_view 1072   core::string_view
1073   host_ipvfuture() const noexcept; 1073   host_ipvfuture() const noexcept;
1074   1074  
1075   /** Return the host name 1075   /** Return the host name
1076   1076  
1077   If the host type is @ref host_type::name, 1077   If the host type is @ref host_type::name,
1078   this function returns the name as 1078   this function returns the name as
1079   a string. 1079   a string.
1080   Otherwise, if the host type is not a 1080   Otherwise, if the host type is not a
1081   name, it returns an empty string. 1081   name, it returns an empty string.
1082   Any percent-escapes in the string are 1082   Any percent-escapes in the string are
1083   decoded first. 1083   decoded first.
1084   1084  
1085   @param token A string token to receive the result 1085   @param token A string token to receive the result
1086   @return The host name 1086   @return The host name
1087   1087  
1088   @par Example 1088   @par Example
1089   @code 1089   @code
1090   assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" ); 1090   assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" );
1091   @endcode 1091   @endcode
1092   1092  
1093   @par Complexity 1093   @par Complexity
1094   Linear in `this->host_name().size()`. 1094   Linear in `this->host_name().size()`.
1095   1095  
1096   @par Exception Safety 1096   @par Exception Safety
1097   Calls to allocate may throw. 1097   Calls to allocate may throw.
1098   1098  
1099   @par BNF 1099   @par BNF
1100   @code 1100   @code
1101   host = IP-literal / IPv4address / reg-name 1101   host = IP-literal / IPv4address / reg-name
1102   1102  
1103   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1103   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1104   1104  
1105   reg-name = *( unreserved / pct-encoded / "-" / ".") 1105   reg-name = *( unreserved / pct-encoded / "-" / ".")
1106   @endcode 1106   @endcode
1107   1107  
1108   @par Specification 1108   @par Specification
1109   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 1109   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1110   >3.2.2. Host (rfc3986)</a> 1110   >3.2.2. Host (rfc3986)</a>
1111   */ 1111   */
1112   template<BOOST_URL_STRTOK_TPARAM> 1112   template<BOOST_URL_STRTOK_TPARAM>
1113   BOOST_URL_STRTOK_RETURN 1113   BOOST_URL_STRTOK_RETURN
1114   host_name( 1114   host_name(
1115   BOOST_URL_STRTOK_ARG(token)) const 1115   BOOST_URL_STRTOK_ARG(token)) const
1116   { 1116   {
1117   encoding_opts opt; 1117   encoding_opts opt;
1118   opt.space_as_plus = false; 1118   opt.space_as_plus = false;
1119   return encoded_host_name().decode( 1119   return encoded_host_name().decode(
1120   opt, std::move(token)); 1120   opt, std::move(token));
1121   } 1121   }
1122   1122  
1123   /** Return the host name 1123   /** Return the host name
1124   1124  
1125   If the host type is @ref host_type::name, 1125   If the host type is @ref host_type::name,
1126   this function returns the name as 1126   this function returns the name as
1127   a string. 1127   a string.
1128   Otherwise, if the host type is not an 1128   Otherwise, if the host type is not an
1129   name, it returns an empty string. 1129   name, it returns an empty string.
1130   The returned string may contain 1130   The returned string may contain
1131   percent escapes. 1131   percent escapes.
1132   1132  
1133   @return The host name 1133   @return The host name
1134   1134  
1135   @par Example 1135   @par Example
1136   @code 1136   @code
1137   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" ); 1137   assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" );
1138   @endcode 1138   @endcode
1139   1139  
1140   @par Complexity 1140   @par Complexity
1141   Constant. 1141   Constant.
1142   1142  
1143   @par Exception Safety 1143   @par Exception Safety
1144   Throws nothing. 1144   Throws nothing.
1145   1145  
1146   @par BNF 1146   @par BNF
1147   @code 1147   @code
1148   host = IP-literal / IPv4address / reg-name 1148   host = IP-literal / IPv4address / reg-name
1149   1149  
1150   IP-literal = "[" ( IPv6address / IPvFuture ) "]" 1150   IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1151   1151  
1152   reg-name = *( unreserved / pct-encoded / "-" / ".") 1152   reg-name = *( unreserved / pct-encoded / "-" / ".")
1153   @endcode 1153   @endcode
1154   1154  
1155   @par Specification 1155   @par Specification
1156   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 1156   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1157   >3.2.2. Host (rfc3986)</a> 1157   >3.2.2. Host (rfc3986)</a>
1158   */ 1158   */
1159   BOOST_URL_CXX20_CONSTEXPR 1159   BOOST_URL_CXX20_CONSTEXPR
1160   pct_string_view 1160   pct_string_view
1161   encoded_host_name() const noexcept; 1161   encoded_host_name() const noexcept;
1162   1162  
1163   //-------------------------------------------- 1163   //--------------------------------------------
1164   // 1164   //
1165   // Port 1165   // Port
1166   // 1166   //
1167   //-------------------------------------------- 1167   //--------------------------------------------
1168   1168  
1169   /** Return true if a port is present 1169   /** Return true if a port is present
1170   1170  
1171   This function returns true if an 1171   This function returns true if an
1172   authority is present and contains a port. 1172   authority is present and contains a port.
1173   1173  
1174   @return `true` if a port is present, otherwise `false` 1174   @return `true` if a port is present, otherwise `false`
1175   1175  
1176   @par Example 1176   @par Example
1177   @code 1177   @code
1178   assert( url_view( "wss://www.example.com:443" ).has_port() ); 1178   assert( url_view( "wss://www.example.com:443" ).has_port() );
1179   @endcode 1179   @endcode
1180   1180  
1181   @par Complexity 1181   @par Complexity
1182   Constant. 1182   Constant.
1183   1183  
1184   @par Exception Safety 1184   @par Exception Safety
1185   Throws nothing. 1185   Throws nothing.
1186   1186  
1187   @par BNF 1187   @par BNF
1188   @code 1188   @code
1189   authority = [ userinfo "@" ] host [ ":" port ] 1189   authority = [ userinfo "@" ] host [ ":" port ]
1190   1190  
1191   port = *DIGIT 1191   port = *DIGIT
1192   @endcode 1192   @endcode
1193   1193  
1194   @par Specification 1194   @par Specification
1195   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3" 1195   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1196   >3.2.3. Port (rfc3986)</a> 1196   >3.2.3. Port (rfc3986)</a>
1197   1197  
1198   @see 1198   @see
1199   @ref encoded_host_and_port, 1199   @ref encoded_host_and_port,
1200   @ref port, 1200   @ref port,
1201   @ref port_number. 1201   @ref port_number.
1202   */ 1202   */
1203   BOOST_URL_CXX20_CONSTEXPR 1203   BOOST_URL_CXX20_CONSTEXPR
1204   bool 1204   bool
1205   has_port() const noexcept; 1205   has_port() const noexcept;
1206   1206  
1207   /** Return the port 1207   /** Return the port
1208   1208  
1209   If present, this function returns a 1209   If present, this function returns a
1210   string representing the port (which 1210   string representing the port (which
1211   may be empty). 1211   may be empty).
1212   Otherwise it returns an empty string. 1212   Otherwise it returns an empty string.
1213   1213  
1214   @return The port as a string 1214   @return The port as a string
1215   1215  
1216   @par Example 1216   @par Example
1217   @code 1217   @code
1218   assert( url_view( "http://localhost.com:8080" ).port() == "8080" ); 1218   assert( url_view( "http://localhost.com:8080" ).port() == "8080" );
1219   @endcode 1219   @endcode
1220   1220  
1221   @par Complexity 1221   @par Complexity
1222   Constant. 1222   Constant.
1223   1223  
1224   @par Exception Safety 1224   @par Exception Safety
1225   Throws nothing. 1225   Throws nothing.
1226   1226  
1227   @par BNF 1227   @par BNF
1228   @code 1228   @code
1229   port = *DIGIT 1229   port = *DIGIT
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.3" 1233   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1234   >3.2.3. Port (rfc3986)</a> 1234   >3.2.3. Port (rfc3986)</a>
1235   1235  
1236   @see 1236   @see
1237   @ref encoded_host_and_port, 1237   @ref encoded_host_and_port,
1238   @ref has_port, 1238   @ref has_port,
1239   @ref port_number. 1239   @ref port_number.
1240   */ 1240   */
1241   BOOST_URL_CXX20_CONSTEXPR 1241   BOOST_URL_CXX20_CONSTEXPR
1242   core::string_view 1242   core::string_view
1243   port() const noexcept; 1243   port() const noexcept;
1244   1244  
1245   /** Return the port 1245   /** Return the port
1246   1246  
1247   If a port is present and the numerical 1247   If a port is present and the numerical
1248   value is representable, it is returned 1248   value is representable, it is returned
1249   as an unsigned integer. Otherwise, the 1249   as an unsigned integer. Otherwise, the
1250   number zero is returned. 1250   number zero is returned.
1251   1251  
1252   @return The port number 1252   @return The port number
1253   1253  
1254   @par Example 1254   @par Example
1255   @code 1255   @code
1256   assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 ); 1256   assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 );
1257   @endcode 1257   @endcode
1258   1258  
1259   @par Complexity 1259   @par Complexity
1260   Constant. 1260   Constant.
1261   1261  
1262   @par Exception Safety 1262   @par Exception Safety
1263   Throws nothing. 1263   Throws nothing.
1264   1264  
1265   @par BNF 1265   @par BNF
1266   @code 1266   @code
1267   port = *DIGIT 1267   port = *DIGIT
1268   @endcode 1268   @endcode
1269   1269  
1270   @par Specification 1270   @par Specification
1271   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3" 1271   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1272   >3.2.3. Port (rfc3986)</a> 1272   >3.2.3. Port (rfc3986)</a>
1273   1273  
1274   @see 1274   @see
1275   @ref encoded_host_and_port, 1275   @ref encoded_host_and_port,
1276   @ref has_port, 1276   @ref has_port,
1277   @ref port. 1277   @ref port.
1278   */ 1278   */
1279   BOOST_URL_CXX20_CONSTEXPR 1279   BOOST_URL_CXX20_CONSTEXPR
1280   std::uint16_t 1280   std::uint16_t
1281   port_number() const noexcept; 1281   port_number() const noexcept;
1282   1282  
1283   /** Return the host and port 1283   /** Return the host and port
1284   1284  
1285   If an authority is present, this 1285   If an authority is present, this
1286   function returns the host and optional 1286   function returns the host and optional
1287   port as a string, which may be empty. 1287   port as a string, which may be empty.
1288   Otherwise it returns an empty string. 1288   Otherwise it returns an empty string.
1289   The returned string may contain 1289   The returned string may contain
1290   percent escapes. 1290   percent escapes.
1291   1291  
1292   @par Example 1292   @par Example
1293   @code 1293   @code
1294   assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" ); 1294   assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
1295   @endcode 1295   @endcode
1296   1296  
1297   @par Complexity 1297   @par Complexity
1298   Constant. 1298   Constant.
1299   1299  
1300   @par Exception Safety 1300   @par Exception Safety
1301   Throws nothing. 1301   Throws nothing.
1302   1302  
1303   @par BNF 1303   @par BNF
1304   @code 1304   @code
1305   authority = [ userinfo "@" ] host [ ":" port ] 1305   authority = [ userinfo "@" ] host [ ":" port ]
1306   @endcode 1306   @endcode
1307   1307  
1308   @par Specification 1308   @par Specification
1309   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2" 1309   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1310   >3.2.2. Host (rfc3986)</a> 1310   >3.2.2. Host (rfc3986)</a>
1311   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3" 1311   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1312   >3.2.3. Port (rfc3986)</a> 1312   >3.2.3. Port (rfc3986)</a>
1313   1313  
1314   @see 1314   @see
1315   @ref has_port, 1315   @ref has_port,
1316   @ref port, 1316   @ref port,
1317   @ref port_number. 1317   @ref port_number.
1318   1318  
1319   @return The host and port 1319   @return The host and port
1320   */ 1320   */
1321   BOOST_URL_CXX20_CONSTEXPR 1321   BOOST_URL_CXX20_CONSTEXPR
1322   pct_string_view 1322   pct_string_view
1323   encoded_host_and_port() const noexcept; 1323   encoded_host_and_port() const noexcept;
1324   1324  
1325   //-------------------------------------------- 1325   //--------------------------------------------
1326   // 1326   //
1327   // Comparison 1327   // Comparison
1328   // 1328   //
1329   //-------------------------------------------- 1329   //--------------------------------------------
1330   1330  
1331   /** Return the result of comparing this with another authority 1331   /** Return the result of comparing this with another authority
1332   1332  
1333   This function compares two authorities 1333   This function compares two authorities
1334   according to Syntax-Based comparison 1334   according to Syntax-Based comparison
1335   algorithm. 1335   algorithm.
1336   1336  
1337   @par Exception Safety 1337   @par Exception Safety
1338   Throws nothing. 1338   Throws nothing.
1339   1339  
1340   @param other The authority to compare 1340   @param other The authority to compare
1341   1341  
1342   @return `-1` if `*this < other`, `0` if 1342   @return `-1` if `*this < other`, `0` if
1343   `this == other`, and 1 if `this > other`. 1343   `this == other`, and 1 if `this > other`.
1344   1344  
1345   @par Specification 1345   @par Specification
1346   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2" 1346   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
1347   >6.2.2 Syntax-Based Normalization (rfc3986)</a> 1347   >6.2.2 Syntax-Based Normalization (rfc3986)</a>
1348   */ 1348   */
1349   int 1349   int
1350   compare(authority_view const& other) const noexcept; 1350   compare(authority_view const& other) const noexcept;
1351   1351  
1352   /** Return the result of comparing two authorities. 1352   /** Return the result of comparing two authorities.
1353   The authorities are compared component 1353   The authorities are compared component
1354   by component as if they were first 1354   by component as if they were first
1355   normalized. 1355   normalized.
1356   1356  
1357   @par Complexity 1357   @par Complexity
1358   Linear in `min( a0.size(), a1.size() )` 1358   Linear in `min( a0.size(), a1.size() )`
1359   1359  
1360   @par Exception Safety 1360   @par Exception Safety
1361   Throws nothing 1361   Throws nothing
1362   1362  
1363   @param a0 The first authority to compare 1363   @param a0 The first authority to compare
1364   @param a1 The second authority to compare 1364   @param a1 The second authority to compare
1365   @return `true` if `a0 == a1`, otherwise `false` 1365   @return `true` if `a0 == a1`, otherwise `false`
1366   */ 1366   */
1367   friend 1367   friend
1368   bool 1368   bool
1369   operator==( 1369   operator==(
1370   authority_view const& a0, 1370   authority_view const& a0,
1371   authority_view const& a1) noexcept 1371   authority_view const& a1) noexcept
1372   { 1372   {
1373   return a0.compare(a1) == 0; 1373   return a0.compare(a1) == 0;
1374   } 1374   }
1375   1375  
1376   /** Return the result of comparing two authorities. 1376   /** Return the result of comparing two authorities.
1377   The authorities are compared component 1377   The authorities are compared component
1378   by component as if they were first 1378   by component as if they were first
1379   normalized. 1379   normalized.
1380   1380  
1381   @par Complexity 1381   @par Complexity
1382   Linear in `min( a0.size(), a1.size() )` 1382   Linear in `min( a0.size(), a1.size() )`
1383   1383  
1384   @par Exception Safety 1384   @par Exception Safety
1385   Throws nothing 1385   Throws nothing
1386   1386  
1387   @param a0 The first authority to compare 1387   @param a0 The first authority to compare
1388   @param a1 The second authority to compare 1388   @param a1 The second authority to compare
1389   @return `true` if `a0 != a1`, otherwise `false` 1389   @return `true` if `a0 != a1`, otherwise `false`
1390   */ 1390   */
1391   friend 1391   friend
1392   bool 1392   bool
1393   operator!=( 1393   operator!=(
1394   authority_view const& a0, 1394   authority_view const& a0,
1395   authority_view const& a1) noexcept 1395   authority_view const& a1) noexcept
1396   { 1396   {
1397   return ! (a0 == a1); 1397   return ! (a0 == a1);
1398   } 1398   }
1399   1399  
1400   /** Return the result of comparing two authorities. 1400   /** Return the result of comparing two authorities.
1401   The authorities are compared component 1401   The authorities are compared component
1402   by component as if they were first 1402   by component as if they were first
1403   normalized. 1403   normalized.
1404   1404  
1405   @par Complexity 1405   @par Complexity
1406   Linear in `min( a0.size(), a1.size() )` 1406   Linear in `min( a0.size(), a1.size() )`
1407   1407  
1408   @par Exception Safety 1408   @par Exception Safety
1409   Throws nothing 1409   Throws nothing
1410   1410  
1411   @param a0 The first authority to compare 1411   @param a0 The first authority to compare
1412   @param a1 The second authority to compare 1412   @param a1 The second authority to compare
1413   @return `true` if `a0 < a1`, otherwise `false` 1413   @return `true` if `a0 < a1`, otherwise `false`
1414   */ 1414   */
1415   friend 1415   friend
1416   bool 1416   bool
1417   operator<( 1417   operator<(
1418   authority_view const& a0, 1418   authority_view const& a0,
1419   authority_view const& a1) noexcept 1419   authority_view const& a1) noexcept
1420   { 1420   {
1421   return a0.compare(a1) < 0; 1421   return a0.compare(a1) < 0;
1422   } 1422   }
1423   1423  
1424   /** Return the result of comparing two authorities. 1424   /** Return the result of comparing two authorities.
1425   The authorities are compared component 1425   The authorities are compared component
1426   by component as if they were first 1426   by component as if they were first
1427   normalized. 1427   normalized.
1428   1428  
1429   @par Complexity 1429   @par Complexity
1430   Linear in `min( a0.size(), a1.size() )` 1430   Linear in `min( a0.size(), a1.size() )`
1431   1431  
1432   @par Exception Safety 1432   @par Exception Safety
1433   Throws nothing 1433   Throws nothing
1434   1434  
1435   @param a0 The first authority to compare 1435   @param a0 The first authority to compare
1436   @param a1 The second authority to compare 1436   @param a1 The second authority to compare
1437   @return `true` if `a0 <= a1`, otherwise `false` 1437   @return `true` if `a0 <= a1`, otherwise `false`
1438   */ 1438   */
1439   friend 1439   friend
1440   bool 1440   bool
1441   operator<=( 1441   operator<=(
1442   authority_view const& a0, 1442   authority_view const& a0,
1443   authority_view const& a1) noexcept 1443   authority_view const& a1) noexcept
1444   { 1444   {
1445   return a0.compare(a1) <= 0; 1445   return a0.compare(a1) <= 0;
1446   } 1446   }
1447   1447  
1448   /** Return the result of comparing two authorities. 1448   /** Return the result of comparing two authorities.
1449   The authorities are compared component 1449   The authorities are compared component
1450   by component as if they were first 1450   by component as if they were first
1451   normalized. 1451   normalized.
1452   1452  
1453   @par Complexity 1453   @par Complexity
1454   Linear in `min( a0.size(), a1.size() )` 1454   Linear in `min( a0.size(), a1.size() )`
1455   1455  
1456   @par Exception Safety 1456   @par Exception Safety
1457   Throws nothing 1457   Throws nothing
1458   1458  
1459   @param a0 The first authority to compare 1459   @param a0 The first authority to compare
1460   @param a1 The second authority to compare 1460   @param a1 The second authority to compare
1461   @return `true` if `a0 > a1`, otherwise `false` 1461   @return `true` if `a0 > a1`, otherwise `false`
1462   */ 1462   */
1463   friend 1463   friend
1464   bool 1464   bool
1465   operator>( 1465   operator>(
1466   authority_view const& a0, 1466   authority_view const& a0,
1467   authority_view const& a1) noexcept 1467   authority_view const& a1) noexcept
1468   { 1468   {
1469   return a0.compare(a1) > 0; 1469   return a0.compare(a1) > 0;
1470   } 1470   }
1471   1471  
1472   /** Return the result of comparing two authorities. 1472   /** Return the result of comparing two authorities.
1473   The authorities are compared component 1473   The authorities are compared component
1474   by component as if they were first 1474   by component as if they were first
1475   normalized. 1475   normalized.
1476   1476  
1477   @par Complexity 1477   @par Complexity
1478   Linear in `min( a0.size(), a1.size() )` 1478   Linear in `min( a0.size(), a1.size() )`
1479   1479  
1480   @par Exception Safety 1480   @par Exception Safety
1481   Throws nothing 1481   Throws nothing
1482   1482  
1483   @param a0 The first authority to compare 1483   @param a0 The first authority to compare
1484   @param a1 The second authority to compare 1484   @param a1 The second authority to compare
1485   @return `true` if `a0 >= a1`, otherwise `false` 1485   @return `true` if `a0 >= a1`, otherwise `false`
1486   */ 1486   */
1487   friend 1487   friend
1488   bool 1488   bool
1489   operator>=( 1489   operator>=(
1490   authority_view const& a0, 1490   authority_view const& a0,
1491   authority_view const& a1) noexcept 1491   authority_view const& a1) noexcept
1492   { 1492   {
1493   return a0.compare(a1) >= 0; 1493   return a0.compare(a1) >= 0;
1494   } 1494   }
1495   1495  
1496   //-------------------------------------------- 1496   //--------------------------------------------
1497   1497  
1498   /** Format the encoded authority to the output stream 1498   /** Format the encoded authority to the output stream
1499   1499  
1500   This hidden friend function serializes the encoded URL 1500   This hidden friend function serializes the encoded URL
1501   to the output stream. 1501   to the output stream.
1502   1502  
1503   @par Example 1503   @par Example
1504   @code 1504   @code
1505   authority_view a( "www.example.com" ); 1505   authority_view a( "www.example.com" );
1506   1506  
1507   std::cout << a << std::endl; 1507   std::cout << a << std::endl;
1508   @endcode 1508   @endcode
1509   1509  
1510   @return A reference to the output stream, for chaining 1510   @return A reference to the output stream, for chaining
1511   1511  
1512   @param os The output stream to write to 1512   @param os The output stream to write to
1513   1513  
1514   @param a The URL to write 1514   @param a The URL to write
1515   */ 1515   */
1516   friend 1516   friend
1517   std::ostream& 1517   std::ostream&
HITCBC 1518   6 operator<<( 1518   6 operator<<(
1519   std::ostream& os, 1519   std::ostream& os,
1520   authority_view const& a) 1520   authority_view const& a)
1521   { 1521   {
HITCBC 1522   6 return os << a.buffer(); 1522   6 return os << a.buffer();
1523   } 1523   }
1524   }; 1524   };
1525   1525  
1526   /** Format the encoded authority to the output stream 1526   /** Format the encoded authority to the output stream
1527   1527  
1528   This function serializes the encoded URL 1528   This function serializes the encoded URL
1529   to the output stream. 1529   to the output stream.
1530   1530  
1531   @par Example 1531   @par Example
1532   @code 1532   @code
1533   authority_view a( "www.example.com" ); 1533   authority_view a( "www.example.com" );
1534   1534  
1535   std::cout << a << std::endl; 1535   std::cout << a << std::endl;
1536   @endcode 1536   @endcode
1537   1537  
1538   @return A reference to the output stream, for chaining 1538   @return A reference to the output stream, for chaining
1539   1539  
1540   @param os The output stream to write to 1540   @param os The output stream to write to
1541   1541  
1542   @param a The URL to write 1542   @param a The URL to write
1543   */ 1543   */
1544   std::ostream& 1544   std::ostream&
1545   operator<<( 1545   operator<<(
1546   std::ostream& os, 1546   std::ostream& os,
1547   authority_view const& a); 1547   authority_view const& a);
1548   1548  
1549   //------------------------------------------------ 1549   //------------------------------------------------
1550   1550  
1551   /** Parse an authority 1551   /** Parse an authority
1552   1552  
1553   This function parses a string according to 1553   This function parses a string according to
1554   the authority grammar below, and returns an 1554   the authority grammar below, and returns an
1555   @ref authority_view referencing the string. 1555   @ref authority_view referencing the string.
1556   Ownership of the string is not transferred; 1556   Ownership of the string is not transferred;
1557   the caller is responsible for ensuring that 1557   the caller is responsible for ensuring that
1558   the lifetime of the string extends until the 1558   the lifetime of the string extends until the
1559   view is no longer being accessed. 1559   view is no longer being accessed.
1560   1560  
1561   @par BNF 1561   @par BNF
1562   @code 1562   @code
1563   authority = [ userinfo "@" ] host [ ":" port ] 1563   authority = [ userinfo "@" ] host [ ":" port ]
1564   1564  
1565   userinfo = user [ ":" [ password ] ] 1565   userinfo = user [ ":" [ password ] ]
1566   1566  
1567   user = *( unreserved / pct-encoded / sub-delims ) 1567   user = *( unreserved / pct-encoded / sub-delims )
1568   password = *( unreserved / pct-encoded / sub-delims / ":" ) 1568   password = *( unreserved / pct-encoded / sub-delims / ":" )
1569   1569  
1570   host = IP-literal / IPv4address / reg-name 1570   host = IP-literal / IPv4address / reg-name
1571   1571  
1572   port = *DIGIT 1572   port = *DIGIT
1573   @endcode 1573   @endcode
1574   1574  
1575   @par Exception Safety 1575   @par Exception Safety
1576   Throws nothing. 1576   Throws nothing.
1577   1577  
1578   @return A view to the parsed authority 1578   @return A view to the parsed authority
1579   1579  
1580   @param s The string to parse 1580   @param s The string to parse
1581   1581  
1582   @par Specification 1582   @par Specification
1583   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2" 1583   @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
1584   >3.2. Authority (rfc3986)</a> 1584   >3.2. Authority (rfc3986)</a>
1585   1585  
1586   @see 1586   @see
1587   @ref authority_view. 1587   @ref authority_view.
1588   */ 1588   */
1589   BOOST_URL_CXX20_CONSTEXPR 1589   BOOST_URL_CXX20_CONSTEXPR
1590   system::result<authority_view> 1590   system::result<authority_view>
1591   parse_authority( 1591   parse_authority(
1592   core::string_view s) noexcept; 1592   core::string_view s) noexcept;
1593   1593  
1594   } // urls 1594   } // urls
1595   } // boost 1595   } // boost
1596   1596  
1597   // When rfc/authority_rule.hpp is being processed, 1597   // When rfc/authority_rule.hpp is being processed,
1598   // it will include impl/authority_view.hpp itself 1598   // it will include impl/authority_view.hpp itself
1599   // after declaring authority_rule. 1599   // after declaring authority_rule.
1600   #if !defined(BOOST_URL_RFC_AUTHORITY_RULE_HPP) 1600   #if !defined(BOOST_URL_RFC_AUTHORITY_RULE_HPP)
1601   #include <boost/url/impl/authority_view.hpp> 1601   #include <boost/url/impl/authority_view.hpp>
1602   #endif 1602   #endif
1603   1603  
1604   #endif 1604   #endif