summaryrefslogtreecommitdiff
path: root/src/core/common/Utils.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-03-03 15:08:18 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-03-03 15:08:18 +0100
commit466ff991bcfad76d78100193aacbfaf74d542b26 (patch)
treedafdb41ec766e83c6e37a8b9865e6ef454ff4def /src/core/common/Utils.cpp
parentb5cdca0331117ad3834b61eadd94ab3fcb6d2fba (diff)
parentfb8d4cdf01909b61e4e5d0806ec6de178ff0058c (diff)
Storing type and name in the HandlerData once again, using a Token
Conflicts: application/src/core/parser/stack/Callbacks.hpp
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