GCC Code Coverage Report


Directory: libs/url/
File: libs/url/src/scheme.cpp
Date: 2024-03-08 17:32:04
Exec Total Coverage
Lines: 75 75 100.0%
Functions: 3 3 100.0%
Branches: 69 70 98.6%

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
11 #include <boost/url/detail/config.hpp>
12 #include <boost/url/scheme.hpp>
13 #include <boost/url/grammar/ci_string.hpp>
14
15 namespace boost {
16 namespace urls {
17
18 scheme
19 4956 string_to_scheme(
20 core::string_view s) noexcept
21 {
22 using grammar::to_lower;
23
6/6
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 311 times.
✓ Branch 3 taken 178 times.
✓ Branch 4 taken 2279 times.
✓ Branch 5 taken 1209 times.
✓ Branch 6 taken 977 times.
4956 switch(s.size())
24 {
25 2 case 0: // none
26 2 return scheme::none;
27
28 311 case 2: // ws
29
6/6
✓ Branch 2 taken 141 times.
✓ Branch 3 taken 170 times.
✓ Branch 4 taken 139 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 139 times.
✓ Branch 7 taken 172 times.
452 if( to_lower(s[0]) == 'w' &&
30 141 to_lower(s[1]) == 's')
31 139 return scheme::ws;
32 172 break;
33
34 178 case 3:
35
3/3
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 78 times.
✓ Branch 4 taken 49 times.
178 switch(to_lower(s[0]))
36 {
37 51 case 'w': // wss
38
6/6
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 43 times.
✓ Branch 7 taken 8 times.
96 if( to_lower(s[1]) == 's' &&
39 45 to_lower(s[2]) == 's')
40 43 return scheme::wss;
41 8 break;
42
43 78 case 'f': // ftp
44
6/6
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 42 times.
115 if( to_lower(s[1]) == 't' &&
45 37 to_lower(s[2]) == 'p')
46 36 return scheme::ftp;
47 42 break;
48
49 49 default:
50 49 break;
51 }
52 99 break;
53
54 2279 case 4:
55
3/3
✓ Branch 2 taken 359 times.
✓ Branch 3 taken 1776 times.
✓ Branch 4 taken 144 times.
2279 switch(to_lower(s[0]))
56 {
57 359 case 'f': // file
58
2/2
✓ Branch 2 taken 346 times.
✓ Branch 3 taken 1 times.
706 if( to_lower(s[1]) == 'i' &&
59
6/6
✓ Branch 0 taken 347 times.
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 345 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 345 times.
✓ Branch 7 taken 14 times.
706 to_lower(s[2]) == 'l' &&
60 346 to_lower(s[3]) == 'e')
61 345 return scheme::file;
62 14 break;
63
64 1776 case 'h': // http
65
2/2
✓ Branch 2 taken 1773 times.
✓ Branch 3 taken 1 times.
3550 if( to_lower(s[1]) == 't' &&
66
5/6
✓ Branch 0 taken 1774 times.
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1773 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1773 times.
✓ Branch 7 taken 3 times.
3550 to_lower(s[2]) == 't' &&
67 1773 to_lower(s[3]) == 'p')
68 1773 return scheme::http;
69 3 break;
70
71 144 default:
72 144 break;
73 }
74 161 break;
75
76 1209 case 5: // https
77
2/2
✓ Branch 2 taken 301 times.
✓ Branch 3 taken 1 times.
1511 if( to_lower(s[0]) == 'h' &&
78
2/2
✓ Branch 2 taken 300 times.
✓ Branch 3 taken 1 times.
603 to_lower(s[1]) == 't' &&
79
2/2
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 1 times.
601 to_lower(s[2]) == 't' &&
80
6/6
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 907 times.
✓ Branch 4 taken 292 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 292 times.
✓ Branch 7 taken 917 times.
1811 to_lower(s[3]) == 'p' &&
81 299 to_lower(s[4]) == 's')
82 292 return scheme::https;
83 917 break;
84
85 977 default:
86 977 break;
87 }
88 2326 return scheme::unknown;
89 }
90
91 core::string_view
92 51 to_string(scheme s) noexcept
93 {
94
8/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 21 times.
51 switch(s)
95 {
96 4 case scheme::ftp: return "ftp";
97 3 case scheme::file: return "file";
98 3 case scheme::http: return "http";
99 3 case scheme::https: return "https";
100 11 case scheme::ws: return "ws";
101 5 case scheme::wss: return "wss";
102 1 case scheme::none: return {};
103 21 default:
104 21 break;
105 }
106 21 return "<unknown>";
107 }
108
109 std::uint16_t
110 8 default_port(scheme s) noexcept
111 {
112
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
8 switch(s)
113 {
114 1 case scheme::ftp:
115 1 return 21;
116 2 case scheme::http:
117 case scheme::ws:
118 2 return 80;
119 2 case scheme::https:
120 case scheme::wss:
121 2 return 443;
122 3 default:
123 3 break;
124 }
125 3 return 0;
126 }
127
128 } // urls
129 } // boost
130
131