17template <
bool has_state_overr
ide>
19 const std::string_view input_with_colon) {
20 ada_log(
"url_aggregator::parse_scheme_with_colon ", input_with_colon);
23 std::string_view input{input_with_colon};
24 input.remove_suffix(1);
31 if (is_input_special) {
32 if constexpr (has_state_override) {
49 components.host_start == components.host_end) {
55 set_scheme_from_view_with_colon(input_with_colon);
57 if constexpr (has_state_override) {
59 uint16_t urls_scheme_port = get_special_port();
63 if (components.port == urls_scheme_port) {
68 std::string _buffer(input);
72 unicode::to_lower_ascii(_buffer.data(), _buffer.size());
74 if constexpr (has_state_override) {
78 if (
is_special() != ada::scheme::is_special(_buffer)) {
92 components.host_start == components.host_end) {
99 if constexpr (has_state_override) {
101 uint16_t urls_scheme_port = get_special_port();
105 if (components.port == urls_scheme_port) {
115 ada_log(
"url_aggregator::copy_scheme ", u.buffer);
119 uint32_t new_difference = u.components.protocol_end - components.protocol_end;
121 buffer.erase(0, components.protocol_end);
122 buffer.insert(0, u.get_protocol());
123 components.protocol_end = u.components.protocol_end;
126 if (new_difference == 0) {
131 components.username_end += new_difference;
132 components.host_start += new_difference;
133 components.host_end += new_difference;
134 components.pathname_start += new_difference;
136 components.search_start += new_difference;
139 components.hash_start += new_difference;
144inline void url_aggregator::set_scheme_from_view_with_colon(
145 std::string_view new_scheme_with_colon) {
146 ada_log(
"url_aggregator::set_scheme_from_view_with_colon ",
147 new_scheme_with_colon);
150 new_scheme_with_colon.back() ==
':');
153 uint32_t new_difference =
154 uint32_t(new_scheme_with_colon.size()) - components.protocol_end;
156 if (buffer.empty()) {
157 buffer.append(new_scheme_with_colon);
159 buffer.erase(0, components.protocol_end);
160 buffer.insert(0, new_scheme_with_colon);
162 components.protocol_end += new_difference;
165 components.username_end += new_difference;
166 components.host_start += new_difference;
167 components.host_end += new_difference;
168 components.pathname_start += new_difference;
170 components.search_start += new_difference;
173 components.hash_start += new_difference;
178inline void url_aggregator::set_scheme(std::string_view new_scheme) {
179 ada_log(
"url_aggregator::set_scheme ", new_scheme);
184 uint32_t new_difference =
185 uint32_t(new_scheme.size()) - components.protocol_end + 1;
188 if (buffer.empty()) {
189 buffer.append(helpers::concat(new_scheme,
":"));
191 buffer.erase(0, components.protocol_end);
192 buffer.insert(0, helpers::concat(new_scheme,
":"));
194 components.protocol_end = uint32_t(new_scheme.size() + 1);
197 components.username_end += new_difference;
198 components.host_start += new_difference;
199 components.host_end += new_difference;
200 components.pathname_start += new_difference;
202 components.search_start += new_difference;
205 components.hash_start += new_difference;
211 ada_log(
"url_aggregator::set_protocol ", input);
214 std::string view(input);
215 helpers::remove_ascii_tab_or_newline(view);
227 std::string::iterator pointer =
228 std::ranges::find_if_not(view, unicode::is_alnum_plus);
230 if (pointer != view.end() && *pointer ==
':') {
231 return parse_scheme_with_colon<true>(
232 view.substr(0, pointer - view.begin() + 1));
238 ada_log(
"url_aggregator::set_username '", input,
"' ");
241 if (cannot_have_credentials_or_port()) {
246 if (idx == input.size()) {
247 update_base_username(input);
250 update_base_username(ada::unicode::percent_encode(
258 ada_log(
"url_aggregator::set_password '", input,
"'");
261 if (cannot_have_credentials_or_port()) {
266 if (idx == input.size()) {
267 update_base_password(input);
270 update_base_password(ada::unicode::percent_encode(
278 ada_log(
"url_aggregator::set_port ", input);
281 if (cannot_have_credentials_or_port()) {
290 std::string trimmed(input);
291 helpers::remove_ascii_tab_or_newline(trimmed);
293 if (trimmed.empty()) {
298 if (!ada::unicode::is_ascii_digit(trimmed.front())) {
303 auto first_non_digit =
304 std::ranges::find_if_not(trimmed, ada::unicode::is_ascii_digit);
305 std::string_view digits_to_parse =
306 std::string_view(trimmed.data(), first_non_digit - trimmed.begin());
309 uint32_t previous_port = components.port;
310 parse_port(digits_to_parse);
314 update_base_port(previous_port);
321 ada_log(
"url_aggregator::set_pathname ", input);
329 if (
get_pathname().starts_with(
"//") && !has_authority() && !has_dash_dot()) {
330 buffer.insert(components.pathname_start,
"/.");
331 components.pathname_start += 2;
333 components.search_start += 2;
336 components.hash_start += 2;
344 ada_log(
"url_aggregator::parse_path ", input);
347 std::string tmp_buffer;
348 std::string_view internal_input;
349 if (unicode::has_tabs_or_newline(input)) {
353 helpers::remove_ascii_tab_or_newline(tmp_buffer);
354 internal_input = tmp_buffer;
356 internal_input = input;
361 if (internal_input.empty()) {
362 update_base_pathname(
"/");
363 }
else if ((internal_input[0] ==
'/') || (internal_input[0] ==
'\\')) {
364 consume_prepared_path(internal_input.substr(1));
366 consume_prepared_path(internal_input);
368 }
else if (!internal_input.empty()) {
369 if (internal_input[0] ==
'/') {
370 consume_prepared_path(internal_input.substr(1));
372 consume_prepared_path(internal_input);
377 if (components.host_start == components.host_end && !has_authority()) {
378 update_base_pathname(
"/");
385 ada_log(
"url_aggregator::set_search ", input);
390 helpers::strip_trailing_spaces_from_opaque_path(*
this);
394 std::string new_value;
395 new_value = input[0] ==
'?' ? input.substr(1) : input;
396 helpers::remove_ascii_tab_or_newline(new_value);
398 auto query_percent_encode_set =
402 update_base_search(new_value, query_percent_encode_set);
407 ada_log(
"url_aggregator::set_hash ", input);
412 buffer.resize(components.hash_start);
415 helpers::strip_trailing_spaces_from_opaque_path(*
this);
419 std::string new_value;
420 new_value = input[0] ==
'#' ? input.substr(1) : input;
421 helpers::remove_ascii_tab_or_newline(new_value);
422 update_unencoded_base_hash(new_value);
428 ada_log(
"url_aggregator::set_href ", input,
" [", input.size(),
" bytes]");
430 ada_log(
"url_aggregator::set_href, success :", out.has_value());
433 ada_log(
"url_aggregator::set_href, parsed ", out->to_string());
438 return out.has_value();
442 ada_log(
"url_aggregator:parse_host \"", input,
"\" [", input.size(),
450 if (input[0] ==
'[') {
452 if (input.back() !=
']') {
455 ada_log(
"parse_host ipv6");
459 input.remove_prefix(1);
460 input.remove_suffix(1);
461 return parse_ipv6(input);
467 return parse_opaque_host(input);
483 if (!input.empty() && input.back() ==
'.') {
484 update_base_hostname(input.substr(0, input.size() - 1));
486 update_base_hostname(input);
489 ada_log(
"parse_host fast path decimal ipv4");
493 uint8_t is_forbidden_or_upper =
494 unicode::contains_forbidden_domain_code_point_or_upper(input.data(),
502 if (is_forbidden_or_upper == 0 &&
503 input.find(
"xn-") == std::string_view::npos) {
505 update_base_hostname(input);
509 ada_log(
"parse_host fast path ipv4");
519 ada_log(
"parse_host calling to_ascii");
520 std::optional<std::string> host = std::string(
get_hostname());
521 is_valid = ada::unicode::to_ascii(host, input, input.find(
'%'));
523 ada_log(
"parse_host to_ascii returns false");
526 ada_log(
"parse_host to_ascii succeeded ", *host,
" [", host->size(),
529 if (std::ranges::any_of(host.value(),
530 ada::unicode::is_forbidden_domain_code_point)) {
536 if (checkers::is_ipv4(host.value())) {
537 ada_log(
"parse_host got ipv4 ", *host);
538 return parse_ipv4(host.value(),
false);
541 update_base_hostname(host.value());
546template <
bool overr
ide_hostname>
547bool url_aggregator::set_host_or_hostname(
const std::string_view input) {
548 ada_log(
"url_aggregator::set_host_or_hostname ", input);
556 uint32_t previous_port = components.port;
558 size_t host_end_pos = input.find(
'#');
559 std::string _host(input.data(), host_end_pos != std::string_view::npos
562 helpers::remove_ascii_tab_or_newline(_host);
563 std::string_view new_host(_host);
568 std::string_view host_view(_host.data(), _host.length());
569 auto [location, found_colon] =
570 helpers::get_host_delimiter_location(
is_special(), host_view);
578 std::string_view host_buffer = host_view.substr(0, location);
579 if (host_buffer.empty()) {
585 if constexpr (override_hostname) {
590 bool succeeded = parse_host(host_buffer);
592 update_base_hostname(previous_host);
593 update_base_port(previous_port);
599 std::string_view port_buffer = new_host.substr(location + 1);
600 if (!port_buffer.empty()) {
627 }
else if (has_dash_dot()) {
628 add_authority_slashes_if_needed();
634 bool succeeded = parse_host(host_view);
636 update_base_hostname(previous_host);
637 update_base_port(previous_port);
639 }
else if (has_dash_dot()) {
647 size_t location = new_host.find_first_of(
"/\\?");
648 if (location != std::string_view::npos) {
649 new_host.remove_suffix(new_host.length() - location);
652 if (new_host.empty()) {
657 if (!parse_host(new_host)) {
658 update_base_hostname(previous_host);
659 update_base_port(previous_port);
664 if (helpers::substring(buffer, components.host_start,
665 components.host_end) ==
"localhost") {
674 ada_log(
"url_aggregator::set_host '", input,
"'");
677 return set_host_or_hostname<false>(input);
681 ada_log(
"url_aggregator::set_hostname '", input,
"'");
684 return set_host_or_hostname<true>(input);
688 ada_log(
"url_aggregator::get_origin");
705 return helpers::concat(out->get_protocol(),
"//", out->get_host());
716 ada_log(
"url_aggregator::get_username");
718 return helpers::substring(buffer, components.protocol_end + 2,
719 components.username_end);
726 ada_log(
"url_aggregator::get_password");
728 return helpers::substring(buffer, components.username_end + 1,
729 components.host_start);
736 ada_log(
"url_aggregator::get_port");
740 return helpers::substring(buffer, components.host_end + 1,
741 components.pathname_start);
746 ada_log(
"url_aggregator::get_hash");
752 if (buffer.size() - components.hash_start <= 1) {
755 return helpers::substring(buffer, components.hash_start);
760 ada_log(
"url_aggregator::get_host");
764 size_t start = components.host_start;
765 if (components.host_end > components.host_start &&
766 buffer[components.host_start] ==
'@') {
771 if (start == components.host_end) {
774 return helpers::substring(buffer, start, components.pathname_start);
779 ada_log(
"url_aggregator::get_hostname");
783 size_t start = components.host_start;
785 if (components.host_end > components.host_start &&
786 buffer[components.host_start] ==
'@') {
789 return helpers::substring(buffer, start, components.host_end);
794 ada_log(
"url_aggregator::get_search");
800 auto ending_index = uint32_t(buffer.size());
802 ending_index = components.hash_start;
804 if (ending_index - components.search_start <= 1) {
807 return helpers::substring(buffer, components.search_start, ending_index);
812 ada_log(
"url_aggregator::get_protocol");
813 return helpers::substring(buffer, 0, components.protocol_end);
817 ada_log(
"url_aggregator::to_string buffer:", buffer,
" [", buffer.size(),
824 auto back = std::back_insert_iterator(answer);
825 answer.append(
"{\n");
827 answer.append(
"\t\"buffer\":\"");
828 helpers::encode_json(buffer, back);
829 answer.append(
"\",\n");
831 answer.append(
"\t\"protocol\":\"");
833 answer.append(
"\",\n");
836 answer.append(
"\t\"username\":\"");
838 answer.append(
"\",\n");
839 answer.append(
"\t\"password\":\"");
841 answer.append(
"\",\n");
844 answer.append(
"\t\"host\":\"");
845 helpers::encode_json(
get_host(), back);
846 answer.append(
"\",\n");
848 answer.append(
"\t\"path\":\"");
850 answer.append(
"\",\n");
851 answer.append(
"\t\"opaque path\":");
853 answer.append(
",\n");
856 answer.append(
"\t\"query\":\"");
858 answer.append(
"\",\n");
861 answer.append(
"\t\"fragment\":\"");
862 helpers::encode_json(
get_hash(), back);
863 answer.append(
"\",\n");
866 auto convert_offset_to_string = [](uint32_t offset) -> std::string {
870 return std::to_string(offset);
874 answer.append(
"\t\"protocol_end\":");
875 answer.append(convert_offset_to_string(components.protocol_end));
876 answer.append(
",\n");
878 answer.append(
"\t\"username_end\":");
879 answer.append(convert_offset_to_string(components.username_end));
880 answer.append(
",\n");
882 answer.append(
"\t\"host_start\":");
883 answer.append(convert_offset_to_string(components.host_start));
884 answer.append(
",\n");
886 answer.append(
"\t\"host_end\":");
887 answer.append(convert_offset_to_string(components.host_end));
888 answer.append(
",\n");
890 answer.append(
"\t\"port\":");
891 answer.append(convert_offset_to_string(components.port));
892 answer.append(
",\n");
894 answer.append(
"\t\"pathname_start\":");
895 answer.append(convert_offset_to_string(components.pathname_start));
896 answer.append(
",\n");
898 answer.append(
"\t\"search_start\":");
899 answer.append(convert_offset_to_string(components.search_start));
900 answer.append(
",\n");
902 answer.append(
"\t\"hash_start\":");
903 answer.append(convert_offset_to_string(components.hash_start));
904 answer.append(
"\n}");
910 if (components.host_start == components.host_end) {
916bool url_aggregator::parse_ipv4(std::string_view input,
bool in_place) {
917 ada_log(
"parse_ipv4 ", input,
" [", input.size(),
918 " bytes], overlaps with buffer: ",
919 helpers::overlaps(input, buffer) ?
"yes" :
"no");
921 const bool trailing_dot = (input.back() ==
'.');
923 input.remove_suffix(1);
925 size_t digit_count{0};
926 int pure_decimal_count = 0;
929 for (; (digit_count < 4) && !(input.empty()); digit_count++) {
933 if (is_hex && ((input.length() == 2) ||
934 ((input.length() > 2) && (input[2] ==
'.')))) {
937 input.remove_prefix(2);
939 std::from_chars_result r{};
941 ada_log(
"parse_ipv4 trying to parse hex number");
942 r = std::from_chars(input.data() + 2, input.data() + input.size(),
944 }
else if ((input.length() >= 2) && input[0] ==
'0' &&
946 ada_log(
"parse_ipv4 trying to parse octal number");
947 r = std::from_chars(input.data() + 1, input.data() + input.size(),
950 ada_log(
"parse_ipv4 trying to parse decimal number");
951 pure_decimal_count++;
952 r = std::from_chars(input.data(), input.data() + input.size(),
955 if (r.ec != std::errc()) {
956 ada_log(
"parse_ipv4 parsing failed");
959 ada_log(
"parse_ipv4 parsed ", segment_result);
960 input.remove_prefix(r.ptr - input.data());
966 if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
969 ipv4 <<= (32 - digit_count * 8);
970 ipv4 |= segment_result;
975 if ((segment_result > 255) || (input[0] !=
'.')) {
979 ipv4 |= segment_result;
980 input.remove_prefix(1);
983 if ((digit_count != 4) || (!input.empty())) {
984 ada_log(
"parse_ipv4 found invalid (more than 4 numbers or empty) ");
988 ada_log(
"url_aggregator::parse_ipv4 completed ",
get_href(),
992 if (in_place && pure_decimal_count == 4 && !trailing_dot) {
994 "url_aggregator::parse_ipv4 completed and was already correct in the "
999 ada_log(
"url_aggregator::parse_ipv4 completed and we need to update it");
1004 update_base_hostname(
1012bool url_aggregator::parse_ipv6(std::string_view input) {
1017 ada_log(
"parse_ipv6 ", input,
" [", input.size(),
" bytes]");
1020 if (input.empty()) {
1024 std::array<uint16_t, 8> address{};
1027 int piece_index = 0;
1030 std::optional<int> compress{};
1033 std::string_view::iterator pointer = input.begin();
1036 if (input[0] ==
':') {
1039 if (input.size() == 1 || input[1] !=
':') {
1040 ada_log(
"parse_ipv6 starts with : but the rest does not start with :");
1048 compress = ++piece_index;
1052 while (pointer != input.end()) {
1054 if (piece_index == 8) {
1055 ada_log(
"parse_ipv6 piece_index == 8");
1060 if (*pointer ==
':') {
1062 if (compress.has_value()) {
1063 ada_log(
"parse_ipv6 compress is non-null");
1070 compress = ++piece_index;
1075 uint16_t value = 0, length = 0;
1080 while (length < 4 && pointer != input.end() &&
1081 unicode::is_ascii_hex_digit(*pointer)) {
1083 value = uint16_t(value * 0x10 + unicode::convert_hex_to_binary(*pointer));
1089 if (pointer != input.end() && *pointer ==
'.') {
1092 ada_log(
"parse_ipv6 length is 0");
1100 if (piece_index > 6) {
1101 ada_log(
"parse_ipv6 piece_index > 6");
1106 int numbers_seen = 0;
1109 while (pointer != input.end()) {
1111 std::optional<uint16_t> ipv4_piece{};
1114 if (numbers_seen > 0) {
1117 if (*pointer ==
'.' && numbers_seen < 4) {
1121 ada_log(
"parse_ipv6 Otherwise, validation error, return failure");
1129 "parse_ipv6 If c is not an ASCII digit, validation error, return "
1137 int number = *pointer -
'0';
1140 if (!ipv4_piece.has_value()) {
1141 ipv4_piece = number;
1144 else if (ipv4_piece == 0) {
1145 ada_log(
"parse_ipv6 if ipv4Piece is 0, validation error");
1150 ipv4_piece = *ipv4_piece * 10 + number;
1154 if (ipv4_piece > 255) {
1155 ada_log(
"parse_ipv6 ipv4_piece > 255");
1166 address[piece_index] =
1167 uint16_t(address[piece_index] * 0x100 + *ipv4_piece);
1173 if (numbers_seen == 2 || numbers_seen == 4) {
1179 if (numbers_seen != 4) {
1187 else if ((pointer != input.end()) && (*pointer ==
':')) {
1192 if (pointer == input.end()) {
1194 "parse_ipv6 If c is the EOF code point, validation error, return "
1201 else if (pointer != input.end()) {
1203 "parse_ipv6 Otherwise, if c is not the EOF code point, validation "
1204 "error, return failure");
1209 address[piece_index] = value;
1216 if (compress.has_value()) {
1218 int swaps = piece_index - *compress;
1226 while (piece_index != 0 && swaps > 0) {
1227 std::swap(address[piece_index], address[*compress + swaps - 1]);
1234 else if (piece_index != 8) {
1236 "parse_ipv6 if compress is null and pieceIndex is not 8, validation "
1237 "error, return failure");
1250bool url_aggregator::parse_opaque_host(std::string_view input) {
1251 ada_log(
"parse_opaque_host ", input,
" [", input.size(),
" bytes]");
1254 if (std::ranges::any_of(input, ada::unicode::is_forbidden_host_code_point)) {
1262 if (idx == input.size()) {
1263 update_base_hostname(input);
1266 update_base_hostname(ada::unicode::percent_encode(
1278 answer.append(buffer);
1279 answer.append(
" [");
1280 answer.append(std::to_string(buffer.size()));
1281 answer.append(
" bytes]");
1282 answer.append(
"\n");
1285 line1.resize(buffer.size(),
' ');
1287 line1[components.hash_start] =
'|';
1290 line1[components.search_start] =
'|';
1292 if (components.pathname_start != buffer.size()) {
1293 line1[components.pathname_start] =
'|';
1295 if (components.host_end != buffer.size()) {
1296 line1[components.host_end] =
'|';
1298 if (components.host_start != buffer.size()) {
1299 line1[components.host_start] =
'|';
1301 if (components.username_end != buffer.size()) {
1302 line1[components.username_end] =
'|';
1304 if (components.protocol_end != buffer.size()) {
1305 line1[components.protocol_end] =
'|';
1307 answer.append(line1);
1308 answer.append(
"\n");
1310 std::string line2 = line1;
1312 line2[components.hash_start] =
'`';
1313 line1[components.hash_start] =
' ';
1315 for (
size_t i = components.hash_start + 1; i < line2.size(); i++) {
1318 line2.append(
" hash_start");
1319 answer.append(line2);
1320 answer.append(
"\n");
1323 std::string line3 = line1;
1325 line3[components.search_start] =
'`';
1326 line1[components.search_start] =
' ';
1328 for (
size_t i = components.search_start + 1; i < line3.size(); i++) {
1331 line3.append(
" search_start ");
1332 line3.append(std::to_string(components.search_start));
1333 answer.append(line3);
1334 answer.append(
"\n");
1337 std::string line4 = line1;
1338 if (components.pathname_start != buffer.size()) {
1339 line4[components.pathname_start] =
'`';
1340 line1[components.pathname_start] =
' ';
1341 for (
size_t i = components.pathname_start + 1; i < line4.size(); i++) {
1344 line4.append(
" pathname_start ");
1345 line4.append(std::to_string(components.pathname_start));
1346 answer.append(line4);
1347 answer.append(
"\n");
1350 std::string line5 = line1;
1351 if (components.host_end != buffer.size()) {
1352 line5[components.host_end] =
'`';
1353 line1[components.host_end] =
' ';
1355 for (
size_t i = components.host_end + 1; i < line5.size(); i++) {
1358 line5.append(
" host_end ");
1359 line5.append(std::to_string(components.host_end));
1360 answer.append(line5);
1361 answer.append(
"\n");
1364 std::string line6 = line1;
1365 if (components.host_start != buffer.size()) {
1366 line6[components.host_start] =
'`';
1367 line1[components.host_start] =
' ';
1369 for (
size_t i = components.host_start + 1; i < line6.size(); i++) {
1372 line6.append(
" host_start ");
1373 line6.append(std::to_string(components.host_start));
1374 answer.append(line6);
1375 answer.append(
"\n");
1378 std::string line7 = line1;
1379 if (components.username_end != buffer.size()) {
1380 line7[components.username_end] =
'`';
1381 line1[components.username_end] =
' ';
1383 for (
size_t i = components.username_end + 1; i < line7.size(); i++) {
1386 line7.append(
" username_end ");
1387 line7.append(std::to_string(components.username_end));
1388 answer.append(line7);
1389 answer.append(
"\n");
1392 std::string line8 = line1;
1393 if (components.protocol_end != buffer.size()) {
1394 line8[components.protocol_end] =
'`';
1395 line1[components.protocol_end] =
' ';
1397 for (
size_t i = components.protocol_end + 1; i < line8.size(); i++) {
1400 line8.append(
" protocol_end ");
1401 line8.append(std::to_string(components.protocol_end));
1402 answer.append(line8);
1403 answer.append(
"\n");
1407 answer.append(
"note: hash omitted\n");
1410 answer.append(
"note: search omitted\n");
1412 if (components.protocol_end > buffer.size()) {
1413 answer.append(
"warning: protocol_end overflows\n");
1415 if (components.username_end > buffer.size()) {
1416 answer.append(
"warning: username_end overflows\n");
1418 if (components.host_start > buffer.size()) {
1419 answer.append(
"warning: host_start overflows\n");
1421 if (components.host_end > buffer.size()) {
1422 answer.append(
"warning: host_end overflows\n");
1424 if (components.pathname_start > buffer.size()) {
1425 answer.append(
"warning: pathname_start overflows\n");
1430void url_aggregator::delete_dash_dot() {
1431 ada_log(
"url_aggregator::delete_dash_dot");
1434 buffer.erase(components.
host_end, 2);
1446inline void url_aggregator::consume_prepared_path(std::string_view input) {
1447 ada_log(
"url_aggregator::consume_prepared_path ", input);
1457 uint8_t accumulator = checkers::path_signature(input);
1462 constexpr uint8_t need_encoding = 1;
1463 constexpr uint8_t backslash_char = 2;
1464 constexpr uint8_t dot_char = 4;
1465 constexpr uint8_t percent_char = 8;
1470 (special ? (accumulator == 0)
1471 : ((accumulator & (need_encoding | dot_char | percent_char)) ==
1473 (!may_need_slow_file_handling);
1474 if (accumulator == dot_char && !may_need_slow_file_handling) {
1482 if (input[0] !=
'.') {
1483 size_t slashdot = 0;
1484 bool dot_is_file =
true;
1486 slashdot = input.find(
"/.", slashdot);
1487 if (slashdot == std::string_view::npos) {
1492 dot_is_file &= !(slashdot == input.size() || input[slashdot] ==
'.' ||
1493 input[slashdot] ==
'/');
1496 trivial_path = dot_is_file;
1499 if (trivial_path && is_at_path()) {
1500 ada_log(
"parse_path trivial");
1512 (accumulator & (need_encoding | backslash_char | percent_char)) == 0) &&
1515 ada_log(
"parse_prepared_path fast");
1520 size_t previous_location = 0;
1522 size_t new_location = input.find(
'/', previous_location);
1525 if (new_location == std::string_view::npos) {
1526 std::string_view path_view = input.substr(previous_location);
1527 if (path_view ==
"..") {
1531 update_base_pathname(path);
1535 if (path.back() ==
'/') {
1536 update_base_pathname(path);
1541 path.resize(path.rfind(
'/') + 1);
1542 update_base_pathname(path);
1546 if (path_view !=
".") {
1547 path.append(path_view);
1549 update_base_pathname(path);
1553 std::string_view path_view =
1554 input.substr(previous_location, new_location - previous_location);
1555 previous_location = new_location + 1;
1556 if (path_view ==
"..") {
1557 size_t last_delimiter = path.rfind(
'/');
1558 if (last_delimiter != std::string::npos) {
1559 path.erase(last_delimiter);
1561 }
else if (path_view !=
".") {
1563 path.append(path_view);
1568 ada_log(
"parse_path slow");
1570 bool needs_percent_encoding = (accumulator & 1);
1571 std::string path_buffer_tmp;
1573 size_t location = (special && (accumulator & 2))
1574 ? input.find_first_of(
"/\\")
1576 std::string_view path_view = input;
1577 if (location != std::string_view::npos) {
1578 path_view.remove_suffix(path_view.size() - location);
1579 input.remove_prefix(location + 1);
1583 std::string_view path_buffer =
1584 (needs_percent_encoding &&
1585 ada::unicode::percent_encode<false>(
1589 if (unicode::is_double_dot_path_segment(path_buffer)) {
1590 helpers::shorten_path(path, type);
1591 if (location == std::string_view::npos) {
1594 }
else if (unicode::is_single_dot_path_segment(path_buffer) &&
1595 (location == std::string_view::npos)) {
1599 else if (!unicode::is_single_dot_path_segment(path_buffer)) {
1606 path += path_buffer[0];
1608 path_buffer.remove_prefix(2);
1609 path.append(path_buffer);
1613 path.append(path_buffer);
1616 if (location == std::string_view::npos) {
1617 update_base_pathname(path);
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.
User-facing functions for URL parsing and manipulation.
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 has_hex_prefix(std::string_view input)
constexpr bool is_windows_drive_letter(std::string_view input) noexcept
constexpr uint64_t ipv4_fast_fail
constexpr bool is_alpha(char x) noexcept
constexpr bool is_digit(char x) noexcept
ada_really_inline constexpr uint64_t try_parse_ipv4_fast(std::string_view input) noexcept
constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept
std::string ipv6(const std::array< uint16_t, 8 > &address)
std::string ipv4(uint64_t address)
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)
URL scheme type definitions and utilities.
Memory-efficient URL representation using a single buffer.
constexpr bool has_non_empty_password() const noexcept
void set_hash(std::string_view input)
constexpr bool validate() const noexcept
void clear_search() override
std::string_view get_search() const ada_lifetime_bound
std::string_view get_hash() const ada_lifetime_bound
std::string to_string() const override
std::string_view get_password() const ada_lifetime_bound
std::string_view get_host() const ada_lifetime_bound
std::string_view get_username() const ada_lifetime_bound
std::string_view get_port() const ada_lifetime_bound
std::string to_diagram() const
constexpr bool has_hostname() const noexcept
bool set_protocol(std::string_view input)
std::string get_origin() const override
constexpr std::string_view get_href() 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)
bool set_href(std::string_view input)
constexpr std::string_view get_pathname() const ada_lifetime_bound
void set_search(std::string_view input)
std::string_view get_hostname() const ada_lifetime_bound
std::string_view get_protocol() const ada_lifetime_bound
constexpr bool has_port() const noexcept
ada_really_inline constexpr bool has_credentials() const noexcept
bool set_host(std::string_view input)
bool set_port(std::string_view input)
constexpr bool has_non_empty_username() const noexcept
bool set_username(std::string_view input)
ada_really_inline constexpr bool is_special() const noexcept
static constexpr uint32_t omitted
Definitions for unicode operations.
Inline functions for url aggregator.
Declaration for the ada::url_aggregator class.
Declaration for the URL Components.