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) {
40 parsed_type == ada::scheme::type::FILE) {
46 if (type == ada::scheme::type::FILE &&
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)) {
89 if (type == ada::scheme::type::FILE &&
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]");
417 ada_log(
"url_aggregator::set_href, parsed ", out->to_string());
426 ada_log(
"url_aggregator:parse_host \"", input,
"\" [", input.size(),
434 if (input[0] ==
'[') {
436 if (input.back() !=
']') {
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);
534 if (type != ada::scheme::type::FILE) {
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());
650 ada_log(
"url_aggregator::get_username");
652 return helpers::substring(buffer, components.
protocol_end + 2,
659 ada_log(
"url_aggregator::get_password");
661 return helpers::substring(buffer, components.
username_end + 1,
668 ada_log(
"url_aggregator::get_port");
672 return helpers::substring(buffer, components.
host_end + 1,
677 ada_log(
"url_aggregator::get_hash");
683 if (buffer.size() - components.
hash_start <= 1) {
686 return helpers::substring(buffer, components.
hash_start);
690 ada_log(
"url_aggregator::get_host");
704 return helpers::substring(buffer, start, components.
pathname_start);
708 ada_log(
"url_aggregator::get_hostname");
718 return helpers::substring(buffer, start, components.
host_end);
722 ada_log(
"url_aggregator::get_pathname pathname_start = ",
725 " components.hash_start = ", components.
hash_start);
726 auto ending_index = uint32_t(buffer.size());
732 return helpers::substring(buffer, components.
pathname_start, ending_index);
736 ada_log(
"url_aggregator::get_search");
742 auto ending_index = uint32_t(buffer.size());
749 return helpers::substring(buffer, components.
search_start, ending_index);
753 ada_log(
"url_aggregator::get_protocol");
754 return helpers::substring(buffer, 0, components.
protocol_end);
758 ada_log(
"url_aggregator::to_string buffer:", buffer,
" [", buffer.size(),
765 auto back = std::back_insert_iterator(answer);
766 answer.append(
"{\n");
768 answer.append(
"\t\"buffer\":\"");
769 helpers::encode_json(buffer, back);
770 answer.append(
"\",\n");
772 answer.append(
"\t\"protocol\":\"");
773 helpers::encode_json(get_protocol(), back);
774 answer.append(
"\",\n");
776 if (has_credentials()) {
777 answer.append(
"\t\"username\":\"");
778 helpers::encode_json(get_username(), back);
779 answer.append(
"\",\n");
780 answer.append(
"\t\"password\":\"");
781 helpers::encode_json(get_password(), back);
782 answer.append(
"\",\n");
785 answer.append(
"\t\"host\":\"");
786 helpers::encode_json(get_host(), back);
787 answer.append(
"\",\n");
789 answer.append(
"\t\"path\":\"");
790 helpers::encode_json(get_pathname(), back);
791 answer.append(
"\",\n");
792 answer.append(
"\t\"opaque path\":");
793 answer.append((has_opaque_path ?
"true" :
"false"));
794 answer.append(
",\n");
797 answer.append(
"\t\"query\":\"");
798 helpers::encode_json(get_search(), back);
799 answer.append(
"\",\n");
802 answer.append(
"\t\"fragment\":\"");
803 helpers::encode_json(get_hash(), back);
804 answer.append(
"\",\n");
807 auto convert_offset_to_string = [](uint32_t offset) -> std::string {
811 return std::to_string(offset);
815 answer.append(
"\t\"protocol_end\":");
816 answer.append(convert_offset_to_string(components.protocol_end));
817 answer.append(
",\n");
819 answer.append(
"\t\"username_end\":");
820 answer.append(convert_offset_to_string(components.username_end));
821 answer.append(
",\n");
823 answer.append(
"\t\"host_start\":");
824 answer.append(convert_offset_to_string(components.host_start));
825 answer.append(
",\n");
827 answer.append(
"\t\"host_end\":");
828 answer.append(convert_offset_to_string(components.host_end));
829 answer.append(
",\n");
831 answer.append(
"\t\"port\":");
832 answer.append(convert_offset_to_string(components.port));
833 answer.append(
",\n");
835 answer.append(
"\t\"pathname_start\":");
836 answer.append(convert_offset_to_string(components.pathname_start));
837 answer.append(
",\n");
839 answer.append(
"\t\"search_start\":");
840 answer.append(convert_offset_to_string(components.search_start));
841 answer.append(
",\n");
843 answer.append(
"\t\"hash_start\":");
844 answer.append(convert_offset_to_string(components.hash_start));
845 answer.append(
"\n}");
857bool url_aggregator::parse_ipv4(std::string_view input,
bool in_place) {
858 ada_log(
"parse_ipv4 ", input,
" [", input.size(),
859 " bytes], overlaps with buffer: ",
860 helpers::overlaps(input, buffer) ?
"yes" :
"no");
862 const bool trailing_dot = (input.back() ==
'.');
864 input.remove_suffix(1);
866 size_t digit_count{0};
867 int pure_decimal_count = 0;
870 for (; (digit_count < 4) && !(input.empty()); digit_count++) {
874 if (is_hex && ((input.length() == 2) ||
875 ((input.length() > 2) && (input[2] ==
'.')))) {
878 input.remove_prefix(2);
880 std::from_chars_result r{};
882 ada_log(
"parse_ipv4 trying to parse hex number");
883 r = std::from_chars(input.data() + 2, input.data() + input.size(),
885 }
else if ((input.length() >= 2) && input[0] ==
'0' &&
887 ada_log(
"parse_ipv4 trying to parse octal number");
888 r = std::from_chars(input.data() + 1, input.data() + input.size(),
891 ada_log(
"parse_ipv4 trying to parse decimal number");
892 pure_decimal_count++;
893 r = std::from_chars(input.data(), input.data() + input.size(),
896 if (r.ec != std::errc()) {
897 ada_log(
"parse_ipv4 parsing failed");
900 ada_log(
"parse_ipv4 parsed ", segment_result);
901 input.remove_prefix(r.ptr - input.data());
907 if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) {
910 ipv4 <<= (32 - digit_count * 8);
911 ipv4 |= segment_result;
916 if ((segment_result > 255) || (input[0] !=
'.')) {
920 ipv4 |= segment_result;
921 input.remove_prefix(1);
924 if ((digit_count != 4) || (!input.empty())) {
925 ada_log(
"parse_ipv4 found invalid (more than 4 numbers or empty) ");
933 if (in_place && pure_decimal_count == 4 && !trailing_dot) {
935 "url_aggregator::parse_ipv4 completed and was already correct in the "
940 ada_log(
"url_aggregator::parse_ipv4 completed and we need to update it");
945 update_base_hostname(
953bool url_aggregator::parse_ipv6(std::string_view input) {
958 ada_log(
"parse_ipv6 ", input,
" [", input.size(),
" bytes]");
965 std::array<uint16_t, 8> address{};
971 std::optional<int> compress{};
974 std::string_view::iterator pointer = input.begin();
977 if (input[0] ==
':') {
980 if (input.size() == 1 || input[1] !=
':') {
981 ada_log(
"parse_ipv6 starts with : but the rest does not start with :");
989 compress = ++piece_index;
993 while (pointer != input.end()) {
995 if (piece_index == 8) {
996 ada_log(
"parse_ipv6 piece_index == 8");
1001 if (*pointer ==
':') {
1003 if (compress.has_value()) {
1004 ada_log(
"parse_ipv6 compress is non-null");
1011 compress = ++piece_index;
1016 uint16_t value = 0, length = 0;
1021 while (length < 4 && pointer != input.end() &&
1022 unicode::is_ascii_hex_digit(*pointer)) {
1024 value = uint16_t(value * 0x10 + unicode::convert_hex_to_binary(*pointer));
1030 if (pointer != input.end() && *pointer ==
'.') {
1033 ada_log(
"parse_ipv6 length is 0");
1041 if (piece_index > 6) {
1042 ada_log(
"parse_ipv6 piece_index > 6");
1047 int numbers_seen = 0;
1050 while (pointer != input.end()) {
1052 std::optional<uint16_t> ipv4_piece{};
1055 if (numbers_seen > 0) {
1058 if (*pointer ==
'.' && numbers_seen < 4) {
1062 ada_log(
"parse_ipv6 Otherwise, validation error, return failure");
1070 "parse_ipv6 If c is not an ASCII digit, validation error, return "
1078 int number = *pointer -
'0';
1081 if (!ipv4_piece.has_value()) {
1082 ipv4_piece = number;
1085 else if (ipv4_piece == 0) {
1086 ada_log(
"parse_ipv6 if ipv4Piece is 0, validation error");
1091 ipv4_piece = *ipv4_piece * 10 + number;
1095 if (ipv4_piece > 255) {
1096 ada_log(
"parse_ipv6 ipv4_piece > 255");
1107 address[piece_index] =
1108 uint16_t(address[piece_index] * 0x100 + *ipv4_piece);
1114 if (numbers_seen == 2 || numbers_seen == 4) {
1120 if (numbers_seen != 4) {
1128 else if ((pointer != input.end()) && (*pointer ==
':')) {
1133 if (pointer == input.end()) {
1135 "parse_ipv6 If c is the EOF code point, validation error, return "
1142 else if (pointer != input.end()) {
1144 "parse_ipv6 Otherwise, if c is not the EOF code point, validation "
1145 "error, return failure");
1150 address[piece_index] = value;
1157 if (compress.has_value()) {
1159 int swaps = piece_index - *compress;
1167 while (piece_index != 0 && swaps > 0) {
1168 std::swap(address[piece_index], address[*compress + swaps - 1]);
1175 else if (piece_index != 8) {
1177 "parse_ipv6 if compress is null and pieceIndex is not 8, validation "
1178 "error, return failure");
1191bool url_aggregator::parse_opaque_host(std::string_view input) {
1192 ada_log(
"parse_opaque_host ", input,
" [", input.size(),
" bytes]");
1195 if (std::any_of(input.begin(), input.end(),
1196 ada::unicode::is_forbidden_host_code_point)) {
1204 if (idx == input.size()) {
1205 update_base_hostname(input);
1208 update_base_hostname(ada::unicode::percent_encode(
1220 answer.append(buffer);
1221 answer.append(
" [");
1222 answer.append(std::to_string(buffer.size()));
1223 answer.append(
" bytes]");
1224 answer.append(
"\n");
1227 line1.resize(buffer.size(),
' ');
1237 if (components.
host_end != buffer.size()) {
1240 if (components.
host_start != buffer.size()) {
1249 answer.append(line1);
1250 answer.append(
"\n");
1252 std::string line2 = line1;
1257 for (
size_t i = components.
hash_start + 1; i < line2.size(); i++) {
1260 line2.append(
" hash_start");
1261 answer.append(line2);
1262 answer.append(
"\n");
1265 std::string line3 = line1;
1270 for (
size_t i = components.
search_start + 1; i < line3.size(); i++) {
1273 line3.append(
" search_start ");
1275 answer.append(line3);
1276 answer.append(
"\n");
1279 std::string line4 = line1;
1283 for (
size_t i = components.
pathname_start + 1; i < line4.size(); i++) {
1286 line4.append(
" pathname_start ");
1288 answer.append(line4);
1289 answer.append(
"\n");
1292 std::string line5 = line1;
1293 if (components.
host_end != buffer.size()) {
1297 for (
size_t i = components.
host_end + 1; i < line5.size(); i++) {
1300 line5.append(
" host_end ");
1301 line5.append(std::to_string(components.
host_end));
1302 answer.append(line5);
1303 answer.append(
"\n");
1306 std::string line6 = line1;
1307 if (components.
host_start != buffer.size()) {
1311 for (
size_t i = components.
host_start + 1; i < line6.size(); i++) {
1314 line6.append(
" host_start ");
1315 line6.append(std::to_string(components.
host_start));
1316 answer.append(line6);
1317 answer.append(
"\n");
1320 std::string line7 = line1;
1325 for (
size_t i = components.
username_end + 1; i < line7.size(); i++) {
1328 line7.append(
" username_end ");
1330 answer.append(line7);
1331 answer.append(
"\n");
1334 std::string line8 = line1;
1339 for (
size_t i = components.
protocol_end + 1; i < line8.size(); i++) {
1342 line8.append(
" protocol_end ");
1344 answer.append(line8);
1345 answer.append(
"\n");
1349 answer.append(
"note: hash omitted\n");
1352 answer.append(
"note: search omitted\n");
1355 answer.append(
"warning: protocol_end overflows\n");
1358 answer.append(
"warning: username_end overflows\n");
1361 answer.append(
"warning: host_start overflows\n");
1363 if (components.
host_end > buffer.size()) {
1364 answer.append(
"warning: host_end overflows\n");
1367 answer.append(
"warning: pathname_start overflows\n");
1377 ada_log(
"url_aggregator::validate inconsistent components \n",
1428 if (components.
host_end > buffer.size()) {
1433 ada_log(
"url_aggregator::validate pathname_start overflow \n",
1441 "url_aggregator::validate missing : at the end of the protocol \n",
1452 "url_aggregator::validate missing : or @ at the end of the username "
1459 if (components.
host_start != buffer.size()) {
1463 "url_aggregator::validate missing @ at the end of the password \n",
1473 "url_aggregator::validate missing // between protocol and host "
1482 "url_aggregator::validate missing @ at the end of the username "
1490 ada_log(
"url_aggregator::validate expected omitted host \n",
1496 if (components.
host_end != buffer.size() &&
1499 buffer[components.
host_end] ==
'/' &&
1500 buffer[components.
host_end + 1] ==
'.') {
1505 "url_aggregator::validate expected the path to begin with // \n",
1509 }
else if (buffer[components.
host_end] !=
':') {
1510 ada_log(
"url_aggregator::validate missing : at the port \n",
1519 ada_log(
"url_aggregator::validate missing / at the path \n",
1526 ada_log(
"url_aggregator::validate missing ? at the search \n",
1533 ada_log(
"url_aggregator::validate missing # at the hash \n",
1542void url_aggregator::delete_dash_dot() {
1543 ada_log(
"url_aggregator::delete_dash_dot");
1546 buffer.erase(components.
host_end, 2);
1558inline void url_aggregator::consume_prepared_path(std::string_view input) {
1559 ada_log(
"url_aggregator::consume_prepared_path ", input);
1569 uint8_t accumulator = checkers::path_signature(input);
1574 constexpr uint8_t need_encoding = 1;
1575 constexpr uint8_t backslash_char = 2;
1576 constexpr uint8_t dot_char = 4;
1577 constexpr uint8_t percent_char = 8;
1579 bool may_need_slow_file_handling = (
type == ada::scheme::type::FILE &&
1582 (special ? (accumulator == 0)
1583 : ((accumulator & (need_encoding | dot_char | percent_char)) ==
1585 (!may_need_slow_file_handling);
1586 if (accumulator == dot_char && !may_need_slow_file_handling) {
1594 if (input[0] !=
'.') {
1595 size_t slashdot = input.find(
"/.");
1596 if (slashdot == std::string_view::npos) {
1597 trivial_path =
true;
1601 !(slashdot + 2 == input.size() || input[slashdot + 2] ==
'.' ||
1602 input[slashdot + 2] ==
'/');
1606 if (trivial_path && is_at_path()) {
1607 ada_log(
"parse_path trivial");
1619 (accumulator & (need_encoding | backslash_char | percent_char)) == 0) &&
1620 (type != ada::scheme::type::FILE);
1622 ada_log(
"parse_prepared_path fast");
1627 size_t previous_location = 0;
1629 size_t new_location = input.find(
'/', previous_location);
1632 if (new_location == std::string_view::npos) {
1633 std::string_view path_view = input.substr(previous_location);
1634 if (path_view ==
"..") {
1638 update_base_pathname(path);
1642 if (path.back() ==
'/') {
1643 update_base_pathname(path);
1648 path.resize(path.rfind(
'/') + 1);
1649 update_base_pathname(path);
1653 if (path_view !=
".") {
1654 path.append(path_view);
1656 update_base_pathname(path);
1660 std::string_view path_view =
1661 input.substr(previous_location, new_location - previous_location);
1662 previous_location = new_location + 1;
1663 if (path_view ==
"..") {
1664 size_t last_delimiter = path.rfind(
'/');
1665 if (last_delimiter != std::string::npos) {
1666 path.erase(last_delimiter);
1668 }
else if (path_view !=
".") {
1670 path.append(path_view);
1677 bool needs_percent_encoding = (accumulator & 1);
1678 std::string path_buffer_tmp;
1680 size_t location = (special && (accumulator & 2))
1681 ? input.find_first_of(
"/\\")
1683 std::string_view path_view = input;
1684 if (location != std::string_view::npos) {
1685 path_view.remove_suffix(path_view.size() - location);
1686 input.remove_prefix(location + 1);
1690 std::string_view path_buffer =
1691 (needs_percent_encoding &&
1692 ada::unicode::percent_encode<false>(
1696 if (unicode::is_double_dot_path_segment(path_buffer)) {
1697 if ((helpers::shorten_path(path, type) || special) &&
1698 location == std::string_view::npos) {
1701 }
else if (unicode::is_single_dot_path_segment(path_buffer) &&
1702 (location == std::string_view::npos)) {
1706 else if (!unicode::is_single_dot_path_segment(path_buffer)) {
1710 if (type == ada::scheme::type::FILE && path.empty() &&
1713 path += path_buffer[0];
1715 path_buffer.remove_prefix(2);
1716 path.append(path_buffer);
1720 path.append(path_buffer);
1723 if (location == std::string_view::npos) {
1724 update_base_pathname(path);
Definitions for URL specific checkers used within Ada.
constexpr bool has_value() const noexcept
#define ADA_ASSERT_TRUE(COND)
#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 C0_CONTROL_PERCENT_ENCODE[32]
constexpr uint8_t PATH_PERCENT_ENCODE[32]
constexpr uint8_t USERINFO_PERCENT_ENCODE[32]
constexpr uint8_t SPECIAL_QUERY_PERCENT_ENCODE[32]
constexpr uint8_t QUERY_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)
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
std::string_view get_pathname() const noexcept
void set_hash(std::string_view input)
void clear_search() override
std::string_view get_host() const noexcept
bool has_hostname() const noexcept
bool has_non_empty_password() const noexcept
ada_really_inline bool has_credentials() const noexcept
std::string_view get_search() const noexcept
std::string_view get_username() const noexcept
std::string to_string() const override
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_protocol() const noexcept
std::string_view get_port() const noexcept
std::string_view get_hostname() const noexcept
bool has_valid_domain() const noexcept override
bool set_hostname(std::string_view input)
std::string_view get_href() const noexcept
bool set_password(std::string_view input)
bool set_pathname(std::string_view input)
std::string_view get_password() const noexcept
bool set_href(std::string_view input)
void set_search(std::string_view input)
bool has_port() const noexcept
std::string_view get_hash() const noexcept
bool set_host(std::string_view input)
bool set_port(std::string_view input)
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.