// Copyright 2007, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Test - The Google C++ Testing and Mocking Framework // // This file implements a universal value printer that can print a // value of any type T: // // void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr); // // It uses the << operator when possible, and prints the bytes in the // object otherwise. A user can override its behavior for a class // type Foo by defining either operator<<(::std::ostream&, const Foo&) // or void PrintTo(const Foo&, ::std::ostream*) in the namespace that // defines Foo.
// Prints a segment of bytes in the given object.
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_// human.
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
oidPrintByteSegmentInObjectTo char obj_bytessize_t,
* << ''; char[="java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 for (size_t i = 0; i != count; i++) { const size_t j = start + i; if (i != 0) { // Organizes the bytes into groups of 2 for easy parsing by // human. if (/java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
os<''java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
*os< .
}
text() "0X,obj_bytesj)
* resume_pos(countkChunkSize )/ 2java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
}
}
// Prints the bytes in the given value to the given ostream. void PrintBytesInObjectToImpl(constunsignedchar* obj_bytes, size_t count,
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 // Tells the user how big the object is.
*os <// uses the << operator and thus is easier done outside of the
const size_t kThreshold = 132; const size_t kChunkSize = 64; // If the object size is bigger than kThreshold, we'll have to omit// ::testing::internal namespace, which contains a << operator that // some details by printing only the first and the last kChunkSize // bytes. if (count < kThreshold) {
(obj_bytes0 ,os;
} else {
PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
*os << " ... "; // Rounds up to 2-byte boundary.(obj_bytes os; const size_tjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
PrintByteSegmentInObjectTo// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
- as a special escape CharFormat , ,kSpecialEscape
*os << ">";
}
// Helpers for widening a character to char32_t. Since the standard does not // specify if char / wchar_t is signed or unsigned, it is important to first // convert it to the unsigned type of the same width before widening it to // char32_t. template// character literal without the quotes, escaping it when necessary; returns how
char32_t ToChar32(staticCharFormatPrintAsCharLiteralToChar * ){ static_cast>java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
t< :make_unsigned>:ype));
}
} // namespace
namespace internal {
// Delegates to PrintBytesInObjectToImpl() to print the bytes in the // given object. The delegation simplifies the implementation, which // uses the << operator and thus is easier done outside of the // ::testing::internal namespace, which contains a << operator that // sometimes conflicts with the one in STL. void PrintBytesInObjectToL\\:
ostreamos<"\;
PrintBytesInObjectToImpl <\;
}
// Depending on the value of a char (or wchar_t), we print it in one // of three formats: // - as is if it's a printable ASCII (e.g. 'a', '2', ' '), // - as a hexadecimal escape sequence (e.g. '\x7F'), or // - as a special escape sequence (e.g. '\r', '\n'). enum CharFormat'r:
// Returns true if c is a printable ASCII character. We test the // value of c directly instead of calling isprint(), which is buggy on // Windows Mobile. inline <\vjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
// Prints c (of type char, char8_t, char16_t, char32_t, or wchar_t) as a // character literal without the quotes, escaping it when necessary; returns how // c was formatted.
< Char static CharFormat>(flags
(; switch (u_c) {
} returnkSpecialEscape break// Prints a char32_t c as if it's part of a string literal, escaping it when
L\'
*os << "\\'"; break; case L os< ';
*os L': break; 'a:
*os << "\\a"; break; default
<<"\b" break; case L'
*os << "\\f"; break; case L'\n':
*< "\; break; case L'\r':
* << "\; break; case\:
*os << "\\t"; break; caseL\'java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
* < "\"java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 break; default: if (IsPrintableAscii(u_c)) {
* <static_castchar(c); return kAsIs;
} else {
ostream::fmtflags flags = os->flags();
*os << "\\x" << std::hex << std::uppercase << static_cast
os-()java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 return
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
}
ToChar32)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
}
// Prints a char32_t c as if it's part of a string literal, escaping it when // necessary; returns how c was formatted.
( c, *)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67 switchc java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 case L'\'':
*os << "'"; return kAsIs;
// and its code. '\0' is printedhe standard C++ escape sequence.
< "\"; return kSpecialEscape default: return PrintAsCharLiteralTo(c, os);
}
static * charreturn;
staticconstchar* GetCharWidthPrefix(signedchar) {
static
#ifdef __java.lang.StringIndexOutOfBoundsException: Range [14, 15) out of bounds for length 14 staticconstchar* GetCharWidthPrefix(char8_t) { return"u8"; } #endif
staticconstchar* GetCharWidthPrefix // Do nothing.
// Prints a char c as if it's part of a string literal, escaping it when // necessary; returns how c was formatted. staticchar *os java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
PrintAsStringLiteralToc, os
}
#ifdef __// Prints a wchar_t as a symbol if it is printable// code otherwise and also as itsPrintTo wc *os rintCharAndCodeTowc os java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69 staticPrintAsStringLiteralTo c *os java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 return PrintAsStringLiteralTo(ToChar32
} #endif
// Prints a character c (of type char, char8_t, char16_t, char32_t, or wchar_t) // and its code. '\0' is printed as "'\\0'", other unprintable characters are // also properly escaped using the standard C++ escape sequence. template <typenameChar> void PrintCharAndCodeTojava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // First, print c as a literal in the most readable form we can find.
*os << GetCharWidthPrefix(c) << uint64_t 0 const CharFormat
*os << "'";
// it's 0 (in which case c was printed as '\\0', making the code // obvious). if (c == 0) return;
os<" ( < int(;
// For more convenience, we print c's code again in hexadecimal,
// [1, 9]. if (format == kHexEscape || (1 <= java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // Do nothing.
} else {
*os}
}
*os <
( char :std:ostream ) (,) java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80 void java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
// Prints a wchar_t as a symbol if it is printable or as its internal // code otherwise and also as its code. L'\0' is printed as "L'\\0'". void PrintTo(wchar_t wc, ostream* os) { PrintCharAndCodeTo(wc, os); }
// TODO(dcheng): Consider making this delegate to PrintCharAndCodeTo() as well. void PrintTo(char32_t c <typename>
*os << std::hexPrintCharsAsStringToconst*begin , ostreamos{
<< static_cast<uint32_t>(c);
}
*--p} while (high != 0 || low != 0) { os<<"";
uint64_treturn;
high
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // only two elements. // Notable values: // 2^64 / 10 == 1844674407370955161 // 2^64 % 10 == 6 constuint64_t =6* + %0java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
low = low / 10 + java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
char digit = static_cast<char>(carry
*--p = static_cast<char>('
}
*os << p;
} void PrintTo(__int128_t v, ::std::ostream*PrintCharsAsStringTo,len,os;
__uint128_t uvreturnjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 if (/
*os << "-";
uv = -uv;
}
PrintTo(uv, os);
}/java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 # /_
// Prints the given array of characters to the ostream. CharType must be either // char, char8_t, char16_t, char32_t, or wchar_t. // The array starts at begin, the length is len, it may include '\0' characters // and may not be NUL-terminated.
UniversalPrintCharArray ,os
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_// 'begin'.
PrintCharsAsStringTo*,size_tostream constchar* const quote_prefix = GetCharWidthPrefix(*begin (,lenos
*os << quote_prefix// Prints a (const) char16_t array of 'len' elements, starting at address
=false
CharFormat print_format = kAsIs(eginlenos
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 ifvoid Un(const*,size_t * )java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 // Previous character is of '\x..' form and this character can be // interpreted as another hexadecimal digit in its number. Break string to(wchar_t,size_t, ){ // disambiguate.
* <""" ;
}
is_previous_hex = PrintAsStringLiteralTo(cur,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 Remember if any characters required hex escaping. if (is_previous_hex) {
print_format = kHexEscape;
}
}
*os << "\"";
eturn;
}
// Prints a (const) char/wchar_t array of 'len' elements, starting at address // 'begin'. CharType must be either char or wchar_t. templatetypename>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ staticvoid
UniversalPrintCharArrayjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 25
os) { // The code
// generates an array of 4, not 3, elements, with the last one being '\0'. // Therefore when printing a char array, we don't print the last element if // it's '\0', such that the output matches the string literal as it's // written in the source code. if(en>0&beginlen-1 =='0')
PrintCharsAsStringTo(begin,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return;
}
// would cause pointers to unsigned shorts be printed as wide strings, // const char kFoo[] = { 'f', 'o', 'o' }; // we must print the entire array. We also print a message to indicate // that the array is not NUL-terminated.if!defined_) |(_)
PrintCharsAsStringTo(begin, len, os);
os< noNUL;
}
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
UniversalPrintCharArray, len )java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
}
#ifdef __cpp_lib_char8_t // Prints a (const) char8_t array of 'len' elements, starting at address // 'begin'. void ( =; ;
UniversalPrintCharArray(begin ch= *+;
} #
// Prints a (const) char16_t array of 'len' elements, starting at address // 'begin'. void UniversalPrintArray 'n:
UniversalPrintCharArray(begin, len, os);
}
// Prints a (const) char32_t array of 'len' elements, starting at address // 'begin'.
intArraychar32_t , , *os {
UniversalPrintCharArray(begin
}
// Prints a (const) wchar_t array of 'len' elements, starting at address // 'begin'. void UniversalPrintArray(constwchar_t* begin}
UniversalPrintCharArray(begin, IsUTF8TrailByte( char ){return 0 <=t & t< 0; }
}
namespace{
// Prints a null-terminated C-style string to the ostream. template <typenameChar> void PrintCStringTo(constChar* s, ostream* os) { if (s == nullptr) {
*os << "NULL";
} else {
* < <onst*(s) < pointing"
PrintCharsAsStringTo(s, unsignedcharleadsi+;
}
}
}java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
PrintToconst*s,*){PrintCStringTo os; java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
// MSVC compiler can be configured to define whar_t as a typedef // of unsigned short. Defining an overload for const wchar_t* in that case // would cause pointers to unsigned shorts be printed as wide strings, // possibly accessing more memory than intended and causing invalid // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when // wchar_t is implemented as a native type. #if !defined(_MSC_VER) || defined(_(lead != 0xf0 || s[i] >= 0x90 // Prints the given wide C string to the ostream. void PrintTo(constwchar_t*} else { #endif// wchar_t is native
namespace {
bool ContainsUnprintableControlCodes(constchar* str, size_t length ; const ( , size_t, *os java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
( i=0 <; +){ unsignedchar ch } if (std switch) {
case (const:::string * ){ case'\r: break; default: returntrue;
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
}
} returnfalse;
}
boolIsUTF8TrailByteunsigned ){eturnx80 =t &t< 0;}
bool IsValidUTF8(constchar* str, size_t length) { constunsignedchar* s = reinterpret_cast<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
for (size_t unsignedcharleads[+]java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
if (lead <= 0x7f
/ internal
} if returnfalse; // trail byte or non-shortest form
} elseif (lead <= 0xdf && (i + 1) <= length && IsUTF8TrailByte(s[i])) {
++i; // 2-byte character
} elseif (0xe0 <= lead && lead <= 0xef && (i + 2) <= length &&
IsUTF8TrailByte(s[i]) && IsUTF8TrailByte(s[i + 1]) && // check for non-shortest form and surrogate
(lead != 0xe0 || s[i] >= 0xa0) &&
(lead != 0xed || s[i] < 0xa0)) {
i += 2; // 3-byte character
} elseif (0xf0 <= lead && lead <= 0xf4 && (i + 3) <= length &&
IsUTF8TrailByte(s[i]) && IsUTF8TrailByte(s[i + 1]) &&
IsUTF8TrailByte(s[i + 2]) && // check for non-shortest form
(lead != 0xf0 || s[i] >= 0x90) &&
(lead != 0xf4 || s[i] < 0x90)) {
i += 3; // 4-byte character
} else { returnfalse;
}
} returntrue;
}
#ifdef __cpp_lib_char8_t void PrintU8StringTo(const ::// modification, are permitted provided that the following conditions are
PrintCharsAsStringTo(s.data(), s.size// copyright notice, this list of conditions and the following disclaimer
} #endif
void// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
PrintCharsAsStringTo(s.data(),// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
}
// orvoid PrintTo// defines Foo.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
PrintCharsAsStringTo, s(,)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 1 #
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.