1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:47:45 +00:00

LibRegex: Remove Lexer::slice_back() and just use StringViews

This commit is contained in:
AnotherTest 2020-12-06 17:03:29 +03:30 committed by Andreas Kling
parent 19bf7734a4
commit 86811683b0
2 changed files with 4 additions and 4 deletions

View file

@ -94,8 +94,6 @@ public:
bool try_skip(char); bool try_skip(char);
char skip(); char skip();
StringView slice_back(size_t offset) const { return m_source.substring_view(m_position - offset - 1, offset); }
private: private:
ALWAYS_INLINE char peek(size_t offset = 0) const; ALWAYS_INLINE char peek(size_t offset = 0) const;
ALWAYS_INLINE void consume(); ALWAYS_INLINE void consume();

View file

@ -803,6 +803,7 @@ Optional<unsigned> ECMA262Parser::read_digits(ECMA262Parser::ReadDigitsInitialZe
int count = 0; int count = 0;
size_t offset = 0; size_t offset = 0;
auto start_token = m_parser_state.current_token;
while (match(TokenType::Char)) { while (match(TokenType::Char)) {
auto c = m_parser_state.current_token.value(); auto c = m_parser_state.current_token.value();
if (follow_policy == ReadDigitFollowPolicy::DisallowDigit) { if (follow_policy == ReadDigitFollowPolicy::DisallowDigit) {
@ -826,7 +827,7 @@ Optional<unsigned> ECMA262Parser::read_digits(ECMA262Parser::ReadDigitsInitialZe
++count; ++count;
} }
auto str = m_parser_state.lexer.slice_back(offset); StringView str { start_token.value().characters_without_null_termination(), offset };
if (hex) if (hex)
return AK::StringUtils::convert_to_uint_from_hex(str); return AK::StringUtils::convert_to_uint_from_hex(str);
@ -1371,6 +1372,7 @@ StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_
if (take_starting_angle_bracket && !consume("<")) if (take_starting_angle_bracket && !consume("<"))
return {}; return {};
auto start_token = m_parser_state.current_token;
size_t offset = 0; size_t offset = 0;
while (match(TokenType::Char)) { while (match(TokenType::Char)) {
auto c = m_parser_state.current_token.value(); auto c = m_parser_state.current_token.value();
@ -1379,7 +1381,7 @@ StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_
offset += consume().value().length(); offset += consume().value().length();
} }
auto name = m_parser_state.lexer.slice_back(offset); StringView name { start_token.value().characters_without_null_termination(), offset };
if (!consume(">") || name.is_empty()) if (!consume(">") || name.is_empty())
set_error(Error::InvalidNameForCaptureGroup); set_error(Error::InvalidNameForCaptureGroup);