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