13template <
bool overr
ide_hostname>
14bool url::set_host_or_hostname(
const std::string_view input) {
19 std::optional<std::string> previous_host = host;
20 std::optional<uint16_t> previous_port = port;
22 size_t host_end_pos = input.find(
'#');
23 std::string _host(input.data(), host_end_pos != std::string_view::npos
26 helpers::remove_ascii_tab_or_newline(_host);
27 std::string_view new_host(_host);
32 std::string_view host_view(_host.data(), _host.length());
33 auto [location, found_colon] =
34 helpers::get_host_delimiter_location(
is_special(), host_view);
40 if (override_hostname) {
43 std::string_view buffer = new_host.substr(location + 1);
44 if (!buffer.empty()) {
52 else if (host_view.empty() &&
63 bool succeeded = parse_host(host_view);
66 update_base_port(previous_port);
71 size_t location = new_host.find_first_of(
"/\\?");
72 if (location != std::string_view::npos) {
73 new_host.remove_suffix(new_host.length() - location);
76 if (new_host.empty()) {
81 if (!parse_host(new_host)) {
83 update_base_port(previous_port);
88 if (host.has_value() && host.value() ==
"localhost") {
96 return set_host_or_hostname<false>(input);
100 return set_host_or_hostname<true>(input);
104 if (cannot_have_credentials_or_port()) {
107 username = ada::unicode::percent_encode(
113 if (cannot_have_credentials_or_port()) {
116 password = ada::unicode::percent_encode(
122 if (cannot_have_credentials_or_port()) {
125 std::string trimmed(input);
126 helpers::remove_ascii_tab_or_newline(trimmed);
127 if (trimmed.empty()) {
132 if (ada::unicode::is_c0_control_or_space(trimmed.front())) {
136 if (input.find_first_of(
"0123456789") == std::string_view::npos) {
141 std::optional<uint16_t> previous_port = port;
146 port = previous_port;
154 helpers::strip_trailing_spaces_from_opaque_path(*
this);
158 std::string new_value;
159 new_value = input[0] ==
'#' ? input.substr(1) : input;
160 helpers::remove_ascii_tab_or_newline(new_value);
161 hash = unicode::percent_encode(new_value,
167 query = std::nullopt;
168 helpers::strip_trailing_spaces_from_opaque_path(*
this);
172 std::string new_value;
173 new_value = input[0] ==
'?' ? input.substr(1) : input;
174 helpers::remove_ascii_tab_or_newline(new_value);
176 auto query_percent_encode_set =
180 query = ada::unicode::percent_encode(std::string_view(new_value),
181 query_percent_encode_set);
194 std::string view(input);
195 helpers::remove_ascii_tab_or_newline(view);
207 std::string::iterator pointer =
208 std::find_if_not(view.begin(), view.end(), unicode::is_alnum_plus);
210 if (pointer != view.end() && *pointer ==
':') {
211 return parse_scheme<true>(
212 std::string_view(view.data(), pointer - view.begin()));
221 username = out->username;
222 password = out->password;
229 non_special_scheme = out->non_special_scheme;
233 return out.has_value();
Includes all definitions for Ada.
Definitions for helper functions used within Ada.
constexpr uint8_t QUERY_PERCENT_ENCODE[32]
constexpr uint8_t SPECIAL_QUERY_PERCENT_ENCODE[32]
constexpr uint8_t USERINFO_PERCENT_ENCODE[32]
constexpr uint8_t FRAGMENT_PERCENT_ENCODE[32]
constexpr bool is_alpha(char x) noexcept
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)
ada_really_inline bool is_special() const noexcept
void set_hash(std::string_view input)
bool set_hostname(std::string_view input)
bool set_host(std::string_view input)
ada_really_inline bool has_credentials() const noexcept
bool set_password(std::string_view input)
void set_search(std::string_view input)
bool set_href(std::string_view input)
bool set_username(std::string_view input)
bool set_pathname(std::string_view input)
bool set_protocol(std::string_view input)
bool set_port(std::string_view input)