Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add const qualifier to several methods #882

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions include/ada/url_pattern_helpers-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ada/implementation.h"

namespace ada::url_pattern_helpers {
#ifdef ADA_TESTING
inline std::string to_string(token_type type) {
switch (type) {
case token_type::INVALID_CHAR:
Expand All @@ -40,6 +41,7 @@ inline std::string to_string(token_type type) {
ada::unreachable();
}
}
#endif // ADA_TESTING

template <url_pattern_regex::regex_concept regex_provider>
void constructor_string_parser<regex_provider>::rewind() {
Expand Down Expand Up @@ -91,7 +93,7 @@ bool constructor_string_parser<regex_provider>::is_search_prefix() {

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_non_special_pattern_char(
size_t index, std::string_view value) {
size_t index, std::string_view value) const {
// Let token be the result of running get a safe token given parser and index.
auto token = get_safe_token(index);
ADA_ASSERT_TRUE(token);
Expand All @@ -113,7 +115,7 @@ bool constructor_string_parser<regex_provider>::is_non_special_pattern_char(

template <url_pattern_regex::regex_concept regex_provider>
const token* constructor_string_parser<regex_provider>::get_safe_token(
size_t index) {
size_t index) const {
// If index is less than parser’s token list's size, then return parser’s
// token list[index].
if (index < token_list.size()) [[likely]] {
Expand Down Expand Up @@ -146,7 +148,8 @@ bool constructor_string_parser<regex_provider>::is_group_close() const {
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::next_is_authority_slashes() {
bool constructor_string_parser<regex_provider>::next_is_authority_slashes()
const {
// If the result of running is a non-special pattern char given parser,
// parser’s token index + 1, and "/" is false, then return false.
if (!is_non_special_pattern_char(token_index + 1, "/")) {
Expand All @@ -161,7 +164,7 @@ bool constructor_string_parser<regex_provider>::next_is_authority_slashes() {
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_protocol_suffix() {
bool constructor_string_parser<regex_provider>::is_protocol_suffix() const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and ":".
return is_non_special_pattern_char(token_index, ":");
Expand Down Expand Up @@ -288,42 +291,43 @@ std::string constructor_string_parser<regex_provider>::make_component_string() {
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_an_identity_terminator() {
bool constructor_string_parser<regex_provider>::is_an_identity_terminator()
const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and "@".
return is_non_special_pattern_char(token_index, "@");
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_pathname_start() {
bool constructor_string_parser<regex_provider>::is_pathname_start() const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and "/".
return is_non_special_pattern_char(token_index, "/");
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_password_prefix() {
bool constructor_string_parser<regex_provider>::is_password_prefix() const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and ":".
return is_non_special_pattern_char(token_index, ":");
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_an_ipv6_open() {
bool constructor_string_parser<regex_provider>::is_an_ipv6_open() const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and "[".
return is_non_special_pattern_char(token_index, "[");
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_an_ipv6_close() {
bool constructor_string_parser<regex_provider>::is_an_ipv6_close() const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and "]".
return is_non_special_pattern_char(token_index, "]");
}

template <url_pattern_regex::regex_concept regex_provider>
bool constructor_string_parser<regex_provider>::is_port_prefix() {
bool constructor_string_parser<regex_provider>::is_port_prefix() const {
// Return the result of running is a non-special pattern char given parser,
// parser’s token index, and ":".
return is_non_special_pattern_char(token_index, ":");
Expand Down Expand Up @@ -625,10 +629,9 @@ std::optional<errors> url_pattern_parser<F>::add_part(
// If name token is not null, then set name to name token’s value.
if (name_token) {
name = name_token->value;
} else if (regexp_or_wildcard_token) {
} else if (regexp_or_wildcard_token != nullptr) {
// Otherwise if regexp or wildcard token is not null:
// Set name to parser’s next numeric name, serialized.
// TODO: Make sure this is correct.
name = std::to_string(next_numeric_name);
// Increment parser’s next numeric name by 1.
next_numeric_name++;
Expand Down
22 changes: 12 additions & 10 deletions include/ada/url_pattern_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ enum class token_type : uint8_t {
END, // 9
};

#ifdef ADA_TESTING
std::string to_string(token_type type);
#endif // ADA_TESTING

// @see https://urlpattern.spec.whatwg.org/#tokenize-policy
enum class token_policy {
Expand Down Expand Up @@ -191,39 +193,39 @@ struct constructor_string_parser {
bool is_group_close() const;

// @see https://urlpattern.spec.whatwg.org/#is-a-protocol-suffix
bool is_protocol_suffix();
bool is_protocol_suffix() const;

// @see
// https://urlpattern.spec.whatwg.org/#compute-protocol-matches-a-special-scheme-flag
std::optional<errors> compute_protocol_matches_special_scheme_flag();

// @see https://urlpattern.spec.whatwg.org/#next-is-authority-slashes
bool next_is_authority_slashes();
bool next_is_authority_slashes() const;

// @see https://urlpattern.spec.whatwg.org/#is-an-identity-terminator
bool is_an_identity_terminator();
bool is_an_identity_terminator() const;

// @see https://urlpattern.spec.whatwg.org/#is-a-pathname-start
bool is_pathname_start();
bool is_pathname_start() const;

// @see https://urlpattern.spec.whatwg.org/#is-a-password-prefix
bool is_password_prefix();
bool is_password_prefix() const;

// @see https://urlpattern.spec.whatwg.org/#is-an-ipv6-open
bool is_an_ipv6_open();
bool is_an_ipv6_open() const;

// @see https://urlpattern.spec.whatwg.org/#is-an-ipv6-close
bool is_an_ipv6_close();
bool is_an_ipv6_close() const;

// @see https://urlpattern.spec.whatwg.org/#is-a-port-prefix
bool is_port_prefix();
bool is_port_prefix() const;

private:
// @see https://urlpattern.spec.whatwg.org/#is-a-non-special-pattern-char
bool is_non_special_pattern_char(size_t index, std::string_view value);
bool is_non_special_pattern_char(size_t index, std::string_view value) const;

// @see https://urlpattern.spec.whatwg.org/#get-a-safe-token
const token* get_safe_token(size_t index);
const token* get_safe_token(size_t index) const;

// @see https://urlpattern.spec.whatwg.org/#make-a-component-string
std::string make_component_string();
Expand Down
Loading