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();
54 size_t running_index = out.protocol_end;
56 if (host.has_value()) {
58 out.host_start = out.protocol_end + 2;
61 out.username_end = uint32_t(out.host_start + username.size());
63 out.host_start += uint32_t(username.size());
65 if (!password.empty()) {
66 out.host_start += uint32_t(password.size() + 1);
69 out.host_end = uint32_t(out.host_start + host.value().size());
71 out.username_end = out.host_start;
74 out.host_end = uint32_t(out.host_start + host.value().size()) - 1;
77 running_index = out.host_end + 1;
81 out.host_start = out.protocol_end;
82 out.host_end = out.host_start;
88 running_index = out.protocol_end + 2;
90 running_index = out.protocol_end;
94 if (port.has_value()) {
96 running_index += helpers::fast_digit_count(*port) + 1;
99 out.pathname_start = uint32_t(running_index);
101 running_index += path.size();
103 if (query.has_value()) {
104 out.search_start = uint32_t(running_index);
111 if (hash.has_value()) {
112 out.hash_start = uint32_t(running_index);
118inline void url::update_base_hostname(std::string_view input) { host = input; }
120inline void url::update_unencoded_base_hash(std::string_view input) {
122 hash = unicode::percent_encode(input,
126inline void url::update_base_search(std::string_view input,
127 const uint8_t query_percent_encode_set[]) {
128 query = ada::unicode::percent_encode(input, query_percent_encode_set);
131inline void url::update_base_search(std::optional<std::string> input) {
135inline void url::update_base_pathname(
const std::string_view input) {
139inline void url::update_base_username(
const std::string_view input) {
143inline void url::update_base_password(
const std::string_view input) {
147inline void url::update_base_port(std::optional<uint16_t> input) {
151inline void url::clear_pathname() { path.clear(); }
153inline void url::clear_search() { query = std::nullopt; }
156 return hash.has_value();
160 return query.has_value();
165inline void url::set_scheme(std::string &&new_scheme)
noexcept {
169 non_special_scheme = new_scheme;
173inline void url::copy_scheme(
ada::url &&u)
noexcept {
174 non_special_scheme = u.non_special_scheme;
178inline void url::copy_scheme(
const ada::url &u) {
179 non_special_scheme = u.non_special_scheme;
186 if (host.has_value()) {
190 if (!password.empty()) {
195 output += host.value();
196 if (port.has_value()) {
206 if (query.has_value()) {
207 output +=
"?" + query.value();
209 if (hash.has_value()) {
210 output +=
"#" + hash.value();
216 bool check_trailing_content)
noexcept {
217 ada_log(
"parse_port('", view,
"') ", view.size());
218 uint16_t parsed_port{};
219 auto r = std::from_chars(view.data(), view.data() + view.size(), parsed_port);
220 if (r.ec == std::errc::result_out_of_range) {
221 ada_log(
"parse_port: std::errc::result_out_of_range");
225 ada_log(
"parse_port: ", parsed_port);
226 const size_t consumed = size_t(r.ptr - view.data());
227 ada_log(
"parse_port: consumed ", consumed);
228 if (check_trailing_content) {
230 (consumed == view.size() || view[consumed] ==
'/' ||
231 view[consumed] ==
'?' || (is_special() && view[consumed] ==
'\\'));
233 ada_log(
"parse_port: is_valid = ", is_valid);
236 auto default_port = scheme_default_port();
237 bool is_port_valid = (default_port == 0 && parsed_port == 0) ||
238 (default_port != parsed_port);
239 port = (r.ec == std::errc() && is_port_valid)
240 ? std::optional<uint16_t>(parsed_port)
Declarations for URL specific checkers used within Ada.
#define ada_really_inline
constexpr uint8_t FRAGMENT_PERCENT_ENCODE[32]
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
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
bool has_hash() const noexcept override
ada_really_inline size_t get_pathname_length() const noexcept
ada_really_inline std::string get_href() const noexcept
bool has_hostname() const noexcept
const std::string & get_password() const noexcept
std::string get_port() const noexcept
std::string to_string() const override
std::string get_protocol() const noexcept
bool has_search() const noexcept override
Declaration for the URL Components.