45 #include "gtest/gtest-printers.h" 50 #include "gtest/internal/gtest-port.h" 59 void PrintByteSegmentInObjectTo(
const unsigned char* obj_bytes,
size_t start,
60 size_t count, ostream* os) {
62 for (
size_t i = 0; i !=
count; i++) {
63 const size_t j = start + i;
78 void PrintBytesInObjectToImpl(
const unsigned char* obj_bytes,
size_t count,
81 *os << count <<
"-byte object <";
83 const size_t kThreshold = 132;
84 const size_t kChunkSize = 64;
89 if (count < kThreshold) {
90 PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
92 PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
95 const size_t resume_pos = (count - kChunkSize + 1)/2*2;
96 PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
103 namespace internal2 {
112 PrintBytesInObjectToImpl(obj_bytes, count, os);
134 return 0x20 <= c && c <= 0x7E;
141 template <
typename Un
signedChar,
typename Char>
143 switch (static_cast<wchar_t>(c)) {
176 *os << static_cast<char>(
c);
179 *os <<
"\\x" + String::FormatHexInt(static_cast<UnsignedChar>(c));
197 return PrintAsCharLiteralTo<wchar_t>(
c, os);
205 static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
212 template <
typename Un
signedChar,
typename Char>
215 *os << ((sizeof(c) > 1) ?
"L'" :
"'");
224 *os <<
" (" <<
static_cast<int>(
c);
229 if (format ==
kHexEscape || (1 <= c && c <= 9)) {
232 *os <<
", 0x" << String::FormatHexInt(static_cast<UnsignedChar>(c));
237 void PrintTo(
unsigned char c, ::std::ostream* os) {
238 PrintCharAndCodeTo<unsigned char>(
c, os);
240 void PrintTo(
signed char c, ::std::ostream* os) {
241 PrintCharAndCodeTo<unsigned char>(
c, os);
246 void PrintTo(
wchar_t wc, ostream* os) {
247 PrintCharAndCodeTo<wchar_t>(wc, os);
254 template <
typename CharType>
256 const CharType* begin,
size_t len, ostream* os) {
257 const char*
const kQuoteBegin =
sizeof(CharType) == 1 ?
"\"" :
"L\"";
259 bool is_previous_hex =
false;
260 for (
size_t index = 0; index < len; ++index) {
261 const CharType cur = begin[index];
262 if (is_previous_hex &&
IsXDigit(cur)) {
266 *os <<
"\" " << kQuoteBegin;
275 template <
typename CharType>
277 const CharType* begin,
size_t len, ostream* os) {
285 if (len > 0 && begin[len - 1] ==
'\0') {
295 *os <<
" (no terminating NUL)";
310 void PrintTo(
const char*
s, ostream* os) {
314 *os << ImplicitCast_<const void*>(s) <<
" pointing to ";
325 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 327 void PrintTo(
const wchar_t* s, ostream* os) {
331 *os << ImplicitCast_<const void*>(s) <<
" pointing to ";
335 #endif // wchar_t is native 338 #if GTEST_HAS_GLOBAL_STRING 342 #endif // GTEST_HAS_GLOBAL_STRING 349 #if GTEST_HAS_GLOBAL_WSTRING 353 #endif // GTEST_HAS_GLOBAL_WSTRING 355 #if GTEST_HAS_STD_WSTRING 359 #endif // GTEST_HAS_STD_WSTRING
void PrintCharAndCodeTo(Char c, ostream *os)
static CharFormat PrintAsStringLiteralTo(char c, ostream *os)
std::string format(CStringRef format_str, ArgList args)
void PrintStringTo(const ::std::string &s, ostream *os)
static CharFormat PrintAsCharLiteralTo(Char c, ostream *os)
void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count, ostream *os)
bool IsPrintableAscii(wchar_t c)
void UniversalPrintArray(const char *begin, size_t len, ostream *os)
void PrintWideStringTo(const ::std::wstring &s, ostream *os)
static void PrintCharsAsStringTo(const CharType *begin, size_t len, ostream *os)
void PrintTo(const ReferenceWrapper< T > &ref,::std::ostream *os)
static void UniversalPrintCharArray(const CharType *begin, size_t len, ostream *os)