diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-08 21:13:12 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-08 21:13:12 +0100 |
commit | d710bf02517225662e80eeeaf93149cfe50c872d (patch) | |
tree | c166811f65a26c6eb53dc2e36fb10256df8da5f0 /src | |
parent | 9ef316ed4ea8542973d272fa9c7b4c6804b28144 (diff) |
Added "expect" function to CharReader
Diffstat (limited to 'src')
-rw-r--r-- | src/core/common/CharReader.cpp | 12 | ||||
-rw-r--r-- | src/core/common/CharReader.hpp | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/core/common/CharReader.cpp b/src/core/common/CharReader.cpp index 5b9b1d4..4d3638c 100644 --- a/src/core/common/CharReader.cpp +++ b/src/core/common/CharReader.cpp @@ -468,6 +468,18 @@ bool CharReader::read(char &c) return res; } +bool CharReader::expect(char c) +{ + char actual = 0; + peek(actual); + if (c == actual) { + consumePeek(); + return true; + } + resetPeek(); + return false; +} + void CharReader::resetPeek() { if (!coherent) { diff --git a/src/core/common/CharReader.hpp b/src/core/common/CharReader.hpp index cbfeaf2..64c80af 100644 --- a/src/core/common/CharReader.hpp +++ b/src/core/common/CharReader.hpp @@ -490,6 +490,15 @@ public: bool read(char &c); /** + * Peeks a character, checks whether this character equals the given + * character -- and if yes -- consumes the peek, otherwise resets it. + * + * @param c is the character that is expected. + * @return true if this character is actually next. + */ + bool expect(char c); + + /** * Resets the peek pointer to the "read" pointer. */ void resetPeek(); |