Converts the buffer in a stringstream to an std::string, converting NUL bytes to "\\0" along the way.
| 1977 | // Converts the buffer in a stringstream to an std::string, converting NUL |
| 1978 | // bytes to "\\0" along the way. |
| 1979 | std::string StringStreamToString(::std::stringstream* ss) { |
| 1980 | const ::std::string& str = ss->str(); |
| 1981 | const char* const start = str.c_str(); |
| 1982 | const char* const end = start + str.length(); |
| 1983 | |
| 1984 | std::string result; |
| 1985 | result.reserve(2 * (end - start)); |
| 1986 | for (const char* ch = start; ch != end; ++ch) { |
| 1987 | if (*ch == '\0') { |
| 1988 | result += "\\0"; // Replaces NUL with "\\0"; |
| 1989 | } else { |
| 1990 | result += *ch; |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | return result; |
| 1995 | } |
| 1996 | |
| 1997 | // Appends the user-supplied message to the Google-Test-generated message. |
| 1998 | std::string AppendUserMessage(const std::string& gtest_msg, |
no test coverage detected