GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.9% 56 / 0 / 59
Functions: 100.0% 1 / 0 / 1
Branches: 92.1% 35 / 0 / 38

libs/url/src/rfc/detail/relative_part_rule.cpp
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
11 #include <boost/url/detail/config.hpp>
12 #include "relative_part_rule.hpp"
13 #include "boost/url/rfc/detail/path_rules.hpp"
14 #include <boost/url/grammar/parse.hpp>
15
16 namespace boost {
17 namespace urls {
18 namespace detail {
19
20 constexpr auto pchars_nc = pchars - ':';
21
22 auto
23 1361 relative_part_rule_t::
24 parse(
25 char const*& it,
26 char const* const end
27 ) const noexcept ->
28 system::result<value_type>
29 {
30 1361 value_type t;
31
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 1235 times.
1361 if(it == end)
32 {
33 // path-empty
34 126 return t;
35 }
36
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1091 times.
1235 if(end - it == 1)
37 {
38
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 66 times.
144 if(*it == '/')
39 {
40 // path-absolute
41 78 t.path = make_pct_string_view_unsafe(
42 it, 1, 1);
43 78 t.segment_count = 1;
44 78 ++it;
45 78 return t;
46 }
47
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 1 time.
66 if(*it != ':')
48 {
49 // path-noscheme or
50 // path-empty
51 65 auto rv = grammar::parse(
52 it, end, segment_rule);
53
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 65 times.
65 if(! rv)
54 return rv.error();
55
2/2
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 36 times.
65 if(! rv->empty())
56 {
57 29 t.path = *rv;
58 29 t.segment_count = 1;
59 }
60 }
61 // path-empty
62 66 return t;
63 }
64
2/2
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 560 times.
1091 if( it[0] == '/' &&
65
2/2
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 287 times.
531 it[1] == '/')
66 {
67 // "//" authority
68 244 it += 2;
69 auto rv = grammar::parse(
70 244 it, end, authority_rule);
71
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
244 if(! rv)
72 return rv.error();
73 244 t.authority = *rv;
74 244 t.has_authority = true;
75 244 }
76
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 968 times.
1091 if(it == end)
77 {
78 // path-empty
79 123 return t;
80 }
81 968 auto const it0 = it;
82 968 std::size_t dn = 0;
83
2/2
✓ Branch 0 taken 563 times.
✓ Branch 1 taken 405 times.
968 if(*it != '/')
84 {
85 // segment_nc
86 563 auto rv = grammar::parse(it, end,
87 563 pct_encoded_rule(pchars_nc));
88
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 562 times.
563 if(! rv)
89 1 return rv.error();
90
2/2
✓ Branch 2 taken 215 times.
✓ Branch 3 taken 347 times.
562 if(rv->empty())
91 215 return t;
92 347 dn += rv->decoded_size();
93 347 ++t.segment_count;
94
2/2
✓ Branch 0 taken 272 times.
✓ Branch 1 taken 75 times.
347 if( it != end &&
95
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 232 times.
272 *it == ':')
96 {
97 40 BOOST_URL_RETURN_EC(
98 grammar::error::mismatch);
99 }
100 }
101
2/2
✓ Branch 0 taken 2534 times.
✓ Branch 1 taken 657 times.
3191 while(it != end)
102 {
103
2/2
✓ Branch 0 taken 1340 times.
✓ Branch 1 taken 1194 times.
2534 if(*it == '/')
104 {
105 1340 ++dn;
106 1340 ++it;
107 1340 ++t.segment_count;
108 1340 continue;
109 }
110 1194 auto rv = grammar::parse(
111 it, end, segment_rule);
112
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1194 times.
1194 if(! rv)
113 return rv.error();
114
2/2
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 1139 times.
1194 if(rv->empty())
115 55 break;
116 1139 dn += rv->decoded_size();
117 }
118 712 t.path = make_pct_string_view_unsafe(
119 712 it0, it - it0, dn);
120 712 return t;
121 1361 }
122
123 } // detail
124 } // urls
125 } // boost
126
127