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  
//
4  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// 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)
6  
//
7  
//
7  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
8  
//
9  
//
9  

10  

10  
#ifndef BOOST_URL_AUTHORITY_VIEW_HPP
11  
#ifndef BOOST_URL_AUTHORITY_VIEW_HPP
11  
#define BOOST_URL_AUTHORITY_VIEW_HPP
12  
#define BOOST_URL_AUTHORITY_VIEW_HPP
12  

13  

13  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/host_type.hpp>
15  
#include <boost/url/host_type.hpp>
15  
#include <boost/url/ipv4_address.hpp>
16  
#include <boost/url/ipv4_address.hpp>
16  
#include <boost/url/ipv6_address.hpp>
17  
#include <boost/url/ipv6_address.hpp>
17  
#include <boost/url/pct_string_view.hpp>
18  
#include <boost/url/pct_string_view.hpp>
18  
#include <boost/url/detail/except.hpp>
19  
#include <boost/url/detail/except.hpp>
19  
#include <boost/url/detail/url_impl.hpp>
20  
#include <boost/url/detail/url_impl.hpp>
20  
#include <boost/assert.hpp>
21  
#include <boost/assert.hpp>
21  
#include <cstddef>
22  
#include <cstddef>
22  
#include <iosfwd>
23  
#include <iosfwd>
23  
#include <utility>
24  
#include <utility>
24  

25  

25  
namespace boost {
26  
namespace boost {
26  
namespace urls {
27  
namespace urls {
27  

28  

28  
/** A non-owning reference to a valid authority
29  
/** A non-owning reference to a valid authority
29  

30  

30  
    Objects of this type represent valid authority
31  
    Objects of this type represent valid authority
31  
    strings constructed from a parsed, external
32  
    strings constructed from a parsed, external
32  
    character buffer whose storage is managed
33  
    character buffer whose storage is managed
33  
    by the caller. That is, it acts like a
34  
    by the caller. That is, it acts like a
34  
    `core::string_view` in terms of ownership.
35  
    `core::string_view` in terms of ownership.
35  
    The caller is responsible for ensuring
36  
    The caller is responsible for ensuring
36  
    that the lifetime of the underlying
37  
    that the lifetime of the underlying
37  
    character buffer extends until it is no
38  
    character buffer extends until it is no
38  
    longer referenced.
39  
    longer referenced.
39  

40  

40  
    @par Example 1
41  
    @par Example 1
41  
    Construction from a string parses the input
42  
    Construction from a string parses the input
42  
    as an <em>authority</em> and throws an
43  
    as an <em>authority</em> and throws an
43  
    exception on error. Upon success, the
44  
    exception on error. Upon success, the
44  
    constructed object points to the passed
45  
    constructed object points to the passed
45  
    character buffer; ownership is not
46  
    character buffer; ownership is not
46  
    transferred.
47  
    transferred.
47  
    @code
48  
    @code
48  
    authority_view a( "user:pass@www.example.com:8080" );
49  
    authority_view a( "user:pass@www.example.com:8080" );
49  
    @endcode
50  
    @endcode
50  

51  

51  
    @par Example 2
52  
    @par Example 2
52  
    The parsing function @ref parse_authority returns
53  
    The parsing function @ref parse_authority returns
53  
    a `boost::system::result` containing either a valid
54  
    a `boost::system::result` containing either a valid
54  
    @ref authority_view upon success, otherwise it
55  
    @ref authority_view upon success, otherwise it
55  
    contains an error. The error can be converted to
56  
    contains an error. The error can be converted to
56  
    an exception by the caller if desired:
57  
    an exception by the caller if desired:
57  
    @code
58  
    @code
58  
    system::result< authority_view > rv = parse_authority( "user:pass@www.example.com:8080" );
59  
    system::result< authority_view > rv = parse_authority( "user:pass@www.example.com:8080" );
59  
    @endcode
60  
    @endcode
60  

61  

61  
    @par BNF
62  
    @par BNF
62  
    @code
63  
    @code
63  
    authority     = [ userinfo "@" ] host [ ":" port ]
64  
    authority     = [ userinfo "@" ] host [ ":" port ]
64  

65  

65  
    userinfo      = user [ ":" [ password ] ]
66  
    userinfo      = user [ ":" [ password ] ]
66  

67  

67  
    user          = *( unreserved / pct-encoded / sub-delims )
68  
    user          = *( unreserved / pct-encoded / sub-delims )
68  
    password      = *( unreserved / pct-encoded / sub-delims / ":" )
69  
    password      = *( unreserved / pct-encoded / sub-delims / ":" )
69  

70  

70  
    host          = IP-literal / IPv4address / reg-name
71  
    host          = IP-literal / IPv4address / reg-name
71  

72  

72  
    port          = *DIGIT
73  
    port          = *DIGIT
73  
    @endcode
74  
    @endcode
74  

75  

75  
    @par Specification
76  
    @par Specification
76  
    @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
77  
    @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
77  
        >3.2. Authority (rfc3986)</a>
78  
        >3.2. Authority (rfc3986)</a>
78  

79  

79  
    @see
80  
    @see
80  
        @ref parse_authority.
81  
        @ref parse_authority.
81  
*/
82  
*/
82 -
class BOOST_URL_DECL
83 +
class BOOST_SYMBOL_VISIBLE
83  
    authority_view
84  
    authority_view
84  
    : private detail::parts_base
85  
    : private detail::parts_base
85  
{
86  
{
86  
    detail::url_impl u_;
87  
    detail::url_impl u_;
87  

88  

88  
    friend struct detail::url_impl;
89  
    friend struct detail::url_impl;
89  

90  

 
91 +
    BOOST_URL_CXX14_CONSTEXPR
90  
    explicit
92  
    explicit
91  
    authority_view(
93  
    authority_view(
92 -
        detail::url_impl const& u) noexcept;
94 +
        detail::url_impl const& u) noexcept
 
95 +
        : u_(u)
 
96 +
    {
 
97 +
    }
93  

98  

94  
public:
99  
public:
95  
    //--------------------------------------------
100  
    //--------------------------------------------
96  
    //
101  
    //
97  
    // Special Members
102  
    // Special Members
98  
    //
103  
    //
99  
    //--------------------------------------------
104  
    //--------------------------------------------
100  

105  

101  
    /** Destructor
106  
    /** Destructor
102  
    */
107  
    */
 
108 +
    BOOST_URL_CXX20_CONSTEXPR
103  
    virtual
109  
    virtual
104  
    ~authority_view();
110  
    ~authority_view();
105  

111  

106  
    /** Constructor
112  
    /** Constructor
107  

113  

108  
        Default constructed authorities
114  
        Default constructed authorities
109  
        refer to a string with zero length,
115  
        refer to a string with zero length,
110  
        which is always valid. This matches
116  
        which is always valid. This matches
111  
        the grammar for a zero-length host.
117  
        the grammar for a zero-length host.
112  

118  

113  
        @par Exception Safety
119  
        @par Exception Safety
114  
        Throws nothing.
120  
        Throws nothing.
115  

121  

116  
        @par Specification
122  
        @par Specification
117  
    */
123  
    */
118 -
    authority_view() noexcept;
124 +
    BOOST_URL_CXX14_CONSTEXPR
 
125 +
    authority_view() noexcept
 
126 +
        : u_(from::authority)
 
127 +
    {
 
128 +
    }
119  

129  

120  
    /** Construct from a string.
130  
    /** Construct from a string.
121  

131  

122  
        This function attempts to construct
132  
        This function attempts to construct
123  
        an authority from the string `s`,
133  
        an authority from the string `s`,
124  
        which must be a valid authority or
134  
        which must be a valid authority or
125  
        else an exception is thrown. Upon
135  
        else an exception is thrown. Upon
126  
        successful construction, the view
136  
        successful construction, the view
127  
        refers to the characters in the
137  
        refers to the characters in the
128  
        buffer pointed to by `s`.
138  
        buffer pointed to by `s`.
129  
        Ownership is not transferred; the
139  
        Ownership is not transferred; the
130  
        caller is responsible for ensuring
140  
        caller is responsible for ensuring
131  
        that the lifetime of the buffer
141  
        that the lifetime of the buffer
132  
        extends until the view is destroyed.
142  
        extends until the view is destroyed.
133  

143  

134  
        @param s The string to parse
144  
        @param s The string to parse
135  

145  

136  
        @par BNF
146  
        @par BNF
137  
        @code
147  
        @code
138  
        authority     = [ userinfo "@" ] host [ ":" port ]
148  
        authority     = [ userinfo "@" ] host [ ":" port ]
139  

149  

140  
        userinfo      = user [ ":" [ password ] ]
150  
        userinfo      = user [ ":" [ password ] ]
141  

151  

142  
        user          = *( unreserved / pct-encoded / sub-delims )
152  
        user          = *( unreserved / pct-encoded / sub-delims )
143  
        password      = *( unreserved / pct-encoded / sub-delims / ":" )
153  
        password      = *( unreserved / pct-encoded / sub-delims / ":" )
144  

154  

145  
        host          = IP-literal / IPv4address / reg-name
155  
        host          = IP-literal / IPv4address / reg-name
146  

156  

147  
        port          = *DIGIT
157  
        port          = *DIGIT
148  
        @endcode
158  
        @endcode
149  

159  

150  
        @par Specification
160  
        @par Specification
151  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
161  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
152  
            >3.2. Authority (rfc3986)</a>
162  
            >3.2. Authority (rfc3986)</a>
153  

163  

154  
        @see
164  
        @see
155  
            @ref parse_authority.
165  
            @ref parse_authority.
156  
    */
166  
    */
 
167 +
    BOOST_URL_CXX20_CONSTEXPR
157  
    explicit
168  
    explicit
158  
    authority_view(core::string_view s);
169  
    authority_view(core::string_view s);
159  

170  

160  
    /** Constructor
171  
    /** Constructor
161  
    */
172  
    */
 
173 +
    BOOST_URL_CXX14_CONSTEXPR
162  
    authority_view(
174  
    authority_view(
163 -
        authority_view const&) noexcept;
175 +
        authority_view const&) noexcept = default;
164  

176  

165  
    /** Assignment
177  
    /** Assignment
166  

178  

167  
        This function assigns the contents of
179  
        This function assigns the contents of
168  
        `other` to this object.
180  
        `other` to this object.
169  

181  

170  
        @param other The object to assign
182  
        @param other The object to assign
171  
        @return A reference to this object
183  
        @return A reference to this object
172  

184  

173  
        @par Exception Safety
185  
        @par Exception Safety
174  
        Throws nothing.
186  
        Throws nothing.
175  
    */
187  
    */
 
188 +
    BOOST_URL_CXX20_CONSTEXPR
176  
    authority_view&
189  
    authority_view&
177  
    operator=(
190  
    operator=(
178 -
        authority_view const& other) noexcept;
191 +
        authority_view const& other) noexcept = default;
179  

192  

180  
    //--------------------------------------------
193  
    //--------------------------------------------
181  
    //
194  
    //
182  
    // Observers
195  
    // Observers
183  
    //
196  
    //
184  
    //--------------------------------------------
197  
    //--------------------------------------------
185  

198  

186  
    /** Return the number of characters in the authority
199  
    /** Return the number of characters in the authority
187  

200  

188  
        This function returns the number of
201  
        This function returns the number of
189  
        characters in the authority.
202  
        characters in the authority.
190  

203  

191  
        @return The number of characters in the authority
204  
        @return The number of characters in the authority
192  

205  

193  
        @par Example
206  
        @par Example
194  
        @code
207  
        @code
195  
        assert( authority_view( "user:pass@www.example.com:8080" ).size() == 30 );
208  
        assert( authority_view( "user:pass@www.example.com:8080" ).size() == 30 );
196  
        @endcode
209  
        @endcode
197  

210  

198  
        @par Exception Safety
211  
        @par Exception Safety
199  
        Throws nothing.
212  
        Throws nothing.
200  
    */
213  
    */
201  
    std::size_t
214  
    std::size_t
202  
    size() const noexcept
215  
    size() const noexcept
203  
    {
216  
    {
204  
        return u_.offset(id_end);
217  
        return u_.offset(id_end);
205  
    }
218  
    }
206  

219  

207  
    /** Return true if the authority is empty
220  
    /** Return true if the authority is empty
208  

221  

209  
        An empty authority has an empty host,
222  
        An empty authority has an empty host,
210  
        no userinfo, and no port.
223  
        no userinfo, and no port.
211  

224  

212  
        @return `true` if the authority is empty
225  
        @return `true` if the authority is empty
213  

226  

214  
        @par Example
227  
        @par Example
215  
        @code
228  
        @code
216  
        assert( authority_view( "" ).empty() );
229  
        assert( authority_view( "" ).empty() );
217  
        @endcode
230  
        @endcode
218  

231  

219  
        @par Exception Safety
232  
        @par Exception Safety
220  
        Throws nothing.
233  
        Throws nothing.
221  
    */
234  
    */
222  
    bool
235  
    bool
223  
    empty() const noexcept
236  
    empty() const noexcept
224  
    {
237  
    {
225  
        return size() == 0;
238  
        return size() == 0;
226  
    }
239  
    }
227  

240  

228  
    /** Return a pointer to the first character
241  
    /** Return a pointer to the first character
229  

242  

230  
        This function returns a pointer to the
243  
        This function returns a pointer to the
231  
        beginning of the view, which is not
244  
        beginning of the view, which is not
232  
        guaranteed to be null-terminated.
245  
        guaranteed to be null-terminated.
233  

246  

234  
        @return A pointer to the first character
247  
        @return A pointer to the first character
235  

248  

236  
        @par Exception Safety
249  
        @par Exception Safety
237  
        Throws nothing.
250  
        Throws nothing.
238  
    */
251  
    */
239  
    char const*
252  
    char const*
240  
    data() const noexcept
253  
    data() const noexcept
241  
    {
254  
    {
242  
        return u_.cs_;
255  
        return u_.cs_;
243  
    }
256  
    }
244  

257  

245  
    /** Return the complete authority
258  
    /** Return the complete authority
246  

259  

247  
        This function returns the authority
260  
        This function returns the authority
248  
        as a percent-encoded string.
261  
        as a percent-encoded string.
249  

262  

250  
        @return The complete authority
263  
        @return The complete authority
251  

264  

252  
        @par Example
265  
        @par Example
253  
        @code
266  
        @code
254  
        assert( parse_authority( "www.example.com" ).value().buffer() == "www.example.com" );
267  
        assert( parse_authority( "www.example.com" ).value().buffer() == "www.example.com" );
255  
        @endcode
268  
        @endcode
256  

269  

257  
        @par BNF
270  
        @par BNF
258  
        @code
271  
        @code
259  
        authority   = [ userinfo "@" ] host [ ":" port ]
272  
        authority   = [ userinfo "@" ] host [ ":" port ]
260  
        @endcode
273  
        @endcode
261  

274  

262  
        @par Exception Safety
275  
        @par Exception Safety
263  
        Throws nothing.
276  
        Throws nothing.
264  

277  

265  
        @par Specification
278  
        @par Specification
266  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
279  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
267  
            >3.2. Authority (rfc3986)</a>
280  
            >3.2. Authority (rfc3986)</a>
268  
    */
281  
    */
269  
    core::string_view
282  
    core::string_view
270  
    buffer() const noexcept
283  
    buffer() const noexcept
271  
    {
284  
    {
272  
        return core::string_view(data(), size());
285  
        return core::string_view(data(), size());
273  
    }
286  
    }
274  

287  

275  
    //--------------------------------------------
288  
    //--------------------------------------------
276  
    //
289  
    //
277  
    // Userinfo
290  
    // Userinfo
278  
    //
291  
    //
279  
    //--------------------------------------------
292  
    //--------------------------------------------
280  

293  

281  
    /** Return true if a userinfo is present
294  
    /** Return true if a userinfo is present
282  

295  

283  
        This function returns true if this
296  
        This function returns true if this
284  
        contains a userinfo.
297  
        contains a userinfo.
285  

298  

286  
        @return `true` if a userinfo is present
299  
        @return `true` if a userinfo is present
287  

300  

288  
        @par Example
301  
        @par Example
289  
        @code
302  
        @code
290  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() );
303  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_userinfo() );
291  
        @endcode
304  
        @endcode
292  

305  

293  
        @par Complexity
306  
        @par Complexity
294  
        Constant.
307  
        Constant.
295  

308  

296  
        @par Exception Safety
309  
        @par Exception Safety
297  
        Throws nothing.
310  
        Throws nothing.
298  

311  

299  
        @par BNF
312  
        @par BNF
300  
        @code
313  
        @code
301  
        userinfo    = user [ ":" [ password ] ]
314  
        userinfo    = user [ ":" [ password ] ]
302  

315  

303  
        authority   = [ userinfo "@" ] host [ ":" port ]
316  
        authority   = [ userinfo "@" ] host [ ":" port ]
304  
        @endcode
317  
        @endcode
305  

318  

306  
        @par Specification
319  
        @par Specification
307  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
320  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
308  
            >3.2.1. User Information (rfc3986)</a>
321  
            >3.2.1. User Information (rfc3986)</a>
309  

322  

310  
        @see
323  
        @see
311  
            @ref has_password,
324  
            @ref has_password,
312  
            @ref encoded_password,
325  
            @ref encoded_password,
313  
            @ref encoded_user,
326  
            @ref encoded_user,
314  
            @ref encoded_userinfo,
327  
            @ref encoded_userinfo,
315  
            @ref password,
328  
            @ref password,
316  
            @ref user,
329  
            @ref user,
317  
            @ref userinfo.
330  
            @ref userinfo.
318  

331  

319  
    */
332  
    */
 
333 +
    BOOST_URL_CXX20_CONSTEXPR
320  
    bool
334  
    bool
321  
    has_userinfo() const noexcept;
335  
    has_userinfo() const noexcept;
322  

336  

323  
    /** Return the userinfo
337  
    /** Return the userinfo
324  

338  

325  
        If present, this function returns a
339  
        If present, this function returns a
326  
        string representing the userinfo (which
340  
        string representing the userinfo (which
327  
        may be empty).
341  
        may be empty).
328  
        Otherwise it returns an empty string.
342  
        Otherwise it returns an empty string.
329  
        Any percent-escapes in the string are
343  
        Any percent-escapes in the string are
330  
        decoded first.
344  
        decoded first.
331  

345  

332  
        @param token A string token to receive the result.
346  
        @param token A string token to receive the result.
333  
        @return The userinfo
347  
        @return The userinfo
334  

348  

335  
        @par Example
349  
        @par Example
336  
        @code
350  
        @code
337  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" );
351  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).userinfo() == "jane-doe:pass" );
338  
        @endcode
352  
        @endcode
339  

353  

340  
        @par Complexity
354  
        @par Complexity
341  
        Linear in `this->userinfo().size()`.
355  
        Linear in `this->userinfo().size()`.
342  

356  

343  
        @par Exception Safety
357  
        @par Exception Safety
344  
        Calls to allocate may throw.
358  
        Calls to allocate may throw.
345  

359  

346  
        @par BNF
360  
        @par BNF
347  
        @code
361  
        @code
348  
        userinfo    = user [ ":" [ password ] ]
362  
        userinfo    = user [ ":" [ password ] ]
349  

363  

350  
        authority   = [ userinfo "@" ] host [ ":" port ]
364  
        authority   = [ userinfo "@" ] host [ ":" port ]
351  
        @endcode
365  
        @endcode
352  

366  

353  
        @par Specification
367  
        @par Specification
354  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
368  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
355  
            >3.2.1. User Information (rfc3986)</a>
369  
            >3.2.1. User Information (rfc3986)</a>
356  

370  

357  
        @see
371  
        @see
358  
            @ref has_password,
372  
            @ref has_password,
359  
            @ref has_userinfo,
373  
            @ref has_userinfo,
360  
            @ref encoded_password,
374  
            @ref encoded_password,
361  
            @ref encoded_user,
375  
            @ref encoded_user,
362  
            @ref encoded_userinfo,
376  
            @ref encoded_userinfo,
363  
            @ref password,
377  
            @ref password,
364  
            @ref user.
378  
            @ref user.
365  
    */
379  
    */
366  
    template<BOOST_URL_STRTOK_TPARAM>
380  
    template<BOOST_URL_STRTOK_TPARAM>
367  
    BOOST_URL_STRTOK_RETURN
381  
    BOOST_URL_STRTOK_RETURN
368  
    userinfo(
382  
    userinfo(
369  
        BOOST_URL_STRTOK_ARG(token)) const
383  
        BOOST_URL_STRTOK_ARG(token)) const
370  
    {
384  
    {
371  
        encoding_opts opt;
385  
        encoding_opts opt;
372  
        opt.space_as_plus = false;
386  
        opt.space_as_plus = false;
373  
        return encoded_userinfo().decode(
387  
        return encoded_userinfo().decode(
374  
            opt, std::move(token));
388  
            opt, std::move(token));
375  
    }
389  
    }
376  

390  

377  
    /** Return the userinfo
391  
    /** Return the userinfo
378  

392  

379  
        If present, this function returns a
393  
        If present, this function returns a
380  
        string representing the userinfo (which
394  
        string representing the userinfo (which
381  
        may be empty).
395  
        may be empty).
382  
        Otherwise it returns an empty string.
396  
        Otherwise it returns an empty string.
383  
        The returned string may contain
397  
        The returned string may contain
384  
        percent escapes.
398  
        percent escapes.
385  

399  

386  
        @return The userinfo
400  
        @return The userinfo
387  

401  

388  
        @par Example
402  
        @par Example
389  
        @code
403  
        @code
390  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" );
404  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_userinfo() == "jane%2Ddoe:pass" );
391  
        @endcode
405  
        @endcode
392  

406  

393  
        @par Complexity
407  
        @par Complexity
394  
        Constant.
408  
        Constant.
395  

409  

396  
        @par Exception Safety
410  
        @par Exception Safety
397  
        Throws nothing
411  
        Throws nothing
398  

412  

399  
        @par BNF
413  
        @par BNF
400  
        @code
414  
        @code
401  
        userinfo    = user [ ":" [ password ] ]
415  
        userinfo    = user [ ":" [ password ] ]
402  

416  

403  
        authority   = [ userinfo "@" ] host [ ":" port ]
417  
        authority   = [ userinfo "@" ] host [ ":" port ]
404  
        @endcode
418  
        @endcode
405  

419  

406  
        @par Specification
420  
        @par Specification
407  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
421  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
408  
            >3.2.1. User Information (rfc3986)</a>
422  
            >3.2.1. User Information (rfc3986)</a>
409  

423  

410  
        @see
424  
        @see
411  
            @ref has_password,
425  
            @ref has_password,
412  
            @ref has_userinfo,
426  
            @ref has_userinfo,
413  
            @ref encoded_password,
427  
            @ref encoded_password,
414  
            @ref encoded_user,
428  
            @ref encoded_user,
415  
            @ref password,
429  
            @ref password,
416  
            @ref user,
430  
            @ref user,
417  
            @ref userinfo.
431  
            @ref userinfo.
418  
    */
432  
    */
 
433 +
    BOOST_URL_CXX20_CONSTEXPR
419  
    pct_string_view
434  
    pct_string_view
420  
    encoded_userinfo() const noexcept;
435  
    encoded_userinfo() const noexcept;
421  

436  

422  
    //--------------------------------------------
437  
    //--------------------------------------------
423  

438  

424  
    /** Return the user
439  
    /** Return the user
425  

440  

426  
        If present, this function returns a
441  
        If present, this function returns a
427  
        string representing the user (which
442  
        string representing the user (which
428  
        may be empty).
443  
        may be empty).
429  
        Otherwise it returns an empty string.
444  
        Otherwise it returns an empty string.
430  
        Any percent-escapes in the string are
445  
        Any percent-escapes in the string are
431  
        decoded first.
446  
        decoded first.
432  

447  

433  
        @param token A string token to receive the result.
448  
        @param token A string token to receive the result.
434  
        @return The user
449  
        @return The user
435  

450  

436  
        @par Example
451  
        @par Example
437  
        @code
452  
        @code
438  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" );
453  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).user() == "jane-doe" );
439  
        @endcode
454  
        @endcode
440  

455  

441  
        @par Complexity
456  
        @par Complexity
442  
        Linear in `this->user().size()`.
457  
        Linear in `this->user().size()`.
443  

458  

444  
        @par Exception Safety
459  
        @par Exception Safety
445  
        Calls to allocate may throw.
460  
        Calls to allocate may throw.
446  

461  

447  
        @par BNF
462  
        @par BNF
448  
        @code
463  
        @code
449  
        userinfo    = user [ ":" [ password ] ]
464  
        userinfo    = user [ ":" [ password ] ]
450  

465  

451  
        user        = *( unreserved / pct-encoded / sub-delims )
466  
        user        = *( unreserved / pct-encoded / sub-delims )
452  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
467  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
453  
        @endcode
468  
        @endcode
454  

469  

455  
        @par Specification
470  
        @par Specification
456  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
471  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
457  
            >3.2.1. User Information (rfc3986)</a>
472  
            >3.2.1. User Information (rfc3986)</a>
458  

473  

459  
        @see
474  
        @see
460  
            @ref has_password,
475  
            @ref has_password,
461  
            @ref has_userinfo,
476  
            @ref has_userinfo,
462  
            @ref encoded_password,
477  
            @ref encoded_password,
463  
            @ref encoded_user,
478  
            @ref encoded_user,
464  
            @ref encoded_userinfo,
479  
            @ref encoded_userinfo,
465  
            @ref password,
480  
            @ref password,
466  
            @ref userinfo.
481  
            @ref userinfo.
467  
    */
482  
    */
468  
    template<BOOST_URL_STRTOK_TPARAM>
483  
    template<BOOST_URL_STRTOK_TPARAM>
469  
    BOOST_URL_STRTOK_RETURN
484  
    BOOST_URL_STRTOK_RETURN
470  
    user(
485  
    user(
471  
        BOOST_URL_STRTOK_ARG(token)) const
486  
        BOOST_URL_STRTOK_ARG(token)) const
472  
    {
487  
    {
473  
        encoding_opts opt;
488  
        encoding_opts opt;
474  
        opt.space_as_plus = false;
489  
        opt.space_as_plus = false;
475  
        return encoded_user().decode(
490  
        return encoded_user().decode(
476  
            opt, std::move(token));
491  
            opt, std::move(token));
477  
    }
492  
    }
478  

493  

479  
    /** Return the user
494  
    /** Return the user
480  

495  

481  
        If present, this function returns a
496  
        If present, this function returns a
482  
        string representing the user (which
497  
        string representing the user (which
483  
        may be empty).
498  
        may be empty).
484  
        Otherwise it returns an empty string.
499  
        Otherwise it returns an empty string.
485  
        The returned string may contain
500  
        The returned string may contain
486  
        percent escapes.
501  
        percent escapes.
487  

502  

488  
        @return The user
503  
        @return The user
489  

504  

490  
        @par Example
505  
        @par Example
491  
        @code
506  
        @code
492  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" );
507  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_user() == "jane%2Ddoe" );
493  
        @endcode
508  
        @endcode
494  

509  

495  
        @par Complexity
510  
        @par Complexity
496  
        Constant.
511  
        Constant.
497  

512  

498  
        @par Exception Safety
513  
        @par Exception Safety
499  
        Throws nothing.
514  
        Throws nothing.
500  

515  

501  
        @par BNF
516  
        @par BNF
502  
        @code
517  
        @code
503  
        userinfo    = user [ ":" [ password ] ]
518  
        userinfo    = user [ ":" [ password ] ]
504  

519  

505  
        user        = *( unreserved / pct-encoded / sub-delims )
520  
        user        = *( unreserved / pct-encoded / sub-delims )
506  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
521  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
507  
        @endcode
522  
        @endcode
508  

523  

509  
        @par Specification
524  
        @par Specification
510  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
525  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
511  
            >3.2.1. User Information (rfc3986)</a>
526  
            >3.2.1. User Information (rfc3986)</a>
512  

527  

513  
        @see
528  
        @see
514  
            @ref has_password,
529  
            @ref has_password,
515  
            @ref has_userinfo,
530  
            @ref has_userinfo,
516  
            @ref encoded_password,
531  
            @ref encoded_password,
517  
            @ref encoded_userinfo,
532  
            @ref encoded_userinfo,
518  
            @ref password,
533  
            @ref password,
519  
            @ref user,
534  
            @ref user,
520  
            @ref userinfo.
535  
            @ref userinfo.
521  
    */
536  
    */
 
537 +
    BOOST_URL_CXX20_CONSTEXPR
522  
    pct_string_view
538  
    pct_string_view
523  
    encoded_user() const noexcept;
539  
    encoded_user() const noexcept;
524  

540  

525  
    /** Return true if a password is present
541  
    /** Return true if a password is present
526  

542  

527  
        This function returns true if the
543  
        This function returns true if the
528  
        userinfo is present and contains
544  
        userinfo is present and contains
529  
        a password.
545  
        a password.
530  

546  

531  
        @return `true` if a password is present
547  
        @return `true` if a password is present
532  

548  

533  
        @par Example
549  
        @par Example
534  
        @code
550  
        @code
535  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() );
551  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).has_password() );
536  
        @endcode
552  
        @endcode
537  

553  

538  
        @par Complexity
554  
        @par Complexity
539  
        Constant.
555  
        Constant.
540  

556  

541  
        @par Exception Safety
557  
        @par Exception Safety
542  
        Throws nothing.
558  
        Throws nothing.
543  

559  

544  
        @par BNF
560  
        @par BNF
545  
        @code
561  
        @code
546  
        userinfo    = user [ ":" [ password ] ]
562  
        userinfo    = user [ ":" [ password ] ]
547  

563  

548  
        user        = *( unreserved / pct-encoded / sub-delims )
564  
        user        = *( unreserved / pct-encoded / sub-delims )
549  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
565  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
550  
        @endcode
566  
        @endcode
551  

567  

552  
        @par Specification
568  
        @par Specification
553  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
569  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
554  
            >3.2.1. User Information (rfc3986)</a>
570  
            >3.2.1. User Information (rfc3986)</a>
555  

571  

556  
        @see
572  
        @see
557  
            @ref has_userinfo,
573  
            @ref has_userinfo,
558  
            @ref encoded_password,
574  
            @ref encoded_password,
559  
            @ref encoded_user,
575  
            @ref encoded_user,
560  
            @ref encoded_userinfo,
576  
            @ref encoded_userinfo,
561  
            @ref password,
577  
            @ref password,
562  
            @ref user,
578  
            @ref user,
563  
            @ref userinfo.
579  
            @ref userinfo.
564  
    */
580  
    */
 
581 +
    BOOST_URL_CXX20_CONSTEXPR
565  
    bool
582  
    bool
566  
    has_password() const noexcept;
583  
    has_password() const noexcept;
567  

584  

568  
    /** Return the password
585  
    /** Return the password
569  

586  

570  
        If present, this function returns a
587  
        If present, this function returns a
571  
        string representing the password (which
588  
        string representing the password (which
572  
        may be an empty string).
589  
        may be an empty string).
573  
        Otherwise it returns an empty string.
590  
        Otherwise it returns an empty string.
574  
        Any percent-escapes in the string are
591  
        Any percent-escapes in the string are
575  
        decoded first.
592  
        decoded first.
576  

593  

577  
        @param token A string token to receive the result.
594  
        @param token A string token to receive the result.
578  
        @return The password
595  
        @return The password
579  

596  

580  
        @par Example
597  
        @par Example
581  
        @code
598  
        @code
582  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" );
599  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).password() == "pass" );
583  
        @endcode
600  
        @endcode
584  

601  

585  
        @par Complexity
602  
        @par Complexity
586  
        Linear in `this->password().size()`.
603  
        Linear in `this->password().size()`.
587  

604  

588  
        @par Exception Safety
605  
        @par Exception Safety
589  
        Calls to allocate may throw.
606  
        Calls to allocate may throw.
590  

607  

591  
        @par BNF
608  
        @par BNF
592  
        @code
609  
        @code
593  
        userinfo    = user [ ":" [ password ] ]
610  
        userinfo    = user [ ":" [ password ] ]
594  

611  

595  
        user        = *( unreserved / pct-encoded / sub-delims )
612  
        user        = *( unreserved / pct-encoded / sub-delims )
596  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
613  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
597  
        @endcode
614  
        @endcode
598  

615  

599  
        @par Specification
616  
        @par Specification
600  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
617  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
601  
            >3.2.1. User Information (rfc3986)</a>
618  
            >3.2.1. User Information (rfc3986)</a>
602  

619  

603  
        @see
620  
        @see
604  
            @ref has_password,
621  
            @ref has_password,
605  
            @ref has_userinfo,
622  
            @ref has_userinfo,
606  
            @ref encoded_password,
623  
            @ref encoded_password,
607  
            @ref encoded_user,
624  
            @ref encoded_user,
608  
            @ref encoded_userinfo,
625  
            @ref encoded_userinfo,
609  
            @ref user,
626  
            @ref user,
610  
            @ref userinfo.
627  
            @ref userinfo.
611  
    */
628  
    */
612  
    template<BOOST_URL_STRTOK_TPARAM>
629  
    template<BOOST_URL_STRTOK_TPARAM>
613  
    BOOST_URL_STRTOK_RETURN
630  
    BOOST_URL_STRTOK_RETURN
614  
    password(
631  
    password(
615  
        BOOST_URL_STRTOK_ARG(token)) const
632  
        BOOST_URL_STRTOK_ARG(token)) const
616  
    {
633  
    {
617  
        encoding_opts opt;
634  
        encoding_opts opt;
618  
        opt.space_as_plus = false;
635  
        opt.space_as_plus = false;
619  
        return encoded_password().decode(
636  
        return encoded_password().decode(
620  
            opt, std::move(token));
637  
            opt, std::move(token));
621  
    }
638  
    }
622  

639  

623  
    /** Return the password
640  
    /** Return the password
624  

641  

625  
        This function returns the password portion
642  
        This function returns the password portion
626  
        of the userinfo as a percent-encoded string.
643  
        of the userinfo as a percent-encoded string.
627  

644  

628  
        @return The password
645  
        @return The password
629  

646  

630  
        @par Example
647  
        @par Example
631  
        @code
648  
        @code
632  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" );
649  
        assert( url_view( "http://jane%2Ddoe:pass@example.com" ).encoded_password() == "pass" );
633  
        @endcode
650  
        @endcode
634  

651  

635  
        @par Complexity
652  
        @par Complexity
636  
        Constant.
653  
        Constant.
637  

654  

638  
        @par Exception Safety
655  
        @par Exception Safety
639  
        Throws nothing.
656  
        Throws nothing.
640  

657  

641  
        @par BNF
658  
        @par BNF
642  
        @code
659  
        @code
643  
        userinfo    = user [ ":" [ password ] ]
660  
        userinfo    = user [ ":" [ password ] ]
644  

661  

645  
        user        = *( unreserved / pct-encoded / sub-delims )
662  
        user        = *( unreserved / pct-encoded / sub-delims )
646  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
663  
        password    = *( unreserved / pct-encoded / sub-delims / ":" )
647  
        @endcode
664  
        @endcode
648  

665  

649  
        @par Specification
666  
        @par Specification
650  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
667  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1"
651  
            >3.2.1. User Information (rfc3986)</a>
668  
            >3.2.1. User Information (rfc3986)</a>
652  

669  

653  
        @see
670  
        @see
654  
            @ref has_password,
671  
            @ref has_password,
655  
            @ref has_userinfo,
672  
            @ref has_userinfo,
656  
            @ref encoded_user,
673  
            @ref encoded_user,
657  
            @ref encoded_userinfo,
674  
            @ref encoded_userinfo,
658  
            @ref password,
675  
            @ref password,
659  
            @ref user,
676  
            @ref user,
660  
            @ref userinfo.
677  
            @ref userinfo.
661  
    */
678  
    */
 
679 +
    BOOST_URL_CXX20_CONSTEXPR
662  
    pct_string_view
680  
    pct_string_view
663  
    encoded_password() const noexcept;
681  
    encoded_password() const noexcept;
664  

682  

665  
    //--------------------------------------------
683  
    //--------------------------------------------
666  
    //
684  
    //
667  
    // Host
685  
    // Host
668  
    //
686  
    //
669  
    //--------------------------------------------
687  
    //--------------------------------------------
670  

688  

671  
    /** Return the host type
689  
    /** Return the host type
672  

690  

673  
        This function returns one of the
691  
        This function returns one of the
674  
        following constants representing the
692  
        following constants representing the
675  
        type of host present.
693  
        type of host present.
676  

694  

677  
        @li @ref host_type::ipv4
695  
        @li @ref host_type::ipv4
678  
        @li @ref host_type::ipv6
696  
        @li @ref host_type::ipv6
679  
        @li @ref host_type::ipvfuture
697  
        @li @ref host_type::ipvfuture
680  
        @li @ref host_type::name
698  
        @li @ref host_type::name
681  

699  

682  
        @return The host type
700  
        @return The host type
683  

701  

684  
        @par Example
702  
        @par Example
685  
        @code
703  
        @code
686  
        assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 );
704  
        assert( url_view( "https://192.168.0.1/local.htm" ).host_type() == host_type::ipv4 );
687  
        @endcode
705  
        @endcode
688  

706  

689  
        @par Complexity
707  
        @par Complexity
690  
        Constant.
708  
        Constant.
691  

709  

692  
        @par Exception Safety
710  
        @par Exception Safety
693  
        Throws nothing.
711  
        Throws nothing.
694  

712  

695  
        @par Specification
713  
        @par Specification
696  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
714  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
697  
            >3.2.2. Host (rfc3986)</a>
715  
            >3.2.2. Host (rfc3986)</a>
698  
    */
716  
    */
699  
    urls::host_type
717  
    urls::host_type
700  
    host_type() const noexcept
718  
    host_type() const noexcept
701  
    {
719  
    {
702  
        return u_.host_type_;
720  
        return u_.host_type_;
703  
    }
721  
    }
704  

722  

705  
    /** Return the host
723  
    /** Return the host
706  

724  

707  
        This function returns the host portion
725  
        This function returns the host portion
708  
        of the authority as a string, or the
726  
        of the authority as a string, or the
709  
        empty string if there is no authority.
727  
        empty string if there is no authority.
710  
        Any percent-escapes in the string are
728  
        Any percent-escapes in the string are
711  
        decoded first.
729  
        decoded first.
712  

730  

713  
        @param token A string token to receive the result.
731  
        @param token A string token to receive the result.
714  
        @return The host
732  
        @return The host
715  

733  

716  
        @par Example
734  
        @par Example
717  
        @code
735  
        @code
718  
        assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" );
736  
        assert( url_view( "https://www%2droot.example.com/" ).host() == "www-root.example.com" );
719  
        @endcode
737  
        @endcode
720  

738  

721  
        @par Complexity
739  
        @par Complexity
722  
        Linear in `this->host().size()`.
740  
        Linear in `this->host().size()`.
723  

741  

724  
        @par Exception Safety
742  
        @par Exception Safety
725  
        Calls to allocate may throw.
743  
        Calls to allocate may throw.
726  

744  

727  
        @par BNF
745  
        @par BNF
728  
        @code
746  
        @code
729  
        host        = IP-literal / IPv4address / reg-name
747  
        host        = IP-literal / IPv4address / reg-name
730  

748  

731  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
749  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
732  

750  

733  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
751  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
734  
        @endcode
752  
        @endcode
735  

753  

736  
        @par Specification
754  
        @par Specification
737  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
755  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
738  
            >3.2.2. Host (rfc3986)</a>
756  
            >3.2.2. Host (rfc3986)</a>
739  
    */
757  
    */
740  
    template<BOOST_URL_STRTOK_TPARAM>
758  
    template<BOOST_URL_STRTOK_TPARAM>
741  
    BOOST_URL_STRTOK_RETURN
759  
    BOOST_URL_STRTOK_RETURN
742  
    host(
760  
    host(
743  
        BOOST_URL_STRTOK_ARG(token)) const
761  
        BOOST_URL_STRTOK_ARG(token)) const
744  
    {
762  
    {
745  
        encoding_opts opt;
763  
        encoding_opts opt;
746  
        opt.space_as_plus = false;
764  
        opt.space_as_plus = false;
747  
        return encoded_host().decode(
765  
        return encoded_host().decode(
748  
            opt, std::move(token));
766  
            opt, std::move(token));
749  
    }
767  
    }
750  

768  

751  
    /** Return the host
769  
    /** Return the host
752  

770  

753  
        This function returns the host portion
771  
        This function returns the host portion
754  
        of the authority as a string, or the
772  
        of the authority as a string, or the
755  
        empty string if there is no authority.
773  
        empty string if there is no authority.
756  
        The returned string may contain
774  
        The returned string may contain
757  
        percent escapes.
775  
        percent escapes.
758  

776  

759  
        @return The host
777  
        @return The host
760  

778  

761  
        @par Example
779  
        @par Example
762  
        @code
780  
        @code
763  
        assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" );
781  
        assert( url_view( "https://www%2droot.example.com/" ).encoded_host() == "www%2droot.example.com" );
764  
        @endcode
782  
        @endcode
765  

783  

766  
        @par Complexity
784  
        @par Complexity
767  
        Constant.
785  
        Constant.
768  

786  

769  
        @par Exception Safety
787  
        @par Exception Safety
770  
        Throws nothing.
788  
        Throws nothing.
771  

789  

772  
        @par BNF
790  
        @par BNF
773  
        @code
791  
        @code
774  
        host        = IP-literal / IPv4address / reg-name
792  
        host        = IP-literal / IPv4address / reg-name
775  

793  

776  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
794  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
777  

795  

778  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
796  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
779  
        @endcode
797  
        @endcode
780  

798  

781  
        @par Specification
799  
        @par Specification
782  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
800  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
783  
            >3.2.2. Host (rfc3986)</a>
801  
            >3.2.2. Host (rfc3986)</a>
784  
    */
802  
    */
 
803 +
    BOOST_URL_CXX20_CONSTEXPR
785  
    pct_string_view
804  
    pct_string_view
786  
    encoded_host() const noexcept;
805  
    encoded_host() const noexcept;
787  

806  

788  
    /** Return the host
807  
    /** Return the host
789  

808  

790  
        The value returned by this function
809  
        The value returned by this function
791  
        depends on the type of host returned
810  
        depends on the type of host returned
792  
        from the function @ref host_type.
811  
        from the function @ref host_type.
793  

812  

794  
        @li If the type is @ref host_type::ipv4,
813  
        @li If the type is @ref host_type::ipv4,
795  
        then the IPv4 address string is returned.
814  
        then the IPv4 address string is returned.
796  

815  

797  
        @li If the type is @ref host_type::ipv6,
816  
        @li If the type is @ref host_type::ipv6,
798  
        then the IPv6 address string is returned,
817  
        then the IPv6 address string is returned,
799  
        without any enclosing brackets.
818  
        without any enclosing brackets.
800  

819  

801  
        @li If the type is @ref host_type::ipvfuture,
820  
        @li If the type is @ref host_type::ipvfuture,
802  
        then the IPvFuture address string is returned,
821  
        then the IPvFuture address string is returned,
803  
        without any enclosing brackets.
822  
        without any enclosing brackets.
804  

823  

805  
        @li If the type is @ref host_type::name,
824  
        @li If the type is @ref host_type::name,
806  
        then the host name string is returned.
825  
        then the host name string is returned.
807  
        Any percent-escapes in the string are
826  
        Any percent-escapes in the string are
808  
        decoded first.
827  
        decoded first.
809  

828  

810  
        @li If the type is @ref host_type::none,
829  
        @li If the type is @ref host_type::none,
811  
        then an empty string is returned.
830  
        then an empty string is returned.
812  

831  

813  
        @param token A string token to receive the result.
832  
        @param token A string token to receive the result.
814  
        @return The host address
833  
        @return The host address
815  

834  

816  
        @par Example
835  
        @par Example
817  
        @code
836  
        @code
818  
        assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" );
837  
        assert( url_view( "https://[1::6:c0a8:1]/" ).host_address() == "1::6:c0a8:1" );
819  
        @endcode
838  
        @endcode
820  

839  

821  
        @par Complexity
840  
        @par Complexity
822  
        Linear in `this->host_address().size()`.
841  
        Linear in `this->host_address().size()`.
823  

842  

824  
        @par Exception Safety
843  
        @par Exception Safety
825  
        Calls to allocate may throw.
844  
        Calls to allocate may throw.
826  

845  

827  
        @par BNF
846  
        @par BNF
828  
        @code
847  
        @code
829  
        host        = IP-literal / IPv4address / reg-name
848  
        host        = IP-literal / IPv4address / reg-name
830  

849  

831  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
850  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
832  

851  

833  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
852  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
834  
        @endcode
853  
        @endcode
835  

854  

836  
        @par Specification
855  
        @par Specification
837  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
856  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
838  
            >3.2.2. Host (rfc3986)</a>
857  
            >3.2.2. Host (rfc3986)</a>
839  
    */
858  
    */
840  
    template<BOOST_URL_STRTOK_TPARAM>
859  
    template<BOOST_URL_STRTOK_TPARAM>
841  
    BOOST_URL_STRTOK_RETURN
860  
    BOOST_URL_STRTOK_RETURN
842  
    host_address(
861  
    host_address(
843  
        BOOST_URL_STRTOK_ARG(token)) const
862  
        BOOST_URL_STRTOK_ARG(token)) const
844  
    {
863  
    {
845  
        encoding_opts opt;
864  
        encoding_opts opt;
846  
        opt.space_as_plus = false;
865  
        opt.space_as_plus = false;
847  
        return encoded_host_address().decode(
866  
        return encoded_host_address().decode(
848  
            opt, std::move(token));
867  
            opt, std::move(token));
849  
    }
868  
    }
850  

869  

851  
    /** Return the host
870  
    /** Return the host
852  

871  

853  
        The value returned by this function
872  
        The value returned by this function
854  
        depends on the type of host returned
873  
        depends on the type of host returned
855  
        from the function @ref host_type.
874  
        from the function @ref host_type.
856  

875  

857  
        @li If the type is @ref host_type::ipv4,
876  
        @li If the type is @ref host_type::ipv4,
858  
        then the IPv4 address string is returned.
877  
        then the IPv4 address string is returned.
859  

878  

860  
        @li If the type is @ref host_type::ipv6,
879  
        @li If the type is @ref host_type::ipv6,
861  
        then the IPv6 address string is returned,
880  
        then the IPv6 address string is returned,
862  
        without any enclosing brackets.
881  
        without any enclosing brackets.
863  

882  

864  
        @li If the type is @ref host_type::ipvfuture,
883  
        @li If the type is @ref host_type::ipvfuture,
865  
        then the IPvFuture address string is returned,
884  
        then the IPvFuture address string is returned,
866  
        without any enclosing brackets.
885  
        without any enclosing brackets.
867  

886  

868  
        @li If the type is @ref host_type::name,
887  
        @li If the type is @ref host_type::name,
869  
        then the host name string is returned.
888  
        then the host name string is returned.
870  
        Any percent-escapes in the string are
889  
        Any percent-escapes in the string are
871  
        decoded first.
890  
        decoded first.
872  

891  

873  
        @li If the type is @ref host_type::none,
892  
        @li If the type is @ref host_type::none,
874  
        then an empty string is returned.
893  
        then an empty string is returned.
875  
        The returned string may contain
894  
        The returned string may contain
876  
        percent escapes.
895  
        percent escapes.
877  

896  

878  
        @return The host address
897  
        @return The host address
879  

898  

880  
        @par Example
899  
        @par Example
881  
        @code
900  
        @code
882  
        assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" );
901  
        assert( url_view( "https://www%2droot.example.com/" ).encoded_host_address() == "www%2droot.example.com" );
883  
        @endcode
902  
        @endcode
884  

903  

885  
        @par Complexity
904  
        @par Complexity
886  
        Constant.
905  
        Constant.
887  

906  

888  
        @par Exception Safety
907  
        @par Exception Safety
889  
        Throws nothing.
908  
        Throws nothing.
890  

909  

891  
        @par BNF
910  
        @par BNF
892  
        @code
911  
        @code
893  
        host        = IP-literal / IPv4address / reg-name
912  
        host        = IP-literal / IPv4address / reg-name
894  

913  

895  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
914  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
896  

915  

897  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
916  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
898  
        @endcode
917  
        @endcode
899  

918  

900  
        @par Specification
919  
        @par Specification
901  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
920  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
902  
            >3.2.2. Host (rfc3986)</a>
921  
            >3.2.2. Host (rfc3986)</a>
903  
    */
922  
    */
 
923 +
    BOOST_URL_CXX20_CONSTEXPR
904  
    pct_string_view
924  
    pct_string_view
905  
    encoded_host_address() const noexcept;
925  
    encoded_host_address() const noexcept;
906  

926  

907  
    /** Return the host IPv4 address
927  
    /** Return the host IPv4 address
908  

928  

909  
        If the host type is @ref host_type::ipv4,
929  
        If the host type is @ref host_type::ipv4,
910  
        this function returns the address as
930  
        this function returns the address as
911  
        a value of type @ref ipv4_address.
931  
        a value of type @ref ipv4_address.
912  
        Otherwise, if the host type is not an IPv4
932  
        Otherwise, if the host type is not an IPv4
913  
        address, it returns a default-constructed
933  
        address, it returns a default-constructed
914  
        value which is equal to the unspecified
934  
        value which is equal to the unspecified
915  
        address "0.0.0.0".
935  
        address "0.0.0.0".
916  

936  

917  
        @return The host IPv4 address
937  
        @return The host IPv4 address
918  

938  

919  
        @par Example
939  
        @par Example
920  
        @code
940  
        @code
921  
        assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) );
941  
        assert( url_view( "http://127.0.0.1/index.htm?user=win95" ).host_ipv4_address() == ipv4_address( "127.0.0.1" ) );
922  
        @endcode
942  
        @endcode
923  

943  

924  
        @par Complexity
944  
        @par Complexity
925  
        Constant.
945  
        Constant.
926  

946  

927  
        @par Exception Safety
947  
        @par Exception Safety
928  
        Throws nothing.
948  
        Throws nothing.
929  

949  

930  
        @par BNF
950  
        @par BNF
931  
        @code
951  
        @code
932  
        IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
952  
        IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
933  

953  

934  
        dec-octet   = DIGIT                 ; 0-9
954  
        dec-octet   = DIGIT                 ; 0-9
935  
                    / %x31-39 DIGIT         ; 10-99
955  
                    / %x31-39 DIGIT         ; 10-99
936  
                    / "1" 2DIGIT            ; 100-199
956  
                    / "1" 2DIGIT            ; 100-199
937  
                    / "2" %x30-34 DIGIT     ; 200-249
957  
                    / "2" %x30-34 DIGIT     ; 200-249
938  
                    / "25" %x30-35          ; 250-255
958  
                    / "25" %x30-35          ; 250-255
939  
        @endcode
959  
        @endcode
940  

960  

941  
        @par Specification
961  
        @par Specification
942  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
962  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
943  
            >3.2.2. Host (rfc3986)</a>
963  
            >3.2.2. Host (rfc3986)</a>
944  
    */
964  
    */
 
965 +
    BOOST_URL_CXX20_CONSTEXPR
945  
    ipv4_address
966  
    ipv4_address
946  
    host_ipv4_address() const noexcept;
967  
    host_ipv4_address() const noexcept;
947  

968  

948  
    /** Return the host IPv6 address
969  
    /** Return the host IPv6 address
949  

970  

950  
        If the host type is @ref host_type::ipv6,
971  
        If the host type is @ref host_type::ipv6,
951  
        this function returns the address as
972  
        this function returns the address as
952  
        a value of type @ref ipv6_address.
973  
        a value of type @ref ipv6_address.
953  
        Otherwise, if the host type is not an IPv6
974  
        Otherwise, if the host type is not an IPv6
954  
        address, it returns a default-constructed
975  
        address, it returns a default-constructed
955  
        value which is equal to the unspecified
976  
        value which is equal to the unspecified
956  
        address "0:0:0:0:0:0:0:0".
977  
        address "0:0:0:0:0:0:0:0".
957  

978  

958  
        @return The host IPv6 address
979  
        @return The host IPv6 address
959  

980  

960  
        @par Example
981  
        @par Example
961  
        @code
982  
        @code
962  
        assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) );
983  
        assert( url_view( "ftp://[::1]/" ).host_ipv6_address() == ipv6_address( "::1" ) );
963  
        @endcode
984  
        @endcode
964  

985  

965  
        @par Complexity
986  
        @par Complexity
966  
        Constant.
987  
        Constant.
967  

988  

968  
        @par Exception Safety
989  
        @par Exception Safety
969  
        Throws nothing.
990  
        Throws nothing.
970  

991  

971  
        @par BNF
992  
        @par BNF
972  
        @code
993  
        @code
973  
        IPv6address =                            6( h16 ":" ) ls32
994  
        IPv6address =                            6( h16 ":" ) ls32
974  
                    /                       "::" 5( h16 ":" ) ls32
995  
                    /                       "::" 5( h16 ":" ) ls32
975  
                    / [               h16 ] "::" 4( h16 ":" ) ls32
996  
                    / [               h16 ] "::" 4( h16 ":" ) ls32
976  
                    / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
997  
                    / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
977  
                    / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
998  
                    / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
978  
                    / [ *3( h16 ":" ) h16 ] "::"    h16 ":"   ls32
999  
                    / [ *3( h16 ":" ) h16 ] "::"    h16 ":"   ls32
979  
                    / [ *4( h16 ":" ) h16 ] "::"              ls32
1000  
                    / [ *4( h16 ":" ) h16 ] "::"              ls32
980  
                    / [ *5( h16 ":" ) h16 ] "::"              h16
1001  
                    / [ *5( h16 ":" ) h16 ] "::"              h16
981  
                    / [ *6( h16 ":" ) h16 ] "::"
1002  
                    / [ *6( h16 ":" ) h16 ] "::"
982  

1003  

983  
        ls32        = ( h16 ":" h16 ) / IPv4address
1004  
        ls32        = ( h16 ":" h16 ) / IPv4address
984  
                    ; least-significant 32 bits of address
1005  
                    ; least-significant 32 bits of address
985  

1006  

986  
        h16         = 1*4HEXDIG
1007  
        h16         = 1*4HEXDIG
987  
                    ; 16 bits of address represented in hexadecimal
1008  
                    ; 16 bits of address represented in hexadecimal
988  
        @endcode
1009  
        @endcode
989  

1010  

990  
        @par Specification
1011  
        @par Specification
991  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1012  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
992  
            >3.2.2. Host (rfc3986)</a>
1013  
            >3.2.2. Host (rfc3986)</a>
993  
    */
1014  
    */
 
1015 +
    BOOST_URL_CXX20_CONSTEXPR
994  
    ipv6_address
1016  
    ipv6_address
995  
    host_ipv6_address() const noexcept;
1017  
    host_ipv6_address() const noexcept;
996  

1018  

997  
    /** Return the host IPvFuture address
1019  
    /** Return the host IPvFuture address
998  

1020  

999  
        If the host type is @ref host_type::ipvfuture,
1021  
        If the host type is @ref host_type::ipvfuture,
1000  
        this function returns the address as
1022  
        this function returns the address as
1001  
        a string.
1023  
        a string.
1002  
        Otherwise, if the host type is not an
1024  
        Otherwise, if the host type is not an
1003  
        IPvFuture address, it returns an
1025  
        IPvFuture address, it returns an
1004  
        empty string.
1026  
        empty string.
1005  

1027  

1006  
        @return The host IPvFuture address
1028  
        @return The host IPvFuture address
1007  

1029  

1008  
        @par Example
1030  
        @par Example
1009  
        @code
1031  
        @code
1010  
        assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" );
1032  
        assert( url_view( "http://[v1fe.d:9]/index.htm" ).host_ipvfuture() == "v1fe.d:9" );
1011  
        @endcode
1033  
        @endcode
1012  

1034  

1013  
        @par Complexity
1035  
        @par Complexity
1014  
        Constant.
1036  
        Constant.
1015  

1037  

1016  
        @par Exception Safety
1038  
        @par Exception Safety
1017  
        Throws nothing.
1039  
        Throws nothing.
1018  

1040  

1019  
        @par BNF
1041  
        @par BNF
1020  
        @code
1042  
        @code
1021  
        IPvFuture  = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1043  
        IPvFuture  = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1022  
        @endcode
1044  
        @endcode
1023  

1045  

1024  
        @par Specification
1046  
        @par Specification
1025  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1047  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1026  
            >3.2.2. Host (rfc3986)</a>
1048  
            >3.2.2. Host (rfc3986)</a>
1027  
    */
1049  
    */
 
1050 +
    BOOST_URL_CXX20_CONSTEXPR
1028  
    core::string_view
1051  
    core::string_view
1029  
    host_ipvfuture() const noexcept;
1052  
    host_ipvfuture() const noexcept;
1030  

1053  

1031  
    /** Return the host name
1054  
    /** Return the host name
1032  

1055  

1033  
        If the host type is @ref host_type::name,
1056  
        If the host type is @ref host_type::name,
1034  
        this function returns the name as
1057  
        this function returns the name as
1035  
        a string.
1058  
        a string.
1036  
        Otherwise, if the host type is not a
1059  
        Otherwise, if the host type is not a
1037  
        name, it returns an empty string.
1060  
        name, it returns an empty string.
1038  
        Any percent-escapes in the string are
1061  
        Any percent-escapes in the string are
1039  
        decoded first.
1062  
        decoded first.
1040  

1063  

1041  
        @param token A string token to receive the result
1064  
        @param token A string token to receive the result
1042  
        @return The host name
1065  
        @return The host name
1043  

1066  

1044  
        @par Example
1067  
        @par Example
1045  
        @code
1068  
        @code
1046  
        assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" );
1069  
        assert( url_view( "https://www%2droot.example.com/" ).host_name() == "www-root.example.com" );
1047  
        @endcode
1070  
        @endcode
1048  

1071  

1049  
        @par Complexity
1072  
        @par Complexity
1050  
        Linear in `this->host_name().size()`.
1073  
        Linear in `this->host_name().size()`.
1051  

1074  

1052  
        @par Exception Safety
1075  
        @par Exception Safety
1053  
        Calls to allocate may throw.
1076  
        Calls to allocate may throw.
1054  

1077  

1055  
        @par BNF
1078  
        @par BNF
1056  
        @code
1079  
        @code
1057  
        host        = IP-literal / IPv4address / reg-name
1080  
        host        = IP-literal / IPv4address / reg-name
1058  

1081  

1059  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
1082  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
1060  

1083  

1061  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
1084  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
1062  
        @endcode
1085  
        @endcode
1063  

1086  

1064  
        @par Specification
1087  
        @par Specification
1065  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1088  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1066  
            >3.2.2. Host (rfc3986)</a>
1089  
            >3.2.2. Host (rfc3986)</a>
1067  
    */
1090  
    */
1068  
    template<BOOST_URL_STRTOK_TPARAM>
1091  
    template<BOOST_URL_STRTOK_TPARAM>
1069  
    BOOST_URL_STRTOK_RETURN
1092  
    BOOST_URL_STRTOK_RETURN
1070  
    host_name(
1093  
    host_name(
1071  
        BOOST_URL_STRTOK_ARG(token)) const
1094  
        BOOST_URL_STRTOK_ARG(token)) const
1072  
    {
1095  
    {
1073  
        encoding_opts opt;
1096  
        encoding_opts opt;
1074  
        opt.space_as_plus = false;
1097  
        opt.space_as_plus = false;
1075  
        return encoded_host_name().decode(
1098  
        return encoded_host_name().decode(
1076  
            opt, std::move(token));
1099  
            opt, std::move(token));
1077  
    }
1100  
    }
1078  

1101  

1079  
    /** Return the host name
1102  
    /** Return the host name
1080  

1103  

1081  
        If the host type is @ref host_type::name,
1104  
        If the host type is @ref host_type::name,
1082  
        this function returns the name as
1105  
        this function returns the name as
1083  
        a string.
1106  
        a string.
1084  
        Otherwise, if the host type is not an
1107  
        Otherwise, if the host type is not an
1085  
        name, it returns an empty string.
1108  
        name, it returns an empty string.
1086  
        The returned string may contain
1109  
        The returned string may contain
1087  
        percent escapes.
1110  
        percent escapes.
1088  

1111  

1089  
        @return The host name
1112  
        @return The host name
1090  

1113  

1091  
        @par Example
1114  
        @par Example
1092  
        @code
1115  
        @code
1093  
        assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" );
1116  
        assert( url_view( "https://www%2droot.example.com/" ).encoded_host_name() == "www%2droot.example.com" );
1094  
        @endcode
1117  
        @endcode
1095  

1118  

1096  
        @par Complexity
1119  
        @par Complexity
1097  
        Constant.
1120  
        Constant.
1098  

1121  

1099  
        @par Exception Safety
1122  
        @par Exception Safety
1100  
        Throws nothing.
1123  
        Throws nothing.
1101  

1124  

1102  
        @par BNF
1125  
        @par BNF
1103  
        @code
1126  
        @code
1104  
        host        = IP-literal / IPv4address / reg-name
1127  
        host        = IP-literal / IPv4address / reg-name
1105  

1128  

1106  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
1129  
        IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
1107  

1130  

1108  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
1131  
        reg-name    = *( unreserved / pct-encoded / "-" / ".")
1109  
        @endcode
1132  
        @endcode
1110  

1133  

1111  
        @par Specification
1134  
        @par Specification
1112  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1135  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1113  
            >3.2.2. Host (rfc3986)</a>
1136  
            >3.2.2. Host (rfc3986)</a>
1114  
    */
1137  
    */
 
1138 +
    BOOST_URL_CXX20_CONSTEXPR
1115  
    pct_string_view
1139  
    pct_string_view
1116  
    encoded_host_name() const noexcept;
1140  
    encoded_host_name() const noexcept;
1117  

1141  

1118  
    //--------------------------------------------
1142  
    //--------------------------------------------
1119  
    //
1143  
    //
1120  
    // Port
1144  
    // Port
1121  
    //
1145  
    //
1122  
    //--------------------------------------------
1146  
    //--------------------------------------------
1123  

1147  

1124  
    /** Return true if a port is present
1148  
    /** Return true if a port is present
1125  

1149  

1126  
        This function returns true if an
1150  
        This function returns true if an
1127  
        authority is present and contains a port.
1151  
        authority is present and contains a port.
1128  

1152  

1129  
        @return `true` if a port is present, otherwise `false`
1153  
        @return `true` if a port is present, otherwise `false`
1130  

1154  

1131  
        @par Example
1155  
        @par Example
1132  
        @code
1156  
        @code
1133  
        assert( url_view( "wss://www.example.com:443" ).has_port() );
1157  
        assert( url_view( "wss://www.example.com:443" ).has_port() );
1134  
        @endcode
1158  
        @endcode
1135  

1159  

1136  
        @par Complexity
1160  
        @par Complexity
1137  
        Constant.
1161  
        Constant.
1138  

1162  

1139  
        @par Exception Safety
1163  
        @par Exception Safety
1140  
        Throws nothing.
1164  
        Throws nothing.
1141  

1165  

1142  
        @par BNF
1166  
        @par BNF
1143  
        @code
1167  
        @code
1144  
        authority   = [ userinfo "@" ] host [ ":" port ]
1168  
        authority   = [ userinfo "@" ] host [ ":" port ]
1145  

1169  

1146  
        port        = *DIGIT
1170  
        port        = *DIGIT
1147  
        @endcode
1171  
        @endcode
1148  

1172  

1149  
        @par Specification
1173  
        @par Specification
1150  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1174  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1151  
            >3.2.3. Port (rfc3986)</a>
1175  
            >3.2.3. Port (rfc3986)</a>
1152  

1176  

1153  
        @see
1177  
        @see
1154  
            @ref encoded_host_and_port,
1178  
            @ref encoded_host_and_port,
1155  
            @ref port,
1179  
            @ref port,
1156  
            @ref port_number.
1180  
            @ref port_number.
1157  
    */
1181  
    */
 
1182 +
    BOOST_URL_CXX20_CONSTEXPR
1158  
    bool
1183  
    bool
1159  
    has_port() const noexcept;
1184  
    has_port() const noexcept;
1160  

1185  

1161  
    /** Return the port
1186  
    /** Return the port
1162  

1187  

1163  
        If present, this function returns a
1188  
        If present, this function returns a
1164  
        string representing the port (which
1189  
        string representing the port (which
1165  
        may be empty).
1190  
        may be empty).
1166  
        Otherwise it returns an empty string.
1191  
        Otherwise it returns an empty string.
1167  

1192  

1168  
        @return The port as a string
1193  
        @return The port as a string
1169  

1194  

1170  
        @par Example
1195  
        @par Example
1171  
        @code
1196  
        @code
1172  
        assert( url_view( "http://localhost.com:8080" ).port() == "8080" );
1197  
        assert( url_view( "http://localhost.com:8080" ).port() == "8080" );
1173  
        @endcode
1198  
        @endcode
1174  

1199  

1175  
        @par Complexity
1200  
        @par Complexity
1176  
        Constant.
1201  
        Constant.
1177  

1202  

1178  
        @par Exception Safety
1203  
        @par Exception Safety
1179  
        Throws nothing.
1204  
        Throws nothing.
1180  

1205  

1181  
        @par BNF
1206  
        @par BNF
1182  
        @code
1207  
        @code
1183  
        port        = *DIGIT
1208  
        port        = *DIGIT
1184  
        @endcode
1209  
        @endcode
1185  

1210  

1186  
        @par Specification
1211  
        @par Specification
1187  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1212  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1188  
            >3.2.3. Port (rfc3986)</a>
1213  
            >3.2.3. Port (rfc3986)</a>
1189  

1214  

1190  
        @see
1215  
        @see
1191  
            @ref encoded_host_and_port,
1216  
            @ref encoded_host_and_port,
1192  
            @ref has_port,
1217  
            @ref has_port,
1193  
            @ref port_number.
1218  
            @ref port_number.
1194  
    */
1219  
    */
 
1220 +
    BOOST_URL_CXX20_CONSTEXPR
1195  
    core::string_view
1221  
    core::string_view
1196  
    port() const noexcept;
1222  
    port() const noexcept;
1197  

1223  

1198  
    /** Return the port
1224  
    /** Return the port
1199  

1225  

1200  
        If a port is present and the numerical
1226  
        If a port is present and the numerical
1201  
        value is representable, it is returned
1227  
        value is representable, it is returned
1202  
        as an unsigned integer. Otherwise, the
1228  
        as an unsigned integer. Otherwise, the
1203  
        number zero is returned.
1229  
        number zero is returned.
1204  

1230  

1205  
        @return The port number
1231  
        @return The port number
1206  

1232  

1207  
        @par Example
1233  
        @par Example
1208  
        @code
1234  
        @code
1209  
        assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 );
1235  
        assert( url_view( "http://localhost.com:8080" ).port_number() == 8080 );
1210  
        @endcode
1236  
        @endcode
1211  

1237  

1212  
        @par Complexity
1238  
        @par Complexity
1213  
        Constant.
1239  
        Constant.
1214  

1240  

1215  
        @par Exception Safety
1241  
        @par Exception Safety
1216  
        Throws nothing.
1242  
        Throws nothing.
1217  

1243  

1218  
        @par BNF
1244  
        @par BNF
1219  
        @code
1245  
        @code
1220  
        port        = *DIGIT
1246  
        port        = *DIGIT
1221  
        @endcode
1247  
        @endcode
1222  

1248  

1223  
        @par Specification
1249  
        @par Specification
1224  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1250  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1225  
            >3.2.3. Port (rfc3986)</a>
1251  
            >3.2.3. Port (rfc3986)</a>
1226  

1252  

1227  
        @see
1253  
        @see
1228  
            @ref encoded_host_and_port,
1254  
            @ref encoded_host_and_port,
1229  
            @ref has_port,
1255  
            @ref has_port,
1230  
            @ref port.
1256  
            @ref port.
1231  
    */
1257  
    */
 
1258 +
    BOOST_URL_CXX20_CONSTEXPR
1232  
    std::uint16_t
1259  
    std::uint16_t
1233  
    port_number() const noexcept;
1260  
    port_number() const noexcept;
1234  

1261  

1235  
    /** Return the host and port
1262  
    /** Return the host and port
1236  

1263  

1237  
        If an authority is present, this
1264  
        If an authority is present, this
1238  
        function returns the host and optional
1265  
        function returns the host and optional
1239  
        port as a string, which may be empty.
1266  
        port as a string, which may be empty.
1240  
        Otherwise it returns an empty string.
1267  
        Otherwise it returns an empty string.
1241  
        The returned string may contain
1268  
        The returned string may contain
1242  
        percent escapes.
1269  
        percent escapes.
1243  

1270  

1244  
        @par Example
1271  
        @par Example
1245  
        @code
1272  
        @code
1246  
        assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
1273  
        assert( url_view( "http://www.example.com:8080/index.htm" ).encoded_host_and_port() == "www.example.com:8080" );
1247  
        @endcode
1274  
        @endcode
1248  

1275  

1249  
        @par Complexity
1276  
        @par Complexity
1250  
        Constant.
1277  
        Constant.
1251  

1278  

1252  
        @par Exception Safety
1279  
        @par Exception Safety
1253  
        Throws nothing.
1280  
        Throws nothing.
1254  

1281  

1255  
        @par BNF
1282  
        @par BNF
1256  
        @code
1283  
        @code
1257  
        authority   = [ userinfo "@" ] host [ ":" port ]
1284  
        authority   = [ userinfo "@" ] host [ ":" port ]
1258  
        @endcode
1285  
        @endcode
1259  

1286  

1260  
        @par Specification
1287  
        @par Specification
1261  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1288  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
1262  
            >3.2.2.  Host (rfc3986)</a>
1289  
            >3.2.2.  Host (rfc3986)</a>
1263  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1290  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3"
1264  
            >3.2.3. Port (rfc3986)</a>
1291  
            >3.2.3. Port (rfc3986)</a>
1265  

1292  

1266  
        @see
1293  
        @see
1267  
            @ref has_port,
1294  
            @ref has_port,
1268  
            @ref port,
1295  
            @ref port,
1269  
            @ref port_number.
1296  
            @ref port_number.
1270  

1297  

1271  
        @return The host and port
1298  
        @return The host and port
1272  
    */
1299  
    */
 
1300 +
    BOOST_URL_CXX20_CONSTEXPR
1273  
    pct_string_view
1301  
    pct_string_view
1274  
    encoded_host_and_port() const noexcept;
1302  
    encoded_host_and_port() const noexcept;
1275  

1303  

1276  
    //--------------------------------------------
1304  
    //--------------------------------------------
1277  
    //
1305  
    //
1278  
    // Comparison
1306  
    // Comparison
1279  
    //
1307  
    //
1280  
    //--------------------------------------------
1308  
    //--------------------------------------------
1281  

1309  

1282  
    /** Return the result of comparing this with another authority
1310  
    /** Return the result of comparing this with another authority
1283  

1311  

1284  
        This function compares two authorities
1312  
        This function compares two authorities
1285  
        according to Syntax-Based comparison
1313  
        according to Syntax-Based comparison
1286  
        algorithm.
1314  
        algorithm.
1287  

1315  

1288  
        @par Exception Safety
1316  
        @par Exception Safety
1289  
        Throws nothing.
1317  
        Throws nothing.
1290  

1318  

1291  
        @param other The authority to compare
1319  
        @param other The authority to compare
1292  

1320  

1293  
        @return `-1` if `*this < other`, `0` if
1321  
        @return `-1` if `*this < other`, `0` if
1294  
        `this == other`, and 1 if `this > other`.
1322  
        `this == other`, and 1 if `this > other`.
1295  

1323  

1296  
        @par Specification
1324  
        @par Specification
1297  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
1325  
        @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
1298  
            >6.2.2 Syntax-Based Normalization (rfc3986)</a>
1326  
            >6.2.2 Syntax-Based Normalization (rfc3986)</a>
1299  
    */
1327  
    */
1300  
    int
1328  
    int
1301  
    compare(authority_view const& other) const noexcept;
1329  
    compare(authority_view const& other) const noexcept;
1302  

1330  

1303  
    /** Return the result of comparing two authorities.
1331  
    /** Return the result of comparing two authorities.
1304  
        The authorities are compared component
1332  
        The authorities are compared component
1305  
        by component as if they were first
1333  
        by component as if they were first
1306  
        normalized.
1334  
        normalized.
1307  

1335  

1308  
        @par Complexity
1336  
        @par Complexity
1309  
        Linear in `min( a0.size(), a1.size() )`
1337  
        Linear in `min( a0.size(), a1.size() )`
1310  

1338  

1311  
        @par Exception Safety
1339  
        @par Exception Safety
1312  
        Throws nothing
1340  
        Throws nothing
1313  

1341  

1314  
        @param a0 The first authority to compare
1342  
        @param a0 The first authority to compare
1315  
        @param a1 The second authority to compare
1343  
        @param a1 The second authority to compare
1316  
        @return `true` if `a0 == a1`, otherwise `false`
1344  
        @return `true` if `a0 == a1`, otherwise `false`
1317  
    */
1345  
    */
1318  
    friend
1346  
    friend
1319  
    bool
1347  
    bool
1320  
    operator==(
1348  
    operator==(
1321  
        authority_view const& a0,
1349  
        authority_view const& a0,
1322  
        authority_view const& a1) noexcept
1350  
        authority_view const& a1) noexcept
1323  
    {
1351  
    {
1324  
        return a0.compare(a1) == 0;
1352  
        return a0.compare(a1) == 0;
1325  
    }
1353  
    }
1326  

1354  

1327  
    /** Return the result of comparing two authorities.
1355  
    /** Return the result of comparing two authorities.
1328  
        The authorities are compared component
1356  
        The authorities are compared component
1329  
        by component as if they were first
1357  
        by component as if they were first
1330  
        normalized.
1358  
        normalized.
1331  

1359  

1332  
        @par Complexity
1360  
        @par Complexity
1333  
        Linear in `min( a0.size(), a1.size() )`
1361  
        Linear in `min( a0.size(), a1.size() )`
1334  

1362  

1335  
        @par Exception Safety
1363  
        @par Exception Safety
1336  
        Throws nothing
1364  
        Throws nothing
1337  

1365  

1338  
        @param a0 The first authority to compare
1366  
        @param a0 The first authority to compare
1339  
        @param a1 The second authority to compare
1367  
        @param a1 The second authority to compare
1340  
        @return `true` if `a0 != a1`, otherwise `false`
1368  
        @return `true` if `a0 != a1`, otherwise `false`
1341  
    */
1369  
    */
1342  
    friend
1370  
    friend
1343  
    bool
1371  
    bool
1344  
    operator!=(
1372  
    operator!=(
1345  
        authority_view const& a0,
1373  
        authority_view const& a0,
1346  
        authority_view const& a1) noexcept
1374  
        authority_view const& a1) noexcept
1347  
    {
1375  
    {
1348  
        return ! (a0 == a1);
1376  
        return ! (a0 == a1);
1349  
    }
1377  
    }
1350  

1378  

1351  
    /** Return the result of comparing two authorities.
1379  
    /** Return the result of comparing two authorities.
1352  
        The authorities are compared component
1380  
        The authorities are compared component
1353  
        by component as if they were first
1381  
        by component as if they were first
1354  
        normalized.
1382  
        normalized.
1355  

1383  

1356  
        @par Complexity
1384  
        @par Complexity
1357  
        Linear in `min( a0.size(), a1.size() )`
1385  
        Linear in `min( a0.size(), a1.size() )`
1358  

1386  

1359  
        @par Exception Safety
1387  
        @par Exception Safety
1360  
        Throws nothing
1388  
        Throws nothing
1361  

1389  

1362  
        @param a0 The first authority to compare
1390  
        @param a0 The first authority to compare
1363  
        @param a1 The second authority to compare
1391  
        @param a1 The second authority to compare
1364  
        @return `true` if `a0 < a1`, otherwise `false`
1392  
        @return `true` if `a0 < a1`, otherwise `false`
1365  
    */
1393  
    */
1366  
    friend
1394  
    friend
1367  
    bool
1395  
    bool
1368  
    operator<(
1396  
    operator<(
1369  
        authority_view const& a0,
1397  
        authority_view const& a0,
1370  
        authority_view const& a1) noexcept
1398  
        authority_view const& a1) noexcept
1371  
    {
1399  
    {
1372  
        return a0.compare(a1) < 0;
1400  
        return a0.compare(a1) < 0;
1373  
    }
1401  
    }
1374  

1402  

1375  
    /** Return the result of comparing two authorities.
1403  
    /** Return the result of comparing two authorities.
1376  
        The authorities are compared component
1404  
        The authorities are compared component
1377  
        by component as if they were first
1405  
        by component as if they were first
1378  
        normalized.
1406  
        normalized.
1379  

1407  

1380  
        @par Complexity
1408  
        @par Complexity
1381  
        Linear in `min( a0.size(), a1.size() )`
1409  
        Linear in `min( a0.size(), a1.size() )`
1382  

1410  

1383  
        @par Exception Safety
1411  
        @par Exception Safety
1384  
        Throws nothing
1412  
        Throws nothing
1385  

1413  

1386  
        @param a0 The first authority to compare
1414  
        @param a0 The first authority to compare
1387  
        @param a1 The second authority to compare
1415  
        @param a1 The second authority to compare
1388  
        @return `true` if `a0 <= a1`, otherwise `false`
1416  
        @return `true` if `a0 <= a1`, otherwise `false`
1389  
    */
1417  
    */
1390  
    friend
1418  
    friend
1391  
    bool
1419  
    bool
1392  
    operator<=(
1420  
    operator<=(
1393  
        authority_view const& a0,
1421  
        authority_view const& a0,
1394  
        authority_view const& a1) noexcept
1422  
        authority_view const& a1) noexcept
1395  
    {
1423  
    {
1396  
        return a0.compare(a1) <= 0;
1424  
        return a0.compare(a1) <= 0;
1397  
    }
1425  
    }
1398  

1426  

1399  
    /** Return the result of comparing two authorities.
1427  
    /** Return the result of comparing two authorities.
1400  
        The authorities are compared component
1428  
        The authorities are compared component
1401  
        by component as if they were first
1429  
        by component as if they were first
1402  
        normalized.
1430  
        normalized.
1403  

1431  

1404  
        @par Complexity
1432  
        @par Complexity
1405  
        Linear in `min( a0.size(), a1.size() )`
1433  
        Linear in `min( a0.size(), a1.size() )`
1406  

1434  

1407  
        @par Exception Safety
1435  
        @par Exception Safety
1408  
        Throws nothing
1436  
        Throws nothing
1409  

1437  

1410  
        @param a0 The first authority to compare
1438  
        @param a0 The first authority to compare
1411  
        @param a1 The second authority to compare
1439  
        @param a1 The second authority to compare
1412  
        @return `true` if `a0 > a1`, otherwise `false`
1440  
        @return `true` if `a0 > a1`, otherwise `false`
1413  
    */
1441  
    */
1414  
    friend
1442  
    friend
1415  
    bool
1443  
    bool
1416  
    operator>(
1444  
    operator>(
1417  
        authority_view const& a0,
1445  
        authority_view const& a0,
1418  
        authority_view const& a1) noexcept
1446  
        authority_view const& a1) noexcept
1419  
    {
1447  
    {
1420  
        return a0.compare(a1) > 0;
1448  
        return a0.compare(a1) > 0;
1421  
    }
1449  
    }
1422  

1450  

1423  
    /** Return the result of comparing two authorities.
1451  
    /** Return the result of comparing two authorities.
1424  
        The authorities are compared component
1452  
        The authorities are compared component
1425  
        by component as if they were first
1453  
        by component as if they were first
1426  
        normalized.
1454  
        normalized.
1427  

1455  

1428  
        @par Complexity
1456  
        @par Complexity
1429  
        Linear in `min( a0.size(), a1.size() )`
1457  
        Linear in `min( a0.size(), a1.size() )`
1430  

1458  

1431  
        @par Exception Safety
1459  
        @par Exception Safety
1432  
        Throws nothing
1460  
        Throws nothing
1433  

1461  

1434  
        @param a0 The first authority to compare
1462  
        @param a0 The first authority to compare
1435  
        @param a1 The second authority to compare
1463  
        @param a1 The second authority to compare
1436  
        @return `true` if `a0 >= a1`, otherwise `false`
1464  
        @return `true` if `a0 >= a1`, otherwise `false`
1437  
    */
1465  
    */
1438  
    friend
1466  
    friend
1439  
    bool
1467  
    bool
1440  
    operator>=(
1468  
    operator>=(
1441  
        authority_view const& a0,
1469  
        authority_view const& a0,
1442  
        authority_view const& a1) noexcept
1470  
        authority_view const& a1) noexcept
1443  
    {
1471  
    {
1444  
        return a0.compare(a1) >= 0;
1472  
        return a0.compare(a1) >= 0;
1445  
    }
1473  
    }
1446  

1474  

1447  
    //--------------------------------------------
1475  
    //--------------------------------------------
1448  

1476  

1449  
    /** Format the encoded authority to the output stream
1477  
    /** Format the encoded authority to the output stream
1450  

1478  

1451  
        This hidden friend function serializes the encoded URL
1479  
        This hidden friend function serializes the encoded URL
1452  
        to the output stream.
1480  
        to the output stream.
1453  

1481  

1454  
        @par Example
1482  
        @par Example
1455  
        @code
1483  
        @code
1456  
        authority_view a( "www.example.com" );
1484  
        authority_view a( "www.example.com" );
1457  

1485  

1458  
        std::cout << a << std::endl;
1486  
        std::cout << a << std::endl;
1459  
        @endcode
1487  
        @endcode
1460  

1488  

1461  
        @return A reference to the output stream, for chaining
1489  
        @return A reference to the output stream, for chaining
1462  

1490  

1463  
        @param os The output stream to write to
1491  
        @param os The output stream to write to
1464  

1492  

1465  
        @param a The URL to write
1493  
        @param a The URL to write
1466  
    */
1494  
    */
1467  
    friend
1495  
    friend
1468  
    std::ostream&
1496  
    std::ostream&
1469  
    operator<<(
1497  
    operator<<(
1470  
        std::ostream& os,
1498  
        std::ostream& os,
1471  
        authority_view const& a)
1499  
        authority_view const& a)
1472  
    {
1500  
    {
1473  
        return os << a.buffer();
1501  
        return os << a.buffer();
1474  
    }
1502  
    }
1475  
};
1503  
};
1476  

1504  

1477  
/** Format the encoded authority to the output stream
1505  
/** Format the encoded authority to the output stream
1478  

1506  

1479  
    This function serializes the encoded URL
1507  
    This function serializes the encoded URL
1480  
    to the output stream.
1508  
    to the output stream.
1481  

1509  

1482  
    @par Example
1510  
    @par Example
1483  
    @code
1511  
    @code
1484  
    authority_view a( "www.example.com" );
1512  
    authority_view a( "www.example.com" );
1485  

1513  

1486  
    std::cout << a << std::endl;
1514  
    std::cout << a << std::endl;
1487  
    @endcode
1515  
    @endcode
1488  

1516  

1489  
    @return A reference to the output stream, for chaining
1517  
    @return A reference to the output stream, for chaining
1490  

1518  

1491  
    @param os The output stream to write to
1519  
    @param os The output stream to write to
1492  

1520  

1493  
    @param a The URL to write
1521  
    @param a The URL to write
1494  
*/
1522  
*/
1495  
std::ostream&
1523  
std::ostream&
1496  
operator<<(
1524  
operator<<(
1497  
    std::ostream& os,
1525  
    std::ostream& os,
1498  
    authority_view const& a);
1526  
    authority_view const& a);
1499  

1527  

1500  
//------------------------------------------------
1528  
//------------------------------------------------
1501  

1529  

1502  
/** Parse an authority
1530  
/** Parse an authority
1503  

1531  

1504  
    This function parses a string according to
1532  
    This function parses a string according to
1505  
    the authority grammar below, and returns an
1533  
    the authority grammar below, and returns an
1506  
    @ref authority_view referencing the string.
1534  
    @ref authority_view referencing the string.
1507  
    Ownership of the string is not transferred;
1535  
    Ownership of the string is not transferred;
1508  
    the caller is responsible for ensuring that
1536  
    the caller is responsible for ensuring that
1509  
    the lifetime of the string extends until the
1537  
    the lifetime of the string extends until the
1510  
    view is no longer being accessed.
1538  
    view is no longer being accessed.
1511  

1539  

1512  
    @par BNF
1540  
    @par BNF
1513  
    @code
1541  
    @code
1514  
    authority     = [ userinfo "@" ] host [ ":" port ]
1542  
    authority     = [ userinfo "@" ] host [ ":" port ]
1515  

1543  

1516  
    userinfo      = user [ ":" [ password ] ]
1544  
    userinfo      = user [ ":" [ password ] ]
1517  

1545  

1518  
    user          = *( unreserved / pct-encoded / sub-delims )
1546  
    user          = *( unreserved / pct-encoded / sub-delims )
1519  
    password      = *( unreserved / pct-encoded / sub-delims / ":" )
1547  
    password      = *( unreserved / pct-encoded / sub-delims / ":" )
1520  

1548  

1521  
    host          = IP-literal / IPv4address / reg-name
1549  
    host          = IP-literal / IPv4address / reg-name
1522  

1550  

1523  
    port          = *DIGIT
1551  
    port          = *DIGIT
1524  
    @endcode
1552  
    @endcode
1525  

1553  

1526  
    @par Exception Safety
1554  
    @par Exception Safety
1527  
    Throws nothing.
1555  
    Throws nothing.
1528  

1556  

1529  
    @return A view to the parsed authority
1557  
    @return A view to the parsed authority
1530  

1558  

1531  
    @param s The string to parse
1559  
    @param s The string to parse
1532  

1560  

1533  
    @par Specification
1561  
    @par Specification
1534  
    @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
1562  
    @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2"
1535  
        >3.2. Authority (rfc3986)</a>
1563  
        >3.2. Authority (rfc3986)</a>
1536  

1564  

1537  
    @see
1565  
    @see
1538  
        @ref authority_view.
1566  
        @ref authority_view.
1539  
*/
1567  
*/
1540 -
BOOST_URL_DECL
1568 +
BOOST_URL_CXX20_CONSTEXPR
1541  
system::result<authority_view>
1569  
system::result<authority_view>
1542  
parse_authority(
1570  
parse_authority(
1543  
    core::string_view s) noexcept;
1571  
    core::string_view s) noexcept;
1544 -
//------------------------------------------------
 
1545 -

 
1546  

1572  

1547  
} // urls
1573  
} // urls
1548  
} // boost
1574  
} // boost
 
1575 +

 
1576 +
// Include url_impl definitions here because
 
1577 +
// detail/url_impl.hpp defers this include when
 
1578 +
// authority_view.hpp is the includer (to break
 
1579 +
// the circular dependency between url_impl
 
1580 +
// definitions and the authority_view type).
 
1581 +
#include <boost/url/detail/impl/url_impl.hpp>
 
1582 +

 
1583 +
#include <boost/url/impl/authority_view.hpp>
 
1584 +

 
1585 +
// Include authority_rule here to provide inline
 
1586 +
// definitions of parse_authority() and
 
1587 +
// authority_view(core::string_view).
 
1588 +
#include <boost/url/rfc/authority_rule.hpp>
1549  

1589  

1550  
#endif
1590  
#endif