diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-09 17:28:52 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-09 17:28:52 +0100 |
commit | 5d156c7a47ae5a743d6245965ffc932301f8a3bd (patch) | |
tree | ccab8aaf9b93ebc2f1a0c8cd09814f1531a06dae /src/core/common | |
parent | bb8c69fbdeba3fa95fc780552252525b222ceb5a (diff) |
Added fetch and fetchPeek functions for reading the current character without advancing any cursor
Diffstat (limited to 'src/core/common')
-rw-r--r-- | src/core/common/CharReader.cpp | 20 | ||||
-rw-r--r-- | src/core/common/CharReader.hpp | 20 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/core/common/CharReader.cpp b/src/core/common/CharReader.cpp index 4d3638c..3e95280 100644 --- a/src/core/common/CharReader.cpp +++ b/src/core/common/CharReader.cpp @@ -468,15 +468,27 @@ bool CharReader::read(char &c) return res; } +bool CharReader::fetch(char &c) +{ + return buffer->fetch(readCursor, c); +} + +bool CharReader::fetchPeek(char &c) +{ + if (coherent) { + return fetch(c); + } + return buffer->fetch(peekCursor, c); +} + bool CharReader::expect(char c) { - char actual = 0; - peek(actual); - if (c == actual) { + char actual; + if (fetch(actual) && (actual == c)) { + peek(actual); consumePeek(); return true; } - resetPeek(); return false; } diff --git a/src/core/common/CharReader.hpp b/src/core/common/CharReader.hpp index 64c80af..a90d337 100644 --- a/src/core/common/CharReader.hpp +++ b/src/core/common/CharReader.hpp @@ -490,6 +490,26 @@ public: bool read(char &c); /** + * Returns the current character at the read cursor without advancing it. + * + * @param c is a reference to the character into which the result should be + * written. + * @return true if the operation was successful, false if the cursor is at + * the end of the file. + */ + bool fetch(char &c); + + /** + * Returns the current character at the peek cursor without advancing it. + * + * @param c is a reference to the character into which the result should be + * written. + * @return true if the operation was successful, false if the cursor is at + * the end of the file. + */ + bool fetchPeek(char &c); + + /** * Peeks a character, checks whether this character equals the given * character -- and if yes -- consumes the peek, otherwise resets it. * |