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

97.2% Lines (35/36) 100.0% Functions (2/2) 92.9% Branches (13/14)
include/boost/url/rfc/impl/uri_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_URI_RULE_HPP
12 #define BOOST_URL_RFC_IMPL_URI_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/hier_part_rule.hpp>
22 #include <boost/url/rfc/detail/query_part_rule.hpp>
23 #include <boost/url/rfc/detail/scheme_rule.hpp>
24
25 namespace boost {
26 namespace urls {
27
28 inline BOOST_URL_CXX20_CONSTEXPR
29 auto
30 3575 implementation_defined::uri_rule_t::
31 parse(
32 char const*& it,
33 char const* const end
34 ) const noexcept ->
35 system::result<value_type>
36 {
37 3575 detail::url_impl u(detail::url_impl::from::string);
38 3575 u.cs_ = it;
39
40 // scheme
41 {
42 3575 auto rv = grammar::parse(
43 it, end,
44 3575 grammar::tuple_rule(
45 3575 detail::scheme_rule(),
46 3575 grammar::squelch(
47 3575 grammar::delim_rule(':'))));
48
2/2
✓ Branch 1 taken 1171 times.
✓ Branch 2 taken 2404 times.
3575 if(! rv)
49 1171 return rv.error();
50 2404 u.apply_scheme(rv->scheme);
51 }
52
53 // hier_part
54 {
55 auto rv = grammar::parse(
56 it, end,
57 2404 detail::hier_part_rule);
58
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 2369 times.
2404 if(! rv)
59 35 return rv.error();
60
2/2
✓ Branch 1 taken 1588 times.
✓ Branch 2 taken 781 times.
2369 if(rv->has_authority)
61 1588 u.apply_authority(rv->authority);
62 2369 u.apply_path(
63 2369 rv->path,
64 2369 rv->segment_count);
65 2404 }
66
67 // [ "?" query ]
68 {
69 2369 auto rv = grammar::parse(
70 it, end, detail::query_part_rule);
71
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2369 times.
2369 if(! rv)
72 return rv.error();
73
2/2
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 2135 times.
2369 if(rv->has_query)
74 {
75 234 u.apply_query(
76 234 rv->query,
77 234 rv->count);
78 }
79 }
80
81 // [ "#" fragment ]
82 {
83 2369 auto rv = grammar::parse(
84 it, end, detail::fragment_part_rule);
85
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2368 times.
2369 if(! rv)
86 1 return rv.error();
87
2/2
✓ Branch 1 taken 181 times.
✓ Branch 2 taken 2187 times.
2368 if(rv->has_fragment)
88 181 u.apply_frag(rv->fragment);
89 }
90
91 2368 return u.construct();
92 }
93
94 inline BOOST_URL_CXX20_CONSTEXPR
95 system::result<url_view>
96 914 parse_uri(
97 core::string_view s)
98 {
99 914 return grammar::parse(
100 914 s, uri_rule);
101 }
102
103 } // urls
104 } // boost
105
106
107 #endif
108