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
This commit is contained in:
Chris Lattner 2009-01-16 19:25:18 +00:00
Родитель 1522bc80df
Коммит 9a81c87503
1 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -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;