From: Chris Lattner Date: Fri, 16 Jan 2009 19:25:18 +0000 (+0000) Subject: make ast-print handle random non-printable characters correctly with octal escapes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a81c87503c7a36a4468a081cadb461833a360a8;p=clang make ast-print handle random non-printable characters correctly with octal escapes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62337 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index ea96411e07..96f5403154 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -663,9 +663,19 @@ void StmtPrinter::VisitStringLiteral(StringLiteral *Str) { // 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;