summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-10-17 20:43:08 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-10-17 20:43:08 +0000
commit4108c43fd1c3b9d8fb996e3836352668190d3c55 (patch)
treeb1f37121611812dd6765ac390759de5a83f63e64 /llvm/lib
parent9b24e8aba6dcaab0cf10fced29ea044449ec5ba1 (diff)
downloadbcm5719-llvm-4108c43fd1c3b9d8fb996e3836352668190d3c55.tar.gz
bcm5719-llvm-4108c43fd1c3b9d8fb996e3836352668190d3c55.zip
Add raw_ostream::write_escaped, for writing escaped strings.
llvm-svn: 84355
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 0a82cc1d10c..31451ccfdb1 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -168,6 +168,40 @@ raw_ostream &raw_ostream::write_hex(unsigned long long N) {
return write(CurPtr, EndPtr-CurPtr);
}
+raw_ostream &raw_ostream::write_escaped(StringRef Str) {
+ for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+ unsigned char c = Str[i];
+
+ switch (c) {
+ case '\\':
+ *this << '\\' << '\\';
+ break;
+ case '\t':
+ *this << '\\' << 't';
+ break;
+ case '\n':
+ *this << '\\' << 'n';
+ break;
+ case '"':
+ *this << '\\' << '"';
+ break;
+ default:
+ if (std::isprint(c)) {
+ *this << c;
+ break;
+ }
+
+ // Always expand to a 3-character octal escape.
+ *this << '\\';
+ *this << char('0' + ((c >> 6) & 7));
+ *this << char('0' + ((c >> 3) & 7));
+ *this << char('0' + ((c >> 0) & 7));
+ }
+ }
+
+ return *this;
+}
+
raw_ostream &raw_ostream::operator<<(const void *P) {
*this << '0' << 'x';
OpenPOWER on IntegriCloud