1#if ADA_INCLUDE_URL_PATTERN
18std::tuple<std::string, std::vector<std::string>>
20 const std::vector<url_pattern_part>&
part_list,
37 if (
part.type == url_pattern_part_type::FIXED_TEXT) {
39 if (
part.modifier == url_pattern_part_modifier::none) {
58 if (
part.type == url_pattern_part_type::SEGMENT_WILDCARD) {
64 }
else if (
part.type == url_pattern_part_type::FULL_WILDCARD) {
70 if (
part.prefix.empty() &&
part.suffix.empty()) {
72 if (
part.modifier == url_pattern_part_modifier::none ||
73 part.modifier == url_pattern_part_modifier::optional) {
91 if (
part.modifier == url_pattern_part_modifier::none ||
92 part.modifier == url_pattern_part_modifier::optional) {
107 part.modifier == url_pattern_part_modifier::one_or_more);
145 if (
part.modifier == url_pattern_part_modifier::zero_or_more) {
159 if (
input.size() < 2)
return false;
163 if (
input.front() ==
'[')
return true;
166 if (
input.starts_with(
"{["))
return true;
169 return input.starts_with(
"\\[");
176 case url_pattern_part_modifier::zero_or_more:
179 case url_pattern_part_modifier::optional:
182 case url_pattern_part_modifier::one_or_more:
193 std::string
result =
"[^";
200 ada_log(
"generate_segment_wildcard_regexp result: ",
result);
214 std::array<uint8_t, 256>
table{};
215 for (
int c =
'a';
c <=
'z';
c++)
217 for (
int c =
'A';
c <=
'Z';
c++)
219 for (
int c =
'0';
c <=
'9';
c++)
233 std::string_view
input) {
234 ada_log(
"canonicalize_protocol called with input=",
input);
239 if (
input.ends_with(
":")) {
240 input.remove_suffix(1);
244 if (scheme::is_special(
input)) {
245 return std::string(
input);
252 input[0] ==
'.' || unicode::is_ascii_digit(
input[0])) {
257 for (
size_t i = 1;
i <
input.size();
i++) {
266 return std::string(
input);
275 std::string_view
input) {
285 return std::string(
input);
288 return ada::unicode::percent_encode(
293 std::string_view
input) {
303 return std::string(
input);
306 return ada::unicode::percent_encode(
311 std::string_view
input) {
324 return std::string(
input);
336 if (!url->set_hostname(
input)) {
341 return std::string(url->get_hostname());
345 std::string_view
input) {
348 if (std::ranges::any_of(
input, [](
char c) {
349 return c !=
'[' &&
c !=
']' &&
c !=
':' &&
350 !unicode::is_ascii_hex_digit(
c);
370 helpers::remove_ascii_tab_or_newline(
trimmed);
377 if (!unicode::is_ascii_digit(
trimmed.front())) {
383 std::ranges::find_if_not(
trimmed, unicode::is_ascii_digit);
418 }
else if (
protocol.ends_with(
":")) {
424 helpers::remove_ascii_tab_or_newline(
trimmed);
431 if (!unicode::is_ascii_digit(
trimmed.front())) {
437 std::ranges::find_if_not(
trimmed, unicode::is_ascii_digit);
447 if (
result.ec == std::errc::result_out_of_range) {
451 if (
result.ec == std::errc()) {
468 std::string_view
input) {
481 return std::string(
input);
493 const auto pathname = url->get_pathname();
502 return std::string(
pathname.substr(2));
511 std::string_view
input) {
523 return std::string(url->get_pathname());
538 helpers::remove_ascii_tab_or_newline(
new_value);
554 return ada::unicode::percent_encode(
567 helpers::remove_ascii_tab_or_newline(
new_value);
581 return ada::unicode::percent_encode(
602 tokenizer.add_token_with_defaults(token_type::ASTERISK);
612 tokenizer.add_token_with_defaults(token_type::OTHER_MODIFIER);
626 ada_log(
"process_tokenizing_error failed");
627 return tl::unexpected(*
error);
650 tokenizer.add_token_with_defaults(token_type::OPEN);
659 tokenizer.add_token_with_defaults(token_type::CLOSE);
697 ada_log(
"process_tokenizing_error failed");
698 return tl::unexpected(*
error);
732 if (!unicode::is_ascii(
tokenizer.code_point)) {
776 if (!unicode::is_ascii(
tokenizer.code_point)) {
804 }
else if (
tokenizer.code_point ==
'(') {
864 ada_log(
"process_tokenizing_error failed");
877 tokenizer.add_token_with_defaults(token_type::CHAR);
891 std::array<uint8_t, 256>
out{};
892 for (
auto&
c : {
'+',
'*',
'?',
':',
'{',
'}',
'(',
')',
'\\'}) {
904 ada_log(
"escape_pattern_string called with input=",
input);
916 for (
const char c :
input) {
930 std::array<uint8_t, 256>
out{};
931 for (
auto&
c : {
'.',
'+',
'*',
'?',
'^',
'$',
'{',
'}',
'(',
')',
'[',
']',
950 for (
const char c :
input) {
963 url_pattern_init::process_type type) {
965 if (type != url_pattern_init::process_type::pattern) {
966 return std::string(
input);
973 std::string_view
input, url_pattern_init::process_type type)
noexcept {
979 if (
input.starts_with(
"/"))
return true;
981 if (type == url_pattern_init::process_type::url)
return false;
983 if (
input.size() < 2)
return false;
991 std::vector<url_pattern_part>&
part_list,
997 for (
size_t index = 0; index <
part_list.size(); index++) {
1011 if (
part.type == url_pattern_part_type::FIXED_TEXT) {
1013 if (
part.modifier == url_pattern_part_modifier::none) {
1040 !
part.suffix.empty() ||
1041 (!
part.prefix.empty() && !
options.get_prefix().empty() &&
1053 part.type == url_pattern_part_type::SEGMENT_WILDCARD &&
1054 part.modifier == url_pattern_part_modifier::none &&
next_part &&
1057 if (
next_part->type == url_pattern_part_type::FIXED_TEXT) {
1067 unicode::is_ascii_digit(
next_part->name[0]);
1106 if (
part.type == url_pattern_part_type::REGEXP) {
1113 }
else if (
part.type == url_pattern_part_type::SEGMENT_WILDCARD &&
1123 }
else if (
part.type == url_pattern_part_type::FULL_WILDCARD) {
1135 previous_part->modifier != url_pattern_part_modifier::none ||
1153 if (
part.type == url_pattern_part_type::SEGMENT_WILDCARD &&
custom_name &&
1154 !
part.suffix.empty() &&
Declaration of the character sets used by unicode functions.
#define ADA_ASSERT_TRUE(COND)
Definitions for helper functions used within Ada.
constexpr uint8_t QUERY_PERCENT_ENCODE[32]
constexpr uint8_t USERINFO_PERCENT_ENCODE[32]
constexpr uint8_t FRAGMENT_PERCENT_ENCODE[32]
bool constexpr is_ascii(std::u32string_view view)
bool valid_name_code_point(char32_t code_point, bool first)
const uint32_t table[8198][2]
constexpr uint16_t get_special_port(std::string_view scheme) noexcept
ada_really_inline size_t percent_encode_index(const std::string_view input, const uint8_t character_set[])
errors
Error codes for URL parsing operations.
tl::expected< result_type, ada::errors > result
template ada::result< url_aggregator > parse< url_aggregator >(std::string_view input, const url_aggregator *base_url)
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
URL scheme type definitions and utilities.
Definitions for all unicode specific functions.
Declaration for the URLPattern helpers.