From ae395324fc5e00751871886ae1a3acfd2dff8e24 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 1 Jan 2025 13:52:12 -0500 Subject: [PATCH] convert Token to class --- include/ada/url_pattern_helpers-inl.h | 10 +++------- include/ada/url_pattern_helpers.h | 6 +++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/ada/url_pattern_helpers-inl.h b/include/ada/url_pattern_helpers-inl.h index f08e4db25..35566ec90 100644 --- a/include/ada/url_pattern_helpers-inl.h +++ b/include/ada/url_pattern_helpers-inl.h @@ -375,12 +375,9 @@ inline void Tokenizer::add_token(token_type type, size_t next_position, // Set token’s index to tokenizer’s index. // Set token’s value to the code point substring from value position with // length value length within tokenizer’s input. - auto token = Token{.type = type, - .index = index, - .value = input.substr(value_position, value_length)}; - // Append token to the back of tokenizer’s token list. - token_list.push_back(std::move(token)); + token_list.emplace_back(type, index, + input.substr(value_position, value_length)); // Set tokenizer’s index to next position. index = next_position; } @@ -430,9 +427,8 @@ Token* url_pattern_parser::try_consume_modifier_token() { if (token) return token; // Set token to the result of running try to consume a token given parser and // "asterisk". - token = try_consume_token(token_type::ASTERISK); // Return token. - return token; + return try_consume_token(token_type::ASTERISK); } template diff --git a/include/ada/url_pattern_helpers.h b/include/ada/url_pattern_helpers.h index 6edc313c1..750c46f35 100644 --- a/include/ada/url_pattern_helpers.h +++ b/include/ada/url_pattern_helpers.h @@ -37,7 +37,11 @@ enum class token_policy { }; // @see https://urlpattern.spec.whatwg.org/#tokens -struct Token { +class Token { + public: + Token(token_type _type, size_t _index, std::string&& _value) + : type(_type), index(_index), value(std::move(_value)) {} + // A token has an associated type, a string, initially "invalid-char". token_type type = token_type::INVALID_CHAR;