summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Convenience.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/Convenience.cpp')
-rw-r--r--src/uscxml/Convenience.cpp115
1 files changed, 82 insertions, 33 deletions
diff --git a/src/uscxml/Convenience.cpp b/src/uscxml/Convenience.cpp
index 6013575..5d81db7 100644
--- a/src/uscxml/Convenience.cpp
+++ b/src/uscxml/Convenience.cpp
@@ -81,48 +81,97 @@ bool envVarIEquals(const char* name, const char* value) {
return iequals(envVarValue, value);
}
-std::string unescape(const std::string& a) {
+std::string escape(const std::string& a) {
std::stringstream b;
// see http://en.cppreference.com/w/cpp/language/escape
std::string::const_iterator it = a.begin();
while (it != a.end()) {
char c = *it++;
- if (c == '\\' && it != a.end()) {
- switch (*it++) {
- case '\\':
- c = '\\';
- break;
- case '0':
- c = '\0';
- break;
- case 'a':
- c = '\a';
- break;
- case 'b':
- c = '\b';
- break;
- case 'f':
- c = '\f';
- break;
- case 'n':
- c = '\n';
- break;
- case 'r':
- c = '\r';
- break;
- case 't':
- c = '\t';
- break;
- case 'v':
- c = '\v';
- break;
- }
- }
- b << c;
+ switch (c) {
+ case '\\':
+ b << '\\' << '\\';
+ break;
+ case '\0':
+ b << '\\' << '0';
+ break;
+ case '"':
+ b << '\\' << '"';
+ break;
+ case '\a':
+ b << '\\' << 'a';
+ break;
+ case '\b':
+ b << '\\' << 'b';
+ break;
+ case '\f':
+ b << '\\' << 'f';
+ break;
+ case '\n':
+ b << '\\' << 'n';
+ break;
+ case '\r':
+ b << '\\' << 'r';
+ break;
+ case '\t':
+ b << '\\' << 't';
+ break;
+ case '\v':
+ b << '\\' << 'v';
+ break;
+ default:
+ b << c;
+ }
}
return b.str();
}
+std::string unescape(const std::string& a) {
+ std::stringstream b;
+ // see http://en.cppreference.com/w/cpp/language/escape
+
+ std::string::const_iterator it = a.begin();
+ while (it != a.end()) {
+ char c = *it++;
+ if (c == '\\' && it != a.end()) {
+ switch (*it++) {
+ case '\\':
+ c = '\\';
+ break;
+ case '0':
+ c = '\0';
+ break;
+ case '"':
+ c = '"';
+ break;
+ case 'a':
+ c = '\a';
+ break;
+ case 'b':
+ c = '\b';
+ break;
+ case 'f':
+ c = '\f';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ case 'v':
+ c = '\v';
+ break;
+ }
+ }
+ b << c;
+ }
+
+ return b.str();
+}
+
}