MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / UniversalPrintCharArray

Function UniversalPrintCharArray

source/test/gtest/gtest-printers.cc:366–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364// 'begin'. CharType must be either char or wchar_t.
365template <typename CharType>
366GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
367 GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
368 GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ static void
369 UniversalPrintCharArray(const CharType* begin, size_t len,
370 ostream* os) {
371 // The code
372 // const char kFoo[] = "foo";
373 // generates an array of 4, not 3, elements, with the last one being '\0'.
374 //
375 // Therefore when printing a char array, we don't print the last element if
376 // it's '\0', such that the output matches the string literal as it's
377 // written in the source code.
378 if (len > 0 && begin[len - 1] == '\0') {
379 PrintCharsAsStringTo(begin, len - 1, os);
380 return;
381 }
382
383 // If, however, the last element in the array is not '\0', e.g.
384 // const char kFoo[] = { 'f', 'o', 'o' };
385 // we must print the entire array. We also print a message to indicate
386 // that the array is not NUL-terminated.
387 PrintCharsAsStringTo(begin, len, os);
388 *os << " (no terminating NUL)";
389}
390
391// Prints a (const) char array of 'len' elements, starting at address 'begin'.
392void UniversalPrintArray(const char* begin, size_t len, ostream* os) {

Callers 1

UniversalPrintArrayFunction · 0.70

Calls 1

PrintCharsAsStringToFunction · 0.70

Tested by

no test coverage detected