diff options
Diffstat (limited to 'src/uscxml/util/String.cpp')
-rw-r--r-- | src/uscxml/util/String.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/uscxml/util/String.cpp b/src/uscxml/util/String.cpp index 6d43301..24c7d42 100644 --- a/src/uscxml/util/String.cpp +++ b/src/uscxml/util/String.cpp @@ -25,6 +25,34 @@ namespace uscxml { #define ISWHITESPACE(char) (isspace(char)) +std::string escapedMacro(std::string const& s) { + // inspired by http://stackoverflow.com/questions/2417588/escaping-a-c-string + std::string returnValue=""; + for (std::string::const_iterator iter = s.begin(), end = s.end(); iter != end; ++iter) { + char c = *iter; + if (' ' <= c && c <= '~' && c != '\\' && c != '"') { + returnValue += c; + } + else { + returnValue += "__"; + switch(c) { + case '"': returnValue += "COLON"; break; + case '\\': returnValue += "BACHSLASH"; break; + case '\t': returnValue += "TAB"; break; + case '\r': returnValue += "RETURN"; break; + case '\n': returnValue += "NEWLINE"; break; + default: + char const* const hexdig = "0123456789ABCDEF"; + returnValue += 'x'; + returnValue += hexdig[c >> 4]; + returnValue += hexdig[c & 0xF]; + } + returnValue += "__"; + } + } + return returnValue; +} + std::list<std::string> tokenize(const std::string& line, const char sep, bool trimWhiteSpace) { std::list<std::string> tokens; |