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..269f943ca06407145ee39359a9e7907a3b0577ba 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 (isASCIIPrintable(character)) { |
+ 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 |