From 0b3cdb4ae2fa176ba74a48ff7a1616395079c151 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 5 Aug 2014 22:46:43 +0200 Subject: too much to tell --- fast/util.hh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 fast/util.hh (limited to 'fast/util.hh') 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 + +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 + -- cgit v1.2.3