GCC Code Coverage Report


Directory: libs/url/
File: boost/url/detail/path.hpp
Date: 2023-12-15 15:31:49
Exec Total Coverage
Lines: 60 60 100.0%
Functions: 3 3 100.0%
Branches: 55 60 91.7%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_DETAIL_PATH_HPP
11 #define BOOST_URL_DETAIL_PATH_HPP
12
13 #include <boost/core/detail/string_view.hpp>
14
15 namespace boost {
16 namespace urls {
17 namespace detail {
18
19 // Return the number of characters at
20 // the front of the path that are reserved
21 inline
22 std::size_t
23 4181 path_prefix(
24 char const* p,
25 std::size_t n) noexcept
26 {
27
4/4
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 247 times.
✓ Branch 2 taken 184 times.
✓ Branch 3 taken 3434 times.
4181 switch(n)
28 {
29 316 case 0:
30 316 return 0;
31
32 247 case 1:
33
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 85 times.
247 if(p[0] == '/')
34 162 return 1;
35 85 return 0;
36
37 184 case 2:
38
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 101 times.
184 if(p[0] == '/')
39 83 return 1;
40
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 15 times.
101 if( p[0] == '.' &&
41
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 29 times.
86 p[1] == '/')
42 57 return 2;
43 44 return 0;
44
45 3434 default:
46
2/2
✓ Branch 0 taken 1823 times.
✓ Branch 1 taken 1611 times.
3434 if(p[0] == '/')
47 {
48
2/2
✓ Branch 0 taken 433 times.
✓ Branch 1 taken 1390 times.
1823 if( p[1] == '.' &&
49
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 199 times.
433 p[2] == '/')
50 234 return 3;
51 1589 return 1;
52 }
53
2/2
✓ Branch 0 taken 622 times.
✓ Branch 1 taken 989 times.
1611 if( p[0] == '.' &&
54
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 271 times.
622 p[1] == '/')
55 351 return 2;
56 1260 break;
57 }
58 1260 return 0;
59 }
60
61 // VFALCO DEPRECATED
62 inline
63 std::size_t
64 4181 path_prefix(
65 core::string_view s) noexcept
66 {
67 4181 return path_prefix(
68 4181 s.data(), s.size());
69 }
70
71 // returns the number of adjusted
72 // segments based on the malleable prefix.
73 inline
74 std::size_t
75 3640 path_segments(
76 core::string_view s,
77 std::size_t nseg) noexcept
78 {
79
4/4
✓ Branch 1 taken 1109 times.
✓ Branch 2 taken 552 times.
✓ Branch 3 taken 166 times.
✓ Branch 4 taken 1813 times.
3640 switch(s.size())
80 {
81 1109 case 0:
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1109 times.
1109 BOOST_ASSERT(nseg == 0);
83 1109 return 0;
84
85 552 case 1:
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 BOOST_ASSERT(nseg == 1);
87
2/2
✓ Branch 1 taken 492 times.
✓ Branch 2 taken 60 times.
552 if(s[0] == '/')
88 492 return 0;
89 60 return 1;
90
91 166 case 2:
92
2/2
✓ Branch 1 taken 124 times.
✓ Branch 2 taken 42 times.
166 if(s[0] == '/')
93 124 return nseg;
94
4/4
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 28 times.
66 if( s[0] == '.' &&
95
2/2
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 10 times.
24 s[1] == '/')
96 {
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 BOOST_ASSERT(nseg > 1);
98 14 return nseg - 1;
99 }
100 28 return nseg;
101
102 1813 default:
103
2/2
✓ Branch 1 taken 898 times.
✓ Branch 2 taken 915 times.
1813 if(s[0] == '/')
104 {
105
4/4
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 832 times.
✓ Branch 3 taken 44 times.
✓ Branch 4 taken 854 times.
964 if( s[1] == '.' &&
106
2/2
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 22 times.
66 s[2] == '/')
107 {
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 BOOST_ASSERT(nseg > 1);
109 44 return nseg - 1;
110 }
111 854 return nseg;
112 }
113
4/4
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 847 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 876 times.
983 if( s[0] == '.' &&
114
2/2
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 29 times.
68 s[1] == '/')
115 {
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 BOOST_ASSERT(nseg > 1);
117 39 return nseg - 1;
118 }
119 876 break;
120 }
121 876 return nseg;
122 }
123
124 // Trim reserved characters from
125 // the front of the path.
126 inline
127 core::string_view
128 clean_path(
129 core::string_view s) noexcept
130 {
131 s.remove_prefix(
132 path_prefix(s));
133 return s;
134 }
135
136 } // detail
137 } // urls
138 } // boost
139
140 #endif
141