Converts the buffer in a stringstream to a String, converting NUL bytes to "\\0" along the way.
| 3036 | // Converts the buffer in a stringstream to a String, converting NUL |
| 3037 | // bytes to "\\0" along the way. |
| 3038 | String StringStreamToString(::std::stringstream* ss) { |
| 3039 | const ::std::string& str = ss->str(); |
| 3040 | const char* const start = str.c_str(); |
| 3041 | const char* const end = start + str.length(); |
| 3042 | |
| 3043 | // We need to use a helper stringstream to do this transformation |
| 3044 | // because String doesn't support push_back(). |
| 3045 | ::std::stringstream helper; |
| 3046 | for (const char* ch = start; ch != end; ++ch) { |
| 3047 | if (*ch == '\0') { |
| 3048 | helper << "\\0"; // Replaces NUL with "\\0"; |
| 3049 | } else { |
| 3050 | helper.put(*ch); |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | return String(helper.str().c_str()); |
| 3055 | } |
| 3056 | |
| 3057 | // Appends the user-supplied message to the Google-Test-generated message. |
| 3058 | String AppendUserMessage(const String& gtest_msg, |
no test coverage detected