1  
//
1  
//
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3  
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
3  
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_URL_RFC_DETAIL_IMPL_USERINFO_RULE_HPP
11  
#ifndef BOOST_URL_RFC_DETAIL_IMPL_USERINFO_RULE_HPP
12  
#define BOOST_URL_RFC_DETAIL_IMPL_USERINFO_RULE_HPP
12  
#define BOOST_URL_RFC_DETAIL_IMPL_USERINFO_RULE_HPP
13  

13  

14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
15  
#include <boost/url/rfc/pct_encoded_rule.hpp>
15  
#include <boost/url/rfc/pct_encoded_rule.hpp>
16  
#include <boost/url/rfc/sub_delim_chars.hpp>
16  
#include <boost/url/rfc/sub_delim_chars.hpp>
17  
#include <boost/url/rfc/unreserved_chars.hpp>
17  
#include <boost/url/rfc/unreserved_chars.hpp>
18  
#include <boost/url/grammar/parse.hpp>
18  
#include <boost/url/grammar/parse.hpp>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace urls {
21  
namespace urls {
22  
namespace detail {
22  
namespace detail {
23  

23  

24  
BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
24  
BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
25  
auto
25  
auto
26  
userinfo_rule_t::
26  
userinfo_rule_t::
27  
parse(
27  
parse(
28  
    char const*& it,
28  
    char const*& it,
29  
    char const* const end
29  
    char const* const end
30  
        ) const noexcept ->
30  
        ) const noexcept ->
31  
    system::result<value_type>
31  
    system::result<value_type>
32  
{
32  
{
33  
    constexpr auto uchars =
33  
    constexpr auto uchars =
34  
        unreserved_chars +
34  
        unreserved_chars +
35  
        sub_delim_chars;
35  
        sub_delim_chars;
36  
    constexpr auto pwchars =
36  
    constexpr auto pwchars =
37  
        uchars + ':';
37  
        uchars + ':';
38  

38  

39  
    value_type t;
39  
    value_type t;
40  

40  

41  
    // user
41  
    // user
42  
    auto rv = grammar::parse(
42  
    auto rv = grammar::parse(
43  
        it, end, pct_encoded_rule(
43  
        it, end, pct_encoded_rule(
44  
            grammar::ref(uchars)));
44  
            grammar::ref(uchars)));
45  
    if(! rv)
45  
    if(! rv)
46  
        return rv.error();
46  
        return rv.error();
47  
    t.user = *rv;
47  
    t.user = *rv;
48  

48  

49  
    // ':'
49  
    // ':'
50  
    if( it == end ||
50  
    if( it == end ||
51  
        *it != ':')
51  
        *it != ':')
52  
    {
52  
    {
53  
        t.has_password = false;
53  
        t.has_password = false;
54  
        t.password = {};
54  
        t.password = {};
55  
        return t;
55  
        return t;
56  
    }
56  
    }
57  
    ++it;
57  
    ++it;
58  

58  

59  
    // pass
59  
    // pass
60  
    rv = grammar::parse(
60  
    rv = grammar::parse(
61  
        it, end, pct_encoded_rule(
61  
        it, end, pct_encoded_rule(
62  
            grammar::ref(pwchars)));
62  
            grammar::ref(pwchars)));
63  
    if(! rv)
63  
    if(! rv)
64  
        return rv.error();
64  
        return rv.error();
65  

65  

66  
    t.has_password = true;
66  
    t.has_password = true;
67  
    t.password = *rv;
67  
    t.password = *rv;
68  
    return t;
68  
    return t;
69  
}
69  
}
70  

70  

71  
} // detail
71  
} // detail
72  
} // urls
72  
} // urls
73  
} // boost
73  
} // boost
74  

74  

75  

75  

76  
#endif
76  
#endif