Fix wrong wxStringOutputStream optimization for UTF-8 build

We can only use utf8_length() if the conversion used with this object
uses UTF-8 too, otherwise we still need to do the conversion to find out
how many bytes does the string content take in the given encoding.

See #17985.
This commit is contained in:
Vadim Zeitlin
2017-11-03 18:47:06 +01:00
parent 724de3e1d1
commit 84b2ba40ee

View File

@@ -136,10 +136,16 @@ wxStringOutputStream::wxStringOutputStream(wxString *pString, wxMBConv& conv)
{
m_str = pString ? pString : &m_strInternal;
#if wxUSE_UNICODE_WCHAR
m_pos = m_conv.FromWChar(NULL, 0, m_str->wc_str(), m_str->length());
#elif wxUSE_UNICODE_UTF8
#if wxUSE_UNICODE
// We can avoid doing the conversion in the common case of using UTF-8
// conversion in UTF-8 build, as it is exactly the same as the string
// length anyhow in this case.
#if wxUSE_UNICODE_UTF8
if ( conv.IsUTF8() )
m_pos = m_str->utf8_length();
else
#endif // wxUSE_UNICODE_UTF8
m_pos = m_conv.FromWChar(NULL, 0, m_str->wc_str(), m_str->length());
#else // !wxUSE_UNICODE
m_pos = m_str->length();
#endif // wxUSE_UNICODE/!wxUSE_UNICODE