MCPcopy Create free account
hub / github.com/apache/singa / PrintColorEncoded

Function PrintColorEncoded

test/gtest/gtest-all.cc:6271–6303  ·  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. TODO(wan@google.com): Write tests for this once we add stdout capturing to Goog

Source from the content-addressed store, hash-verified

6269// TODO(wan@google.com): Write tests for this once we add stdout
6270// capturing to Google Test.
6271static void PrintColorEncoded(const char* str) {
6272 GTestColor color = COLOR_DEFAULT; // The current color.
6273
6274 // Conceptually, we split the string into segments divided by escape
6275 // sequences. Then we print one segment at a time. At the end of
6276 // each iteration, the str pointer advances to the beginning of the
6277 // next segment.
6278 for (;;) {
6279 const char* p = strchr(str, '@');
6280 if (p == NULL) {
6281 ColoredPrintf(color, "%s", str);
6282 return;
6283 }
6284
6285 ColoredPrintf(color, "%s", std::string(str, p).c_str());
6286
6287 const char ch = p[1];
6288 str = p + 2;
6289 if (ch == '@') {
6290 ColoredPrintf(color, "@");
6291 } else if (ch == 'D') {
6292 color = COLOR_DEFAULT;
6293 } else if (ch == 'R') {
6294 color = COLOR_RED;
6295 } else if (ch == 'G') {
6296 color = COLOR_GREEN;
6297 } else if (ch == 'Y') {
6298 color = COLOR_YELLOW;
6299 } else {
6300 --str;
6301 }
6302 }
6303}
6304
6305static const char kColorEncodedHelpMessage[] =
6306"This program contains tests written using " GTEST_NAME_ ". You can use the\n"

Callers 1

Calls 1

ColoredPrintfFunction · 0.85

Tested by

no test coverage detected