summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-31 22:49:25 +0800
committerJohn Hodge <tpg@mutabah.net>2016-12-31 22:49:25 +0800
commitb2cea0a04b8da30865e98fd2d19e83af4867dc8a (patch)
tree48699624fce592da41af92b92f21372fcfbbacfa /src/common.hpp
parent6179f6637ccff6479e3d979abfc766f530bf0c49 (diff)
downloadmrust-b2cea0a04b8da30865e98fd2d19e83af4867dc8a.tar.gz
MIR Dump - Clean string printing
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/common.hpp b/src/common.hpp
index d421e368..0b0fad14 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -289,7 +289,27 @@ inline ::std::ostream& operator<<(::std::ostream& os, const ::std::multimap<T,U,
return os;
}
-}
+} // namespace std
+
+struct FmtEscaped {
+ const char* s;
+ FmtEscaped(const ::std::string& s):
+ s(s.c_str())
+ {}
+ friend ::std::ostream& operator<<(::std::ostream& os, const FmtEscaped& x) {
+ for(auto s = x.s; *s != '\0'; s ++)
+ {
+ switch(*s)
+ {
+ case '\n': os << "\\n"; break;
+ case '\\': os << "\\\\"; break;
+ case '"': os << "\\\""; break;
+ default: os << *s; break;
+ }
+ }
+ return os;
+ }
+};
// -------------------------------------------------------------------
// --- Reversed iterable