GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/rfc/detail/relative_part_rule.cpp
Date: 2024-01-19 15:42:54
Exec Total Coverage
Lines: 52 55 94.5%
Functions: 1 1 100.0%
Branches: 35 38 92.1%

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_RELATIVE_PART_RULE_IPP
11 #define BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_IPP
12
13 #include <boost/url/detail/config.hpp>
14 #include "relative_part_rule.hpp"
15 #include "boost/url/rfc/detail/path_rules.hpp"
16 #include <boost/url/grammar/parse.hpp>
17
18 namespace boost {
19 namespace urls {
20 namespace detail {
21
22 constexpr auto pchars_nc = pchars - ':';
23
24 auto
25 1339 relative_part_rule_t::
26 parse(
27 char const*& it,
28 char const* const end
29 ) const noexcept ->
30 system::result<value_type>
31 {
32 2678 value_type t;
33
2/2
✓ Branch 0 taken 125 times.
✓ Branch 1 taken 1214 times.
1339 if(it == end)
34 {
35 // path-empty
36 125 return t;
37 }
38
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 1072 times.
1214 if(end - it == 1)
39 {
40
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 64 times.
142 if(*it == '/')
41 {
42 // path-absolute
43 t.path = make_pct_string_view_unsafe(
44 78 it, 1, 1);
45 78 t.segment_count = 1;
46 78 ++it;
47 78 return t;
48 }
49
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 1 times.
64 if(*it != ':')
50 {
51 // path-noscheme or
52 // path-empty
53 auto rv = grammar::parse(
54 63 it, end, segment_rule);
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
63 if(! rv)
56 return rv.error();
57
2/2
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 34 times.
63 if(! rv->empty())
58 {
59 29 t.path = *rv;
60 29 t.segment_count = 1;
61 }
62 }
63 // path-empty
64 64 return t;
65 }
66
2/2
✓ Branch 0 taken 523 times.
✓ Branch 1 taken 549 times.
1072 if( it[0] == '/' &&
67
2/2
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 279 times.
523 it[1] == '/')
68 {
69 // "//" authority
70 244 it += 2;
71 auto rv = grammar::parse(
72 244 it, end, authority_rule);
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
244 if(! rv)
74 return rv.error();
75 244 t.authority = *rv;
76 244 t.has_authority = true;
77 }
78
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 949 times.
1072 if(it == end)
79 {
80 // path-empty
81 123 return t;
82 }
83 949 auto const it0 = it;
84 949 std::size_t dn = 0;
85
2/2
✓ Branch 0 taken 552 times.
✓ Branch 1 taken 397 times.
949 if(*it != '/')
86 {
87 // segment_nc
88 auto rv = grammar::parse(it, end,
89 552 pct_encoded_rule(pchars_nc));
90
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 551 times.
552 if(! rv)
91 1 return rv.error();
92
2/2
✓ Branch 2 taken 207 times.
✓ Branch 3 taken 344 times.
551 if(rv->empty())
93 207 return t;
94 344 dn += rv->decoded_size();
95 344 ++t.segment_count;
96
2/2
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 75 times.
344 if( it != end &&
97
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 228 times.
269 *it == ':')
98 {
99 41 BOOST_URL_RETURN_EC(
100 grammar::error::mismatch);
101 }
102 }
103
2/2
✓ Branch 0 taken 2490 times.
✓ Branch 1 taken 647 times.
3137 while(it != end)
104 {
105
2/2
✓ Branch 0 taken 1319 times.
✓ Branch 1 taken 1171 times.
2490 if(*it == '/')
106 {
107 1319 ++dn;
108 1319 ++it;
109 1319 ++t.segment_count;
110 1319 continue;
111 }
112 auto rv = grammar::parse(
113 1171 it, end, segment_rule);
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1171 times.
1171 if(! rv)
115 return rv.error();
116
2/2
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 1118 times.
1171 if(rv->empty())
117 53 break;
118 1118 dn += rv->decoded_size();
119 }
120 t.path = make_pct_string_view_unsafe(
121 700 it0, it - it0, dn);
122 700 return t;
123 }
124
125 } // detail
126 } // urls
127 } // boost
128
129 #endif
130