From d710bf02517225662e80eeeaf93149cfe50c872d Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 8 Feb 2015 21:13:12 +0100 Subject: Added "expect" function to CharReader --- src/core/common/CharReader.cpp | 12 ++++++++++++ src/core/common/CharReader.hpp | 9 +++++++++ 2 files changed, 21 insertions(+) (limited to 'src/core') 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 @@ -489,6 +489,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. */ -- cgit v1.2.3 From 89339e77879cb97d5ddecbc21d62e094f9c700fa Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 8 Feb 2015 21:13:40 +0100 Subject: Changed definition of identifier (do not allow them to start with an underscore) --- src/core/common/Utils.cpp | 4 ++-- src/core/common/Utils.hpp | 16 ++++++++++++---- test/core/common/UtilsTest.cpp | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src/core') 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/test/core/common/UtilsTest.cpp b/test/core/common/UtilsTest.cpp index c8f6922..917f45c 100644 --- a/test/core/common/UtilsTest.cpp +++ b/test/core/common/UtilsTest.cpp @@ -26,7 +26,7 @@ TEST(Utils, isIdentifier) { ASSERT_TRUE(Utils::isIdentifier("test")); ASSERT_TRUE(Utils::isIdentifier("t0-_est")); - ASSERT_TRUE(Utils::isIdentifier("_t0-_EST")); + ASSERT_FALSE(Utils::isIdentifier("_t0-_EST")); ASSERT_FALSE(Utils::isIdentifier("-t0-_EST")); ASSERT_FALSE(Utils::isIdentifier("0t-_EST")); ASSERT_FALSE(Utils::isIdentifier("invalid key")); -- cgit v1.2.3 From bb8c69fbdeba3fa95fc780552252525b222ceb5a Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 8 Feb 2015 21:14:07 +0100 Subject: Added newline --- src/core/common/VariantReader.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core') 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 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 -- cgit v1.2.3