scheme.ipp
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//
#ifndef BOOST_URL_IMPL_SCHEME_IPP
#define BOOST_URL_IMPL_SCHEME_IPP
#include <boost/url/scheme.hpp>
#include <boost/url/grammar/ci_string.hpp>
namespace boost {
namespace urls {
scheme
string_to_scheme(
string_view s) noexcept
{
using grammar::to_lower;
switch(s.size())
{
case 0: // none
return scheme::none;
case 2: // ws
if( to_lower(s[0]) == 'w' &&
to_lower(s[1]) == 's')
return scheme::ws;
break;
case 3:
switch(to_lower(s[0]))
{
case 'w': // wss
if( to_lower(s[1]) == 's' &&
to_lower(s[2]) == 's')
return scheme::wss;
break;
case 'f': // ftp
if( to_lower(s[1]) == 't' &&
to_lower(s[2]) == 'p')
return scheme::ftp;
break;
default:
break;
}
break;
case 4:
switch(to_lower(s[0]))
{
case 'f': // file
if( to_lower(s[1]) == 'i' &&
to_lower(s[2]) == 'l' &&
to_lower(s[3]) == 'e')
return scheme::file;
break;
case 'h': // http
if( to_lower(s[1]) == 't' &&
to_lower(s[2]) == 't' &&
to_lower(s[3]) == 'p')
return scheme::http;
break;
default:
break;
}
break;
case 5: // https
if( to_lower(s[0]) == 'h' &&
to_lower(s[1]) == 't' &&
to_lower(s[2]) == 't' &&
to_lower(s[3]) == 'p' &&
to_lower(s[4]) == 's')
return scheme::https;
break;
default:
break;
}
return scheme::unknown;
}
string_view
to_string(scheme s) noexcept
{
switch(s)
{
case scheme::ftp: return "ftp";
case scheme::file: return "file";
case scheme::http: return "http";
case scheme::https: return "https";
case scheme::ws: return "ws";
case scheme::wss: return "wss";
case scheme::none: return {};
default:
break;
}
return "<unknown>";
}
std::uint16_t
default_port(scheme s) noexcept
{
switch(s)
{
case scheme::ftp:
return 21;
case scheme::http:
case scheme::ws:
return 80;
case scheme::https:
case scheme::wss:
return 443;
default:
break;
}
return 0;
}
} // urls
} // boost
#endif