Chromium Code Reviews| 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..6939af4671f59ea7f37598491fa92b1b073a2db5 |
| --- /dev/null |
| +++ b/testing/fx_string_testhelpers.cpp |
| @@ -0,0 +1,54 @@ |
| +// 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') << '"'; |
|
brucedawson
2015/01/07 00:35:24
I assume that the goal is just to produce a reason
Tom Sepez
2015/01/07 00:42:24
Exactly. There's no inverse operation provided.
|
| + 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); |
| + continue; |
| + } |
| + if (sizeof(typename T::value_type) == 1) { |
| + if (c < 0x100) { |
|
brucedawson
2015/01/07 00:35:24
Are there any plausible platforms where this check
Tom Sepez
2015/01/07 00:42:24
Done.
|
| + out << "\\x" << std::setw(2) << c << std::setw(0); |
| + continue; |
| + } |
| + } else { |
| + if (c < 0x10000) { |
| + out << "\\u" << std::setw(4) << c << std::setw(0); |
| + continue; |
| + } |
| + } |
| + out << "<invalid>"; |
| + } |
| + out << '"' << std::dec << std::setfill(' '); |
| + return out; |
| +} |
| + |
| +} // namespace |
| + |
| +std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str) { |
| + return output_string<CFX_ByteStringC>(out, str); |
|
brucedawson
2015/01/07 00:35:24
The explicit template parameter in this call and i
Tom Sepez
2015/01/07 00:42:24
Done.
|
| +} |
| + |
| +std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str) { |
| + return output_string<CFX_ByteString>(out, str); |
| +} |
| + |
| +std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str) { |
| + return output_string<CFX_WideStringC>(out, str); |
| +} |
| + |
| +std::ostream& operator<<(std::ostream& out, const CFX_WideString& str) { |
| + return output_string<CFX_WideString>(out, str); |
| +} |