GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/rfc/detail/hier_part_rule.cpp
Date: 2023-12-15 15:31:49
Exec Total Coverage
Lines: 53 54 98.1%
Functions: 1 1 100.0%
Branches: 37 38 97.4%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/url
8 //
9
10 #ifndef BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_IPP
11 #define BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_IPP
12
13 #include <boost/url/detail/config.hpp>
14 #include <boost/url/rfc/detail/hier_part_rule.hpp>
15 #include <boost/url/rfc/detail/path_rules.hpp>
16 #include <boost/url/grammar/parse.hpp>
17 #include <boost/url/grammar/parse.hpp>
18
19 namespace boost {
20 namespace urls {
21 namespace detail {
22
23 auto
24 2233 hier_part_rule_t::
25 parse(
26 char const*& it,
27 char const* const end
28 ) const noexcept ->
29 system::result<value_type>
30 {
31 4466 value_type t;
32
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2189 times.
2233 if(it == end)
33 {
34 // path-empty
35 44 return t;
36 }
37
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 2153 times.
2189 if(end - it == 1)
38 {
39
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 10 times.
36 if(*it == '/')
40 {
41 // path-absolute
42 t.path = make_pct_string_view_unsafe(
43 26 it, 1, 1);
44 26 t.segment_count = 1;
45 26 ++it;
46 26 return t;
47 }
48 // path-rootless
49 auto rv = grammar::parse(
50 10 it, end, segment_rule);
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if(! rv)
52 return rv.error();
53 10 t.path = *rv;
54 10 t.segment_count = !t.path.empty();
55 10 return t;
56 }
57
2/2
✓ Branch 0 taken 1556 times.
✓ Branch 1 taken 597 times.
2153 if( it[0] == '/' &&
58
2/2
✓ Branch 0 taken 1464 times.
✓ Branch 1 taken 92 times.
1556 it[1] == '/')
59 {
60 // "//" authority
61 1464 it += 2;
62 auto rv = grammar::parse(
63 1464 it, end, authority_rule);
64
2/2
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 1434 times.
1464 if(! rv)
65 30 return rv.error();
66 1434 t.authority = *rv;
67 1434 t.has_authority = true;
68 }
69 // the authority requires an absolute path
70 // or an empty path
71
2/2
✓ Branch 0 taken 1717 times.
✓ Branch 1 taken 406 times.
2123 if(it == end || (
72
2/2
✓ Branch 0 taken 1028 times.
✓ Branch 1 taken 689 times.
1717 t.has_authority && (
73
2/2
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 882 times.
1028 *it != '/' &&
74
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 43 times.
146 *it != '?' &&
75
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 14 times.
103 *it != '#')))
76 {
77 // path-empty
78 495 return t;
79 }
80 1628 auto const it0 = it;
81 1628 std::size_t dn = 0;
82
2/2
✓ Branch 0 taken 654 times.
✓ Branch 1 taken 974 times.
1628 if(*it != '/')
83 {
84 auto rv = grammar::parse(
85 654 it, end, segment_rule);
86
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 652 times.
654 if(! rv)
87 2 return rv.error();
88
2/2
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 577 times.
652 if(rv->empty())
89 75 return t;
90 577 dn += rv->decoded_size();
91 577 ++t.segment_count;
92 }
93
2/2
✓ Branch 0 taken 2894 times.
✓ Branch 1 taken 1367 times.
4261 while(it != end)
94 {
95
2/2
✓ Branch 0 taken 1625 times.
✓ Branch 1 taken 1269 times.
2894 if(*it == '/')
96 {
97 1625 ++dn;
98 1625 ++it;
99 1625 ++t.segment_count;
100 1625 continue;
101 }
102 auto rv = grammar::parse(
103 1269 it, end, segment_rule);
104
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1265 times.
1269 if(! rv)
105 4 return rv.error();
106
2/2
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 1085 times.
1265 if(rv->empty())
107 180 break;
108 1085 dn += rv->decoded_size();
109 }
110 t.path = make_pct_string_view_unsafe(
111 1547 it0, it - it0, dn);
112 1547 return t;
113 }
114
115 } // detail
116 } // urls
117 } // boost
118
119 #endif
120