14#if ADA_REGULAR_VISUAL_STUDIO
20 return !username.empty() || !password.empty();
23 return port.has_value();
25[[nodiscard]]
inline bool url::cannot_have_credentials_or_port()
const {
26 return !host.has_value() || host.value().empty() ||
30 if (!host.has_value()) {
33 return host.value().empty();
36 return host.has_value();
58 size_t running_index = out.protocol_end;
60 if (host.has_value()) {
62 out.host_start = out.protocol_end + 2;
65 out.username_end = uint32_t(out.host_start + username.size());
67 out.host_start += uint32_t(username.size());
69 if (!password.empty()) {
70 out.host_start += uint32_t(password.size() + 1);
73 out.host_end = uint32_t(out.host_start + host.value().size());
75 out.username_end = out.host_start;
78 out.host_end = uint32_t(out.host_start + host.value().size()) - 1;
81 running_index = out.host_end + 1;
85 out.host_start = out.protocol_end;
86 out.host_end = out.host_start;
92 running_index = out.protocol_end + 2;
94 running_index = out.protocol_end;
98 if (port.has_value()) {
100 running_index += helpers::fast_digit_count(*port) + 1;
103 out.pathname_start = uint32_t(running_index);
105 running_index += path.size();
107 if (query.has_value()) {
108 out.search_start = uint32_t(running_index);
115 if (hash.has_value()) {
116 out.hash_start = uint32_t(running_index);
122inline void url::update_base_hostname(std::string_view input) { host = input; }
124inline void url::update_unencoded_base_hash(std::string_view input) {
126 hash = unicode::percent_encode(input,
130inline void url::update_base_search(std::string_view input,
131 const uint8_t query_percent_encode_set[]) {
132 query = ada::unicode::percent_encode(input, query_percent_encode_set);
135inline void url::update_base_search(std::optional<std::string> &&input) {
136 query = std::move(input);
139inline void url::update_base_pathname(
const std::string_view input) {
143inline void url::update_base_username(
const std::string_view input) {
147inline void url::update_base_password(
const std::string_view input) {
151inline void url::update_base_port(std::optional<uint16_t> input) {
155constexpr void url::clear_pathname() { path.clear(); }
157constexpr void url::clear_search() { query = std::nullopt; }
160 return hash.has_value();
164 return query.has_value();
169inline void url::set_scheme(std::string &&new_scheme)
noexcept {
173 non_special_scheme = std::move(new_scheme);
177constexpr void url::copy_scheme(
ada::url &&u)
noexcept {
178 non_special_scheme = u.non_special_scheme;
182constexpr void url::copy_scheme(
const ada::url &u) {
183 non_special_scheme = u.non_special_scheme;
190 if (host.has_value()) {
194 if (!password.empty()) {
199 output += host.value();
200 if (port.has_value()) {
210 if (query.has_value()) {
211 output +=
"?" + query.value();
213 if (hash.has_value()) {
214 output +=
"#" + hash.value();
220 bool check_trailing_content)
noexcept {
221 ada_log(
"parse_port('", view,
"') ", view.size());
222 if (!view.empty() && view[0] ==
'-') {
223 ada_log(
"parse_port: view[0] == '0' && view.size() > 1");
227 uint16_t parsed_port{};
228 auto r = std::from_chars(view.data(), view.data() + view.size(), parsed_port);
229 if (r.ec == std::errc::result_out_of_range) {
230 ada_log(
"parse_port: r.ec == std::errc::result_out_of_range");
234 ada_log(
"parse_port: ", parsed_port);
235 const auto consumed = size_t(r.ptr - view.data());
236 ada_log(
"parse_port: consumed ", consumed);
237 if (check_trailing_content) {
239 (consumed == view.size() || view[consumed] ==
'/' ||
240 view[consumed] ==
'?' || (is_special() && view[consumed] ==
'\\'));
242 ada_log(
"parse_port: is_valid = ", is_valid);
245 auto default_port = scheme_default_port();
246 bool is_port_valid = (default_port == 0 && parsed_port == 0) ||
247 (default_port != parsed_port);
248 port = (r.ec == std::errc() && is_port_valid) ? std::optional(parsed_port)
Declarations for URL specific checkers used within Ada.
#define ada_really_inline
constexpr uint8_t FRAGMENT_PERCENT_ENCODE[32]
constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept
std::ostream & operator<<(std::ostream &out, const ada::url &u)
URL Component representations using offsets.
Generic URL struct reliant on std::string instantiation.
std::string get_search() const noexcept
ada_really_inline ada::url_components get_components() const noexcept
bool has_empty_hostname() const noexcept
bool has_port() const noexcept
ada_really_inline bool has_credentials() const noexcept
ada_really_inline size_t get_pathname_length() const noexcept
ada_really_inline std::string get_href() const noexcept
bool has_hostname() const noexcept
constexpr std::string_view get_pathname() const noexcept
const std::string & get_password() const noexcept
std::string get_port() const noexcept
constexpr bool has_search() const noexcept override
std::string to_string() const override
std::string get_protocol() const noexcept
constexpr bool has_hash() const noexcept override
Declaration for the URL Components.