]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxTextOutputStream::Flush(): this is necessary with the stateful encodings...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 1 Jun 2008 03:09:25 +0000 (03:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 1 Jun 2008 03:09:25 +0000 (03:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/txtstrm.h
interface/txtstrm.h
src/common/txtstrm.cpp
tests/mbconv/mbconvtest.cpp

index a2614ab5593b03db40599c404be470d4709d647b..0c3983799c2a0a25b278d1988268af66ecda7ef4 100644 (file)
@@ -127,6 +127,8 @@ public:
 
     wxTextOutputStream& PutChar(wxChar c);
 
+    void Flush();
+
     wxTextOutputStream& operator<<(const wxString& string);
     wxTextOutputStream& operator<<(char c);
 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
index 83ab454d9b5f4a3f566ca2b45d6db9822e161dc4..89dd37741a7cb32c2e420b3661f32e597eee294f 100644 (file)
@@ -196,10 +196,10 @@ typedef enum
     @class wxTextOutputStream
     @wxheader{txtstrm.h}
 
-    This class provides functions that writes text data using an output stream,
+    This class provides functions that write text data using an output stream,
     allowing you to write text, floats, and integers.
 
-    You can also simulate the C++ cout class:
+    You can also simulate the C++ @c std::cout class:
 
     @code
     wxFFileOutputStream output( stderr );
@@ -239,9 +239,22 @@ public:
 
     /**
         Destroys the wxTextOutputStream object.
+
+        Also calls Flush().
     */
     ~wxTextOutputStream();
 
+    /**
+        Flushes the stream.
+
+        This method should be called when using stateful encodings (currently
+        the only example of such encoding in wxWidgets is wxMBConvUTF7) to
+        write the end of the encoded data to the stream.
+
+        @since 2.9.0
+     */
+    void Flush();
+
     /**
         Returns the end-of-line mode. One of ::wxEOL_DOS, ::wxEOL_MAC and
         ::wxEOL_UNIX.
index e516fb413034221ee8f7fcb8dd5cc965f2688e39..f7d6c09efd66d542d993168acdf42736f69146e0 100644 (file)
@@ -426,6 +426,19 @@ wxTextOutputStream& wxTextOutputStream::PutChar(wxChar c)
     return *this;
 }
 
+void wxTextOutputStream::Flush()
+{
+#if wxUSE_UNICODE
+    const size_t len = m_conv->FromWChar(NULL, 0, L"", 1);
+    if ( len > m_conv->GetMBNulLen() )
+    {
+        wxCharBuffer buf(len);
+        m_conv->FromWChar(buf.data(), len, L"", 1);
+        m_output.Write(buf, len - m_conv->GetMBNulLen());
+    }
+#endif // wxUSE_UNICODE
+}
+
 wxTextOutputStream& wxTextOutputStream::operator<<(const wxString& string)
 {
     WriteString( string );
index d25230d2e343eb22d4cd1e02534b96470d02afa6..a0674519899f3de807d8604d9f0de6ffed14b071 100644 (file)
@@ -1050,6 +1050,9 @@ void MBConvTestCase::TestStreamEncoder(
     {
         textOutputStream.PutChar( wideBuffer[i] );
     }
+
+    textOutputStream.Flush();
+
     CPPUNIT_ASSERT_EQUAL( (wxFileOffset)multiBytes, memoryOutputStream.TellO() );
     wxCharBuffer copy( memoryOutputStream.TellO() );
     memoryOutputStream.CopyTo( copy.data(), memoryOutputStream.TellO());