Ada
3.1.0
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
scheme-inl.h
Go to the documentation of this file.
1
5
#ifndef ADA_SCHEME_INL_H
6
#define ADA_SCHEME_INL_H
7
8
#include "
ada/scheme.h
"
9
10
namespace
ada::scheme
{
11
16
namespace
details
{
17
// for use with is_special and get_special_port
18
// Spaces, if present, are removed from URL.
19
constexpr
std::string_view
is_special_list
[] = {
"http"
,
" "
,
"https"
,
"ws"
,
20
"ftp"
,
"wss"
,
"file"
,
" "
};
21
// for use with get_special_port
22
constexpr
uint16_t
special_ports
[] = {80, 0, 443, 80, 21, 443, 0, 0};
23
}
// namespace details
24
25
48
49
ada_really_inline
constexpr
bool
is_special(std::string_view
scheme
) {
50
if
(
scheme
.empty()) {
51
return
false
;
52
}
53
int
hash_value = (2 * scheme.size() + (
unsigned
)(scheme[0])) & 7;
54
const
std::string_view target =
details::is_special_list
[hash_value];
55
return
(target[0] == scheme[0]) && (target.substr(1) == scheme.substr(1));
56
}
57
constexpr
uint16_t
get_special_port
(std::string_view
scheme
)
noexcept
{
58
if
(
scheme
.empty()) {
59
return
0;
60
}
61
int
hash_value = (2 *
scheme
.size() + (
unsigned
)(
scheme
[0])) & 7;
62
const
std::string_view target =
details::is_special_list
[hash_value];
63
if
((target[0] ==
scheme
[0]) && (target.substr(1) ==
scheme
.substr(1))) {
64
return
details::special_ports
[hash_value];
65
}
else
{
66
return
0;
67
}
68
}
69
constexpr
uint16_t
get_special_port
(
ada::scheme::type
type
)
noexcept
{
70
return
details::special_ports
[int(
type
)];
71
}
72
constexpr
ada::scheme::type
get_scheme_type
(std::string_view
scheme
)
noexcept
{
73
if
(
scheme
.empty()) {
74
return
ada::scheme::NOT_SPECIAL
;
75
}
76
int
hash_value = (2 *
scheme
.size() + (
unsigned
)(
scheme
[0])) & 7;
77
const
std::string_view target =
details::is_special_list
[hash_value];
78
if
((target[0] ==
scheme
[0]) && (target.substr(1) ==
scheme
.substr(1))) {
79
return
ada::scheme::type
(hash_value);
80
}
else
{
81
return
ada::scheme::NOT_SPECIAL
;
82
}
83
}
84
85
}
// namespace ada::scheme
86
87
#endif
// ADA_SCHEME_INL_H
ada_really_inline
#define ada_really_inline
Definition
common_defs.h:81
ada::scheme::details
Includes the definitions for scheme specific entities.
ada::scheme::details::is_special_list
constexpr std::string_view is_special_list[]
Definition
scheme-inl.h:19
ada::scheme::details::special_ports
constexpr uint16_t special_ports[]
Definition
scheme-inl.h:22
ada::scheme
Includes the scheme declarations.
Definition
scheme-inl.h:10
ada::scheme::get_scheme_type
constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept
Definition
scheme-inl.h:72
ada::scheme::type
type
Definition
scheme.h:28
ada::scheme::NOT_SPECIAL
@ NOT_SPECIAL
Definition
scheme.h:30
ada::scheme::get_special_port
constexpr uint16_t get_special_port(std::string_view scheme) noexcept
Definition
scheme-inl.h:57
scheme.h
Declarations for the URL scheme.