Ada 3.1.0
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
checkers-inl.h
Go to the documentation of this file.
1
5#ifndef ADA_CHECKERS_INL_H
6#define ADA_CHECKERS_INL_H
7
8#include <bit>
9#include <string_view>
10
11namespace ada::checkers {
12
13constexpr bool has_hex_prefix_unsafe(std::string_view input) {
14 // This is actually efficient code, see has_hex_prefix for the assembly.
15 constexpr bool is_little_endian = std::endian::native == std::endian::little;
16 constexpr uint16_t word0x = 0x7830;
17 uint16_t two_first_bytes =
18 static_cast<uint16_t>(input[0]) |
19 static_cast<uint16_t>((static_cast<uint16_t>(input[1]) << 8));
20 if constexpr (is_little_endian) {
21 two_first_bytes |= 0x2000;
22 } else {
23 two_first_bytes |= 0x020;
24 }
25 return two_first_bytes == word0x;
26}
27
28constexpr bool has_hex_prefix(std::string_view input) {
29 return input.size() >= 2 && has_hex_prefix_unsafe(input);
30}
31
32constexpr bool is_digit(char x) noexcept { return (x >= '0') & (x <= '9'); }
33
34constexpr char to_lower(char x) noexcept { return (x | 0x20); }
35
36constexpr bool is_alpha(char x) noexcept {
37 return (to_lower(x) >= 'a') && (to_lower(x) <= 'z');
38}
39
40constexpr bool is_windows_drive_letter(std::string_view input) noexcept {
41 return input.size() >= 2 &&
42 (is_alpha(input[0]) && ((input[1] == ':') || (input[1] == '|'))) &&
43 ((input.size() == 2) || (input[2] == '/' || input[2] == '\\' ||
44 input[2] == '?' || input[2] == '#'));
45}
46
48 std::string_view input) noexcept {
49 return input.size() >= 2 && (is_alpha(input[0]) && (input[1] == ':'));
50}
51
52} // namespace ada::checkers
53
54#endif // ADA_CHECKERS_INL_H
Includes the definitions for validation functions.
constexpr bool has_hex_prefix_unsafe(std::string_view input)
constexpr bool has_hex_prefix(std::string_view input)
constexpr bool is_normalized_windows_drive_letter(std::string_view input) noexcept
constexpr bool is_windows_drive_letter(std::string_view input) noexcept
constexpr char to_lower(char x) noexcept
constexpr bool is_alpha(char x) noexcept
constexpr bool is_digit(char x) noexcept