summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/common/Utils.cpp13
-rw-r--r--src/core/common/Utils.hpp5
-rw-r--r--src/core/model/Node.cpp2
3 files changed, 15 insertions, 5 deletions
diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp
index fc8ee00..f8b53c6 100644
--- a/src/core/common/Utils.cpp
+++ b/src/core/common/Utils.cpp
@@ -37,22 +37,27 @@ bool Utils::isIdentifier(const std::string &name)
}
first = false;
}
- return true;
+ return !first;
}
-bool Utils::isNamespaceIdentifier(const std::string &name)
+bool Utils::isIdentifierOrEmpty(const std::string &name)
+{
+ return name.empty() || isIdentifier(name);
+}
+
+bool Utils::isNamespacedIdentifier(const std::string &name)
{
bool first = true;
for (char c : name) {
if (first && !isIdentifierStartCharacter(c)) {
return false;
}
- if (!first && (!isIdentifierCharacter(c) || c == ':')) {
+ if (!first && (!isIdentifierCharacter(c) && c != ':')) {
return false;
}
first = (c == ':');
}
- return true;
+ return !first;
}
bool Utils::hasNonWhitepaceChar(const std::string &s)
diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp
index b5cd178..b5a54fc 100644
--- a/src/core/common/Utils.hpp
+++ b/src/core/common/Utils.hpp
@@ -86,6 +86,11 @@ public:
static bool isIdentifier(const std::string &name);
/**
+ * Returns true if the given string is an identifier or an empty string.
+ */
+ static bool isIdentifierOrEmpty(const std::string &name);
+
+ /**
* Returns true if the given string is in
* \code{.txt}
* ([A-Za-z][A-Za-z0-9_-]*)(:[A-Za-z][A-Za-z0-9_-]*)*
diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp
index 39ee2e4..ce15cad 100644
--- a/src/core/model/Node.cpp
+++ b/src/core/model/Node.cpp
@@ -448,7 +448,7 @@ bool Node::doValidate(Logger &logger) const { return true; }
bool Node::validateName(Logger &logger) const
{
- if (!Utils::isIdentifier(name)) {
+ if (!Utils::isIdentifierOrEmpty(name)) {
logger.error(type()->name + std::string(" name \"") + name +
std::string("\" is not a valid identifier"),
this);