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

96.2% Lines (25/26) 100.0% Functions (2/2) 91.7% Branches (11/12)
include/boost/url/rfc/impl/relative_ref_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_RELATIVE_REF_RULE_HPP
12 #define BOOST_URL_RFC_IMPL_RELATIVE_REF_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/url_view.hpp>
16 #include <boost/url/grammar/delim_rule.hpp>
17 #include <boost/url/grammar/tuple_rule.hpp>
18 #include <boost/url/grammar/optional_rule.hpp>
19 #include <boost/url/grammar/parse.hpp>
20 #include <boost/url/rfc/detail/fragment_part_rule.hpp>
21 #include <boost/url/rfc/detail/query_part_rule.hpp>
22 #include <boost/url/rfc/detail/relative_part_rule.hpp>
23
24 namespace boost {
25 namespace urls {
26
27 inline BOOST_URL_CXX20_CONSTEXPR
28 auto
29 1362 implementation_defined::relative_ref_rule_t::
30 parse(
31 char const*& it,
32 char const* const end
33 ) const noexcept ->
34 system::result<value_type>
35 {
36 1362 detail::url_impl u(detail::url_impl::from::string);
37 1362 u.cs_ = it;
38
39 // relative-part
40 {
41 auto rv = grammar::parse(
42 it, end,
43 1362 detail::relative_part_rule);
44
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 1321 times.
1362 if(! rv)
45 41 return rv.error();
46
2/2
✓ Branch 1 taken 243 times.
✓ Branch 2 taken 1078 times.
1321 if(rv->has_authority)
47 243 u.apply_authority(rv->authority);
48 1321 u.apply_path(
49 1321 rv->path, rv->segment_count);
50 1362 }
51
52 // [ "?" query ]
53 {
54 1321 auto rv = grammar::parse(
55 it, end, detail::query_part_rule);
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1321 times.
1321 if(! rv)
57 return rv.error();
58 1321 auto& v = *rv;
59
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 1090 times.
1321 if(v.has_query)
60 {
61 231 u.apply_query(
62 v.query,
63 v.count);
64 }
65 }
66
67 // [ "#" fragment ]
68 {
69 1321 auto rv = grammar::parse(
70 it, end, detail::fragment_part_rule);
71
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1320 times.
1321 if(! rv)
72 1 return rv.error();
73
2/2
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 1257 times.
1320 if(rv->has_fragment)
74 63 u.apply_frag(rv->fragment);
75 }
76
77 1320 return u.construct();
78 }
79
80 inline BOOST_URL_CXX20_CONSTEXPR
81 system::result<url_view>
82 158 parse_relative_ref(
83 core::string_view s)
84 {
85 158 return grammar::parse(
86 158 s, relative_ref_rule);
87 }
88
89 } // urls
90 } // boost
91
92
93 #endif
94