summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/common/Utils.cpp4
-rw-r--r--src/core/common/Utils.hpp16
-rw-r--r--test/core/common/UtilsTest.cpp2
3 files changed, 15 insertions, 7 deletions
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"));