15template <
bool has_state_overr
ide>
17 const std::string_view input_with_colon) {
18 ada_log(
"url_aggregator::parse_scheme_with_colon ", input_with_colon);
21 std::string_view input{input_with_colon};
22 input.remove_suffix(1);
29 if (is_input_special) {
30 if (has_state_override) {
53 set_scheme_from_view_with_colon(input_with_colon);
55 if (has_state_override) {
61 if (components.
port == urls_scheme_port) {
66 std::string _buffer(input);
70 unicode::to_lower_ascii(_buffer.data(), _buffer.size());
72 if (has_state_override) {
76 if (
is_special() != ada::scheme::is_special(_buffer)) {
97 if (has_state_override) {
103 if (components.
port == urls_scheme_port) {
112inline void url_aggregator::copy_scheme(
const url_aggregator& u)
noexcept {
113 ada_log(
"url_aggregator::copy_scheme ", u.buffer);
117 uint32_t new_difference = u.components.protocol_end - components.protocol_end;
119 buffer.erase(0, components.protocol_end);
120 buffer.insert(0, u.get_protocol());
121 components.protocol_end = u.components.protocol_end;
124 if (new_difference == 0) {
129 components.username_end += new_difference;
130 components.host_start += new_difference;
131 components.host_end += new_difference;
132 components.pathname_start += new_difference;
134 components.search_start += new_difference;
137 components.hash_start += new_difference;
142inline void url_aggregator::set_scheme_from_view_with_colon(
143 std::string_view new_scheme_with_colon)
noexcept {
144 ada_log(
"url_aggregator::set_scheme_from_view_with_colon ",
145 new_scheme_with_colon);
148 new_scheme_with_colon.back() ==
':');
151 uint32_t new_difference =
152 uint32_t(new_scheme_with_colon.size()) - components.protocol_end;
154 if (buffer.empty()) {
155 buffer.append(new_scheme_with_colon);
157 buffer.erase(0, components.protocol_end);
158 buffer.insert(0, new_scheme_with_colon);
160 components.protocol_end += new_difference;
163 components.username_end += new_difference;
164 components.host_start += new_difference;
165 components.host_end += new_difference;
166 components.pathname_start += new_difference;
168 components.search_start += new_difference;
171 components.hash_start += new_difference;
176inline void url_aggregator::set_scheme(std::string_view new_scheme)
noexcept {
177 ada_log(
"url_aggregator::set_scheme ", new_scheme);
182 uint32_t new_difference =
183 uint32_t(new_scheme.size()) - components.protocol_end + 1;
186 if (buffer.empty()) {
187 buffer.append(helpers::concat(new_scheme,
":"));
189 buffer.erase(0, components.protocol_end);
190 buffer.insert(0, helpers::concat(new_scheme,
":"));
192 components.protocol_end = uint32_t(new_scheme.size() + 1);
195 components.username_end += new_difference;
196 components.host_start += new_difference;
197 components.host_end += new_difference;
198 components.pathname_start += new_difference;
200 components.search_start += new_difference;
203 components.hash_start += new_difference;
209 ada_log(
"url_aggregator::set_protocol ", input);
212 std::string view(input);
213 helpers::remove_ascii_tab_or_newline(view);
225 std::string::iterator pointer =
226 std::find_if_not(view.begin(), view.end(), unicode::is_alnum_plus);
228 if (pointer != view.end() && *pointer ==
':') {
229 return parse_scheme_with_colon<true>(
230 std::string_view(view.data(), pointer - view.begin() + 1));
236 ada_log(
"url_aggregator::set_username '", input,
"' ");
239 if (cannot_have_credentials_or_port()) {
244 if (idx == input.size()) {
245 update_base_username(input);
248 update_base_username(ada::unicode::percent_encode(
256 ada_log(
"url_aggregator::set_password '", input,
"'");
259 if (cannot_have_credentials_or_port()) {
264 if (idx == input.size()) {
265 update_base_password(input);
268 update_base_password(ada::unicode::percent_encode(
276 ada_log(
"url_aggregator::set_port ", input);
279 if (cannot_have_credentials_or_port()) {
282 std::string trimmed(input);
283 helpers::remove_ascii_tab_or_newline(trimmed);
284 if (trimmed.empty()) {
289 if (ada::unicode::is_c0_control_or_space(trimmed.front())) {
293 if (input.find_first_of(
"0123456789") == std::string_view::npos) {
298 uint32_t previous_port = components.
port;
303 update_base_port(previous_port);
310 ada_log(
"url_aggregator::set_pathname ", input);
328 ada_log(
"url_aggregator::parse_path ", input);
331 std::string tmp_buffer;
332 std::string_view internal_input;
333 if (unicode::has_tabs_or_newline(input)) {
337 helpers::remove_ascii_tab_or_newline(tmp_buffer);
338 internal_input = tmp_buffer;
340 internal_input = input;
345 if (internal_input.empty()) {
346 update_base_pathname(
"/");
347 }
else if ((internal_input[0] ==
'/') || (internal_input[0] ==
'\\')) {
348 consume_prepared_path(internal_input.substr(1));
350 consume_prepared_path(internal_input);
352 }
else if (!internal_input.empty()) {
353 if (internal_input[0] ==
'/') {
354 consume_prepared_path(internal_input.substr(1));
356 consume_prepared_path(internal_input);
362 update_base_pathname(
"/");
369 ada_log(
"url_aggregator::set_search ", input);
374 helpers::strip_trailing_spaces_from_opaque_path(*
this);
378 std::string new_value;
379 new_value = input[0] ==
'?' ? input.substr(1) : input;
380 helpers::remove_ascii_tab_or_newline(new_value);
382 auto query_percent_encode_set =
386 update_base_search(new_value, query_percent_encode_set);
391 ada_log(
"url_aggregator::set_hash ", input);
399 helpers::strip_trailing_spaces_from_opaque_path(*
this);
403 std::string new_value;
404 new_value = input[0] ==
'#' ? input.substr(1) : input;
405 helpers::remove_ascii_tab_or_newline(new_value);
406 update_unencoded_base_hash(new_value);
412 ada_log(
"url_aggregator::set_href ", input,
" [", input.size(),
" bytes]");
414 ada_log(
"url_aggregator::set_href, success :", out.has_value());
417 ada_log(
"url_aggregator::set_href, parsed ", out->to_string());
422 return out.has_value();
426 ada_log(
"url_aggregator:parse_host \"", input,
"\" [", input.size(),
434 if (input[0] ==
'[') {
436 if (input.back() !=
']') {
439 ada_log(
"parse_host ipv6");
443 input.remove_prefix(1);
444 input.remove_suffix(1);
445 return parse_ipv6(input);
451 return parse_opaque_host(input);
462 uint8_t is_forbidden_or_upper =
463 unicode::contains_forbidden_domain_code_point_or_upper(input.data(),
471 if (is_forbidden_or_upper == 0 &&
472 input.find(
"xn-") == std::string_view::npos) {
474 update_base_hostname(input);
476 ada_log(
"parse_host fast path ipv4");
486 ada_log(
"parse_host calling to_ascii");
487 std::optional<std::string> host = std::string(
get_hostname());
488 is_valid = ada::unicode::to_ascii(host, input, input.find(
'%'));
490 ada_log(
"parse_host to_ascii returns false");
493 ada_log(
"parse_host to_ascii succeeded ", *host,
" [", host->size(),
496 if (std::any_of(host.value().begin(), host.value().end(),
497 ada::unicode::is_forbidden_domain_code_point)) {
503 if (checkers::is_ipv4(host.value())) {
504 ada_log(
"parse_host got ipv4 ", *host);
505 return parse_ipv4(host.value(),
false);
508 update_base_hostname(host.value());
513template <
bool overr
ide_hostname>
514bool url_aggregator::set_host_or_hostname(
const std::string_view input) {
515 ada_log(
"url_aggregator::set_host_or_hostname ", input);
523 uint32_t previous_port = components.
port;
525 size_t host_end_pos = input.find(
'#');
526 std::string _host(input.data(), host_end_pos != std::string_view::npos
529 helpers::remove_ascii_tab_or_newline(_host);
530 std::string_view new_host(_host);
535 std::string_view host_view(_host.data(), _host.length());
536 auto [location, found_colon] =
537 helpers::get_host_delimiter_location(
is_special(), host_view);
543 if (override_hostname) {
546 std::string_view sub_buffer = new_host.substr(location + 1);
547 if (!sub_buffer.empty()) {
555 else if (host_view.empty() &&
564 }
else if (has_dash_dot()) {
565 add_authority_slashes_if_needed();
571 bool succeeded = parse_host(host_view);
573 update_base_hostname(previous_host);
574 update_base_port(previous_port);
575 }
else if (has_dash_dot()) {
582 size_t location = new_host.find_first_of(
"/\\?");
583 if (location != std::string_view::npos) {
584 new_host.remove_suffix(new_host.length() - location);
587 if (new_host.empty()) {
592 if (!parse_host(new_host)) {
593 update_base_hostname(previous_host);
594 update_base_port(previous_port);
599 if (helpers::substring(buffer, components.
host_start,
600 components.
host_end) ==
"localhost") {
609 ada_log(
"url_aggregator::set_host '", input,
"'");
612 return set_host_or_hostname<false>(input);
616 ada_log(
"url_aggregator::set_hostname '", input,
"'");
619 return set_host_or_hostname<true>(input);
623 ada_log(
"url_aggregator::get_origin");
640 return helpers::concat(out->get_protocol(),
"//", out->get_host());
651 ada_log(
"url_aggregator::get_username");
653 return helpers::substring(buffer, components.
protocol_end + 2,
661 ada_log(
"url_aggregator::get_password");
663 return helpers::substring(buffer, components.
username_end + 1,
671 ada_log(
"url_aggregator::get_port");
675 return helpers::substring(buffer, components.
host_end + 1,
681 ada_log(
"url_aggregator::get_hash");
687 if (buffer.size() - components.
hash_start <= 1) {
690 return helpers::substring(buffer, components.
hash_start);
695 ada_log(
"url_aggregator::get_host");
709 return helpers::substring(buffer, start, components.
pathname_start);
714 ada_log(
"url_aggregator::get_hostname");
724 return helpers::substring(buffer, start, components.
host_end);
729 ada_log(
"url_aggregator::get_pathname pathname_start = ",
732 " components.hash_start = ", components.
hash_start);
733 auto ending_index = uint32_t(buffer.size());
739 return helpers::substring(buffer, components.
pathname_start, ending_index);
744 ada_log(
"url_aggregator::get_search");
750 auto ending_index = uint32_t(buffer.size());
757 return helpers::substring(buffer, components.
search_start, ending_index);
762 ada_log(
"url_aggregator::get_protocol");
763 return helpers::substring(buffer, 0, components.
protocol_end);
767 ada_log(
"url_aggregator::to_string buffer:", buffer,
" [", buffer.size(),
774 auto back = std::back_insert_iterator(answer);
775 answer.append(
"{\n");
777 answer.append(
"\t\"buffer\":\"");
778 helpers::encode_json(buffer, back);
779 answer.append(
"\",\n");
781 answer.append(
"\t\"protocol\":\"");
782 helpers::encode_json(get_protocol(), back);
783 answer.append(
"\",\n");
785 if (has_credentials()) {
786 answer.append(
"\t\"username\":\"");
787 helpers::encode_json(get_username(), back);
788 answer.append(
"\",\n");
789 answer.append(
"\t\"password\":\"");
790 helpers::encode_json(get_password(), back);
791 answer.append(
"\",\n");
794 answer.append(
"\t\"host\":\"");
795 helpers::encode_json(get_host(), back);
796 answer.append(
"\",\n");
798 answer.append(
"\t\"path\":\"");
799 helpers::encode_json(get_pathname(), back);
800 answer.append(
"\",\n");
801 answer.append(
"\t\"opaque path\":");
802 answer.append((has_opaque_path ?
"true" :
"false"));
803 answer.append(
",\n");
806 answer.append(
"\t\"query\":\"");
807 helpers::encode_json(get_search(), back);
808 answer.append(
"\",\n");
811 answer.append(
"\t\"fragment\":\"");
812 helpers::encode_json(get_hash(), back);
813 answer.append(
"\",\n");
816 auto convert_offset_to_string = [](uint32_t offset) -> std::string {
820 return std::to_string(offset);
824 answer.append(
"\t\"protocol_end\":");
825 answer.append(convert_offset_to_string(components.protocol_end));
826 answer.append(
",\n");
828 answer.append(
"\t\"username_end\":");
829 answer.append(convert_offset_to_string(components.username_end));
830 answer.append(
",\n");
832 answer.append(
"\t\"host_start\":");
833 answer.append(convert_offset_to_string(components.host_start));
834 answer.append(
",\n");
836 answer.append(
"\t\"host_end\":");
837 answer.append(convert_offset_to_string(components.host_end));
838 answer.append(
",\n");
840 answer.append(
"\t\"port\":");
841 answer.append(convert_offset_to_string(components.port));
842 answer.append(
",\n");
844 answer.append(
"\t\"pathname_start\":");
845 answer.append(convert_offset_to_string(components.pathname_start));
846 answer.append(
",\n");
848 answer.append(
"\t\"search_start\":");
849 answer.append(convert_offset_to_string(components.search_start));
850 answer.append(
",\n");
852 answer.append(
"\t\"hash_start\":");
853 answer.append(convert_offset_to_string(components.hash_start));
854 answer.append(
"\n}");
866bool url_aggregator::parse_ipv4(std::string_view input,
bool in_place) {
867 ada_log(
"parse_ipv4 ", input,
" [", input.size(),
868 " bytes], overlaps with buffer: ",
869 helpers::overlaps(input, buffer) ?
"yes" :
"no");
871 const bool trailing_dot = (input.back() ==
'.');
873 input.remove_suffix(1);
875 size_t digit_count{0};
876 int pure_decimal_count = 0;
879 for (; (digit_count < 4) && !(input.empty()); digit_count++) {
883 if (is_hex && ((input.length() == 2) ||
884 ((input.length() > 2) && (input[2] ==
'.')))) {
887 input.remove_prefix(2);
889 std::from_chars_result r{};
891 ada_log(
"parse_ipv4 trying to parse hex number");
892 r = std::from_chars(input.data() + 2, input.data() + input.size(),
894 }
else if ((input.length() >= 2) && input[0] ==
'0' &&
896 ada_log(
"parse_ipv4 trying to parse octal number");
897 r = std::from_chars(input.data() + 1, input.data() + input.size(),
900 ada_log(
"parse_ipv4 trying to parse decimal number");
901 pure_decimal_count++;
902 r = std::from_chars(input.data(), input.data() + input.size(),
905 if (r.ec != std::errc()) {
906 ada_log(
"parse_ipv4 parsing failed");
909 ada_log(
"parse_ipv4 parsed ", segment_result);
910 input.remove_prefix(r.ptr - input.data());
916 if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
919 ipv4 <<= (32 - digit_count * 8);
920 ipv4 |= segment_result;
925 if ((segment_result > 255) || (input[0] !=
'.')) {
929 ipv4 |= segment_result;
930 input.remove_prefix(1);
933 if ((digit_count != 4) || (!input.empty())) {
934 ada_log(
"parse_ipv4 found invalid (more than 4 numbers or empty) ");
938 ada_log(
"url_aggregator::parse_ipv4 completed ",
get_href(),
942 if (in_place && pure_decimal_count == 4 && !trailing_dot) {
944 "url_aggregator::parse_ipv4 completed and was already correct in the "
949 ada_log(
"url_aggregator::parse_ipv4 completed and we need to update it");
954 update_base_hostname(
962bool url_aggregator::parse_ipv6(std::string_view input) {
967 ada_log(
"parse_ipv6 ", input,
" [", input.size(),
" bytes]");
974 std::array<uint16_t, 8> address{};
980 std::optional<int> compress{};
983 std::string_view::iterator pointer = input.begin();
986 if (input[0] ==
':') {
989 if (input.size() == 1 || input[1] !=
':') {
990 ada_log(
"parse_ipv6 starts with : but the rest does not start with :");
998 compress = ++piece_index;
1002 while (pointer != input.end()) {
1004 if (piece_index == 8) {
1005 ada_log(
"parse_ipv6 piece_index == 8");
1010 if (*pointer ==
':') {
1012 if (compress.has_value()) {
1013 ada_log(
"parse_ipv6 compress is non-null");
1020 compress = ++piece_index;
1025 uint16_t value = 0, length = 0;
1030 while (length < 4 && pointer != input.end() &&
1031 unicode::is_ascii_hex_digit(*pointer)) {
1033 value = uint16_t(value * 0x10 + unicode::convert_hex_to_binary(*pointer));
1039 if (pointer != input.end() && *pointer ==
'.') {
1042 ada_log(
"parse_ipv6 length is 0");
1050 if (piece_index > 6) {
1051 ada_log(
"parse_ipv6 piece_index > 6");
1056 int numbers_seen = 0;
1059 while (pointer != input.end()) {
1061 std::optional<uint16_t> ipv4_piece{};
1064 if (numbers_seen > 0) {
1067 if (*pointer ==
'.' && numbers_seen < 4) {
1071 ada_log(
"parse_ipv6 Otherwise, validation error, return failure");
1079 "parse_ipv6 If c is not an ASCII digit, validation error, return "
1087 int number = *pointer -
'0';
1090 if (!ipv4_piece.has_value()) {
1091 ipv4_piece = number;
1094 else if (ipv4_piece == 0) {
1095 ada_log(
"parse_ipv6 if ipv4Piece is 0, validation error");
1100 ipv4_piece = *ipv4_piece * 10 + number;
1104 if (ipv4_piece > 255) {
1105 ada_log(
"parse_ipv6 ipv4_piece > 255");
1116 address[piece_index] =
1117 uint16_t(address[piece_index] * 0x100 + *ipv4_piece);
1123 if (numbers_seen == 2 || numbers_seen == 4) {
1129 if (numbers_seen != 4) {
1137 else if ((pointer != input.end()) && (*pointer ==
':')) {
1142 if (pointer == input.end()) {
1144 "parse_ipv6 If c is the EOF code point, validation error, return "
1151 else if (pointer != input.end()) {
1153 "parse_ipv6 Otherwise, if c is not the EOF code point, validation "
1154 "error, return failure");
1159 address[piece_index] = value;
1166 if (compress.has_value()) {
1168 int swaps = piece_index - *compress;
1176 while (piece_index != 0 && swaps > 0) {
1177 std::swap(address[piece_index], address[*compress + swaps - 1]);
1184 else if (piece_index != 8) {
1186 "parse_ipv6 if compress is null and pieceIndex is not 8, validation "
1187 "error, return failure");
1200bool url_aggregator::parse_opaque_host(std::string_view input) {
1201 ada_log(
"parse_opaque_host ", input,
" [", input.size(),
" bytes]");
1204 if (std::any_of(input.begin(), input.end(),
1205 ada::unicode::is_forbidden_host_code_point)) {
1213 if (idx == input.size()) {
1214 update_base_hostname(input);
1217 update_base_hostname(ada::unicode::percent_encode(
1229 answer.append(buffer);
1230 answer.append(
" [");
1231 answer.append(std::to_string(buffer.size()));
1232 answer.append(
" bytes]");
1233 answer.append(
"\n");
1236 line1.resize(buffer.size(),
' ');
1246 if (components.
host_end != buffer.size()) {
1249 if (components.
host_start != buffer.size()) {
1258 answer.append(line1);
1259 answer.append(
"\n");
1261 std::string line2 = line1;
1266 for (
size_t i = components.
hash_start + 1; i < line2.size(); i++) {
1269 line2.append(
" hash_start");
1270 answer.append(line2);
1271 answer.append(
"\n");
1274 std::string line3 = line1;
1279 for (
size_t i = components.
search_start + 1; i < line3.size(); i++) {
1282 line3.append(
" search_start ");
1284 answer.append(line3);
1285 answer.append(
"\n");
1288 std::string line4 = line1;
1292 for (
size_t i = components.
pathname_start + 1; i < line4.size(); i++) {
1295 line4.append(
" pathname_start ");
1297 answer.append(line4);
1298 answer.append(
"\n");
1301 std::string line5 = line1;
1302 if (components.
host_end != buffer.size()) {
1306 for (
size_t i = components.
host_end + 1; i < line5.size(); i++) {
1309 line5.append(
" host_end ");
1310 line5.append(std::to_string(components.
host_end));
1311 answer.append(line5);
1312 answer.append(
"\n");
1315 std::string line6 = line1;
1316 if (components.
host_start != buffer.size()) {
1320 for (
size_t i = components.
host_start + 1; i < line6.size(); i++) {
1323 line6.append(
" host_start ");
1324 line6.append(std::to_string(components.
host_start));
1325 answer.append(line6);
1326 answer.append(
"\n");
1329 std::string line7 = line1;
1334 for (
size_t i = components.
username_end + 1; i < line7.size(); i++) {
1337 line7.append(
" username_end ");
1339 answer.append(line7);
1340 answer.append(
"\n");
1343 std::string line8 = line1;
1348 for (
size_t i = components.
protocol_end + 1; i < line8.size(); i++) {
1351 line8.append(
" protocol_end ");
1353 answer.append(line8);
1354 answer.append(
"\n");
1358 answer.append(
"note: hash omitted\n");
1361 answer.append(
"note: search omitted\n");
1364 answer.append(
"warning: protocol_end overflows\n");
1367 answer.append(
"warning: username_end overflows\n");
1370 answer.append(
"warning: host_start overflows\n");
1372 if (components.
host_end > buffer.size()) {
1373 answer.append(
"warning: host_end overflows\n");
1376 answer.append(
"warning: pathname_start overflows\n");
1386 ada_log(
"url_aggregator::validate inconsistent components \n",
1405 ada_log(
"url_aggregator::validate omitted protocol_end \n",
to_diagram());
1409 ada_log(
"url_aggregator::validate omitted username_end \n",
to_diagram());
1413 ada_log(
"url_aggregator::validate omitted host_start \n",
to_diagram());
1417 ada_log(
"url_aggregator::validate omitted host_end \n",
to_diagram());
1421 ada_log(
"url_aggregator::validate omitted pathname_start \n",
to_diagram());
1426 ada_log(
"url_aggregator::validate protocol_end overflow \n",
to_diagram());
1430 ada_log(
"url_aggregator::validate username_end overflow \n",
to_diagram());
1434 ada_log(
"url_aggregator::validate host_start overflow \n",
to_diagram());
1437 if (components.
host_end > buffer.size()) {
1438 ada_log(
"url_aggregator::validate host_end overflow \n",
to_diagram());
1442 ada_log(
"url_aggregator::validate pathname_start overflow \n",
1450 "url_aggregator::validate missing : at the end of the protocol \n",
1461 "url_aggregator::validate missing : or @ at the end of the username "
1468 if (components.
host_start != buffer.size()) {
1472 "url_aggregator::validate missing @ at the end of the password \n",
1482 "url_aggregator::validate missing // between protocol and host "
1491 "url_aggregator::validate missing @ at the end of the username "
1499 ada_log(
"url_aggregator::validate expected omitted host \n",
1505 if (components.
host_end != buffer.size() &&
1508 buffer[components.
host_end] ==
'/' &&
1509 buffer[components.
host_end + 1] ==
'.') {
1514 "url_aggregator::validate expected the path to begin with // \n",
1518 }
else if (buffer[components.
host_end] !=
':') {
1519 ada_log(
"url_aggregator::validate missing : at the port \n",
1528 ada_log(
"url_aggregator::validate missing / at the path \n",
1535 ada_log(
"url_aggregator::validate missing ? at the search \n",
1542 ada_log(
"url_aggregator::validate missing # at the hash \n",
1551void url_aggregator::delete_dash_dot() {
1552 ada_log(
"url_aggregator::delete_dash_dot");
1555 buffer.erase(components.
host_end, 2);
1567inline void url_aggregator::consume_prepared_path(std::string_view input) {
1568 ada_log(
"url_aggregator::consume_prepared_path ", input);
1578 uint8_t accumulator = checkers::path_signature(input);
1583 constexpr uint8_t need_encoding = 1;
1584 constexpr uint8_t backslash_char = 2;
1585 constexpr uint8_t dot_char = 4;
1586 constexpr uint8_t percent_char = 8;
1591 (special ? (accumulator == 0)
1592 : ((accumulator & (need_encoding | dot_char | percent_char)) ==
1594 (!may_need_slow_file_handling);
1595 if (accumulator == dot_char && !may_need_slow_file_handling) {
1603 if (input[0] !=
'.') {
1604 size_t slashdot = input.find(
"/.");
1605 if (slashdot == std::string_view::npos) {
1606 trivial_path =
true;
1610 !(slashdot + 2 == input.size() || input[slashdot + 2] ==
'.' ||
1611 input[slashdot + 2] ==
'/');
1615 if (trivial_path && is_at_path()) {
1616 ada_log(
"parse_path trivial");
1628 (accumulator & (need_encoding | backslash_char | percent_char)) == 0) &&
1631 ada_log(
"parse_prepared_path fast");
1636 size_t previous_location = 0;
1638 size_t new_location = input.find(
'/', previous_location);
1641 if (new_location == std::string_view::npos) {
1642 std::string_view path_view = input.substr(previous_location);
1643 if (path_view ==
"..") {
1647 update_base_pathname(path);
1651 if (path.back() ==
'/') {
1652 update_base_pathname(path);
1657 path.resize(path.rfind(
'/') + 1);
1658 update_base_pathname(path);
1662 if (path_view !=
".") {
1663 path.append(path_view);
1665 update_base_pathname(path);
1669 std::string_view path_view =
1670 input.substr(previous_location, new_location - previous_location);
1671 previous_location = new_location + 1;
1672 if (path_view ==
"..") {
1673 size_t last_delimiter = path.rfind(
'/');
1674 if (last_delimiter != std::string::npos) {
1675 path.erase(last_delimiter);
1677 }
else if (path_view !=
".") {
1679 path.append(path_view);
1684 ada_log(
"parse_path slow");
1686 bool needs_percent_encoding = (accumulator & 1);
1687 std::string path_buffer_tmp;
1689 size_t location = (special && (accumulator & 2))
1690 ? input.find_first_of(
"/\\")
1692 std::string_view path_view = input;
1693 if (location != std::string_view::npos) {
1694 path_view.remove_suffix(path_view.size() - location);
1695 input.remove_prefix(location + 1);
1699 std::string_view path_buffer =
1700 (needs_percent_encoding &&
1701 ada::unicode::percent_encode<false>(
1705 if (unicode::is_double_dot_path_segment(path_buffer)) {
1706 if ((helpers::shorten_path(path, type) || special) &&
1707 location == std::string_view::npos) {
1710 }
else if (unicode::is_single_dot_path_segment(path_buffer) &&
1711 (location == std::string_view::npos)) {
1715 else if (!unicode::is_single_dot_path_segment(path_buffer)) {
1722 path += path_buffer[0];
1724 path_buffer.remove_prefix(2);
1725 path.append(path_buffer);
1729 path.append(path_buffer);
1732 if (location == std::string_view::npos) {
1733 update_base_pathname(path);
Includes all definitions for Ada.
Definitions for URL specific checkers used within Ada.
#define ADA_ASSERT_TRUE(COND)
#define ada_lifetime_bound
#define ada_really_inline
Definitions for helper functions used within Ada.
Definitions for user facing functions for parsing URL and it's components.
constexpr uint8_t QUERY_PERCENT_ENCODE[32]
constexpr uint8_t SPECIAL_QUERY_PERCENT_ENCODE[32]
constexpr uint8_t PATH_PERCENT_ENCODE[32]
constexpr uint8_t C0_CONTROL_PERCENT_ENCODE[32]
constexpr uint8_t USERINFO_PERCENT_ENCODE[32]
constexpr bool is_windows_drive_letter(std::string_view input) noexcept
bool has_hex_prefix(std::string_view input)
constexpr bool is_alpha(char x) noexcept
constexpr bool is_digit(char x) noexcept
ada_really_inline bool begins_with(std::string_view view, std::string_view prefix)
constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept
constexpr uint16_t get_special_port(std::string_view scheme) noexcept
std::string ipv6(const std::array< uint16_t, 8 > &address) noexcept
std::string ipv4(uint64_t address) noexcept
ada_really_inline size_t percent_encode_index(const std::string_view input, const uint8_t character_set[])
template ada::result< url_aggregator > parse< url_aggregator >(std::string_view input, const url_aggregator *base_url)
tl::expected< result_type, ada::errors > result
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
Declarations for the URL scheme.
bool has_non_empty_username() const noexcept
void set_hash(std::string_view input)
void clear_search() override
bool has_hostname() const noexcept
std::string_view get_hostname() const noexcept ada_lifetime_bound
bool has_non_empty_password() const noexcept
ada_really_inline bool has_credentials() const noexcept
std::string to_string() const override
std::string_view get_pathname() const noexcept ada_lifetime_bound
std::string_view get_hash() const noexcept ada_lifetime_bound
std::string to_diagram() const
bool set_protocol(std::string_view input)
std::string get_origin() const noexcept override
bool validate() const noexcept
std::string_view get_search() const noexcept ada_lifetime_bound
bool has_valid_domain() const noexcept override
bool set_hostname(std::string_view input)
bool set_password(std::string_view input)
bool set_pathname(std::string_view input)
std::string_view get_protocol() const noexcept ada_lifetime_bound
std::string_view get_password() const noexcept ada_lifetime_bound
bool set_href(std::string_view input)
void set_search(std::string_view input)
std::string_view get_port() const noexcept ada_lifetime_bound
bool has_port() const noexcept
std::string_view get_href() const noexcept ada_lifetime_bound
bool set_host(std::string_view input)
std::string_view get_host() const noexcept ada_lifetime_bound
bool set_port(std::string_view input)
std::string_view get_username() const noexcept ada_lifetime_bound
bool set_username(std::string_view input)
ada_really_inline bool is_special() const noexcept
bool check_offset_consistency() const noexcept
static constexpr uint32_t omitted
Definitions for unicode operations.
Inline functions for url aggregator.
Declaration for the basic URL definitions.
Declaration for the URL Components.