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

Unified Diff: testing/fx_string_testhelpers.cpp

Issue 809313008: Merge to XFA: Add ostream helpers for FX String classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 11 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
« no previous file with comments | « testing/fx_string_testhelpers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/fx_string_testhelpers.cpp
diff --git a/testing/fx_string_testhelpers.cpp b/testing/fx_string_testhelpers.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1ee705fa4c75ef831da2ee0f273d7017fe0cb057
--- /dev/null
+++ b/testing/fx_string_testhelpers.cpp
@@ -0,0 +1,47 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fx_string_testhelpers.h"
+
+#include <ios>
+#include <iomanip>
+
+namespace {
+
+template <typename T>
+std::ostream& output_string(std::ostream& out, const T& str) {
+ out << std::hex << std::setfill('0') << '"';
+ for (size_t i = 0; i < str.GetLength(); ++i) {
+ unsigned int c = str.GetAt(i);
+ if (c >= 0x20 && c < 0x7F) {
+ out << static_cast<char>(c);
+ } else if (sizeof(typename T::value_type) == 1) {
+ out << "\\x" << std::setw(2) << c << std::setw(0);
+ } else if (c < 0x10000) {
+ out << "\\u" << std::setw(4) << c << std::setw(0);
+ } else {
+ out << "<invalid>";
+ }
+ }
+ out << '"' << std::dec << std::setfill(' ');
+ return out;
+}
+
+} // namespace
+
+std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str) {
+ return output_string(out, str);
+}
+
+std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str) {
+ return output_string(out, str);
+}
+
+std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str) {
+ return output_string(out, str);
+}
+
+std::ostream& operator<<(std::ostream& out, const CFX_WideString& str) {
+ return output_string(out, str);
+}
« no previous file with comments | « testing/fx_string_testhelpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698