Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/text/WTFString.cpp |
| diff --git a/third_party/WebKit/Source/wtf/text/WTFString.cpp b/third_party/WebKit/Source/wtf/text/WTFString.cpp |
| index b67387516f033f4813df7bf79234e99544ceb1a4..1f4be45f87acef6bedd922841e4f166d8b614173 100644 |
| --- a/third_party/WebKit/Source/wtf/text/WTFString.cpp |
| +++ b/third_party/WebKit/Source/wtf/text/WTFString.cpp |
| @@ -1198,6 +1198,49 @@ const String& emptyString16Bit() |
| return emptyString; |
| } |
| +std::ostream& operator<<(std::ostream& out, const String& string) |
| +{ |
| + if (string.isNull()) |
| + return out << "<null>"; |
| + |
| + out << '"'; |
| + for (unsigned index = 0; index < string.length(); ++index) { |
| + // Print shorthands for select cases. |
| + UChar character = string[index]; |
| + switch (character) { |
| + case '\t': |
| + out << "\\t"; |
| + break; |
| + case '\n': |
| + out << "\\n"; |
| + break; |
| + case '\r': |
| + out << "\\r"; |
| + break; |
| + case '"': |
| + out << "\\\""; |
| + break; |
| + case '\\': |
| + out << "\\\\"; |
| + break; |
| + default: |
| + if (character >= 0x20 && character < 0x7F) { |
|
esprehn
2016/03/18 04:58:31
This is just isASCII ?
tkent
2016/03/18 05:19:20
I changed it to isASCIIPrintable()
|
| + out << static_cast<char>(character); |
| + } else { |
| + // Print "\uXXXX" for control or non-ASCII characters. |
| + out << "\\u"; |
| + out.width(4); |
| + out.fill('0'); |
| + out.setf(std::ios_base::hex, std::ios_base::basefield); |
| + out.setf(std::ios::uppercase); |
| + out << character; |
| + } |
| + break; |
| + } |
| + } |
| + return out << '"'; |
| +} |
| + |
| } // namespace WTF |
| #ifndef NDEBUG |