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

95.7% Lines (22/23) 100.0% Functions (1/1)
include/boost/url/rfc/impl/relative_ref_rule.hpp
Line TLA 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 BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
28 auto
29 1376 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 1376 detail::url_impl u(detail::url_impl::from::string);
37 1376 u.cs_ = it;
38
39 // relative-part
40 {
41 auto rv = grammar::parse(
42 it, end,
43 1376 detail::relative_part_rule);
44 1376 if(! rv)
45 41 return rv.error();
46 1335 if(rv->has_authority)
47 243 u.apply_authority(rv->authority.u_);
48 2670 u.apply_path(
49 1335 rv->path, rv->segment_count);
50 1376 }
51
52 // [ "?" query ]
53 {
54 1335 auto rv = grammar::parse(
55 it, end, detail::query_part_rule);
56 1335 if(! rv)
57 return rv.error();
58 1335 auto& v = *rv;
59 1335 if(v.has_query)
60 {
61 // map "?" to { {} }
62 245 u.apply_query(
63 v.query,
64 v.count);
65 }
66 }
67
68 // [ "#" fragment ]
69 {
70 1335 auto rv = grammar::parse(
71 it, end, detail::fragment_part_rule);
72 1335 if(! rv)
73 1 return rv.error();
74 1334 if(rv->has_fragment)
75 63 u.apply_frag(rv->fragment);
76 }
77
78 1334 return url_view(u);
79 }
80
81 } // urls
82 } // boost
83
84
85 #endif
86