include/boost/url/rfc/impl/authority_rule.hpp

94.1% Lines (32/34) 100.0% Functions (3/3) 84.6% Branches (11/13)
include/boost/url/rfc/impl/authority_rule.hpp
Line Branch Hits 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_IMPL_AUTHORITY_RULE_HPP
12 #define BOOST_URL_RFC_IMPL_AUTHORITY_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/grammar/delim_rule.hpp>
16 #include <boost/url/grammar/optional_rule.hpp>
17 #include <boost/url/grammar/parse.hpp>
18 #include <boost/url/grammar/tuple_rule.hpp>
19 #include <boost/url/rfc/detail/host_rule.hpp>
20 #include <boost/url/rfc/detail/port_rule.hpp>
21 #include <boost/url/rfc/detail/userinfo_rule.hpp>
22
23 namespace boost {
24 namespace urls {
25
26 inline BOOST_URL_CXX20_CONSTEXPR
27 auto
28 2052 implementation_defined::authority_rule_t::
29 parse(
30 char const*& it,
31 char const* const end
32 ) const noexcept ->
33 system::result<value_type>
34 {
35 2052 detail::url_impl u(detail::url_impl::from::authority);
36 2052 u.cs_ = it;
37
38 // [ userinfo "@" ]
39 {
40 auto rv = grammar::parse(
41 it, end,
42 2052 grammar::optional_rule(
43 2052 grammar::tuple_rule(
44 detail::userinfo_rule,
45 2052 grammar::squelch(
46 4104 grammar::delim_rule('@')))));
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2052 times.
2052 if(! rv)
48 return rv.error();
49
2/2
✓ Branch 2 taken 405 times.
✓ Branch 3 taken 1647 times.
2052 if(rv->has_value())
50 {
51 135 u.apply_userinfo(
52 405 (*rv)->user,
53
2/2
✓ Branch 2 taken 270 times.
✓ Branch 3 taken 135 times.
405 (*rv)->has_password
54 270 ? &(*rv)->password
55 : nullptr);
56 }
57 }
58
59 // host
60 {
61 2052 auto rv = grammar::parse(
62 it, end, detail::host_rule);
63
2/2
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 2021 times.
2052 if(! rv)
64 31 return rv.error();
65 2021 u.apply_host(rv->host_type,
66 2021 rv->match, rv->addr);
67 }
68
69 // [ ":" port ]
70 {
71 2021 auto rv = grammar::parse(
72 it, end, detail::port_part_rule);
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2021 times.
2021 if(! rv)
74 return rv.error();
75
2/2
✓ Branch 1 taken 284 times.
✓ Branch 2 taken 1737 times.
2021 if(rv->has_port)
76 284 u.apply_port(
77 284 rv->port,
78 284 rv->port_number);
79 }
80
81 2021 return u.construct_authority();
82 }
83
84 //------------------------------------------------
85
86 inline BOOST_URL_CXX20_CONSTEXPR
87 2 authority_view::
88 authority_view(
89 2 core::string_view s)
90 : authority_view(
91 2 parse_authority(s
92
1/1
✓ Branch 2 taken 2 times.
2 ).value(BOOST_URL_POS))
93 {
94 2 }
95
96 inline BOOST_URL_CXX20_CONSTEXPR
97 system::result<authority_view>
98 46 parse_authority(
99 core::string_view s) noexcept
100 {
101 46 return grammar::parse(s, authority_rule);
102 }
103
104 } // urls
105 } // boost
106
107
108 #endif
109