Converts the buffer in a stringstream to an std::string, converting NUL bytes to "\\0" along the way.
| 2162 | // Converts the buffer in a stringstream to an std::string, converting NUL |
| 2163 | // bytes to "\\0" along the way. |
| 2164 | std::string StringStreamToString(::std::stringstream* ss) { |
| 2165 | const ::std::string& str = ss->str(); |
| 2166 | const char* const start = str.c_str(); |
| 2167 | const char* const end = start + str.length(); |
| 2168 | |
| 2169 | std::string result; |
| 2170 | result.reserve(static_cast<size_t>(2 * (end - start))); |
| 2171 | for (const char* ch = start; ch != end; ++ch) { |
| 2172 | if (*ch == '\0') { |
| 2173 | result += "\\0"; // Replaces NUL with "\\0"; |
| 2174 | } else { |
| 2175 | result += *ch; |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | return result; |
| 2180 | } |
| 2181 | |
| 2182 | // Appends the user-supplied message to the Google-Test-generated message. |
| 2183 | std::string AppendUserMessage(const std::string& gtest_msg, |
no test coverage detected