Ada 2.9.2
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
10namespace ada::scheme {
11
16namespace details {
17// for use with is_special and get_special_port
18// Spaces, if present, are removed from URL.
19constexpr std::string_view is_special_list[] = {"http", " ", "https", "ws",
20 "ftp", "wss", "file", " "};
21// for use with get_special_port
22constexpr uint16_t special_ports[] = {80, 0, 443, 80, 21, 443, 0, 0};
23} // namespace details
24
25
49ada_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}
57constexpr 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}
69constexpr uint16_t get_special_port(ada::scheme::type type) noexcept {
70 return details::special_ports[int(type)];
71}
72constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept {
73 if (scheme.empty()) {
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 {
82 }
83}
84
85} // namespace ada::scheme
86
87#endif // ADA_SCHEME_INL_H
#define ada_really_inline
Definition common_defs.h:77
constexpr std::string_view is_special_list[]
Definition scheme-inl.h:19
constexpr uint16_t special_ports[]
Definition scheme-inl.h:22
Includes the scheme declarations.
Definition scheme-inl.h:10
constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept
Definition scheme-inl.h:72
@ NOT_SPECIAL
Definition scheme.h:31
constexpr uint16_t get_special_port(std::string_view scheme) noexcept
Definition scheme-inl.h:57
Declarations for the URL scheme.