45 #include "gtest/gtest-printers.h" 51 #include "gtest/internal/gtest-port.h" 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;
93 if (count < kThreshold) {
94 PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
96 PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
99 const size_t resume_pos = (count - kChunkSize + 1)/2*2;
100 PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
107 namespace internal2 {
116 PrintBytesInObjectToImpl(obj_bytes, count, os);
138 return 0x20 <= c && c <= 0x7E;
145 template <
typename Un
signedChar,
typename Char>
147 switch (static_cast<wchar_t>(c)) {
180 *os << static_cast<char>(
c);
183 *os <<
"\\x" + String::FormatHexInt(static_cast<UnsignedChar>(c));
201 return PrintAsCharLiteralTo<wchar_t>(
c, os);
209 static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
216 template <
typename Un
signedChar,
typename Char>
219 *os << ((sizeof(c) > 1) ?
"L'" :
"'");
228 *os <<
" (" <<
static_cast<int>(
c);
233 if (format ==
kHexEscape || (1 <= c && c <= 9)) {
236 *os <<
", 0x" << String::FormatHexInt(static_cast<UnsignedChar>(c));
241 void PrintTo(
unsigned char c, ::std::ostream* os) {
242 PrintCharAndCodeTo<unsigned char>(
c, os);
245 PrintCharAndCodeTo<unsigned char>(
c, os);
251 PrintCharAndCodeTo<wchar_t>(wc, os);
258 template <
typename CharType>
263 const CharType*
begin,
size_t len, ostream* os) {
264 const char*
const kQuoteBegin =
sizeof(CharType) == 1 ?
"\"" :
"L\"";
266 bool is_previous_hex =
false;
267 for (
size_t index = 0; index < len; ++index) {
268 const CharType cur = begin[index];
269 if (is_previous_hex &&
IsXDigit(cur)) {
273 *os <<
"\" " << kQuoteBegin;
282 template <
typename CharType>
287 const CharType*
begin,
size_t len, ostream* os) {
295 if (len > 0 && begin[len - 1] ==
'\0') {
305 *os <<
" (no terminating NUL)";
324 *os << ImplicitCast_<const void*>(
s) <<
" pointing to ";
335 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 341 *os << ImplicitCast_<const void*>(
s) <<
" pointing to ";
345 #endif // wchar_t is native 348 #if GTEST_HAS_GLOBAL_STRING 352 #endif // GTEST_HAS_GLOBAL_STRING 359 #if GTEST_HAS_GLOBAL_WSTRING 363 #endif // GTEST_HAS_GLOBAL_WSTRING 365 #if GTEST_HAS_STD_WSTRING 369 #endif // GTEST_HAS_STD_WSTRING
void PrintCharAndCodeTo(Char c, ostream *os)
static CharFormat PrintAsStringLiteralTo(char c, ostream *os)
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ static GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ void UniversalPrintCharArray(const CharType *begin, size_t len, ostream *os)
auto begin(TestAdlIterable &instance)
void PrintStringTo(const ::std::string &s, ostream *os)
static CharFormat PrintAsCharLiteralTo(Char c, ostream *os)
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ static GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ void PrintCharsAsStringTo(const CharType *begin, size_t len, ostream *os)
void PrintTo(const wchar_t *s, ostream *os)
GTEST_API_ void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count,::std::ostream *os)
bool IsPrintableAscii(wchar_t c)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
void UniversalPrintArray(const wchar_t *begin, size_t len, ostream *os)
#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_