Converts the buffer in a stringstream to an std::string, converting NUL bytes to "\\0" along the way.
| 2196 | // Converts the buffer in a stringstream to an std::string, converting NUL |
| 2197 | // bytes to "\\0" along the way. |
| 2198 | std::string StringStreamToString(::std::stringstream* ss) { |
| 2199 | const ::std::string& str = ss->str(); |
| 2200 | const char* const start = str.c_str(); |
| 2201 | const char* const end = start + str.length(); |
| 2202 | |
| 2203 | std::string result; |
| 2204 | result.reserve(static_cast<size_t>(2 * (end - start))); |
| 2205 | for (const char* ch = start; ch != end; ++ch) { |
| 2206 | if (*ch == '\0') { |
| 2207 | result += "\\0"; // Replaces NUL with "\\0"; |
| 2208 | } else { |
| 2209 | result += *ch; |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | return result; |
| 2214 | } |
| 2215 | |
| 2216 | // Appends the user-supplied message to the Google-Test-generated message. |
| 2217 | std::string AppendUserMessage(const std::string& gtest_msg, |
no test coverage detected