1
- /* auto-generated on 2025-02-11 09:47:50 -0500. Do not edit! */
1
+ /* auto-generated on 2025-02-23 20:08:55 -0500. Do not edit! */
2
2
/* begin file src/ada.cpp */
3
3
#include "ada.h"
4
4
/* begin file src/checkers.cpp */
@@ -64,23 +64,24 @@ ada_really_inline constexpr bool is_ipv4(std::string_view view) noexcept {
64
64
// encoding.
65
65
static constexpr std::array<uint8_t, 256> path_signature_table =
66
66
[]() consteval {
67
- std::array<uint8_t, 256> result{};
68
- for (size_t i = 0; i < 256; i++) {
69
- if (i <= 0x20 || i == 0x22 || i == 0x23 || i == 0x3c || i == 0x3e ||
70
- i == 0x3f || i == 0x60 || i == 0x7b || i == 0x7d || i > 0x7e) {
71
- result[i] = 1;
72
- } else if (i == 0x25) {
73
- result[i] = 8;
74
- } else if (i == 0x2e) {
75
- result[i] = 4;
76
- } else if (i == 0x5c) {
77
- result[i] = 2;
78
- } else {
79
- result[i] = 0;
80
- }
81
- }
82
- return result;
83
- }();
67
+ std::array<uint8_t, 256> result{};
68
+ for (size_t i = 0; i < 256; i++) {
69
+ if (i <= 0x20 || i == 0x22 || i == 0x23 || i == 0x3c || i == 0x3e ||
70
+ i == 0x3f || i == 0x60 || i == 0x7b || i == 0x7d || i > 0x7e) {
71
+ result[i] = 1;
72
+ } else if (i == 0x25) {
73
+ result[i] = 8;
74
+ } else if (i == 0x2e) {
75
+ result[i] = 4;
76
+ } else if (i == 0x5c) {
77
+ result[i] = 2;
78
+ } else {
79
+ result[i] = 0;
80
+ }
81
+ }
82
+ return result;
83
+ }
84
+ ();
84
85
85
86
ada_really_inline constexpr uint8_t path_signature(
86
87
std::string_view input) noexcept {
@@ -15225,7 +15226,7 @@ inline void url_aggregator::consume_prepared_path(std::string_view input) {
15225
15226
namespace ada {
15226
15227
15227
15228
tl::expected<url_pattern_init, errors> url_pattern_init::process(
15228
- url_pattern_init init, std::string_view type,
15229
+ url_pattern_init init, url_pattern_init::process_type type,
15229
15230
std::optional<std::string_view> protocol,
15230
15231
std::optional<std::string_view> username,
15231
15232
std::optional<std::string_view> password,
@@ -15287,8 +15288,8 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
15287
15288
// If type is not "pattern" and init contains none of "protocol",
15288
15289
// "hostname", "port" and "username", then set result["username"] to the
15289
15290
// result of processing a base URL string given baseURL’s username and type.
15290
- if (type != " pattern" && !init.protocol && !init.hostname && !init.port &&
15291
- !init.username) {
15291
+ if (type != process_type:: pattern && !init.protocol && !init.hostname &&
15292
+ !init.port && !init. username) {
15292
15293
result.username = url_pattern_helpers::process_base_url_string(
15293
15294
base_url->get_username(), type);
15294
15295
}
@@ -15298,8 +15299,8 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
15298
15299
// "hostname", "port", "username" and "password", then set
15299
15300
// result["password"] to the result of processing a base URL string given
15300
15301
// baseURL’s password and type.
15301
- if (type != " pattern" && !init.protocol && !init.hostname && !init.port &&
15302
- !init.username && !init.password) {
15302
+ if (type != process_type:: pattern && !init.protocol && !init.hostname &&
15303
+ !init.port && !init. username && !init.password) {
15303
15304
result.password = url_pattern_helpers::process_base_url_string(
15304
15305
base_url->get_password(), type);
15305
15306
}
@@ -15418,6 +15419,8 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
15418
15419
!url_pattern_helpers::is_absolute_pathname(*result.pathname, type)) {
15419
15420
// Let baseURLPath be the result of running process a base URL string
15420
15421
// given the result of URL path serializing baseURL and type.
15422
+ // TODO: Optimization opportunity: Avoid returning a string if no slash
15423
+ // exist.
15421
15424
std::string base_url_path = url_pattern_helpers::process_base_url_string(
15422
15425
base_url->get_pathname(), type);
15423
15426
@@ -15430,12 +15433,12 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
15430
15433
if (slash_index != std::string::npos) {
15431
15434
// Let new pathname be the code point substring from 0 to slash index +
15432
15435
// 1 within baseURLPath.
15433
- std::string new_pathname = base_url_path.substr(0, slash_index + 1);
15436
+ base_url_path.resize( slash_index + 1);
15434
15437
// Append result["pathname"] to the end of new pathname.
15435
15438
ADA_ASSERT_TRUE(result.pathname.has_value());
15436
- new_pathname .append(result.pathname.value( ));
15439
+ base_url_path .append(std::move(* result.pathname));
15437
15440
// Set result["pathname"] to new pathname.
15438
- result.pathname = std::move(new_pathname );
15441
+ result.pathname = std::move(base_url_path );
15439
15442
}
15440
15443
}
15441
15444
@@ -15473,56 +15476,56 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
15473
15476
}
15474
15477
15475
15478
tl::expected<std::string, errors> url_pattern_init::process_protocol(
15476
- std::string_view value, std::string_view type) {
15479
+ std::string_view value, process_type type) {
15477
15480
ada_log("process_protocol=", value, " [", type, "]");
15478
15481
// Let strippedValue be the given value with a single trailing U+003A (:)
15479
15482
// removed, if any.
15480
15483
if (value.ends_with(":")) {
15481
15484
value.remove_suffix(1);
15482
15485
}
15483
15486
// If type is "pattern" then return strippedValue.
15484
- if (type == " pattern" ) {
15487
+ if (type == process_type:: pattern) {
15485
15488
return std::string(value);
15486
15489
}
15487
15490
// Return the result of running canonicalize a protocol given strippedValue.
15488
15491
return url_pattern_helpers::canonicalize_protocol(value);
15489
15492
}
15490
15493
15491
15494
tl::expected<std::string, errors> url_pattern_init::process_username(
15492
- std::string_view value, std::string_view type) {
15495
+ std::string_view value, process_type type) {
15493
15496
// If type is "pattern" then return value.
15494
- if (type == " pattern" ) {
15497
+ if (type == process_type:: pattern) {
15495
15498
return std::string(value);
15496
15499
}
15497
15500
// Return the result of running canonicalize a username given value.
15498
15501
return url_pattern_helpers::canonicalize_username(value);
15499
15502
}
15500
15503
15501
15504
tl::expected<std::string, errors> url_pattern_init::process_password(
15502
- std::string_view value, std::string_view type) {
15505
+ std::string_view value, process_type type) {
15503
15506
// If type is "pattern" then return value.
15504
- if (type == " pattern" ) {
15507
+ if (type == process_type:: pattern) {
15505
15508
return std::string(value);
15506
15509
}
15507
15510
// Return the result of running canonicalize a password given value.
15508
15511
return url_pattern_helpers::canonicalize_password(value);
15509
15512
}
15510
15513
15511
15514
tl::expected<std::string, errors> url_pattern_init::process_hostname(
15512
- std::string_view value, std::string_view type) {
15515
+ std::string_view value, process_type type) {
15513
15516
ada_log("process_hostname value=", value, " type=", type);
15514
15517
// If type is "pattern" then return value.
15515
- if (type == " pattern" ) {
15518
+ if (type == process_type:: pattern) {
15516
15519
return std::string(value);
15517
15520
}
15518
15521
// Return the result of running canonicalize a hostname given value.
15519
15522
return url_pattern_helpers::canonicalize_hostname(value);
15520
15523
}
15521
15524
15522
15525
tl::expected<std::string, errors> url_pattern_init::process_port(
15523
- std::string_view port, std::string_view protocol, std::string_view type) {
15526
+ std::string_view port, std::string_view protocol, process_type type) {
15524
15527
// If type is "pattern" then return portValue.
15525
- if (type == " pattern" ) {
15528
+ if (type == process_type:: pattern) {
15526
15529
return std::string(port);
15527
15530
}
15528
15531
// Return the result of running canonicalize a port given portValue and
@@ -15531,9 +15534,9 @@ tl::expected<std::string, errors> url_pattern_init::process_port(
15531
15534
}
15532
15535
15533
15536
tl::expected<std::string, errors> url_pattern_init::process_pathname(
15534
- std::string_view value, std::string_view protocol, std::string_view type) {
15537
+ std::string_view value, std::string_view protocol, process_type type) {
15535
15538
// If type is "pattern" then return pathnameValue.
15536
- if (type == " pattern" ) {
15539
+ if (type == process_type:: pattern) {
15537
15540
return std::string(value);
15538
15541
}
15539
15542
@@ -15549,31 +15552,31 @@ tl::expected<std::string, errors> url_pattern_init::process_pathname(
15549
15552
}
15550
15553
15551
15554
tl::expected<std::string, errors> url_pattern_init::process_search(
15552
- std::string_view value, std::string_view type) {
15555
+ std::string_view value, process_type type) {
15553
15556
// Let strippedValue be the given value with a single leading U+003F (?)
15554
15557
// removed, if any.
15555
15558
if (value.starts_with("?")) {
15556
15559
value.remove_prefix(1);
15557
15560
}
15558
15561
ADA_ASSERT_TRUE(!value.starts_with("?"));
15559
15562
// If type is "pattern" then return strippedValue.
15560
- if (type == " pattern" ) {
15563
+ if (type == process_type:: pattern) {
15561
15564
return std::string(value);
15562
15565
}
15563
15566
// Return the result of running canonicalize a search given strippedValue.
15564
15567
return url_pattern_helpers::canonicalize_search(value);
15565
15568
}
15566
15569
15567
15570
tl::expected<std::string, errors> url_pattern_init::process_hash(
15568
- std::string_view value, std::string_view type) {
15571
+ std::string_view value, process_type type) {
15569
15572
// Let strippedValue be the given value with a single leading U+0023 (#)
15570
15573
// removed, if any.
15571
15574
if (value.starts_with("#")) {
15572
15575
value.remove_prefix(1);
15573
15576
}
15574
15577
ADA_ASSERT_TRUE(!value.starts_with("#"));
15575
15578
// If type is "pattern" then return strippedValue.
15576
- if (type == " pattern" ) {
15579
+ if (type == process_type:: pattern) {
15577
15580
return std::string(value);
15578
15581
}
15579
15582
// Return the result of running canonicalize a hash given strippedValue.
@@ -15599,7 +15602,6 @@ generate_regular_expression_and_name_list(
15599
15602
15600
15603
// Let name list be a new list
15601
15604
std::vector<std::string> name_list{};
15602
- const std::string full_wildcard_regexp_value = ".*";
15603
15605
15604
15606
// For each part of part list:
15605
15607
for (const url_pattern_part& part : part_list) {
@@ -15645,7 +15647,7 @@ generate_regular_expression_and_name_list(
15645
15647
// Otherwise if part's type is "full-wildcard"
15646
15648
else if (part.type == url_pattern_part_type::FULL_WILDCARD) {
15647
15649
// then set regexp value to full wildcard regexp value.
15648
- regexp_value = full_wildcard_regexp_value ;
15650
+ regexp_value = ".*" ;
15649
15651
}
15650
15652
15651
15653
// If part's prefix is the empty string and part's suffix is the empty
@@ -15724,7 +15726,7 @@ generate_regular_expression_and_name_list(
15724
15726
result += "$";
15725
15727
15726
15728
// Return (result, name list)
15727
- return {result, name_list};
15729
+ return {std::move( result), std::move( name_list) };
15728
15730
}
15729
15731
15730
15732
bool is_ipv6_address(std::string_view input) noexcept {
@@ -16387,33 +16389,31 @@ std::string escape_regexp_string(std::string_view input) {
16387
16389
}
16388
16390
16389
16391
std::string process_base_url_string(std::string_view input,
16390
- std::string_view type) {
16392
+ url_pattern_init::process_type type) {
16391
16393
// If type is not "pattern" return input.
16392
- if (type != " pattern" ) {
16394
+ if (type != url_pattern_init::process_type:: pattern) {
16393
16395
return std::string(input);
16394
16396
}
16395
16397
// Return the result of escaping a pattern string given input.
16396
16398
return escape_pattern_string(input);
16397
16399
}
16398
16400
16399
- constexpr bool is_absolute_pathname(std::string_view input,
16400
- std::string_view type) noexcept {
16401
+ constexpr bool is_absolute_pathname(
16402
+ std::string_view input, url_pattern_init::process_type type) noexcept {
16401
16403
// If input is the empty string, then return false.
16402
16404
if (input.empty()) [[unlikely]] {
16403
16405
return false;
16404
16406
}
16405
16407
// If input[0] is U+002F (/), then return true.
16406
16408
if (input.starts_with("/")) return true;
16407
16409
// If type is "url", then return false.
16408
- if (type == " url" ) return false;
16410
+ if (type == url_pattern_init::process_type:: url) return false;
16409
16411
// If input’s code point length is less than 2, then return false.
16410
16412
if (input.size() < 2) return false;
16411
16413
// If input[0] is U+005C (\) and input[1] is U+002F (/), then return true.
16412
- if (input.starts_with("\\/")) return true;
16413
16414
// If input[0] is U+007B ({) and input[1] is U+002F (/), then return true.
16414
- if (input.starts_with("{/")) return true;
16415
16415
// Return false.
16416
- return false ;
16416
+ return input[1] == '/' && (input[0] == '\\' || input[0] == '{') ;
16417
16417
}
16418
16418
16419
16419
std::string generate_pattern_string(
0 commit comments