Line data Source code
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 1966 : userinfo_rule_t::
27 : parse(
28 : char const*& it,
29 : char const* const end
30 : ) const noexcept ->
31 : system::result<value_type>
32 : {
33 1966 : constexpr auto uchars =
34 : unreserved_chars +
35 : sub_delim_chars;
36 1966 : constexpr auto pwchars =
37 : uchars + ':';
38 :
39 1966 : value_type t;
40 :
41 1966 : auto rv = grammar::parse(
42 1966 : it, end, pct_encoded_rule(
43 1966 : grammar::ref(uchars)));
44 1966 : if(! rv)
45 8 : return rv.error();
46 1958 : t.user = *rv;
47 :
48 1958 : if( it == end ||
49 1670 : *it != ':')
50 : {
51 1519 : t.has_password = false;
52 1519 : t.password = {};
53 1519 : return t;
54 : }
55 439 : ++it;
56 :
57 439 : rv = grammar::parse(
58 439 : it, end, pct_encoded_rule(
59 439 : grammar::ref(pwchars)));
60 439 : if(! rv)
61 0 : return rv.error();
62 :
63 439 : t.has_password = true;
64 439 : t.password = *rv;
65 439 : return t;
66 : }
67 :
68 : } // detail
69 : } // urls
70 : } // boost
71 :
72 :
73 : #endif
|