diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-15 00:10:16 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-15 00:10:16 +0100 |
commit | b04364cdbc2144661a28f78e0aa4e5e337254c50 (patch) | |
tree | f0e0f17eaad61f62f37daf4fa07f716f3d14f259 /src/core | |
parent | 93780dde6d52d72961ffc322b16e1fcc9575e85e (diff) |
Added isNamespacedIdentifier method to Utils
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/common/Utils.cpp | 15 | ||||
-rw-r--r-- | src/core/common/Utils.hpp | 21 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp index 3739c61..fc8ee00 100644 --- a/src/core/common/Utils.cpp +++ b/src/core/common/Utils.cpp @@ -40,6 +40,21 @@ bool Utils::isIdentifier(const std::string &name) return true; } +bool Utils::isNamespaceIdentifier(const std::string &name) +{ + bool first = true; + for (char c : name) { + if (first && !isIdentifierStartCharacter(c)) { + return false; + } + if (!first && (!isIdentifierCharacter(c) || c == ':')) { + return false; + } + first = (c == ':'); + } + return true; +} + bool Utils::hasNonWhitepaceChar(const std::string &s) { for (char c : s) { diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp index 8361973..b5cd178 100644 --- a/src/core/common/Utils.hpp +++ b/src/core/common/Utils.hpp @@ -74,11 +74,30 @@ public: } /** - * Returns true if the given character is in [A-Za-z][A-Za-z0-9_-]* + * Returns true if the given string is in + * \code{.txt} + * [A-Za-z][A-Za-z0-9_-]* + * \endCode + * + * @param name is the string that should be tested. + * @return true if the string matches the regular expression given above, + * false otherwise. */ static bool isIdentifier(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_-]*)* + * \endCode + * + * @param name is the string that should be tested. + * @return true if the string matches the regular expression given above, + * false otherwise. + */ + static bool isNamespacedIdentifier(const std::string &name); + + /** * Returns true if the given character is a linebreak character. */ static bool isLinebreak(const char c) { return (c == '\n') || (c == '\r'); } |