Index: src/ostreams.cc |
diff --git a/src/ostreams.cc b/src/ostreams.cc |
index 847dc31bad6630227c227d2fddd08e305009ee79..62304eb9081240a1e9942fbaeb2a5076fdeecc05 100644 |
--- a/src/ostreams.cc |
+++ b/src/ostreams.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include <algorithm> |
+#include <cctype> |
#include <cmath> |
#include "src/base/platform/platform.h" // For isinf/isnan with MSVC |
@@ -165,9 +166,10 @@ OFStream& OFStream::flush() { |
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) { |
char buf[10]; |
- const char* format = (0x20 <= c.value && c.value <= 0x7F) && (c.value != 0x52) |
- ? "%c" |
- : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x"; |
+ const char* format = |
+ (std::isprint(c.value) || std::isspace(c.value)) && c.value != '\\' |
+ ? "%c" |
+ : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x"; |
snprintf(buf, sizeof(buf), format, c.value); |
return os << buf; |
} |
@@ -175,9 +177,8 @@ OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) { |
OStream& operator<<(OStream& os, const AsUC16& c) { |
char buf[10]; |
- const char* format = (0x20 <= c.value && c.value <= 0x7F) |
- ? "%c" |
- : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x"; |
+ const char* format = |
+ std::isprint(c.value) ? "%c" : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x"; |
snprintf(buf, sizeof(buf), format, c.value); |
return os << buf; |
} |