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

Includes the declarations for unicode operations. More...

Namespaces

namespace  anonymous_namespace{unicode_percent_encode.cpp}

Functions

ada_really_inline size_t percent_encode_index (const std::string_view input, const uint8_t character_set[])
std::string form_urlencoded_decode (std::string_view input)
constexpr bool is_tabs_or_newline (char c) noexcept
constexpr uint64_t broadcast (uint8_t v) noexcept
void percent_encode_suffix (const char *p, const char *end, const uint8_t character_set[], std::string &out)
template bool percent_encode< true > (std::string_view input, const uint8_t character_set[], std::string &out)
template bool percent_encode< false > (std::string_view input, const uint8_t character_set[], std::string &out)

Variables

static constexpr std::array< uint8_t, 256 > is_forbidden_host_code_point_table
static constexpr std::array< uint8_t, 256 > is_forbidden_domain_code_point_table
static constexpr std::array< uint8_t, 256 > is_forbidden_domain_code_point_table_or_upper
static constexpr std::array< bool, 256 > is_alnum_plus_table
constexpr std::string_view table_is_double_dot_path_segment []
static constexpr char hex_to_binary_table []
static constexpr std::array< uint8_t, 256 > unhex_table

Detailed Description

Includes the declarations for unicode operations.

Includes the definitions for unicode operations.

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

private

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

Function Documentation

◆ broadcast()

uint64_t ada::unicode::broadcast ( uint8_t v)
constexprnoexcept

Definition at line 41 of file unicode.cpp.

◆ form_urlencoded_decode()

std::string ada::unicode::form_urlencoded_decode ( std::string_view input)

Decode an application/x-www-form-urlencoded component: map '+' to space, then percent-decode. Single allocation; no intermediate string.

Parameters
inputA form-urlencoded component (key or value).
Returns
The decoded string.
See also
https://url.spec.whatwg.org/#concept-urlencoded-parser

Definition at line 538 of file unicode.cpp.

References unhex_table.

◆ is_tabs_or_newline()

bool ada::unicode::is_tabs_or_newline ( char c)
constexprnoexcept

Definition at line 37 of file unicode.cpp.

◆ percent_encode< false >()

template bool ada::unicode::percent_encode< false > ( std::string_view input,
const uint8_t character_set[],
std::string & out )

Referenced by LLVMFuzzerTestOneInput().

◆ percent_encode< true >()

template bool ada::unicode::percent_encode< true > ( std::string_view input,
const uint8_t character_set[],
std::string & out )

Referenced by LLVMFuzzerTestOneInput().

◆ percent_encode_index()

ada_really_inline size_t ada::unicode::percent_encode_index ( std::string_view input,
const uint8_t character_set[] )

Returns the index at which percent encoding should start, or (equivalently), the length of the prefix that does not require percent encoding.

Definition at line 24 of file unicode-inl.h.

References ada_really_inline, and ada::character_sets::bit_at().

Referenced by LLVMFuzzerTestOneInput(), ada::url_aggregator::set_password(), and ada::url_aggregator::set_username().

◆ percent_encode_suffix()

void ada::unicode::percent_encode_suffix ( const char * p,
const char * end,
const uint8_t character_set[],
std::string & out )

Definition at line 296 of file unicode_percent_encode.cpp.

Variable Documentation

◆ hex_to_binary_table

char ada::unicode::hex_to_binary_table[]
staticconstexpr
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11,
12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}

Definition at line 461 of file unicode.cpp.

◆ is_alnum_plus_table

std::array<bool, 256> ada::unicode::is_alnum_plus_table
staticconstexpr
Initial value:
= []() consteval {
std::array<bool, 256> result{};
for (size_t c = 0; c < 256; c++) {
result[c] = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') || c == '+' || c == '-' || c == '.';
}
return result;
}()
tl::expected< result_type, ada::errors > result

Definition at line 359 of file unicode.cpp.

◆ is_forbidden_domain_code_point_table

std::array<uint8_t, 256> ada::unicode::is_forbidden_domain_code_point_table
staticconstexpr
Initial value:
=
[]() consteval {
std::array<uint8_t, 256> result{};
for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<',
'>', '?', '@', '[', '\\', ']', '^', '|', '%'}) {
result[c] = true;
}
for (uint8_t c = 0; c <= 32; c++) {
result[c] = true;
}
for (size_t c = 127; c < 256; c++) {
result[c] = true;
}
return result;
}()

Definition at line 278 of file unicode.cpp.

◆ is_forbidden_domain_code_point_table_or_upper

std::array<uint8_t, 256> ada::unicode::is_forbidden_domain_code_point_table_or_upper
staticconstexpr
Initial value:
= []() consteval {
std::array<uint8_t, 256> result{};
for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<',
'>', '?', '@', '[', '\\', ']', '^', '|', '%'}) {
result[c] = 1;
}
for (uint8_t c = 'A'; c <= 'Z'; c++) {
result[c] = 2;
}
for (uint8_t c = 0; c <= 32; c++) {
result[c] = 1;
}
for (size_t c = 127; c < 256; c++) {
result[c] = 1;
}
return result;
}()

Definition at line 318 of file unicode.cpp.

◆ is_forbidden_host_code_point_table

std::array<uint8_t, 256> ada::unicode::is_forbidden_host_code_point_table
staticconstexpr
Initial value:
=
[]() consteval {
std::array<uint8_t, 256> result{};
for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<',
'>', '?', '@', '[', '\\', ']', '^', '|'}) {
result[c] = true;
}
return result;
}()

Definition at line 263 of file unicode.cpp.

◆ table_is_double_dot_path_segment

std::string_view ada::unicode::table_is_double_dot_path_segment[]
constexpr
Initial value:
= {
"..", "%2e.", ".%2e", "%2e%2e"}

Definition at line 400 of file unicode.cpp.

◆ unhex_table

std::array<uint8_t, 256> ada::unicode::unhex_table
staticconstexpr
Initial value:
= []() consteval {
std::array<uint8_t, 256> t{};
for (size_t i = 0; i < 256; ++i) {
t[i] = 0xFF;
}
for (uint8_t i = 0; i < 10; ++i) {
t[static_cast<size_t>('0') + i] = i;
}
for (uint8_t i = 0; i < 6; ++i) {
t[static_cast<size_t>('A') + i] = static_cast<uint8_t>(10 + i);
t[static_cast<size_t>('a') + i] = static_cast<uint8_t>(10 + i);
}
return t;
}()

Definition at line 523 of file unicode.cpp.

Referenced by form_urlencoded_decode().