Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 5 #include "fx_string_testhelpers.h" | |
| 6 | |
| 7 #include <ios> | |
| 8 #include <iomanip> | |
| 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') << '"'; | |
|
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.
| |
| 15 for (size_t i = 0; i < str.GetLength(); ++i) { | |
| 16 unsigned int c = str.GetAt(i); | |
| 17 if (c >= 0x20 && c < 0x7F) { | |
| 18 out << static_cast<char>(c); | |
| 19 continue; | |
| 20 } | |
| 21 if (sizeof(typename T::value_type) == 1) { | |
| 22 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.
| |
| 23 out << "\\x" << std::setw(2) << c << std::setw(0); | |
| 24 continue; | |
| 25 } | |
| 26 } else { | |
| 27 if (c < 0x10000) { | |
| 28 out << "\\u" << std::setw(4) << c << std::setw(0); | |
| 29 continue; | |
| 30 } | |
| 31 } | |
| 32 out << "<invalid>"; | |
| 33 } | |
| 34 out << '"' << std::dec << std::setfill(' '); | |
| 35 return out; | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str) { | |
| 41 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.
| |
| 42 } | |
| 43 | |
| 44 std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str) { | |
| 45 return output_string<CFX_ByteString>(out, str); | |
| 46 } | |
| 47 | |
| 48 std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str) { | |
| 49 return output_string<CFX_WideStringC>(out, str); | |
| 50 } | |
| 51 | |
| 52 std::ostream& operator<<(std::ostream& out, const CFX_WideString& str) { | |
| 53 return output_string<CFX_WideString>(out, str); | |
| 54 } | |
| OLD | NEW |