diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/common/CharReader.cpp | 12 | ||||
-rw-r--r-- | src/core/common/CharReader.hpp | 9 | ||||
-rw-r--r-- | src/core/common/Utils.cpp | 4 | ||||
-rw-r--r-- | src/core/common/Utils.hpp | 16 | ||||
-rw-r--r-- | src/core/common/VariantReader.hpp | 1 |
5 files changed, 36 insertions, 6 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(); diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp index e5e2d39..563fe2a 100644 --- a/src/core/common/Utils.cpp +++ b/src/core/common/Utils.cpp @@ -35,10 +35,10 @@ bool Utils::isIdentifier(const std::string &name) { bool first = true; for (char c : name) { - if (first && !(isAlphabetic(c) || c == '_')) { + if (first && !isIdentifierStartCharacter(c)) { return false; } - if (!first && !(isAlphanumeric(c) || c == '_' || c == '-')) { + if (!first && !isIdentifierCharacter(c)) { return false; } first = false; diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp index 457d446..2c8a5b3 100644 --- a/src/core/common/Utils.hpp +++ b/src/core/common/Utils.hpp @@ -58,15 +58,23 @@ public: } /** - * Returns true if the given character is in [A-Za-z_] + * Returns true if the given character is in [A-Za-z]. */ - static bool isIdentifierStart(const char c) + static bool isIdentifierStartCharacter(const char c) { - return isAlphabetic(c) || (c == '_'); + return isAlphabetic(c); } /** - * Returns true if the given character is in [A-Za-z_][A-Za-z0-9_-]* + * Returns true if the given character is in [A-Za-z0-9_-]. + */ + static bool isIdentifierCharacter(const char c) + { + return isAlphanumeric(c) || (c == '_') || (c == '-'); + } + + /** + * Returns true if the given character is in [A-Za-z][A-Za-z0-9_-]* */ static bool isIdentifier(const std::string &name); diff --git a/src/core/common/VariantReader.hpp b/src/core/common/VariantReader.hpp index 7f00251..6b157d8 100644 --- a/src/core/common/VariantReader.hpp +++ b/src/core/common/VariantReader.hpp @@ -195,6 +195,7 @@ public: static std::pair<bool, Variant::mapType> parseObject(CharReader &reader, Logger &logger, char delim = 0); + /** * Parses a Cardinality. A Cardinality is specified as a list of Ranges, * separated by commas and enclosed in curly braces. The ranges can be |