Change basic_string_stream to not clear the buffer on flush

If the buffer is cleared when flushed, the class does not function
correctly as a string builder. For example, if a string is built with a
newline inside, everything before the newline will be cleared and the
string will be incomplete. Clearing the buffer on flush only makes sense
for applications such as logging or writting to a file.
This commit is contained in:
Myles Busig 2024-04-10 08:46:21 -06:00
parent dff9316987
commit 4c14f1e9e2

View File

@ -49,14 +49,11 @@ public:
* \brief Flushes the buffer to the underlying output sequence and
* clears the buffer
*
* By default simply clears the buffer, but can be overriden to
* provide more functionality. This function is called internally when
* mtl::flush and mtl::endl are piped to the stream. The derived
* class must be sure to clear the buffer when finished.
* By default is a NOP, but can be overriden to provide more
* functionality. This function is called internally when
* mtl::flush and mtl::endl are piped to the stream.
*/
virtual void flush() {
m_str.clear();
}
virtual void flush() { }
void clear() {
m_str.clear();