63 void PrintByteSegmentInObjectTo(
const unsigned char* obj_bytes,
size_t start,
64 size_t count, ostream* os) {
66 for (
size_t i = 0;
i !=
count;
i++) {
67 const size_t j =
start +
i;
82 void PrintBytesInObjectToImpl(
const unsigned char* obj_bytes,
size_t count,
85 *os <<
count <<
"-byte object <";
87 const size_t kThreshold = 132;
88 const size_t kChunkSize = 64;
92 if (
count < kThreshold) {
93 PrintByteSegmentInObjectTo(obj_bytes, 0,
count, os);
95 PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
98 const size_t resume_pos = (
count - kChunkSize + 1)/2*2;
99 PrintByteSegmentInObjectTo(obj_bytes, resume_pos,
count - resume_pos, os);
106 namespace internal2 {
115 PrintBytesInObjectToImpl(obj_bytes,
count, os);
137 return 0x20 <= c && c <= 0x7E;
144 template <
typename Un
signedChar,
typename Char>
146 switch (
static_cast<wchar_t>(c)) {
179 *os << static_cast<char>(c);
182 ostream::fmtflags
flags = os->flags();
183 *os <<
"\\x" << std::hex << std::uppercase
184 <<
static_cast<int>(
static_cast<UnsignedChar
>(c));
203 return PrintAsCharLiteralTo<wchar_t>(c, os);
211 static_cast<wchar_t>(
static_cast<unsigned char>(c)), os);
218 template <
typename Un
signedChar,
typename Char>
221 *os << ((
sizeof(c) > 1) ?
"L'" :
"'");
230 *os <<
" (" <<
static_cast<int>(c);
243 void PrintTo(
unsigned char c, ::std::ostream* os) {
244 PrintCharAndCodeTo<unsigned char>(c, os);
246 void PrintTo(
signed char c, ::std::ostream* os) {
247 PrintCharAndCodeTo<unsigned char>(c, os);
253 PrintCharAndCodeTo<wchar_t>(wc, os);
260 template <
typename CharType>
265 const CharType*
begin,
size_t len, ostream* os) {
266 const char*
const kQuoteBegin =
sizeof(CharType) == 1 ?
"\"" :
"L\"";
268 bool is_previous_hex =
false;
272 if (is_previous_hex &&
IsXDigit(cur)) {
276 *os <<
"\" " << kQuoteBegin;
280 if (is_previous_hex) {
290 template <
typename CharType>
295 const CharType*
begin,
size_t len, ostream* os) {
313 *os <<
" (no terminating NUL)";
332 *os << ImplicitCast_<const void*>(
s) <<
" pointing to ";
343 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
349 *os << ImplicitCast_<const void*>(
s) <<
" pointing to ";
353 #endif // wchar_t is native
357 bool ContainsUnprintableControlCodes(
const char*
str,
size_t length) {
358 const unsigned char *
s =
reinterpret_cast<const unsigned char *
>(
str);
361 unsigned char ch = *
s++;
362 if (std::iscntrl(
ch)) {
376 bool IsUTF8TrailByte(
unsigned char t) {
return 0x80 <= t && t<= 0xbf; }
379 const unsigned char *
s =
reinterpret_cast<const unsigned char *
>(
str);
382 unsigned char lead =
s[
i++];
389 }
else if (lead <= 0xdf && (
i + 1) <=
length && IsUTF8TrailByte(s[
i])) {
391 }
else if (0xe0 <= lead && lead <= 0xef && (
i + 2) <=
length &&
392 IsUTF8TrailByte(s[
i]) &&
393 IsUTF8TrailByte(s[
i + 1]) &&
395 (lead != 0xe0 ||
s[
i] >= 0xa0) &&
396 (lead != 0xed || s[
i] < 0xa0)) {
398 }
else if (0xf0 <= lead && lead <= 0xf4 && (
i + 3) <=
length &&
399 IsUTF8TrailByte(s[
i]) &&
400 IsUTF8TrailByte(s[
i + 1]) &&
401 IsUTF8TrailByte(s[
i + 2]) &&
403 (lead != 0xf0 ||
s[
i] >= 0x90) &&
404 (lead != 0xf4 || s[
i] < 0x90)) {
413 void ConditionalPrintAsText(
const char*
str,
size_t length, ostream* os) {
414 if (!ContainsUnprintableControlCodes(
str,
length) &&
416 *os <<
"\n As Text: \"" <<
str <<
"\"";
423 #if GTEST_HAS_GLOBAL_STRING
427 ConditionalPrintAsText(
s.data(),
s.size(), os);
431 #endif // GTEST_HAS_GLOBAL_STRING
436 ConditionalPrintAsText(
s.data(),
s.size(), os);
442 #if GTEST_HAS_GLOBAL_WSTRING
446 #endif // GTEST_HAS_GLOBAL_WSTRING
448 #if GTEST_HAS_STD_WSTRING
452 #endif // GTEST_HAS_STD_WSTRING