summaryrefslogtreecommitdiff
path: root/src/core/common/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/common/Utils.cpp')
-rw-r--r--src/core/common/Utils.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp
index a77951e..a87ff6d 100644
--- a/src/core/common/Utils.cpp
+++ b/src/core/common/Utils.cpp
@@ -108,12 +108,6 @@ std::string Utils::extractFileExtension(const std::string &filename)
return std::string{};
}
-std::string Utils::trim(const std::string &s)
-{
- std::pair<size_t, size_t> bounds = trim(s, Utils::isWhitespace);
- return s.substr(bounds.first, bounds.second - bounds.first);
-}
-
bool Utils::startsWith(const std::string &s, const std::string &prefix)
{
return prefix.size() <= s.size() && s.substr(0, prefix.size()) == prefix;
@@ -124,5 +118,36 @@ bool Utils::endsWith(const std::string &s, const std::string &suffix)
return suffix.size() <= s.size() &&
s.substr(s.size() - suffix.size(), suffix.size()) == suffix;
}
-}
+bool Utils::isUserDefinedToken(const std::string &token)
+{
+ // Make sure the token meets is neither empty, nor starts or ends with an
+ // alphanumeric character
+ const size_t len = token.size();
+ if (len == 0 || isAlphanumeric(token[0]) ||
+ isAlphanumeric(token[len - 1])) {
+ return false;
+ }
+
+ // Make sure the token is not any special OSML token
+ if (token == "\\" || token == "%" || token == "%{" || token == "}%" ||
+ token == "{!" || token == "<\\" || token == "\\>") {
+ return false;
+ }
+
+ // Make sure the token does not contain any whitespaces.
+ for (char c : token) {
+ if (isWhitespace(c)) {
+ return false;
+ }
+ }
+
+ // Make sure the token contains other characters but { and }
+ for (char c : token) {
+ if (c != '{' && c != '}') {
+ return true;
+ }
+ }
+ return false;
+}
+} \ No newline at end of file