Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: third_party/WebKit/Source/wtf/text/CString.cpp

Issue 2240053002: Replace WTF_LOG() with NETWORK_DVLOG() or RESOURCE_LOADING_DVLOG(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sstream, EXPECT_STREQ Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/text/CString.cpp
diff --git a/third_party/WebKit/Source/wtf/text/CString.cpp b/third_party/WebKit/Source/wtf/text/CString.cpp
index 9d850267c6873cc9cffeeaf325197ace5522f736..56895abfd01b91d330ca093fefc8d343790346d3 100644
--- a/third_party/WebKit/Source/wtf/text/CString.cpp
+++ b/third_party/WebKit/Source/wtf/text/CString.cpp
@@ -26,6 +26,7 @@
#include "wtf/text/CString.h"
+#include "wtf/ASCIICType.h"
#include "wtf/allocator/PartitionAlloc.h"
#include "wtf/allocator/Partitions.h"
#include <string.h>
@@ -128,4 +129,47 @@ bool operator==(const CString& a, const char* b)
return !strcmp(a.data(), b);
}
+std::ostream& operator<<(std::ostream& ostream, const CString& string)
+{
+ if (string.isNull())
+ return ostream << "<null>";
+
+ ostream << '"';
+ for (size_t index = 0; index < string.length(); ++index) {
+ // Print shorthands for select cases.
+ char character = string.data()[index];
+ switch (character) {
+ case '\t':
+ ostream << "\\t";
+ break;
+ case '\n':
+ ostream << "\\n";
+ break;
+ case '\r':
+ ostream << "\\r";
+ break;
+ case '"':
+ ostream << "\\\"";
+ break;
+ case '\\':
+ ostream << "\\\\";
+ break;
+ default:
+ if (isASCIIPrintable(character)) {
+ ostream << character;
+ } else {
+ // Print "\xHH" for control or non-ASCII characters.
+ ostream << "\\x";
+ if (character >= 0 && character < 0x10)
+ ostream << "0";
+ ostream.setf(std::ios_base::hex, std::ios_base::basefield);
+ ostream.setf(std::ios::uppercase);
+ ostream << (character & 0xff);
+ }
+ break;
+ }
+ }
+ return ostream << '"';
+}
+
} // namespace WTF

Powered by Google App Engine
This is Rietveld 408576698