1
- /* auto-generated on 2023-07-23 15:03:22 -0400. Do not edit! */
1
+ /* auto-generated on 2023-08-30 11:44:21 -0400. Do not edit! */
2
2
/* begin file src/ada.cpp */
3
3
#include "ada.h"
4
4
/* begin file src/checkers.cpp */
@@ -116,10 +116,11 @@ ada_really_inline constexpr bool verify_dns_length(
116
116
117
117
ADA_PUSH_DISABLE_ALL_WARNINGS
118
118
/* begin file src/ada_idna.cpp */
119
- /* auto-generated on 2023-05-07 19:12:14 -0400. Do not edit! */
119
+ /* auto-generated on 2023-08-29 15:28:19 -0400. Do not edit! */
120
120
/* begin file src/idna.cpp */
121
121
/* begin file src/unicode_transcoding.cpp */
122
122
123
+ #include <algorithm>
123
124
#include <cstdint>
124
125
#include <cstring>
125
126
@@ -226,38 +227,22 @@ size_t utf8_length_from_utf32(const char32_t* buf, size_t len) {
226
227
// We are not BOM aware.
227
228
const uint32_t* p = reinterpret_cast<const uint32_t*>(buf);
228
229
size_t counter{0};
229
- for (size_t i = 0; i < len; i++) {
230
- /** ASCII **/
231
- if (p[i] <= 0x7F) {
232
- counter++;
233
- }
234
- /** two-byte **/
235
- else if (p[i] <= 0x7FF) {
236
- counter += 2;
237
- }
238
- /** three-byte **/
239
- else if (p[i] <= 0xFFFF) {
240
- counter += 3;
241
- }
242
- /** four-bytes **/
243
- else {
244
- counter += 4;
245
- }
230
+ for (size_t i = 0; i != len; ++i) {
231
+ ++counter; // ASCII
232
+ counter += static_cast<size_t>(p[i] > 0x7F); // two-byte
233
+ counter += static_cast<size_t>(p[i] > 0x7FF); // three-byte
234
+ counter += static_cast<size_t>(p[i] > 0xFFFF); // four-bytes
246
235
}
247
236
return counter;
248
237
}
249
238
250
239
size_t utf32_length_from_utf8(const char* buf, size_t len) {
251
240
const int8_t* p = reinterpret_cast<const int8_t*>(buf);
252
- size_t counter{0};
253
- for (size_t i = 0; i < len; i++) {
241
+ return std::count_if(p, std::next(p, len), [](int8_t c) {
254
242
// -65 is 0b10111111, anything larger in two-complement's
255
243
// should start a new code point.
256
- if (p[i] > -65) {
257
- counter++;
258
- }
259
- }
260
- return counter;
244
+ return c > -65;
245
+ });
261
246
}
262
247
263
248
size_t utf32_to_utf8(const char32_t* buf, size_t len, char* utf8_output) {
@@ -9525,14 +9510,14 @@ bool constexpr begins_with(std::u32string_view view,
9525
9510
if (view.size() < prefix.size()) {
9526
9511
return false;
9527
9512
}
9528
- return view.substr(0 , prefix.size()) == prefix ;
9513
+ return std::equal(prefix.begin() , prefix.end(), view.begin()) ;
9529
9514
}
9530
9515
9531
9516
bool constexpr begins_with(std::string_view view, std::string_view prefix) {
9532
9517
if (view.size() < prefix.size()) {
9533
9518
return false;
9534
9519
}
9535
- return view.substr(0 , prefix.size()) == prefix ;
9520
+ return std::equal(prefix.begin() , prefix.end(), view.begin()) ;
9536
9521
}
9537
9522
9538
9523
bool constexpr is_ascii(std::u32string_view view) {
@@ -10144,13 +10129,12 @@ ada_really_inline constexpr bool is_lowercase_hex(const char c) noexcept {
10144
10129
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
10145
10130
}
10146
10131
10132
+ constexpr static char hex_to_binary_table[] = {
10133
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11,
10134
+ 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10135
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15};
10147
10136
unsigned constexpr convert_hex_to_binary(const char c) noexcept {
10148
- // this code can be optimized.
10149
- if (c <= '9') {
10150
- return c - '0';
10151
- }
10152
- char del = c >= 'a' ? 'a' : 'A';
10153
- return 10 + (c - del);
10137
+ return hex_to_binary_table[c - '0'];
10154
10138
}
10155
10139
10156
10140
std::string percent_decode(const std::string_view input, size_t first_percent) {
@@ -10159,8 +10143,9 @@ std::string percent_decode(const std::string_view input, size_t first_percent) {
10159
10143
if (first_percent == std::string_view::npos) {
10160
10144
return std::string(input);
10161
10145
}
10162
- std::string dest(input.substr(0, first_percent)) ;
10146
+ std::string dest;
10163
10147
dest.reserve(input.length());
10148
+ dest.append(input.substr(0, first_percent));
10164
10149
const char* pointer = input.data() + first_percent;
10165
10150
const char* end = input.data() + input.size();
10166
10151
// Optimization opportunity: if the following code gets
@@ -10197,9 +10182,10 @@ std::string percent_encode(const std::string_view input,
10197
10182
return std::string(input);
10198
10183
}
10199
10184
10200
- std::string result(input.substr(0, std::distance(input.begin(), pointer))) ;
10185
+ std::string result;
10201
10186
result.reserve(input.length()); // in the worst case, percent encoding might
10202
10187
// produce 3 characters.
10188
+ result.append(input.substr(0, std::distance(input.begin(), pointer)));
10203
10189
10204
10190
for (; pointer != input.end(); pointer++) {
10205
10191
if (character_sets::bit_at(character_set, *pointer)) {
@@ -11231,6 +11217,7 @@ bool url::parse_ipv4(std::string_view input) {
11231
11217
} else {
11232
11218
host = ada::serializers::ipv4(ipv4); // We have to reserialize the address.
11233
11219
}
11220
+ host_type = IPV4;
11234
11221
return true;
11235
11222
}
11236
11223
@@ -11460,6 +11447,7 @@ bool url::parse_ipv6(std::string_view input) {
11460
11447
}
11461
11448
host = ada::serializers::ipv6(address);
11462
11449
ada_log("parse_ipv6 ", *host);
11450
+ host_type = IPV6;
11463
11451
return true;
11464
11452
}
11465
11453
@@ -12569,7 +12557,6 @@ result_type parse_url(std::string_view user_input,
12569
12557
// If c is U+002F (/) and remaining starts with U+002F (/),
12570
12558
// then set state to special authority ignore slashes state and increase
12571
12559
// pointer by 1.
12572
- state = ada::state::SPECIAL_AUTHORITY_IGNORE_SLASHES;
12573
12560
std::string_view view = helpers::substring(url_data, input_position);
12574
12561
if (ada::checkers::begins_with(view, "//")) {
12575
12562
input_position += 2;
@@ -14021,6 +14008,7 @@ bool url_aggregator::parse_ipv4(std::string_view input) {
14021
14008
update_base_hostname(
14022
14009
ada::serializers::ipv4(ipv4)); // We have to reserialize the address.
14023
14010
}
14011
+ host_type = IPV4;
14024
14012
ADA_ASSERT_TRUE(validate());
14025
14013
return true;
14026
14014
}
@@ -14256,6 +14244,7 @@ bool url_aggregator::parse_ipv6(std::string_view input) {
14256
14244
update_base_hostname(ada::serializers::ipv6(address));
14257
14245
ada_log("parse_ipv6 ", get_hostname());
14258
14246
ADA_ASSERT_TRUE(validate());
14247
+ host_type = IPV6;
14259
14248
return true;
14260
14249
}
14261
14250
@@ -14890,6 +14879,11 @@ void ada_free(ada_url result) noexcept {
14890
14879
delete r;
14891
14880
}
14892
14881
14882
+ ada_url ada_copy(ada_url input) noexcept {
14883
+ ada::result<ada::url_aggregator>& r = get_instance(input);
14884
+ return new ada::result<ada::url_aggregator>(r);
14885
+ }
14886
+
14893
14887
bool ada_is_valid(ada_url result) noexcept {
14894
14888
ada::result<ada::url_aggregator>& r = get_instance(result);
14895
14889
return r.has_value();
@@ -15007,6 +15001,14 @@ ada_string ada_get_protocol(ada_url result) noexcept {
15007
15001
return ada_string_create(out.data(), out.length());
15008
15002
}
15009
15003
15004
+ uint8_t ada_get_host_type(ada_url result) noexcept {
15005
+ ada::result<ada::url_aggregator>& r = get_instance(result);
15006
+ if (!r) {
15007
+ return 0;
15008
+ }
15009
+ return r->host_type;
15010
+ }
15011
+
15010
15012
bool ada_set_href(ada_url result, const char* input, size_t length) noexcept {
15011
15013
ada::result<ada::url_aggregator>& r = get_instance(result);
15012
15014
if (!r) {
@@ -15076,20 +15078,67 @@ bool ada_set_pathname(ada_url result, const char* input,
15076
15078
return r->set_pathname(std::string_view(input, length));
15077
15079
}
15078
15080
15081
+ /**
15082
+ * Update the search/query of the URL.
15083
+ *
15084
+ * If a URL has `?` as the search value, passing empty string to this function
15085
+ * does not remove the attribute. If you need to remove it, please use
15086
+ * `ada_clear_search` method.
15087
+ */
15079
15088
void ada_set_search(ada_url result, const char* input, size_t length) noexcept {
15080
15089
ada::result<ada::url_aggregator>& r = get_instance(result);
15081
15090
if (r) {
15082
15091
r->set_search(std::string_view(input, length));
15083
15092
}
15084
15093
}
15085
15094
15095
+ /**
15096
+ * Update the hash/fragment of the URL.
15097
+ *
15098
+ * If a URL has `#` as the hash value, passing empty string to this function
15099
+ * does not remove the attribute. If you need to remove it, please use
15100
+ * `ada_clear_hash` method.
15101
+ */
15086
15102
void ada_set_hash(ada_url result, const char* input, size_t length) noexcept {
15087
15103
ada::result<ada::url_aggregator>& r = get_instance(result);
15088
15104
if (r) {
15089
15105
r->set_hash(std::string_view(input, length));
15090
15106
}
15091
15107
}
15092
15108
15109
+ void ada_clear_port(ada_url result) noexcept {
15110
+ ada::result<ada::url_aggregator>& r = get_instance(result);
15111
+ if (r) {
15112
+ r->clear_port();
15113
+ }
15114
+ }
15115
+
15116
+ /**
15117
+ * Removes the hash of the URL.
15118
+ *
15119
+ * Despite `ada_set_hash` method, this function allows the complete
15120
+ * removal of the hash attribute, even if it has a value of `#`.
15121
+ */
15122
+ void ada_clear_hash(ada_url result) noexcept {
15123
+ ada::result<ada::url_aggregator>& r = get_instance(result);
15124
+ if (r) {
15125
+ r->clear_hash();
15126
+ }
15127
+ }
15128
+
15129
+ /**
15130
+ * Removes the search of the URL.
15131
+ *
15132
+ * Despite `ada_set_search` method, this function allows the complete
15133
+ * removal of the search attribute, even if it has a value of `?`.
15134
+ */
15135
+ void ada_clear_search(ada_url result) noexcept {
15136
+ ada::result<ada::url_aggregator>& r = get_instance(result);
15137
+ if (r) {
15138
+ r->clear_search();
15139
+ }
15140
+ }
15141
+
15093
15142
bool ada_has_credentials(ada_url result) noexcept {
15094
15143
ada::result<ada::url_aggregator>& r = get_instance(result);
15095
15144
if (!r) {
0 commit comments