From 4dd979ef543a7489d1bf9533de75850f4b09586c Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Wed, 10 Apr 2024 08:46:21 -0600 Subject: [PATCH] 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. --- include/mtl/string_stream.hpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/include/mtl/string_stream.hpp b/include/mtl/string_stream.hpp index 732d8aa..f461f5a 100644 --- a/include/mtl/string_stream.hpp +++ b/include/mtl/string_stream.hpp @@ -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();