Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update ada to 2.6.9 #49340

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 101 additions & 44 deletions deps/ada/ada.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2023-07-23 15:03:22 -0400. Do not edit! */
/* auto-generated on 2023-09-29 13:28:16 -0400. Do not edit! */
/* begin file src/ada.cpp */
#include "ada.h"
/* begin file src/checkers.cpp */
Expand Down Expand Up @@ -116,10 +116,11 @@ ada_really_inline constexpr bool verify_dns_length(

ADA_PUSH_DISABLE_ALL_WARNINGS
/* begin file src/ada_idna.cpp */
/* auto-generated on 2023-05-07 19:12:14 -0400. Do not edit! */
/* auto-generated on 2023-09-19 15:58:51 -0400. Do not edit! */
/* begin file src/idna.cpp */
/* begin file src/unicode_transcoding.cpp */

#include <algorithm>
#include <cstdint>
#include <cstring>

Expand Down Expand Up @@ -226,38 +227,22 @@ size_t utf8_length_from_utf32(const char32_t* buf, size_t len) {
// We are not BOM aware.
const uint32_t* p = reinterpret_cast<const uint32_t*>(buf);
size_t counter{0};
for (size_t i = 0; i < len; i++) {
/** ASCII **/
if (p[i] <= 0x7F) {
counter++;
}
/** two-byte **/
else if (p[i] <= 0x7FF) {
counter += 2;
}
/** three-byte **/
else if (p[i] <= 0xFFFF) {
counter += 3;
}
/** four-bytes **/
else {
counter += 4;
}
for (size_t i = 0; i != len; ++i) {
++counter; // ASCII
counter += static_cast<size_t>(p[i] > 0x7F); // two-byte
counter += static_cast<size_t>(p[i] > 0x7FF); // three-byte
counter += static_cast<size_t>(p[i] > 0xFFFF); // four-bytes
}
return counter;
}

size_t utf32_length_from_utf8(const char* buf, size_t len) {
const int8_t* p = reinterpret_cast<const int8_t*>(buf);
size_t counter{0};
for (size_t i = 0; i < len; i++) {
return std::count_if(p, std::next(p, len), [](int8_t c) {
// -65 is 0b10111111, anything larger in two-complement's
// should start a new code point.
if (p[i] > -65) {
counter++;
}
}
return counter;
return c > -65;
});
}

size_t utf32_to_utf8(const char32_t* buf, size_t len, char* utf8_output) {
Expand Down Expand Up @@ -9520,19 +9505,20 @@ bool is_label_valid(const std::u32string_view label) {

namespace ada::idna {

bool constexpr begins_with(std::u32string_view view,
std::u32string_view prefix) {
bool begins_with(std::u32string_view view, std::u32string_view prefix) {
if (view.size() < prefix.size()) {
return false;
}
return view.substr(0, prefix.size()) == prefix;
// constexpr as of C++20
return std::equal(prefix.begin(), prefix.end(), view.begin());
}

bool constexpr begins_with(std::string_view view, std::string_view prefix) {
bool begins_with(std::string_view view, std::string_view prefix) {
if (view.size() < prefix.size()) {
return false;
}
return view.substr(0, prefix.size()) == prefix;
// constexpr as of C++20
return std::equal(prefix.begin(), prefix.end(), view.begin());
}

bool constexpr is_ascii(std::u32string_view view) {
Expand Down Expand Up @@ -10144,13 +10130,12 @@ ada_really_inline constexpr bool is_lowercase_hex(const char c) noexcept {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
}

constexpr static char hex_to_binary_table[] = {
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};
unsigned constexpr convert_hex_to_binary(const char c) noexcept {
// this code can be optimized.
if (c <= '9') {
return c - '0';
}
char del = c >= 'a' ? 'a' : 'A';
return 10 + (c - del);
return hex_to_binary_table[c - '0'];
}

std::string percent_decode(const std::string_view input, size_t first_percent) {
Expand All @@ -10159,8 +10144,9 @@ std::string percent_decode(const std::string_view input, size_t first_percent) {
if (first_percent == std::string_view::npos) {
return std::string(input);
}
std::string dest(input.substr(0, first_percent));
std::string dest;
dest.reserve(input.length());
dest.append(input.substr(0, first_percent));
const char* pointer = input.data() + first_percent;
const char* end = input.data() + input.size();
// Optimization opportunity: if the following code gets
Expand Down Expand Up @@ -10197,9 +10183,10 @@ std::string percent_encode(const std::string_view input,
return std::string(input);
}

std::string result(input.substr(0, std::distance(input.begin(), pointer)));
std::string result;
result.reserve(input.length()); // in the worst case, percent encoding might
// produce 3 characters.
result.append(input.substr(0, std::distance(input.begin(), pointer)));

for (; pointer != input.end(); pointer++) {
if (character_sets::bit_at(character_set, *pointer)) {
Expand Down Expand Up @@ -11231,6 +11218,7 @@ bool url::parse_ipv4(std::string_view input) {
} else {
host = ada::serializers::ipv4(ipv4); // We have to reserialize the address.
}
host_type = IPV4;
return true;
}

Expand Down Expand Up @@ -11460,6 +11448,7 @@ bool url::parse_ipv6(std::string_view input) {
}
host = ada::serializers::ipv6(address);
ada_log("parse_ipv6 ", *host);
host_type = IPV6;
return true;
}

Expand Down Expand Up @@ -11876,7 +11865,7 @@ bool url::set_host_or_hostname(const std::string_view input) {
}

// Let host be the result of host parsing host_view with url is not special.
if (host_view.empty()) {
if (host_view.empty() && !is_special()) {
host = "";
return true;
}
Expand Down Expand Up @@ -12569,7 +12558,6 @@ result_type parse_url(std::string_view user_input,
// If c is U+002F (/) and remaining starts with U+002F (/),
// then set state to special authority ignore slashes state and increase
// pointer by 1.
state = ada::state::SPECIAL_AUTHORITY_IGNORE_SLASHES;
std::string_view view = helpers::substring(url_data, input_position);
if (ada::checkers::begins_with(view, "//")) {
input_position += 2;
Expand Down Expand Up @@ -13638,13 +13626,12 @@ bool url_aggregator::set_host_or_hostname(const std::string_view input) {
// empty string, and either url includes credentials or url's port is
// non-null, return.
else if (host_view.empty() &&
(is_special() || has_credentials() ||
components.port != url_components::omitted)) {
(is_special() || has_credentials() || has_port())) {
return false;
}

// Let host be the result of host parsing host_view with url is not special.
if (host_view.empty()) {
if (host_view.empty() && !is_special()) {
if (has_hostname()) {
clear_hostname(); // easy!
} else if (has_dash_dot()) {
Expand Down Expand Up @@ -14021,6 +14008,7 @@ bool url_aggregator::parse_ipv4(std::string_view input) {
update_base_hostname(
ada::serializers::ipv4(ipv4)); // We have to reserialize the address.
}
host_type = IPV4;
ADA_ASSERT_TRUE(validate());
return true;
}
Expand Down Expand Up @@ -14256,6 +14244,7 @@ bool url_aggregator::parse_ipv6(std::string_view input) {
update_base_hostname(ada::serializers::ipv6(address));
ada_log("parse_ipv6 ", get_hostname());
ADA_ASSERT_TRUE(validate());
host_type = IPV6;
return true;
}

Expand Down Expand Up @@ -14890,6 +14879,11 @@ void ada_free(ada_url result) noexcept {
delete r;
}

ada_url ada_copy(ada_url input) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(input);
return new ada::result<ada::url_aggregator>(r);
}

bool ada_is_valid(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
return r.has_value();
Expand Down Expand Up @@ -15007,6 +15001,22 @@ ada_string ada_get_protocol(ada_url result) noexcept {
return ada_string_create(out.data(), out.length());
}

uint8_t ada_get_host_type(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return 0;
}
return r->host_type;
}

uint8_t ada_get_scheme_type(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return 0;
}
return r->type;
}

bool ada_set_href(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
Expand Down Expand Up @@ -15076,20 +15086,67 @@ bool ada_set_pathname(ada_url result, const char* input,
return r->set_pathname(std::string_view(input, length));
}

/**
* Update the search/query of the URL.
*
* If a URL has `?` as the search value, passing empty string to this function
* does not remove the attribute. If you need to remove it, please use
* `ada_clear_search` method.
*/
void ada_set_search(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->set_search(std::string_view(input, length));
}
}

/**
* Update the hash/fragment of the URL.
*
* If a URL has `#` as the hash value, passing empty string to this function
* does not remove the attribute. If you need to remove it, please use
* `ada_clear_hash` method.
*/
void ada_set_hash(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->set_hash(std::string_view(input, length));
}
}

void ada_clear_port(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->clear_port();
}
}

/**
* Removes the hash of the URL.
*
* Despite `ada_set_hash` method, this function allows the complete
* removal of the hash attribute, even if it has a value of `#`.
*/
void ada_clear_hash(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->clear_hash();
}
}

/**
* Removes the search of the URL.
*
* Despite `ada_set_search` method, this function allows the complete
* removal of the search attribute, even if it has a value of `?`.
*/
void ada_clear_search(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->clear_search();
}
}

bool ada_has_credentials(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
Expand Down
Loading