浏览代码

Shell: Make Parser::expect() revert the offset when matching fails

AnotherTest 4 年之前
父节点
当前提交
53b85bcdd0
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      Shell/Parser.cpp

+ 5 - 1
Shell/Parser.cpp

@@ -58,12 +58,16 @@ bool Parser::expect(char ch)
 
 bool Parser::expect(const StringView& expected)
 {
+    auto offset_at_start = m_offset;
+
     if (expected.length() + m_offset > m_input.length())
         return false;
 
     for (size_t i = 0; i < expected.length(); ++i) {
-        if (peek() != expected[i])
+        if (peek() != expected[i]) {
+            m_offset = offset_at_start;
             return false;
+        }
 
         consume();
     }