MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / PrintColorEncoded

Function PrintColorEncoded

cpp/test/src/gtest.cc:5124–5156  ·  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

5122// TODO(wan@google.com): Write tests for this once we add stdout
5123// capturing to Google Test.
5124static void PrintColorEncoded(const char* str) {
5125 GTestColor color = COLOR_DEFAULT; // The current color.
5126
5127 // Conceptually, we split the string into segments divided by escape
5128 // sequences. Then we print one segment at a time. At the end of
5129 // each iteration, the str pointer advances to the beginning of the
5130 // next segment.
5131 for (;;) {
5132 const char* p = strchr(str, '@');
5133 if (p == NULL) {
5134 ColoredPrintf(color, "%s", str);
5135 return;
5136 }
5137
5138 ColoredPrintf(color, "%s", std::string(str, p).c_str());
5139
5140 const char ch = p[1];
5141 str = p + 2;
5142 if (ch == '@') {
5143 ColoredPrintf(color, "@");
5144 } else if (ch == 'D') {
5145 color = COLOR_DEFAULT;
5146 } else if (ch == 'R') {
5147 color = COLOR_RED;
5148 } else if (ch == 'G') {
5149 color = COLOR_GREEN;
5150 } else if (ch == 'Y') {
5151 color = COLOR_YELLOW;
5152 } else {
5153 --str;
5154 }
5155 }
5156}
5157
5158static const char kColorEncodedHelpMessage[] =
5159"This program contains tests written using " GTEST_NAME_ ". You can use the\n"

Callers 1

Calls 2

ColoredPrintfFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected