diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 5e6b8e400..bea0a5099 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -1101,14 +1101,16 @@ bool Lexer::isWord (std::string& token, Lexer::Type& type) } //////////////////////////////////////////////////////////////////////////////// -bool Lexer::isLiteral (const std::string& literal) +bool Lexer::isLiteral (const std::string& literal, bool endBoundary) { - if (_text.find (literal, _cursor) == 0 && - (isEOS () || - Lexer::isWhitespace (_text[_cursor + literal.length ()]) || - Lexer::isSingleCharOperator (_text[_cursor + literal.length ()]))) + auto len = literal.length (); + if (_text.find (literal, _cursor) == _cursor && + (! endBoundary || + _text.length () == _cursor + len || + Lexer::isWhitespace (_text[_cursor + len]) || + Lexer::isSingleCharOperator (_text[_cursor + len]))) { - _cursor += literal.length (); + _cursor += len; return true; } @@ -1116,10 +1118,10 @@ bool Lexer::isLiteral (const std::string& literal) } //////////////////////////////////////////////////////////////////////////////// -bool Lexer::isOneOf (const std::vector & options) +bool Lexer::isOneOf (const std::vector & options, bool endBoundary) { for (auto& item : options) - if (isLiteral (item)) + if (isLiteral (item, endBoundary)) return true; return false; diff --git a/src/Lexer.h b/src/Lexer.h index b6b806dc3..93aec21cb 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -105,8 +105,8 @@ public: bool isDOM (std::string&, Lexer::Type&); bool isIdentifier (std::string&, Lexer::Type&); bool isWord (std::string&, Lexer::Type&); - bool isLiteral (const std::string&); - bool isOneOf (const std::vector &); + bool isLiteral (const std::string&, bool); + bool isOneOf (const std::vector &, bool); private: std::string _text;