11bool url::parse_opaque_host(std::string_view
input) {
14 ada::unicode::is_forbidden_host_code_point)) {
20 host = ada::unicode::percent_encode(
25bool url::parse_ipv4(std::string_view
input) {
27 if (
input.back() ==
'.') {
28 input.remove_suffix(1);
41 ((
input.length() > 2) && (
input[2] ==
'.')))) {
44 input.remove_prefix(2);
46 std::from_chars_result
r;
50 }
else if ((
input.length() >= 2) &&
input[0] ==
'0' &&
59 if (
r.ec != std::errc()) {
82 input.remove_prefix(1);
100bool url::parse_ipv6(std::string_view
input) {
107 std::array<uint16_t, 8>
address{};
119 if (
input[0] ==
':') {
123 ada_log(
"parse_ipv6 starts with : but the rest does not start with :");
138 ada_log(
"parse_ipv6 piece_index == 8");
146 ada_log(
"parse_ipv6 compress is non-null");
164 unicode::is_ascii_hex_digit(*
pointer)) {
166 value =
uint16_t(value * 0x10 + unicode::convert_hex_to_binary(*
pointer));
175 ada_log(
"parse_ipv6 length is 0");
184 ada_log(
"parse_ipv6 piece_index > 6");
205 ada_log(
"parse_ipv6 Otherwise, validation error, return failure");
213 "parse_ipv6 If c is not an ASCII digit, validation error, return "
229 ada_log(
"parse_ipv6 if ipv4Piece is 0, validation error");
239 ada_log(
"parse_ipv6 ipv4_piece > 255");
278 "parse_ipv6 If c is the EOF code point, validation error, return "
287 "parse_ipv6 Otherwise, if c is not the EOF code point, validation "
288 "error, return failure");
320 "parse_ipv6 if compress is null and pieceIndex is not 8, validation "
321 "error, return failure");
330template <
bool has_state_overr
ide>
356 host.value().empty()) {
400 host.value().empty()) {
405 set_scheme(std::move(
_buffer));
430 if (
input[0] ==
'[') {
432 if (
input.back() !=
']') {
439 input.remove_prefix(1);
440 input.remove_suffix(1);
441 return parse_ipv6(
input);
447 return parse_opaque_host(
input);
454 std::string buffer = std::string(
input);
458 unicode::to_lower_ascii(buffer.data(), buffer.size());
459 bool is_forbidden = unicode::contains_forbidden_domain_code_point(
460 buffer.data(), buffer.size());
461 if (
is_forbidden == 0 && buffer.find(
"xn-") == std::string_view::npos) {
463 host = std::move(buffer);
464 if (checkers::is_ipv4(host.value())) {
465 ada_log(
"parse_host fast path ipv4");
466 return parse_ipv4(host.value());
468 ada_log(
"parse_host fast path ", *host);
471 ada_log(
"parse_host calling to_ascii");
474 ada_log(
"parse_host to_ascii returns false");
477 ada_log(
"parse_host to_ascii succeeded ", *host,
" [", host->size(),
480 if (std::any_of(host.value().begin(), host.value().end(),
481 ada::unicode::is_forbidden_domain_code_point)) {
488 if (checkers::is_ipv4(host.value())) {
489 ada_log(
"parse_host got ipv4 ", *host);
490 return parse_ipv4(host.value());
500 if (unicode::has_tabs_or_newline(
input)) {
504 helpers::remove_ascii_tab_or_newline(
tmp_buffer);
515 helpers::parse_prepared_path(
internal_input.substr(1), type, path);
523 helpers::parse_prepared_path(
internal_input.substr(1), type, path);
530 if (!host.has_value()) {
541 auto back = std::back_insert_iterator(
answer);
543 answer.append(
"\t\"protocol\":\"");
547 answer.append(
"\t\"username\":\"");
548 helpers::encode_json(username, back);
550 answer.append(
"\t\"password\":\"");
551 helpers::encode_json(password, back);
554 if (host.has_value()) {
555 answer.append(
"\t\"host\":\"");
556 helpers::encode_json(host.value(), back);
559 if (port.has_value()) {
560 answer.append(
"\t\"port\":\"");
561 answer.append(std::to_string(port.value()));
564 answer.append(
"\t\"path\":\"");
565 helpers::encode_json(path, back);
567 answer.append(
"\t\"opaque path\":");
571 answer.append(
"\t\"query\":\"");
572 helpers::encode_json(query.value(), back);
575 if (hash.has_value()) {
577 answer.append(
"\t\"hash\":\"");
578 helpers::encode_json(hash.value(), back);
586 if (!host.has_value()) {
589 return checkers::verify_dns_length(host.value());
Includes all definitions for Ada.
#define ada_really_inline
constexpr uint8_t C0_CONTROL_PERCENT_ENCODE[32]
bool has_hex_prefix(std::string_view input)
constexpr bool is_digit(char x) noexcept
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_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
Declarations for the URL scheme.
ada_really_inline bool is_special() const noexcept
ada_really_inline bool has_credentials() const noexcept
std::string to_string() const override
std::string get_protocol() const noexcept
bool has_valid_domain() const noexcept override
bool has_search() const noexcept override