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  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// 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)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/url
7  
// Official repository: https://github.com/boostorg/url
8  
//
8  
//
9  

9  

10  

10  

11  
#include <boost/url/detail/config.hpp>
11  
#include <boost/url/detail/config.hpp>
12  
#include "userinfo_rule.hpp"
12  
#include "userinfo_rule.hpp"
13  
#include <boost/core/detail/string_view.hpp>
13  
#include <boost/core/detail/string_view.hpp>
14  
#include <boost/url/rfc/pct_encoded_rule.hpp>
14  
#include <boost/url/rfc/pct_encoded_rule.hpp>
15  
#include <boost/url/rfc/sub_delim_chars.hpp>
15  
#include <boost/url/rfc/sub_delim_chars.hpp>
16  
#include <boost/url/rfc/unreserved_chars.hpp>
16  
#include <boost/url/rfc/unreserved_chars.hpp>
17  
#include <boost/url/grammar/parse.hpp>
17  
#include <boost/url/grammar/parse.hpp>
18  

18  

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

22  

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

36  

37  
    value_type t;
37  
    value_type t;
38  

38  

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

46  

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

56  

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

63  

64  
    t.has_password = true;
64  
    t.has_password = true;
65  
    t.password = *rv;
65  
    t.password = *rv;
66  
    return t;
66  
    return t;
67  
}
67  
}
68  

68  

69  
} // detail
69  
} // detail
70  
} // urls
70  
} // urls
71  
} // boost
71  
} // boost
72  

72