mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 17:55:08 +00:00
Shell: Make Parser::expect() revert the offset when matching fails
This commit is contained in:
parent
afe0ae586c
commit
53b85bcdd0
1 changed files with 5 additions and 1 deletions
|
@ -58,12 +58,16 @@ bool Parser::expect(char ch)
|
||||||
|
|
||||||
bool Parser::expect(const StringView& expected)
|
bool Parser::expect(const StringView& expected)
|
||||||
{
|
{
|
||||||
|
auto offset_at_start = m_offset;
|
||||||
|
|
||||||
if (expected.length() + m_offset > m_input.length())
|
if (expected.length() + m_offset > m_input.length())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t i = 0; i < expected.length(); ++i) {
|
for (size_t i = 0; i < expected.length(); ++i) {
|
||||||
if (peek() != expected[i])
|
if (peek() != expected[i]) {
|
||||||
|
m_offset = offset_at_start;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
consume();
|
consume();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue