summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-11-27 07:59:50 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-11-27 07:59:50 +0000
commit65dc891942695acced166006df978d4e1c56da75 (patch)
tree0991c750a198cb8d9cf92dedc76314d3f2dbcb0d /llvm/lib/Support/raw_ostream.cpp
parent768a5e8004b660810f85abfffa5f012b1bde4e45 (diff)
downloadbcm5719-llvm-65dc891942695acced166006df978d4e1c56da75.tar.gz
bcm5719-llvm-65dc891942695acced166006df978d4e1c56da75.zip
raw_ostream::write_escaped: Add a UseHexEscapes argument.
llvm-svn: 120200
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index dceccad161d..d3d653983b0 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -15,6 +15,7 @@
#include "llvm/Support/Format.h"
#include "llvm/System/Program.h"
#include "llvm/System/Process.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
@@ -167,7 +168,8 @@ raw_ostream &raw_ostream::write_hex(unsigned long long N) {
return write(CurPtr, EndPtr-CurPtr);
}
-raw_ostream &raw_ostream::write_escaped(StringRef Str) {
+raw_ostream &raw_ostream::write_escaped(StringRef Str,
+ bool UseHexEscapes) {
for (unsigned i = 0, e = Str.size(); i != e; ++i) {
unsigned char c = Str[i];
@@ -190,11 +192,18 @@ raw_ostream &raw_ostream::write_escaped(StringRef Str) {
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));
+ // Write out the escaped representation.
+ if (UseHexEscapes) {
+ *this << '\\' << 'x';
+ *this << hexdigit((c >> 4 & 0xF));
+ *this << hexdigit((c >> 0) & 0xF);
+ } else {
+ // Always use a full 3-character octal escape.
+ *this << '\\';
+ *this << char('0' + ((c >> 6) & 7));
+ *this << char('0' + ((c >> 3) & 7));
+ *this << char('0' + ((c >> 0) & 7));
+ }
}
}
OpenPOWER on IntegriCloud