Converts the buffer in a stringstream to a String, converting NUL bytes to "\\0" along the way.
| 1733 | // Converts the buffer in a stringstream to a String, converting NUL |
| 1734 | // bytes to "\\0" along the way. |
| 1735 | String StringStreamToString(::std::stringstream* ss) { |
| 1736 | const ::std::string& str = ss->str(); |
| 1737 | const char* const start = str.c_str(); |
| 1738 | const char* const end = start + str.length(); |
| 1739 | |
| 1740 | // We need to use a helper stringstream to do this transformation |
| 1741 | // because String doesn't support push_back(). |
| 1742 | ::std::stringstream helper; |
| 1743 | for (const char* ch = start; ch != end; ++ch) { |
| 1744 | if (*ch == '\0') { |
| 1745 | helper << "\\0"; // Replaces NUL with "\\0"; |
| 1746 | } else { |
| 1747 | helper.put(*ch); |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | return String(helper.str().c_str()); |
| 1752 | } |
| 1753 | |
| 1754 | // Appends the user-supplied message to the Google-Test-generated message. |
| 1755 | String AppendUserMessage(const String& gtest_msg, |
no test coverage detected