Skip to content

Commit

Permalink
convert Token to class
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 1, 2025
1 parent ea7e886 commit ae39532
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 3 additions & 7 deletions include/ada/url_pattern_helpers-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -430,9 +427,8 @@ Token* url_pattern_parser<F>::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 <url_pattern_encoding_callback F>
Expand Down
6 changes: 5 additions & 1 deletion include/ada/url_pattern_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ae39532

Please sign in to comment.