From 21f17793fbe449b20a93752577fe0ee898a519f6 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 1 Jan 2025 14:03:43 -0500 Subject: [PATCH] simplify parser --- include/ada/url_pattern_helpers-inl.h | 2 +- include/ada/url_pattern_helpers.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/ada/url_pattern_helpers-inl.h b/include/ada/url_pattern_helpers-inl.h index e852ff293..22fb4cb03 100644 --- a/include/ada/url_pattern_helpers-inl.h +++ b/include/ada/url_pattern_helpers-inl.h @@ -656,7 +656,7 @@ parse_pattern_string(std::string_view input, parser.tokens = std::move(*tokenize_result); // While parser’s index is less than parser’s token list's size: - while (parser.index < parser.tokens.size()) { + while (parser.can_continue()) { // Let char token be the result of running try to consume a token given // parser and "char". auto char_token = parser.try_consume_token(token_type::CHAR); diff --git a/include/ada/url_pattern_helpers.h b/include/ada/url_pattern_helpers.h index f635cad15..d64de0dcb 100644 --- a/include/ada/url_pattern_helpers.h +++ b/include/ada/url_pattern_helpers.h @@ -61,7 +61,9 @@ class url_pattern_parser { url_pattern_parser(F& encoding_callback_, std::string_view segment_wildcard_regexp_) : encoding_callback(encoding_callback_), - segment_wildcard_regexp(std::string(segment_wildcard_regexp_)) {} + segment_wildcard_regexp(segment_wildcard_regexp_) {} + + bool can_continue() const { return index < tokens.size(); } // @see https://urlpattern.spec.whatwg.org/#try-to-consume-a-token Token* try_consume_token(token_type type); @@ -123,9 +125,9 @@ class Tokenizer { size_t next_position, size_t value_position) ada_warn_unused; // has an associated input, a pattern string, initially the empty string. - std::string input{}; + std::string input; // has an associated policy, a tokenize policy, initially "strict". - token_policy policy = token_policy::STRICT; + token_policy policy; // has an associated token list, a token list, initially an empty list. std::vector token_list{}; // has an associated index, a number, initially 0.