Tom Sepez | a5c9431 | 2015-01-07 12:28:56 -0800 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Dan Sinclair | efbc191 | 2016-02-17 16:54:43 -0500 | [diff] [blame] | 5 | #include "testing/fx_string_testhelpers.h" |
Tom Sepez | a5c9431 | 2015-01-07 12:28:56 -0800 | [diff] [blame] | 6 | |
Tom Sepez | a5c9431 | 2015-01-07 12:28:56 -0800 | [diff] [blame] | 7 | #include <iomanip> |
Dan Sinclair | 61046b9 | 2016-02-18 14:48:48 -0500 | [diff] [blame] | 8 | #include <ios> |
Tom Sepez | a5c9431 | 2015-01-07 12:28:56 -0800 | [diff] [blame] | 9 | |
| 10 | namespace { |
| 11 | |
| 12 | template <typename T> |
| 13 | std::ostream& output_string(std::ostream& out, const T& str) { |
| 14 | out << std::hex << std::setfill('0') << '"'; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 15 | // This function is used for FX strings whose length is defined as int. |
| 16 | for (int i = 0; i < str.GetLength(); ++i) { |
Tom Sepez | a5c9431 | 2015-01-07 12:28:56 -0800 | [diff] [blame] | 17 | unsigned int c = str.GetAt(i); |
| 18 | if (c >= 0x20 && c < 0x7F) { |
| 19 | out << static_cast<char>(c); |
tsepez | f7036ba | 2016-05-13 15:02:43 -0700 | [diff] [blame] | 20 | } else if (sizeof(typename T::CharType) == 1) { |
Tom Sepez | a5c9431 | 2015-01-07 12:28:56 -0800 | [diff] [blame] | 21 | out << "\\x" << std::setw(2) << c << std::setw(0); |
| 22 | } else if (c < 0x10000) { |
| 23 | out << "\\u" << std::setw(4) << c << std::setw(0); |
| 24 | } else { |
| 25 | out << "<invalid>"; |
| 26 | } |
| 27 | } |
| 28 | out << '"' << std::dec << std::setfill(' '); |
| 29 | return out; |
| 30 | } |
| 31 | |
| 32 | } // namespace |
| 33 | |
| 34 | std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str) { |
| 35 | return output_string(out, str); |
| 36 | } |
| 37 | |
| 38 | std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str) { |
| 39 | return output_string(out, str); |
| 40 | } |
| 41 | |
| 42 | std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str) { |
| 43 | return output_string(out, str); |
| 44 | } |
| 45 | |
| 46 | std::ostream& operator<<(std::ostream& out, const CFX_WideString& str) { |
| 47 | return output_string(out, str); |
| 48 | } |