diff --git a/include/ada/url-inl.h b/include/ada/url-inl.h index 6b7a4cd10..436ef3669 100644 --- a/include/ada/url-inl.h +++ b/include/ada/url-inl.h @@ -26,13 +26,13 @@ namespace ada { return !host.has_value() || host.value().empty() || type == ada::scheme::type::FILE; } -[[nodiscard]] inline bool url::has_empty_hostname() const noexcept { +[[nodiscard]] constexpr bool url::has_empty_hostname() const noexcept { if (!host.has_value()) { return false; } return host.value().empty(); } -[[nodiscard]] inline bool url::has_hostname() const noexcept { +[[nodiscard]] constexpr bool url::has_hostname() const noexcept { return host.has_value(); } inline std::ostream &operator<<(std::ostream &out, const ada::url &u) { @@ -188,7 +188,7 @@ inline void url::copy_scheme(const ada::url &u) { if (has_credentials()) { output += username; if (!password.empty()) { - output += ":" + get_password(); + output += ":" + std::string(get_password()); } output += "@"; } diff --git a/include/ada/url.h b/include/ada/url.h index 1418d9bb7..9915fc7cb 100644 --- a/include/ada/url.h +++ b/include/ada/url.h @@ -92,11 +92,11 @@ struct url : url_base { std::optional hash{}; /** @return true if it has an host but it is the empty string */ - [[nodiscard]] inline bool has_empty_hostname() const noexcept; + [[nodiscard]] constexpr bool has_empty_hostname() const noexcept; /** @return true if the URL has a (non default) port */ [[nodiscard]] inline bool has_port() const noexcept; /** @return true if it has a host (included an empty host) */ - [[nodiscard]] inline bool has_hostname() const noexcept; + [[nodiscard]] constexpr bool has_hostname() const noexcept; [[nodiscard]] bool has_valid_domain() const noexcept override; /** @@ -141,7 +141,7 @@ struct url : url_base { * @return a newly allocated string. * @see https://url.spec.whatwg.org/#dom-url-hostname */ - [[nodiscard]] std::string get_hostname() const noexcept; + [[nodiscard]] constexpr std::string_view get_hostname() const noexcept; /** * The pathname getter steps are to return the result of URL path serializing @@ -149,7 +149,7 @@ struct url : url_base { * @return a newly allocated string. * @see https://url.spec.whatwg.org/#dom-url-pathname */ - [[nodiscard]] std::string_view get_pathname() const noexcept; + [[nodiscard]] constexpr std::string_view get_pathname() const noexcept; /** * Compute the pathname length in bytes without instantiating a view or a @@ -171,7 +171,7 @@ struct url : url_base { * @return a constant reference to the underlying string. * @see https://url.spec.whatwg.org/#dom-url-username */ - [[nodiscard]] const std::string &get_username() const noexcept; + [[nodiscard]] constexpr std::string_view get_username() const noexcept; /** * @return Returns true on successful operation. @@ -237,7 +237,7 @@ struct url : url_base { * @return a constant reference to the underlying string. * @see https://url.spec.whatwg.org/#dom-url-password */ - [[nodiscard]] const std::string &get_password() const noexcept; + [[nodiscard]] constexpr std::string_view get_password() const noexcept; /** * Return this's URL's port, serialized. diff --git a/include/ada/url_aggregator-inl.h b/include/ada/url_aggregator-inl.h index fb7c46380..ecf851912 100644 --- a/include/ada/url_aggregator-inl.h +++ b/include/ada/url_aggregator-inl.h @@ -451,10 +451,9 @@ inline void url_aggregator::update_base_password(const std::string_view input) { return; } - bool password_exists = has_password(); - uint32_t difference = uint32_t(input.size()); + auto difference = static_cast(input.size()); - if (password_exists) { + if (has_password()) { uint32_t current_length = components.host_start - components.username_end - 1; buffer.erase(components.username_end + 1, current_length); @@ -493,7 +492,7 @@ inline void url_aggregator::append_base_password(const std::string_view input) { ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer)); #if ADA_DEVELOPMENT_CHECKS // computing the expected password. - std::string password_expected = std::string(get_password()); + auto password_expected = std::string(get_password()); password_expected.append(input); #endif // ADA_DEVELOPMENT_CHECKS add_authority_slashes_if_needed(); @@ -503,7 +502,7 @@ inline void url_aggregator::append_base_password(const std::string_view input) { return; } - uint32_t difference = uint32_t(input.size()); + auto difference = static_cast(input.size()); if (has_password()) { buffer.insert(components.host_start, input); } else { @@ -548,7 +547,7 @@ inline void url_aggregator::update_base_port(uint32_t input) { // calling std::to_string(input.value()) is unfortunate given that the port // value is probably already available as a string. std::string value = helpers::concat(":", std::to_string(input)); - uint32_t difference = uint32_t(value.size()); + auto difference = static_cast(value.size()); if (components.port != url_components::omitted) { difference -= components.pathname_start - components.host_end; @@ -568,7 +567,7 @@ inline void url_aggregator::update_base_port(uint32_t input) { ADA_ASSERT_TRUE(validate()); } -inline void url_aggregator::clear_port() { +constexpr void url_aggregator::clear_port() { ada_log("url_aggregator::clear_port"); ADA_ASSERT_TRUE(validate()); if (components.port == url_components::omitted) { @@ -587,7 +586,7 @@ inline void url_aggregator::clear_port() { ADA_ASSERT_TRUE(validate()); } -[[nodiscard]] inline uint32_t url_aggregator::retrieve_base_port() const { +[[nodiscard]] constexpr uint32_t url_aggregator::retrieve_base_port() const { ada_log("url_aggregator::retrieve_base_port"); return components.port; } @@ -610,9 +609,9 @@ inline void url_aggregator::clear_search() { components.search_start = url_components::omitted; #if ADA_DEVELOPMENT_CHECKS - ADA_ASSERT_EQUAL(get_search(), "", - "search should have been cleared on buffer=" + buffer + - " with " + components.to_string() + "\n" + to_diagram()); + ADA_ASSERT_TRUE(get_search().empty(), + "search should have been cleared on buffer=" + buffer + + " with " + components.to_string() + "\n" + to_diagram()); #endif ADA_ASSERT_TRUE(validate()); } @@ -627,7 +626,7 @@ inline void url_aggregator::clear_hash() { components.hash_start = url_components::omitted; #if ADA_DEVELOPMENT_CHECKS - ADA_ASSERT_EQUAL(get_hash(), "", + ADA_ASSERT_TRUE(get_hash().empty(), "hash should have been cleared on buffer=" + buffer + " with " + components.to_string() + "\n" + to_diagram()); #endif @@ -637,7 +636,7 @@ inline void url_aggregator::clear_hash() { inline void url_aggregator::clear_pathname() { ada_log("url_aggregator::clear_pathname"); ADA_ASSERT_TRUE(validate()); - uint32_t ending_index = uint32_t(buffer.size()); + auto ending_index = static_cast(buffer.size()); if (components.search_start != url_components::omitted) { ending_index = components.search_start; } else if (components.hash_start != url_components::omitted) { @@ -661,7 +660,7 @@ inline void url_aggregator::clear_pathname() { } ada_log("url_aggregator::clear_pathname completed, running checks..."); #if ADA_DEVELOPMENT_CHECKS - ADA_ASSERT_EQUAL(get_pathname(), "", + ADA_ASSERT_TRUE(get_pathname().empty(), "pathname should have been cleared on buffer=" + buffer + " with " + components.to_string() + "\n" + to_diagram()); #endif @@ -706,22 +705,22 @@ inline void url_aggregator::clear_hostname() { ADA_ASSERT_TRUE(validate()); } -[[nodiscard]] inline bool url_aggregator::has_hash() const noexcept { +[[nodiscard]] constexpr bool url_aggregator::has_hash() const noexcept { ada_log("url_aggregator::has_hash"); return components.hash_start != url_components::omitted; } -[[nodiscard]] inline bool url_aggregator::has_search() const noexcept { +[[nodiscard]] constexpr bool url_aggregator::has_search() const noexcept { ada_log("url_aggregator::has_search"); return components.search_start != url_components::omitted; } -ada_really_inline bool url_aggregator::has_credentials() const noexcept { +ada_really_inline constexpr bool url_aggregator::has_credentials() const noexcept { ada_log("url_aggregator::has_credentials"); return has_non_empty_username() || has_non_empty_password(); } -inline bool url_aggregator::cannot_have_credentials_or_port() const { +constexpr bool url_aggregator::cannot_have_credentials_or_port() const { ada_log("url_aggregator::cannot_have_credentials_or_port"); return type == ada::scheme::type::FILE || components.host_start == components.host_end; @@ -732,7 +731,7 @@ url_aggregator::get_components() const noexcept { return components; } -[[nodiscard]] inline bool ada::url_aggregator::has_authority() const noexcept { +[[nodiscard]] constexpr bool ada::url_aggregator::has_authority() const noexcept { ada_log("url_aggregator::has_authority"); // Performance: instead of doing this potentially expensive check, we could // have a boolean in the struct. @@ -767,28 +766,28 @@ inline void ada::url_aggregator::add_authority_slashes_if_needed() noexcept { ADA_ASSERT_TRUE(validate()); } -inline void ada::url_aggregator::reserve(uint32_t capacity) { +constexpr void ada::url_aggregator::reserve(uint32_t capacity) { buffer.reserve(capacity); } -inline bool url_aggregator::has_non_empty_username() const noexcept { +constexpr bool url_aggregator::has_non_empty_username() const noexcept { ada_log("url_aggregator::has_non_empty_username"); return components.protocol_end + 2 < components.username_end; } -inline bool url_aggregator::has_non_empty_password() const noexcept { +constexpr bool url_aggregator::has_non_empty_password() const noexcept { ada_log("url_aggregator::has_non_empty_password"); return components.host_start - components.username_end > 0; } -inline bool url_aggregator::has_password() const noexcept { +constexpr bool url_aggregator::has_password() const noexcept { ada_log("url_aggregator::has_password"); // This function does not care about the length of the password return components.host_start > components.username_end && buffer[components.username_end] == ':'; } -inline bool url_aggregator::has_empty_hostname() const noexcept { +constexpr bool url_aggregator::has_empty_hostname() const noexcept { if (!has_hostname()) { return false; } @@ -801,11 +800,11 @@ inline bool url_aggregator::has_empty_hostname() const noexcept { return components.username_end != components.host_start; } -inline bool url_aggregator::has_hostname() const noexcept { +constexpr bool url_aggregator::has_hostname() const noexcept { return has_authority(); } -inline bool url_aggregator::has_port() const noexcept { +constexpr bool url_aggregator::has_port() const noexcept { ada_log("url_aggregator::has_port"); // A URL cannot have a username/password/port if its host is null or the empty // string, or its scheme is "file". diff --git a/include/ada/url_aggregator.h b/include/ada/url_aggregator.h index 0a81a1094..d5e9c098b 100644 --- a/include/ada/url_aggregator.h +++ b/include/ada/url_aggregator.h @@ -65,7 +65,7 @@ struct url_aggregator : url_base { * @return a lightweight std::string_view. * @see https://url.spec.whatwg.org/#dom-url-username */ - [[nodiscard]] std::string_view get_username() const noexcept + [[nodiscard]] constexpr std::string_view get_username() const noexcept ada_lifetime_bound; /** * The password getter steps are to return this's URL's password. @@ -73,7 +73,7 @@ struct url_aggregator : url_base { * @return a lightweight std::string_view. * @see https://url.spec.whatwg.org/#dom-url-password */ - [[nodiscard]] std::string_view get_password() const noexcept + [[nodiscard]] constexpr std::string_view get_password() const noexcept ada_lifetime_bound; /** * Return this's URL's port, serialized. @@ -81,14 +81,14 @@ struct url_aggregator : url_base { * @return a lightweight std::string_view. * @see https://url.spec.whatwg.org/#dom-url-port */ - [[nodiscard]] std::string_view get_port() const noexcept ada_lifetime_bound; + [[nodiscard]] constexpr std::string_view get_port() const noexcept ada_lifetime_bound; /** * Return U+0023 (#), followed by this's URL's fragment. * This function does not allocate memory. * @return a lightweight std::string_view.. * @see https://url.spec.whatwg.org/#dom-url-hash */ - [[nodiscard]] std::string_view get_hash() const noexcept ada_lifetime_bound; + [[nodiscard]] constexpr std::string_view get_hash() const noexcept ada_lifetime_bound; /** * Return url's host, serialized, followed by U+003A (:) and url's port, * serialized. @@ -97,7 +97,7 @@ struct url_aggregator : url_base { * @return a lightweight std::string_view. * @see https://url.spec.whatwg.org/#dom-url-host */ - [[nodiscard]] std::string_view get_host() const noexcept ada_lifetime_bound; + [[nodiscard]] constexpr std::string_view get_host() const noexcept; /** * Return this's URL's host, serialized. * This function does not allocate memory. @@ -144,7 +144,7 @@ struct url_aggregator : url_base { * A URL includes credentials if its username or password is not the empty * string. */ - [[nodiscard]] ada_really_inline bool has_credentials() const noexcept; + [[nodiscard]] ada_really_inline constexpr bool has_credentials() const noexcept; /** * Useful for implementing efficient serialization for the URL. @@ -186,23 +186,23 @@ struct url_aggregator : url_base { [[nodiscard]] bool validate() const noexcept; /** @return true if it has an host but it is the empty string */ - [[nodiscard]] inline bool has_empty_hostname() const noexcept; + [[nodiscard]] constexpr bool has_empty_hostname() const noexcept; /** @return true if it has a host (included an empty host) */ - [[nodiscard]] inline bool has_hostname() const noexcept; + [[nodiscard]] constexpr bool has_hostname() const noexcept; /** @return true if the URL has a non-empty username */ - [[nodiscard]] inline bool has_non_empty_username() const noexcept; + [[nodiscard]] constexpr bool has_non_empty_username() const noexcept; /** @return true if the URL has a non-empty password */ - [[nodiscard]] inline bool has_non_empty_password() const noexcept; + [[nodiscard]] constexpr bool has_non_empty_password() const noexcept; /** @return true if the URL has a (non default) port */ - [[nodiscard]] inline bool has_port() const noexcept; + [[nodiscard]] constexpr bool has_port() const noexcept; /** @return true if the URL has a password */ - [[nodiscard]] inline bool has_password() const noexcept; + [[nodiscard]] constexpr bool has_password() const noexcept; /** @return true if the URL has a hash component */ - [[nodiscard]] inline bool has_hash() const noexcept override; + [[nodiscard]] constexpr bool has_hash() const noexcept override; /** @return true if the URL has a search component */ - [[nodiscard]] inline bool has_search() const noexcept override; + [[nodiscard]] constexpr bool has_search() const noexcept override; - inline void clear_port(); + constexpr void clear_port(); inline void clear_hash(); inline void clear_search() override; @@ -233,7 +233,7 @@ struct url_aggregator : url_base { * To optimize performance, you may indicate how much memory to allocate * within this instance. */ - inline void reserve(uint32_t capacity); + constexpr void reserve(uint32_t capacity); ada_really_inline size_t parse_port( std::string_view view, bool check_trailing_content) noexcept override; @@ -268,7 +268,7 @@ struct url_aggregator : url_base { * A URL cannot have a username/password/port if its host is null or the empty * string, or its scheme is "file". */ - [[nodiscard]] inline bool cannot_have_credentials_or_port() const; + [[nodiscard]] constexpr bool cannot_have_credentials_or_port() const; template bool set_host_or_hostname(std::string_view input); @@ -289,7 +289,7 @@ struct url_aggregator : url_base { inline void append_base_password(std::string_view input); inline void update_base_port(uint32_t input); inline void append_base_pathname(std::string_view input); - [[nodiscard]] inline uint32_t retrieve_base_port() const; + [[nodiscard]] constexpr uint32_t retrieve_base_port() const; inline void clear_hostname(); inline void clear_password(); inline void clear_pathname() override; @@ -301,7 +301,7 @@ struct url_aggregator : url_base { std::string_view input); ada_really_inline uint32_t replace_and_resize(uint32_t start, uint32_t end, std::string_view input); - [[nodiscard]] inline bool has_authority() const noexcept; + [[nodiscard]] constexpr bool has_authority() const noexcept; inline void set_protocol_as_file(); inline void set_scheme(std::string_view new_scheme) noexcept; /** diff --git a/src/url-getters.cpp b/src/url-getters.cpp index 227863a71..23008df69 100644 --- a/src/url-getters.cpp +++ b/src/url-getters.cpp @@ -58,11 +58,14 @@ namespace ada { return host.value(); } -[[nodiscard]] std::string url::get_hostname() const noexcept { - return host.value_or(""); +[[nodiscard]] constexpr std::string_view url::get_hostname() const noexcept { + if (host.has_value()) { + return *host; + } + return {}; } -[[nodiscard]] std::string_view url::get_pathname() const noexcept { +[[nodiscard]] constexpr std::string_view url::get_pathname() const noexcept { return path; } @@ -73,11 +76,11 @@ namespace ada { : "?" + query.value(); } -[[nodiscard]] const std::string& url::get_username() const noexcept { +[[nodiscard]] constexpr std::string_view url::get_username() const noexcept { return username; } -[[nodiscard]] const std::string& url::get_password() const noexcept { +[[nodiscard]] constexpr std::string_view url::get_password() const noexcept ada_lifetime_bound { return password; } diff --git a/src/url-setters.cpp b/src/url-setters.cpp index a3c416620..1cc38bdf2 100644 --- a/src/url-setters.cpp +++ b/src/url-setters.cpp @@ -37,7 +37,7 @@ bool url::set_host_or_hostname(const std::string_view input) { // Note: the 'found_colon' value is true if and only if a colon was // encountered while not inside brackets. if (found_colon) { - if (override_hostname) { + if constexpr (override_hostname) { return false; } std::string_view buffer = new_host.substr(location + 1); @@ -204,8 +204,8 @@ bool url::set_protocol(const std::string_view input) { view.append(":"); - std::string::iterator pointer = - std::find_if_not(view.begin(), view.end(), unicode::is_alnum_plus); + auto pointer = + std::ranges::find_if_not(view, unicode::is_alnum_plus); if (pointer != view.end() && *pointer == ':') { return parse_scheme( @@ -215,19 +215,10 @@ bool url::set_protocol(const std::string_view input) { } bool url::set_href(const std::string_view input) { - ada::result out = ada::parse(input); + auto out = ada::parse(input); if (out) { - username = out->username; - password = out->password; - host = out->host; - port = out->port; - path = out->path; - query = out->query; - hash = out->hash; - type = out->type; - non_special_scheme = out->non_special_scheme; - has_opaque_path = out->has_opaque_path; + *this = *out; } return out.has_value(); diff --git a/src/url.cpp b/src/url.cpp index c3121056b..145d08755 100644 --- a/src/url.cpp +++ b/src/url.cpp @@ -10,7 +10,7 @@ namespace ada { bool url::parse_opaque_host(std::string_view input) { ada_log("parse_opaque_host ", input, " [", input.size(), " bytes]"); - if (std::any_of(input.begin(), input.end(), + if (std::ranges::any_of(input, ada::unicode::is_forbidden_host_code_point)) { return is_valid = false; } @@ -65,7 +65,7 @@ bool url::parse_ipv4(std::string_view input) { // We have the last value. // At this stage, ipv4 contains digit_count*8 bits. // So we have 32-digit_count*8 bits left. - if (segment_result >= (uint64_t(1) << (32 - digit_count * 8))) { + if (segment_result >= (static_cast(1) << (32 - digit_count * 8))) { return is_valid = false; } ipv4 <<= (32 - digit_count * 8); @@ -113,7 +113,7 @@ bool url::parse_ipv6(std::string_view input) { std::optional compress{}; // Let pointer be a pointer for input. - std::string_view::iterator pointer = input.begin(); + auto pointer = input.begin(); // If c is U+003A (:), then: if (input[0] == ':') { @@ -163,7 +163,8 @@ bool url::parse_ipv6(std::string_view input) { while (length < 4 && pointer != input.end() && unicode::is_ascii_hex_digit(*pointer)) { // https://stackoverflow.com/questions/39060852/why-does-the-addition-of-two-shorts-return-an-int - value = uint16_t(value * 0x10 + unicode::convert_hex_to_binary(*pointer)); + value = static_cast(value * 0x10 + + unicode::convert_hex_to_binary(*pointer)); pointer++; length++; } @@ -248,7 +249,7 @@ bool url::parse_ipv6(std::string_view input) { // ipv4Piece. // https://stackoverflow.com/questions/39060852/why-does-the-addition-of-two-shorts-return-an-int address[piece_index] = - uint16_t(address[piece_index] * 0x100 + *ipv4_piece); + static_cast(address[piece_index] * 0x100 + *ipv4_piece); // Increase numbersSeen by 1. numbers_seen++; @@ -330,12 +331,12 @@ bool url::parse_ipv6(std::string_view input) { template ada_really_inline bool url::parse_scheme(const std::string_view input) { auto parsed_type = ada::scheme::get_scheme_type(input); - bool is_input_special = (parsed_type != ada::scheme::NOT_SPECIAL); /** * In the common case, we will immediately recognize a special scheme (e.g., *http, https), in which case, we can go really fast. **/ - if (is_input_special) { // fast path!!! + if (bool is_input_special = + (parsed_type != ada::scheme::NOT_SPECIAL)) { // fast path!!! if (has_state_override) { // If url's scheme is not a special scheme and buffer is a special scheme, // then return. diff --git a/src/url_aggregator.cpp b/src/url_aggregator.cpp index dd753568c..82d547602 100644 --- a/src/url_aggregator.cpp +++ b/src/url_aggregator.cpp @@ -27,7 +27,7 @@ template *http, https), in which case, we can go really fast. **/ if (is_input_special) { // fast path!!! - if (has_state_override) { + if constexpr (has_state_override) { // If url's scheme is not a special scheme and buffer is a special scheme, // then return. if (is_special() != is_input_special) { @@ -52,7 +52,7 @@ template type = parsed_type; set_scheme_from_view_with_colon(input_with_colon); - if (has_state_override) { + if constexpr (has_state_override) { // This is uncommon. uint16_t urls_scheme_port = get_special_port(); @@ -69,7 +69,7 @@ template // need to check the return value. unicode::to_lower_ascii(_buffer.data(), _buffer.size()); - if (has_state_override) { + if constexpr (has_state_override) { // If url's scheme is a special scheme and buffer is not a special scheme, // then return. If url's scheme is not a special scheme and buffer is a // special scheme, then return. @@ -94,7 +94,7 @@ template set_scheme(_buffer); - if (has_state_override) { + if constexpr (has_state_override) { // This is uncommon. uint16_t urls_scheme_port = get_special_port(); @@ -222,8 +222,8 @@ bool url_aggregator::set_protocol(const std::string_view input) { view.append(":"); - std::string::iterator pointer = - std::find_if_not(view.begin(), view.end(), unicode::is_alnum_plus); + auto pointer = + std::ranges::find_if_not(view, unicode::is_alnum_plus); if (pointer != view.end() && *pointer == ':') { return parse_scheme_with_colon( @@ -539,7 +539,7 @@ bool url_aggregator::set_host_or_hostname(const std::string_view input) { // Note: the 'found_colon' value is true if and only if a colon was // encountered while not inside brackets. if (found_colon) { - if (override_hostname) { + if constexpr (override_hostname) { return false; } std::string_view sub_buffer = new_host.substr(location + 1); @@ -645,52 +645,51 @@ bool url_aggregator::set_hostname(const std::string_view input) { return "null"; } -[[nodiscard]] std::string_view url_aggregator::get_username() const noexcept +[[nodiscard]] constexpr std::string_view url_aggregator::get_username() const noexcept ada_lifetime_bound { ada_log("url_aggregator::get_username"); if (has_non_empty_username()) { return helpers::substring(buffer, components.protocol_end + 2, components.username_end); } - return ""; + return {}; } -[[nodiscard]] std::string_view url_aggregator::get_password() const noexcept +[[nodiscard]] constexpr std::string_view url_aggregator::get_password() const noexcept ada_lifetime_bound { ada_log("url_aggregator::get_password"); if (has_non_empty_password()) { return helpers::substring(buffer, components.username_end + 1, components.host_start); } - return ""; + return {}; } -[[nodiscard]] std::string_view url_aggregator::get_port() const noexcept +[[nodiscard]] constexpr std::string_view url_aggregator::get_port() const noexcept ada_lifetime_bound { ada_log("url_aggregator::get_port"); if (components.port == url_components::omitted) { - return ""; + return {}; } return helpers::substring(buffer, components.host_end + 1, components.pathname_start); } -[[nodiscard]] std::string_view url_aggregator::get_hash() const noexcept +[[nodiscard]] constexpr std::string_view url_aggregator::get_hash() const noexcept ada_lifetime_bound { ada_log("url_aggregator::get_hash"); - // If this's URL's fragment is either null or the empty string, then return + // If this URL's fragment is either null or the empty string, then return // the empty string. Return U+0023 (#), followed by this's URL's fragment. if (components.hash_start == url_components::omitted) { - return ""; + return {}; } if (buffer.size() - components.hash_start <= 1) { - return ""; + return {}; } return helpers::substring(buffer, components.hash_start); } -[[nodiscard]] std::string_view url_aggregator::get_host() const noexcept - ada_lifetime_bound { +[[nodiscard]] constexpr std::string_view url_aggregator::get_host() const noexcept { ada_log("url_aggregator::get_host"); // Technically, we should check if there is a hostname, but // the code below works even if there isn't. @@ -729,7 +728,7 @@ bool url_aggregator::set_hostname(const std::string_view input) { components.pathname_start, " buffer.size() = ", buffer.size(), " components.search_start = ", components.search_start, " components.hash_start = ", components.hash_start); - auto ending_index = uint32_t(buffer.size()); + auto ending_index = static_cast(buffer.size()); if (components.search_start != url_components::omitted) { ending_index = components.search_start; } else if (components.hash_start != url_components::omitted) { @@ -746,7 +745,7 @@ bool url_aggregator::set_hostname(const std::string_view input) { if (components.search_start == url_components::omitted) { return ""; } - auto ending_index = uint32_t(buffer.size()); + auto ending_index = static_cast(buffer.size()); if (components.hash_start != url_components::omitted) { ending_index = components.hash_start; }