MCPcopy Create free account
hub / github.com/BVLC/caffe / PrintColorEncoded

Function PrintColorEncoded

src/gtest/gtest-all.cpp:5973–6005  ·  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

5971// TODO(wan@google.com): Write tests for this once we add stdout
5972// capturing to Google Test.
5973static void PrintColorEncoded(const char* str) {
5974 GTestColor color = COLOR_DEFAULT; // The current color.
5975
5976 // Conceptually, we split the string into segments divided by escape
5977 // sequences. Then we print one segment at a time. At the end of
5978 // each iteration, the str pointer advances to the beginning of the
5979 // next segment.
5980 for (;;) {
5981 const char* p = strchr(str, '@');
5982 if (p == NULL) {
5983 ColoredPrintf(color, "%s", str);
5984 return;
5985 }
5986
5987 ColoredPrintf(color, "%s", String(str, p - str).c_str());
5988
5989 const char ch = p[1];
5990 str = p + 2;
5991 if (ch == '@') {
5992 ColoredPrintf(color, "@");
5993 } else if (ch == 'D') {
5994 color = COLOR_DEFAULT;
5995 } else if (ch == 'R') {
5996 color = COLOR_RED;
5997 } else if (ch == 'G') {
5998 color = COLOR_GREEN;
5999 } else if (ch == 'Y') {
6000 color = COLOR_YELLOW;
6001 } else {
6002 --str;
6003 }
6004 }
6005}
6006
6007static const char kColorEncodedHelpMessage[] =
6008"This program contains tests written using " GTEST_NAME_ ". You can use the\n"

Callers 1

Calls 2

ColoredPrintfFunction · 0.85
StringFunction · 0.70

Tested by

no test coverage detected