StmtPrinter: Write large char values using \u or \U.
This may not always be valid, but we were previously just
emitting them raw.
While here, s/isprint/isPrintable/ (using the new CharInfo).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174766 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index fb9c70c..9d95c81 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -21,7 +21,9 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/CharInfo.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Format.h"
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -710,15 +712,14 @@
OS << "'\\v'";
break;
default:
- if (value < 256 && isprint(value)) {
+ if (value < 256 && isPrintable((unsigned char)value))
OS << "'" << (char)value << "'";
- } else if (value < 256) {
- OS << "'\\x";
- OS.write_hex(value) << "'";
- } else {
- // FIXME what to really do here?
- OS << value;
- }
+ else if (value < 256)
+ OS << "'\\x" << llvm::format("%02x", value) << "'";
+ else if (value <= 0xFFFF)
+ OS << "'\\u" << llvm::format("%04x", value) << "'";
+ else
+ OS << "'\\U" << llvm::format("%08x", value) << "'";
}
}