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

93.9% Lines (31/33) 100.0% Functions (2/2) 87.5% Branches (14/16)
include/boost/url/rfc/impl/origin_form_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) 2024 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_ORIGIN_FORM_RULE_HPP
12 #define BOOST_URL_RFC_IMPL_ORIGIN_FORM_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/url_view.hpp>
16 #include <boost/url/rfc/detail/path_rules.hpp>
17 #include <boost/url/rfc/detail/query_part_rule.hpp>
18 #include <boost/url/grammar/parse.hpp>
19
20 namespace boost {
21 namespace urls {
22
23 inline BOOST_URL_CXX20_CONSTEXPR
24 auto
25 18 implementation_defined::origin_form_rule_t::
26 parse(
27 char const*& it,
28 char const* end
29 ) const noexcept ->
30 system::result<value_type>
31 {
32 18 detail::url_impl u(detail::url_impl::from::string);
33 18 u.cs_ = it;
34
35 // absolute-path = 1*( "/" segment )
36 {
37
4/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 14 times.
18 if(it == end || *it != '/')
38 {
39 4 BOOST_URL_CONSTEXPR_RETURN_EC(
40 grammar::error::mismatch);
41 }
42 14 auto const it0 = it;
43 14 std::size_t dn = 0;
44 14 std::size_t nseg = 0;
45
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 5 times.
42 while(it != end)
46 {
47
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 19 times.
37 if(*it == '/')
48 {
49 18 ++dn;
50 18 ++it;
51 18 ++nseg;
52 18 continue;
53 }
54 19 auto rv = grammar::parse(
55 it, end, detail::segment_rule);
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
19 if(! rv)
57 return rv.error();
58
2/2
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 10 times.
19 if(rv->empty())
59 9 break;
60 10 dn += rv->decoded_size();
61 }
62 14 u.apply_path(
63 make_pct_string_view_unsafe(
64 14 it0, it - it0, dn),
65 nseg);
66 }
67
68 // [ "?" query ]
69 {
70 14 auto rv = grammar::parse(
71 it, end, detail::query_part_rule);
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if(! rv)
73 return rv.error();
74
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 5 times.
14 if(rv->has_query)
75 {
76 9 u.apply_query(
77 9 rv->query,
78 9 rv->count);
79 }
80 }
81
82 14 return u.construct();
83 }
84
85 inline BOOST_URL_CXX20_CONSTEXPR
86 system::result<url_view>
87 15 parse_origin_form(
88 core::string_view s)
89 {
90 15 return grammar::parse(
91 15 s, origin_form_rule);
92 }
93
94 } // urls
95 } // boost
96
97
98 #endif
99