diff options
Diffstat (limited to 'src/core/common')
| -rw-r--r-- | src/core/common/Utils.cpp | 24 | ||||
| -rw-r--r-- | src/core/common/Utils.hpp | 19 | 
2 files changed, 43 insertions, 0 deletions
diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp index 85d2c28..219b437 100644 --- a/src/core/common/Utils.cpp +++ b/src/core/common/Utils.cpp @@ -118,5 +118,29 @@ 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 contains other characters but { and } +	for (char c: token) { +		if (c != '{' && c != '}') { +			return true; +		} +	} +	return false; +}  } diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp index 82a8f8c..25a4de5 100644 --- a/src/core/common/Utils.hpp +++ b/src/core/common/Utils.hpp @@ -103,6 +103,25 @@ public:  	static bool isNamespacedIdentifier(const std::string &name);  	/** +	 * Returns true if the given characters form a valid user-defined token. +	 * This function returns true under the following circumstances: +	 * <ul> +	 *   <li>The given token is not empty</li> +	 *   <li>The given token starts and ends with a non-alphanumeric character +	 *       </li> +	 *   <li>The token is none of the following character sequences (which are +	 *       special in OSML): +	 *      <ul> +	 *        <li>'{', '}' or any combined repetition of these characters</li> +	 *        <li>'\', '{!', '<\', '\>'</li> +	 *        <li>'%', '%{', '}%'</li> +	 *      </ul> +	 *   </li> +	 * </ul> +	 */ +	static bool isUserDefinedToken(const std::string &token); + +	/**  	 * Returns true if the given character is a linebreak character.  	 */  	static bool isLinebreak(const char c) { return (c == '\n') || (c == '\r'); }  | 
