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) {
114inline void url_aggregator::copy_scheme(
const url_aggregator& u)
noexcept {
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)
noexcept {
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)
noexcept {
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;
338 ada_log(
"url_aggregator::parse_path ", input);
341 std::string tmp_buffer;
342 std::string_view internal_input;
343 if (unicode::has_tabs_or_newline(input)) {
347 helpers::remove_ascii_tab_or_newline(tmp_buffer);
348 internal_input = tmp_buffer;
350 internal_input = input;
355 if (internal_input.empty()) {
356 update_base_pathname(
"/");
357 }
else if ((internal_input[0] ==
'/') || (internal_input[0] ==
'\\')) {
358 consume_prepared_path(internal_input.substr(1));
360 consume_prepared_path(internal_input);
362 }
else if (!internal_input.empty()) {
363 if (internal_input[0] ==
'/') {
364 consume_prepared_path(internal_input.substr(1));
366 consume_prepared_path(internal_input);
371 if (components.host_start == components.host_end && !has_authority()) {
372 update_base_pathname(
"/");
379 ada_log(
"url_aggregator::set_search ", input);
384 helpers::strip_trailing_spaces_from_opaque_path(*
this);
388 std::string new_value;
389 new_value = input[0] ==
'?' ? input.substr(1) : input;
390 helpers::remove_ascii_tab_or_newline(new_value);
392 auto query_percent_encode_set =
396 update_base_search(new_value, query_percent_encode_set);
401 ada_log(
"url_aggregator::set_hash ", input);
406 buffer.resize(components.hash_start);
409 helpers::strip_trailing_spaces_from_opaque_path(*
this);
413 std::string new_value;
414 new_value = input[0] ==
'#' ? input.substr(1) : input;
415 helpers::remove_ascii_tab_or_newline(new_value);
416 update_unencoded_base_hash(new_value);
422 ada_log(
"url_aggregator::set_href ", input,
" [", input.size(),
" bytes]");
424 ada_log(
"url_aggregator::set_href, success :", out.has_value());
427 ada_log(
"url_aggregator::set_href, parsed ", out->to_string());
432 return out.has_value();
436 ada_log(
"url_aggregator:parse_host \"", input,
"\" [", input.size(),
444 if (input[0] ==
'[') {
446 if (input.back() !=
']') {
449 ada_log(
"parse_host ipv6");
453 input.remove_prefix(1);
454 input.remove_suffix(1);
455 return parse_ipv6(input);
461 return parse_opaque_host(input);
472 uint8_t is_forbidden_or_upper =
473 unicode::contains_forbidden_domain_code_point_or_upper(input.data(),
481 if (is_forbidden_or_upper == 0 &&
482 input.find(
"xn-") == std::string_view::npos) {
484 update_base_hostname(input);
486 ada_log(
"parse_host fast path ipv4");
496 ada_log(
"parse_host calling to_ascii");
497 std::optional<std::string> host = std::string(
get_hostname());
498 is_valid = ada::unicode::to_ascii(host, input, input.find(
'%'));
500 ada_log(
"parse_host to_ascii returns false");
503 ada_log(
"parse_host to_ascii succeeded ", *host,
" [", host->size(),
506 if (std::ranges::any_of(host.value(),
507 ada::unicode::is_forbidden_domain_code_point)) {
513 if (checkers::is_ipv4(host.value())) {
514 ada_log(
"parse_host got ipv4 ", *host);
515 return parse_ipv4(host.value(),
false);
518 update_base_hostname(host.value());
523template <
bool overr
ide_hostname>
524bool url_aggregator::set_host_or_hostname(
const std::string_view input) {
525 ada_log(
"url_aggregator::set_host_or_hostname ", input);
533 uint32_t previous_port = components.port;
535 size_t host_end_pos = input.find(
'#');
536 std::string _host(input.data(), host_end_pos != std::string_view::npos
539 helpers::remove_ascii_tab_or_newline(_host);
540 std::string_view new_host(_host);
545 std::string_view host_view(_host.data(), _host.length());
546 auto [location, found_colon] =
547 helpers::get_host_delimiter_location(
is_special(), host_view);
555 std::string_view host_buffer = host_view.substr(0, location);
556 if (host_buffer.empty()) {
562 if constexpr (override_hostname) {
567 bool succeeded = parse_host(host_buffer);
569 update_base_hostname(previous_host);
570 update_base_port(previous_port);
576 std::string_view port_buffer = new_host.substr(location + 1);
577 if (!port_buffer.empty()) {
604 }
else if (has_dash_dot()) {
605 add_authority_slashes_if_needed();
611 bool succeeded = parse_host(host_view);
613 update_base_hostname(previous_host);
614 update_base_port(previous_port);
616 }
else if (has_dash_dot()) {
624 size_t location = new_host.find_first_of(
"/\\?");
625 if (location != std::string_view::npos) {
626 new_host.remove_suffix(new_host.length() - location);
629 if (new_host.empty()) {
634 if (!parse_host(new_host)) {
635 update_base_hostname(previous_host);
636 update_base_port(previous_port);
641 if (helpers::substring(buffer, components.host_start,
642 components.host_end) ==
"localhost") {
651 ada_log(
"url_aggregator::set_host '", input,
"'");
654 return set_host_or_hostname<false>(input);
658 ada_log(
"url_aggregator::set_hostname '", input,
"'");
661 return set_host_or_hostname<true>(input);
665 ada_log(
"url_aggregator::get_origin");
682 return helpers::concat(out->get_protocol(),
"//", out->get_host());
693 ada_log(
"url_aggregator::get_username");
695 return helpers::substring(buffer, components.protocol_end + 2,
696 components.username_end);
703 ada_log(
"url_aggregator::get_password");
705 return helpers::substring(buffer, components.username_end + 1,
706 components.host_start);
713 ada_log(
"url_aggregator::get_port");
717 return helpers::substring(buffer, components.host_end + 1,
718 components.pathname_start);
723 ada_log(
"url_aggregator::get_hash");
729 if (buffer.size() - components.hash_start <= 1) {
732 return helpers::substring(buffer, components.hash_start);
737 ada_log(
"url_aggregator::get_host");
741 size_t start = components.host_start;
742 if (components.host_end > components.host_start &&
743 buffer[components.host_start] ==
'@') {
748 if (start == components.host_end) {
751 return helpers::substring(buffer, start, components.pathname_start);
756 ada_log(
"url_aggregator::get_hostname");
760 size_t start = components.host_start;
762 if (components.host_end > components.host_start &&
763 buffer[components.host_start] ==
'@') {
766 return helpers::substring(buffer, start, components.host_end);
771 ada_log(
"url_aggregator::get_search");
777 auto ending_index = uint32_t(buffer.size());
779 ending_index = components.hash_start;
781 if (ending_index - components.search_start <= 1) {
784 return helpers::substring(buffer, components.search_start, ending_index);
789 ada_log(
"url_aggregator::get_protocol");
790 return helpers::substring(buffer, 0, components.protocol_end);
794 ada_log(
"url_aggregator::to_string buffer:", buffer,
" [", buffer.size(),
801 auto back = std::back_insert_iterator(answer);
802 answer.append(
"{\n");
804 answer.append(
"\t\"buffer\":\"");
805 helpers::encode_json(buffer, back);
806 answer.append(
"\",\n");
808 answer.append(
"\t\"protocol\":\"");
810 answer.append(
"\",\n");
813 answer.append(
"\t\"username\":\"");
815 answer.append(
"\",\n");
816 answer.append(
"\t\"password\":\"");
818 answer.append(
"\",\n");
821 answer.append(
"\t\"host\":\"");
822 helpers::encode_json(
get_host(), back);
823 answer.append(
"\",\n");
825 answer.append(
"\t\"path\":\"");
827 answer.append(
"\",\n");
828 answer.append(
"\t\"opaque path\":");
830 answer.append(
",\n");
833 answer.append(
"\t\"query\":\"");
835 answer.append(
"\",\n");
838 answer.append(
"\t\"fragment\":\"");
839 helpers::encode_json(
get_hash(), back);
840 answer.append(
"\",\n");
843 auto convert_offset_to_string = [](uint32_t offset) -> std::string {
847 return std::to_string(offset);
851 answer.append(
"\t\"protocol_end\":");
852 answer.append(convert_offset_to_string(components.protocol_end));
853 answer.append(
",\n");
855 answer.append(
"\t\"username_end\":");
856 answer.append(convert_offset_to_string(components.username_end));
857 answer.append(
",\n");
859 answer.append(
"\t\"host_start\":");
860 answer.append(convert_offset_to_string(components.host_start));
861 answer.append(
",\n");
863 answer.append(
"\t\"host_end\":");
864 answer.append(convert_offset_to_string(components.host_end));
865 answer.append(
",\n");
867 answer.append(
"\t\"port\":");
868 answer.append(convert_offset_to_string(components.port));
869 answer.append(
",\n");
871 answer.append(
"\t\"pathname_start\":");
872 answer.append(convert_offset_to_string(components.pathname_start));
873 answer.append(
",\n");
875 answer.append(
"\t\"search_start\":");
876 answer.append(convert_offset_to_string(components.search_start));
877 answer.append(
",\n");
879 answer.append(
"\t\"hash_start\":");
880 answer.append(convert_offset_to_string(components.hash_start));
881 answer.append(
"\n}");
887 if (components.host_start == components.host_end) {
893bool url_aggregator::parse_ipv4(std::string_view input,
bool in_place) {
894 ada_log(
"parse_ipv4 ", input,
" [", input.size(),
895 " bytes], overlaps with buffer: ",
896 helpers::overlaps(input, buffer) ?
"yes" :
"no");
898 const bool trailing_dot = (input.back() ==
'.');
900 input.remove_suffix(1);
902 size_t digit_count{0};
903 int pure_decimal_count = 0;
906 for (; (digit_count < 4) && !(input.empty()); digit_count++) {
910 if (is_hex && ((input.length() == 2) ||
911 ((input.length() > 2) && (input[2] ==
'.')))) {
914 input.remove_prefix(2);
916 std::from_chars_result r{};
918 ada_log(
"parse_ipv4 trying to parse hex number");
919 r = std::from_chars(input.data() + 2, input.data() + input.size(),
921 }
else if ((input.length() >= 2) && input[0] ==
'0' &&
923 ada_log(
"parse_ipv4 trying to parse octal number");
924 r = std::from_chars(input.data() + 1, input.data() + input.size(),
927 ada_log(
"parse_ipv4 trying to parse decimal number");
928 pure_decimal_count++;
929 r = std::from_chars(input.data(), input.data() + input.size(),
932 if (r.ec != std::errc()) {
933 ada_log(
"parse_ipv4 parsing failed");
936 ada_log(
"parse_ipv4 parsed ", segment_result);
937 input.remove_prefix(r.ptr - input.data());
943 if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
946 ipv4 <<= (32 - digit_count * 8);
947 ipv4 |= segment_result;
952 if ((segment_result > 255) || (input[0] !=
'.')) {
956 ipv4 |= segment_result;
957 input.remove_prefix(1);
960 if ((digit_count != 4) || (!input.empty())) {
961 ada_log(
"parse_ipv4 found invalid (more than 4 numbers or empty) ");
965 ada_log(
"url_aggregator::parse_ipv4 completed ",
get_href(),
969 if (in_place && pure_decimal_count == 4 && !trailing_dot) {
971 "url_aggregator::parse_ipv4 completed and was already correct in the "
976 ada_log(
"url_aggregator::parse_ipv4 completed and we need to update it");
981 update_base_hostname(
989bool url_aggregator::parse_ipv6(std::string_view input) {
994 ada_log(
"parse_ipv6 ", input,
" [", input.size(),
" bytes]");
1001 std::array<uint16_t, 8> address{};
1004 int piece_index = 0;
1007 std::optional<int> compress{};
1010 std::string_view::iterator pointer = input.begin();
1013 if (input[0] ==
':') {
1016 if (input.size() == 1 || input[1] !=
':') {
1017 ada_log(
"parse_ipv6 starts with : but the rest does not start with :");
1025 compress = ++piece_index;
1029 while (pointer != input.end()) {
1031 if (piece_index == 8) {
1032 ada_log(
"parse_ipv6 piece_index == 8");
1037 if (*pointer ==
':') {
1039 if (compress.has_value()) {
1040 ada_log(
"parse_ipv6 compress is non-null");
1047 compress = ++piece_index;
1052 uint16_t value = 0, length = 0;
1057 while (length < 4 && pointer != input.end() &&
1058 unicode::is_ascii_hex_digit(*pointer)) {
1060 value = uint16_t(value * 0x10 + unicode::convert_hex_to_binary(*pointer));
1066 if (pointer != input.end() && *pointer ==
'.') {
1069 ada_log(
"parse_ipv6 length is 0");
1077 if (piece_index > 6) {
1078 ada_log(
"parse_ipv6 piece_index > 6");
1083 int numbers_seen = 0;
1086 while (pointer != input.end()) {
1088 std::optional<uint16_t> ipv4_piece{};
1091 if (numbers_seen > 0) {
1094 if (*pointer ==
'.' && numbers_seen < 4) {
1098 ada_log(
"parse_ipv6 Otherwise, validation error, return failure");
1106 "parse_ipv6 If c is not an ASCII digit, validation error, return "
1114 int number = *pointer -
'0';
1117 if (!ipv4_piece.has_value()) {
1118 ipv4_piece = number;
1121 else if (ipv4_piece == 0) {
1122 ada_log(
"parse_ipv6 if ipv4Piece is 0, validation error");
1127 ipv4_piece = *ipv4_piece * 10 + number;
1131 if (ipv4_piece > 255) {
1132 ada_log(
"parse_ipv6 ipv4_piece > 255");
1143 address[piece_index] =
1144 uint16_t(address[piece_index] * 0x100 + *ipv4_piece);
1150 if (numbers_seen == 2 || numbers_seen == 4) {
1156 if (numbers_seen != 4) {
1164 else if ((pointer != input.end()) && (*pointer ==
':')) {
1169 if (pointer == input.end()) {
1171 "parse_ipv6 If c is the EOF code point, validation error, return "
1178 else if (pointer != input.end()) {
1180 "parse_ipv6 Otherwise, if c is not the EOF code point, validation "
1181 "error, return failure");
1186 address[piece_index] = value;
1193 if (compress.has_value()) {
1195 int swaps = piece_index - *compress;
1203 while (piece_index != 0 && swaps > 0) {
1204 std::swap(address[piece_index], address[*compress + swaps - 1]);
1211 else if (piece_index != 8) {
1213 "parse_ipv6 if compress is null and pieceIndex is not 8, validation "
1214 "error, return failure");
1227bool url_aggregator::parse_opaque_host(std::string_view input) {
1228 ada_log(
"parse_opaque_host ", input,
" [", input.size(),
" bytes]");
1231 if (std::ranges::any_of(input, ada::unicode::is_forbidden_host_code_point)) {
1239 if (idx == input.size()) {
1240 update_base_hostname(input);
1243 update_base_hostname(ada::unicode::percent_encode(
1255 answer.append(buffer);
1256 answer.append(
" [");
1257 answer.append(std::to_string(buffer.size()));
1258 answer.append(
" bytes]");
1259 answer.append(
"\n");
1262 line1.resize(buffer.size(),
' ');
1264 line1[components.hash_start] =
'|';
1267 line1[components.search_start] =
'|';
1269 if (components.pathname_start != buffer.size()) {
1270 line1[components.pathname_start] =
'|';
1272 if (components.host_end != buffer.size()) {
1273 line1[components.host_end] =
'|';
1275 if (components.host_start != buffer.size()) {
1276 line1[components.host_start] =
'|';
1278 if (components.username_end != buffer.size()) {
1279 line1[components.username_end] =
'|';
1281 if (components.protocol_end != buffer.size()) {
1282 line1[components.protocol_end] =
'|';
1284 answer.append(line1);
1285 answer.append(
"\n");
1287 std::string line2 = line1;
1289 line2[components.hash_start] =
'`';
1290 line1[components.hash_start] =
' ';
1292 for (
size_t i = components.hash_start + 1; i < line2.size(); i++) {
1295 line2.append(
" hash_start");
1296 answer.append(line2);
1297 answer.append(
"\n");
1300 std::string line3 = line1;
1302 line3[components.search_start] =
'`';
1303 line1[components.search_start] =
' ';
1305 for (
size_t i = components.search_start + 1; i < line3.size(); i++) {
1308 line3.append(
" search_start ");
1309 line3.append(std::to_string(components.search_start));
1310 answer.append(line3);
1311 answer.append(
"\n");
1314 std::string line4 = line1;
1315 if (components.pathname_start != buffer.size()) {
1316 line4[components.pathname_start] =
'`';
1317 line1[components.pathname_start] =
' ';
1318 for (
size_t i = components.pathname_start + 1; i < line4.size(); i++) {
1321 line4.append(
" pathname_start ");
1322 line4.append(std::to_string(components.pathname_start));
1323 answer.append(line4);
1324 answer.append(
"\n");
1327 std::string line5 = line1;
1328 if (components.host_end != buffer.size()) {
1329 line5[components.host_end] =
'`';
1330 line1[components.host_end] =
' ';
1332 for (
size_t i = components.host_end + 1; i < line5.size(); i++) {
1335 line5.append(
" host_end ");
1336 line5.append(std::to_string(components.host_end));
1337 answer.append(line5);
1338 answer.append(
"\n");
1341 std::string line6 = line1;
1342 if (components.host_start != buffer.size()) {
1343 line6[components.host_start] =
'`';
1344 line1[components.host_start] =
' ';
1346 for (
size_t i = components.host_start + 1; i < line6.size(); i++) {
1349 line6.append(
" host_start ");
1350 line6.append(std::to_string(components.host_start));
1351 answer.append(line6);
1352 answer.append(
"\n");
1355 std::string line7 = line1;
1356 if (components.username_end != buffer.size()) {
1357 line7[components.username_end] =
'`';
1358 line1[components.username_end] =
' ';
1360 for (
size_t i = components.username_end + 1; i < line7.size(); i++) {
1363 line7.append(
" username_end ");
1364 line7.append(std::to_string(components.username_end));
1365 answer.append(line7);
1366 answer.append(
"\n");
1369 std::string line8 = line1;
1370 if (components.protocol_end != buffer.size()) {
1371 line8[components.protocol_end] =
'`';
1372 line1[components.protocol_end] =
' ';
1374 for (
size_t i = components.protocol_end + 1; i < line8.size(); i++) {
1377 line8.append(
" protocol_end ");
1378 line8.append(std::to_string(components.protocol_end));
1379 answer.append(line8);
1380 answer.append(
"\n");
1384 answer.append(
"note: hash omitted\n");
1387 answer.append(
"note: search omitted\n");
1389 if (components.protocol_end > buffer.size()) {
1390 answer.append(
"warning: protocol_end overflows\n");
1392 if (components.username_end > buffer.size()) {
1393 answer.append(
"warning: username_end overflows\n");
1395 if (components.host_start > buffer.size()) {
1396 answer.append(
"warning: host_start overflows\n");
1398 if (components.host_end > buffer.size()) {
1399 answer.append(
"warning: host_end overflows\n");
1401 if (components.pathname_start > buffer.size()) {
1402 answer.append(
"warning: pathname_start overflows\n");
1407void url_aggregator::delete_dash_dot() {
1408 ada_log(
"url_aggregator::delete_dash_dot");
1411 buffer.erase(components.
host_end, 2);
1423inline void url_aggregator::consume_prepared_path(std::string_view input) {
1424 ada_log(
"url_aggregator::consume_prepared_path ", input);
1434 uint8_t accumulator = checkers::path_signature(input);
1439 constexpr uint8_t need_encoding = 1;
1440 constexpr uint8_t backslash_char = 2;
1441 constexpr uint8_t dot_char = 4;
1442 constexpr uint8_t percent_char = 8;
1447 (special ? (accumulator == 0)
1448 : ((accumulator & (need_encoding | dot_char | percent_char)) ==
1450 (!may_need_slow_file_handling);
1451 if (accumulator == dot_char && !may_need_slow_file_handling) {
1459 if (input[0] !=
'.') {
1460 size_t slashdot = 0;
1461 bool dot_is_file =
true;
1463 slashdot = input.find(
"/.", slashdot);
1464 if (slashdot == std::string_view::npos) {
1469 dot_is_file &= !(slashdot == input.size() || input[slashdot] ==
'.' ||
1470 input[slashdot] ==
'/');
1473 trivial_path = dot_is_file;
1476 if (trivial_path && is_at_path()) {
1477 ada_log(
"parse_path trivial");
1489 (accumulator & (need_encoding | backslash_char | percent_char)) == 0) &&
1492 ada_log(
"parse_prepared_path fast");
1497 size_t previous_location = 0;
1499 size_t new_location = input.find(
'/', previous_location);
1502 if (new_location == std::string_view::npos) {
1503 std::string_view path_view = input.substr(previous_location);
1504 if (path_view ==
"..") {
1508 update_base_pathname(path);
1512 if (path.back() ==
'/') {
1513 update_base_pathname(path);
1518 path.resize(path.rfind(
'/') + 1);
1519 update_base_pathname(path);
1523 if (path_view !=
".") {
1524 path.append(path_view);
1526 update_base_pathname(path);
1530 std::string_view path_view =
1531 input.substr(previous_location, new_location - previous_location);
1532 previous_location = new_location + 1;
1533 if (path_view ==
"..") {
1534 size_t last_delimiter = path.rfind(
'/');
1535 if (last_delimiter != std::string::npos) {
1536 path.erase(last_delimiter);
1538 }
else if (path_view !=
".") {
1540 path.append(path_view);
1545 ada_log(
"parse_path slow");
1547 bool needs_percent_encoding = (accumulator & 1);
1548 std::string path_buffer_tmp;
1550 size_t location = (special && (accumulator & 2))
1551 ? input.find_first_of(
"/\\")
1553 std::string_view path_view = input;
1554 if (location != std::string_view::npos) {
1555 path_view.remove_suffix(path_view.size() - location);
1556 input.remove_prefix(location + 1);
1560 std::string_view path_buffer =
1561 (needs_percent_encoding &&
1562 ada::unicode::percent_encode<false>(
1566 if (unicode::is_double_dot_path_segment(path_buffer)) {
1567 helpers::shorten_path(path, type);
1568 if (location == std::string_view::npos) {
1571 }
else if (unicode::is_single_dot_path_segment(path_buffer) &&
1572 (location == std::string_view::npos)) {
1576 else if (!unicode::is_single_dot_path_segment(path_buffer)) {
1583 path += path_buffer[0];
1585 path_buffer.remove_prefix(2);
1586 path.append(path_buffer);
1590 path.append(path_buffer);
1593 if (location == std::string_view::npos) {
1594 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.
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 has_hex_prefix(std::string_view input)
constexpr bool is_windows_drive_letter(std::string_view input) noexcept
constexpr bool is_alpha(char x) noexcept
constexpr bool is_digit(char x) noexcept
constexpr ada::scheme::type get_scheme_type(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.
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_hostname() const noexcept ada_lifetime_bound
std::string to_string() const override
std::string_view get_hash() const noexcept 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 noexcept override
constexpr std::string_view get_href() const noexcept ada_lifetime_bound
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)
constexpr std::string_view get_pathname() const noexcept ada_lifetime_bound
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
constexpr bool has_port() const noexcept
ada_really_inline constexpr bool has_credentials() const noexcept
bool set_host(std::string_view input)
std::string_view get_host() const noexcept ada_lifetime_bound
bool set_port(std::string_view input)
constexpr bool has_non_empty_username() const noexcept
std::string_view get_username() const noexcept ada_lifetime_bound
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 basic URL definitions.
Declaration for the URL Components.