MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / PrintColorEncoded

Function PrintColorEncoded

tests/gtest/src/gtest.cc:6373–6405  ·  view source on GitHub ↗

Prints a string containing code-encoded text. The following escape sequences can be used in the string to control the text color: @@ prints a single '@' character. @R changes the color to red. @G changes the color to green. @Y changes the color to yellow. @D changes to the default terminal text color.

Source from the content-addressed store, hash-verified

6371// @D changes to the default terminal text color.
6372//
6373static void PrintColorEncoded(const char* str) {
6374 GTestColor color = GTestColor::kDefault; // The current color.
6375
6376 // Conceptually, we split the string into segments divided by escape
6377 // sequences. Then we print one segment at a time. At the end of
6378 // each iteration, the str pointer advances to the beginning of the
6379 // next segment.
6380 for (;;) {
6381 const char* p = strchr(str, '@');
6382 if (p == nullptr) {
6383 ColoredPrintf(color, "%s", str);
6384 return;
6385 }
6386
6387 ColoredPrintf(color, "%s", std::string(str, p).c_str());
6388
6389 const char ch = p[1];
6390 str = p + 2;
6391 if (ch == '@') {
6392 ColoredPrintf(color, "@");
6393 } else if (ch == 'D') {
6394 color = GTestColor::kDefault;
6395 } else if (ch == 'R') {
6396 color = GTestColor::kRed;
6397 } else if (ch == 'G') {
6398 color = GTestColor::kGreen;
6399 } else if (ch == 'Y') {
6400 color = GTestColor::kYellow;
6401 } else {
6402 --str;
6403 }
6404 }
6405}
6406
6407static const char kColorEncodedHelpMessage[] =
6408 "This program contains tests written using " GTEST_NAME_

Callers 1

Calls 3

ColoredPrintfFunction · 0.70
stringClass · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected