summaryrefslogtreecommitdiff
path: root/fast/util.hh
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-08-05 22:46:43 +0200
committerPatrick Simianer <p@simianer.de>2014-08-05 22:46:43 +0200
commit0b3cdb4ae2fa176ba74a48ff7a1616395079c151 (patch)
tree7092a57ed7d29920df3ae2f97c39efc17c5e6095 /fast/util.hh
parenta27e2c529ddb7dc1be0c6bcc44e3ab558126d15d (diff)
too much to tell
Diffstat (limited to 'fast/util.hh')
-rw-r--r--fast/util.hh29
1 files changed, 29 insertions, 0 deletions
diff --git a/fast/util.hh b/fast/util.hh
new file mode 100644
index 0000000..2a28f16
--- /dev/null
+++ b/fast/util.hh
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <string>
+
+using namespace std;
+
+
+namespace util {
+
+ inline string
+ json_escape(const string& s) { // FIXME: only inline?
+ ostringstream os;
+ for (auto it = s.cbegin(); it != s.cend(); it++) {
+ switch (*it) {
+ case '"': os << "\\\""; break;
+ case '\\': os << "\\\\"; break;
+ case '\b': os << "\\b"; break;
+ case '\f': os << "\\f"; break;
+ case '\n': os << "\\n"; break;
+ case '\r': os << "\\r"; break;
+ case '\t': os << "\\t"; break;
+ default: os << *it; break;
+ }
+ }
+ return os.str();
+ };
+
+} // namespace util
+