Ada 4.1.1
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
ada::checkers Namespace Reference

Includes the definitions for validation functions. More...

Namespaces

namespace  detail

Functions

constexpr bool is_digit (char x) noexcept
constexpr bool is_ipv4_number_char (char x) noexcept
constexpr bool last_label_may_be_a_number (std::string_view view) noexcept
constexpr char to_lower (char x) noexcept
constexpr bool is_alpha (char x) noexcept
constexpr bool is_windows_drive_letter (std::string_view input) noexcept
constexpr bool is_normalized_windows_drive_letter (std::string_view input) noexcept
ada_really_inline uint64_t try_parse_ipv4_fast (std::string_view input) noexcept

Variables

constexpr uint64_t ipv4_fast_fail = uint64_t(1) << 32
static constexpr std::array< uint8_t, 256 > path_signature_table

Detailed Description

Includes the definitions for validation functions.

These functions are not part of our public API and may change at any time.

Function Documentation

◆ is_alpha()

bool ada::checkers::is_alpha ( char x)
constexprnoexcept

Returns true if the character is an ASCII letter. Equivalent to std::isalpha but more likely to be inlined by the compiler.

Attention
std::isalpha is not constexpr generally.

Definition at line 56 of file checkers-inl.h.

References to_lower().

Referenced by is_normalized_windows_drive_letter(), is_windows_drive_letter(), LLVMFuzzerTestOneInput(), ada::parser::parse_url_impl(), ada::url::set_protocol(), ada::url_aggregator::set_protocol(), and ada::anonymous_namespace{implementation.cpp}::try_can_parse_absolute_fast().

◆ is_digit()

bool ada::checkers::is_digit ( char x)
constexprnoexcept

Check whether x is an ASCII digit. More likely to be inlined than std::isdigit.

Definition at line 21 of file checkers-inl.h.

Referenced by last_label_may_be_a_number(), and LLVMFuzzerTestOneInput().

◆ is_ipv4_number_char()

bool ada::checkers::is_ipv4_number_char ( char x)
constexprnoexcept

Definition at line 23 of file checkers-inl.h.

Referenced by last_label_may_be_a_number().

◆ is_normalized_windows_drive_letter()

bool ada::checkers::is_normalized_windows_drive_letter ( std::string_view input)
inlineconstexprnoexcept

A normalized Windows drive letter is a Windows drive letter of which the second code point is U+003A (:).

Definition at line 67 of file checkers-inl.h.

References is_alpha().

Referenced by LLVMFuzzerTestOneInput(), and ada::parser::parse_url_impl().

◆ is_windows_drive_letter()

bool ada::checkers::is_windows_drive_letter ( std::string_view input)
inlineconstexprnoexcept

A string starts with a Windows drive letter if all of the following are true:

  • its length is greater than or equal to 2
  • its first two code points are a Windows drive letter
  • its length is 2 or its third code point is U+002F (/), U+005C (), U+003F (?), or U+0023 (#).

https://url.spec.whatwg.org/#start-with-a-windows-drive-letter

Definition at line 60 of file checkers-inl.h.

References is_alpha().

Referenced by LLVMFuzzerTestOneInput(), and ada::parser::parse_url_impl().

◆ last_label_may_be_a_number()

ada_really_inline constexpr bool ada::checkers::last_label_may_be_a_number ( std::string_view view)
constexprnoexcept

Cheap pre-check for the WHATWG "ends in a number" / IPv4-host cases. False means the host cannot be IPv4: the last label is empty, does not start with an ASCII digit, or contains a character other than a hex digit or x/X. True means the slower IPv4 parsers should run.

Safe on mixed-case input (unlike is_ipv4, which expects a lowercased host).

Definition at line 29 of file checkers-inl.h.

References is_digit(), and is_ipv4_number_char().

Referenced by ada::anonymous_namespace{implementation.cpp}::try_can_parse_absolute_fast(), ada::anonymous_namespace{implementation.cpp}::try_can_parse_clean_http(), and ada::parser::try_parse_simple_absolute().

◆ to_lower()

char ada::checkers::to_lower ( char x)
constexprnoexcept

Assuming that x is an ASCII letter, this function returns the lower case equivalent.

More likely to be inlined by the compiler and constexpr.

Definition at line 54 of file checkers-inl.h.

Referenced by is_alpha(), and LLVMFuzzerTestOneInput().

◆ try_parse_ipv4_fast()

ada_really_inline uint64_t ada::checkers::try_parse_ipv4_fast ( std::string_view input)
noexcept

Fast pure-decimal IPv4 parse. Returns packed address or ipv4_fast_fail. Accepts an optional single trailing dot.

On AVX-512BW+VL+VBMI2 targets, uses a table-free SIMD parse (masked load, no source over-read) based on parse_ipv4_avx512vl_notab5. Otherwise uses an unrolled scalar path (typically faster than SSE2/NEON pre-validation for these 7-16 byte hosts).

Fast-path parser for pure decimal IPv4 addresses (e.g., "192.168.1.1"). Returns the packed 32-bit IPv4 address on success, or a value > 0xFFFFFFFF to indicate failure (caller should fall back to general parser). This is optimized for the common case where the input is a well-formed decimal IPv4 address with exactly 4 octets.

Definition at line 235 of file checkers-inl.h.

References ipv4_fast_fail, and ada::checkers::detail::parse_ipv4_decimal_scalar().

Referenced by LLVMFuzzerTestOneInput(), and ada::anonymous_namespace{implementation.cpp}::try_can_parse_absolute_fast().

Variable Documentation

◆ ipv4_fast_fail

uint64_t ada::checkers::ipv4_fast_fail = uint64_t(1) << 32
constexpr

Sentinel value indicating try_parse_ipv4_fast() did not succeed. Any value > 0xFFFFFFFF indicates the fast path should not be used.

Definition at line 128 of file checkers.h.

Referenced by ada::checkers::detail::parse_ipv4_decimal_scalar(), ada::anonymous_namespace{implementation.cpp}::try_can_parse_absolute_fast(), and try_parse_ipv4_fast().

◆ path_signature_table

std::array<uint8_t, 256> ada::checkers::path_signature_table
staticconstexpr
Initial value:
=
[]() consteval {
std::array<uint8_t, 256> result{};
for (size_t i = 0; i < 256; i++) {
if (i <= 0x20 || i == 0x22 || i == 0x23 || i == 0x3c || i == 0x3e ||
i == 0x3f || i == 0x5e || i == 0x60 || i == 0x7b || i == 0x7d ||
i > 0x7e) {
result[i] = 1;
} else if (i == 0x25) {
result[i] = 8;
} else if (i == 0x2e) {
result[i] = 4;
} else if (i == 0x5c) {
result[i] = 2;
} else {
result[i] = 0;
}
}
return result;
}()
tl::expected< result_type, ada::errors > result

Definition at line 55 of file checkers.cpp.