diff options
author | Jens Heuschkel <heuschkel@tk.tu-darmstadt.de> | 2016-11-17 16:53:06 (GMT) |
---|---|---|
committer | Jens Heuschkel <heuschkel@tk.tu-darmstadt.de> | 2016-11-17 16:53:06 (GMT) |
commit | 8756dd45ef6a245f30eb23b678ca6d4f6ddab917 (patch) | |
tree | 7084e51987037109df53eb6279bb092c87bd8557 /src | |
parent | 6fff21bd785f4ee410192080251348d7228b92b4 (diff) | |
download | uscxml-8756dd45ef6a245f30eb23b678ca6d4f6ddab917.zip uscxml-8756dd45ef6a245f30eb23b678ca6d4f6ddab917.tar.gz uscxml-8756dd45ef6a245f30eb23b678ca6d4f6ddab917.tar.bz2 |
Add convenient macro escape function
Diffstat (limited to 'src')
-rw-r--r-- | src/uscxml/util/String.cpp | 27 | ||||
-rw-r--r-- | src/uscxml/util/String.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/uscxml/util/String.cpp b/src/uscxml/util/String.cpp index 6d43301..894148d 100644 --- a/src/uscxml/util/String.cpp +++ b/src/uscxml/util/String.cpp @@ -25,6 +25,33 @@ namespace uscxml { #define ISWHITESPACE(char) (isspace(char)) +std::string macro_escaped(std::string const& s) { + std::string returnValue=""; + for (std::string::const_iterator iter = s.begin(), end = s.end(); iter != end; ++iter) { + char c = *iter; + if (' ' <= c and c <= '~' and c != '\\' and 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; diff --git a/src/uscxml/util/String.h b/src/uscxml/util/String.h index 5344245..b0832c8 100644 --- a/src/uscxml/util/String.h +++ b/src/uscxml/util/String.h @@ -25,6 +25,7 @@ namespace uscxml { +std::string macro_escaped(std::string const& s); std::list<std::string> tokenize(const std::string& line, const char seperator = ' ', bool trimWhiteSpace = true); std::string spaceNormalize(const std::string& text); bool nameMatch(const std::string& eventDescs, const std::string& event); |