1 +
//
 
2 +
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
 
3 +
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
 
4 +
//
 
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)
 
7 +
//
 
8 +
// Official repository: https://github.com/boostorg/url
 
9 +
//
 
10 +

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

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

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

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

 
39 +
    value_type t;
 
40 +

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

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

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

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

 
68 +
} // detail
 
69 +
} // urls
 
70 +
} // boost
 
71 +

 
72 +

 
73 +
#endif