[cfe-commits] r62337 - /cfe/trunk/lib/AST/StmtPrinter.cpp
Chris Lattner
sabre at nondot.org
Fri Jan 16 11:25:18 PST 2009
Author: lattner
Date: Fri Jan 16 13:25:18 2009
New Revision: 62337
URL: http://llvm.org/viewvc/llvm-project?rev=62337&view=rev
Log:
make ast-print handle random non-printable characters correctly with octal escapes.
Modified:
cfe/trunk/lib/AST/StmtPrinter.cpp
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=62337&r1=62336&r2=62337&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Jan 16 13:25:18 2009
@@ -663,9 +663,19 @@
// FIXME: this doesn't print wstrings right.
for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
- switch (Str->getStrData()[i]) {
- default: OS << Str->getStrData()[i]; break;
- // Handle some common ones to make dumps prettier.
+ unsigned char Char = Str->getStrData()[i];
+
+ switch (Char) {
+ default:
+ if (isprint(Char))
+ OS << (char)Char;
+ else // Output anything hard as an octal escape.
+ OS << '\\'
+ << (char)('0'+ ((Char >> 6) & 7))
+ << (char)('0'+ ((Char >> 3) & 7))
+ << (char)('0'+ ((Char >> 0) & 7));
+ break;
+ // Handle some common non-printable cases to make dumps prettier.
case '\\': OS << "\\\\"; break;
case '"': OS << "\\\""; break;
case '\n': OS << "\\n"; break;
More information about the cfe-commits
mailing list