Fix wxStringOutputStream in wxUSE_UNICODE_UTF8 build.

For some reason the conversion of the bytes written to this stream to Unicode
was only done in wxUSE_UNICODE_WCHAR build but not in wxUSE_UNICODE_UTF8 one.
Do it in any wxUSE_UNICODE build now.

This allows to use wxStringOutputStream under Unix again, in particular it
fixes an assert in samples/html/zip when trying to load the raw contents of a
ZIP file in wxHtmlWindow.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67968 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2011-06-16 16:22:15 +00:00
parent 31eb730728
commit ff8a5f3d77
2 changed files with 8 additions and 9 deletions

View File

@ -66,9 +66,9 @@ public:
wxStringOutputStream(wxString *pString = NULL,
wxMBConv& conv = wxConvUTF8)
: m_conv(conv)
#if wxUSE_UNICODE_WCHAR
#if wxUSE_UNICODE
, m_unconv(0)
#endif // wxUSE_UNICODE_WCHAR
#endif // wxUSE_UNICODE
{
m_str = pString ? pString : &m_strInternal;
m_pos = m_str->length() / sizeof(wxChar);
@ -98,10 +98,10 @@ private:
// arbitrary 8 bit data
wxMBConv& m_conv;
#if wxUSE_UNICODE_WCHAR
#if wxUSE_UNICODE
// unconverted data from the last call to OnSysWrite()
wxMemoryBuffer m_unconv;
#endif // wxUSE_UNICODE_WCHAR
#endif // wxUSE_UNICODE
wxDECLARE_NO_COPY_CLASS(wxStringOutputStream);
};

View File

@ -146,7 +146,7 @@ size_t wxStringOutputStream::OnSysWrite(const void *buffer, size_t size)
{
const char *p = static_cast<const char *>(buffer);
#if wxUSE_UNICODE_WCHAR
#if wxUSE_UNICODE
// the part of the string we have here may be incomplete, i.e. it can stop
// in the middle of an UTF-8 character and so converting it would fail; if
// this is the case, accumulate the part which we failed to convert until
@ -188,11 +188,10 @@ size_t wxStringOutputStream::OnSysWrite(const void *buffer, size_t size)
// not update m_pos as m_str hasn't changed
return size;
}
#else // !wxUSE_UNICODE_WCHAR
// no recoding necessary, the data is supposed to already be in UTF-8 (if
// supported) or ASCII otherwise
#else // !wxUSE_UNICODE
// no recoding necessary
m_str->append(p, size);
#endif // wxUSE_UNICODE_WCHAR/!wxUSE_UNICODE_WCHAR
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
// update position
m_pos += size;