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();
59 size_t running_index = out.protocol_end;
61 if (host.has_value()) {
63 out.host_start = out.protocol_end + 2;
66 out.username_end = uint32_t(out.host_start + username.size());
68 out.host_start += uint32_t(username.size());
70 if (!password.empty()) {
71 out.host_start += uint32_t(password.size() + 1);
74 out.host_end = uint32_t(out.host_start + host.value().size());
76 out.username_end = out.host_start;
79 out.host_end = uint32_t(out.host_start + host.value().size()) - 1;
82 running_index = out.host_end + 1;
86 out.host_start = out.protocol_end;
87 out.host_end = out.host_start;
93 running_index = out.protocol_end + 2;
95 running_index = out.protocol_end;
99 if (port.has_value()) {
101 running_index += helpers::fast_digit_count(*port) + 1;
104 out.pathname_start = uint32_t(running_index);
106 running_index += path.size();
108 if (query.has_value()) {
109 out.search_start = uint32_t(running_index);
116 if (hash.has_value()) {
117 out.hash_start = uint32_t(running_index);
123inline void url::update_base_hostname(std::string_view input) { host = input; }
125inline void url::update_unencoded_base_hash(std::string_view input) {
127 hash = unicode::percent_encode(input,
131inline void url::update_base_search(std::string_view input,
132 const uint8_t query_percent_encode_set[]) {
133 query = ada::unicode::percent_encode(input, query_percent_encode_set);
136inline void url::update_base_search(std::optional<std::string> &&input) {
137 query = std::move(input);
140inline void url::update_base_pathname(
const std::string_view input) {
144inline void url::update_base_username(
const std::string_view input) {
148inline void url::update_base_password(
const std::string_view input) {
152inline void url::update_base_port(std::optional<uint16_t> input) {
156constexpr void url::clear_pathname() { path.clear(); }
158constexpr void url::clear_search() { query = std::nullopt; }
161 return hash.has_value();
165 return query.has_value();
170inline void url::set_scheme(std::string &&new_scheme)
noexcept {
174 non_special_scheme = std::move(new_scheme);
178constexpr void url::copy_scheme(ada::url &&u)
noexcept {
179 non_special_scheme = u.non_special_scheme;
183constexpr void url::copy_scheme(
const ada::url &u) {
184 non_special_scheme = u.non_special_scheme;
191 if (host.has_value()) {
195 if (!password.empty()) {
200 output += host.value();
201 if (port.has_value()) {
211 if (query.has_value()) {
212 output +=
"?" + query.value();
214 if (hash.has_value()) {
215 output +=
"#" + hash.value();
221 bool check_trailing_content)
noexcept {
222 ada_log(
"parse_port('", view,
"') ", view.size());
223 if (!view.empty() && view[0] ==
'-') {
224 ada_log(
"parse_port: view[0] == '0' && view.size() > 1");
228 uint16_t parsed_port{};
229 auto r = std::from_chars(view.data(), view.data() + view.size(), parsed_port);
230 if (r.ec == std::errc::result_out_of_range) {
231 ada_log(
"parse_port: r.ec == std::errc::result_out_of_range");
235 ada_log(
"parse_port: ", parsed_port);
236 const auto consumed = size_t(r.ptr - view.data());
237 ada_log(
"parse_port: consumed ", consumed);
238 if (check_trailing_content) {
240 (consumed == view.size() || view[consumed] ==
'/' ||
241 view[consumed] ==
'?' || (is_special() && view[consumed] ==
'\\'));
243 ada_log(
"parse_port: is_valid = ", is_valid);
246 auto default_port = scheme_default_port();
247 bool is_port_valid = (default_port == 0 && parsed_port == 0) ||
248 (default_port != parsed_port);
249 port = (r.ec == std::errc() && is_port_valid) ? std::optional(parsed_port)
#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.