Make wxTextStream classes work with surrogates under MSW
On the platforms using UTF-16 for wchar_t we can't read nor write Unicode data one wchar_t at a time as a single half of a surrogate character can't be converted to or from the encoding of the stream. To fix this, we may need to store the last wchar_t already read from the stream but not returned yet in wxTextInputStream::NextChar() and store, without writing it, the wchar_t passed to wxTextOutputStream::PutChar() until the second half of the surrogate is written. See #17070.
This commit is contained in:
@@ -87,7 +87,16 @@ protected:
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
wxMBConv *m_conv;
|
||||
#endif
|
||||
|
||||
// The second half of a surrogate character when using UTF-16 for wchar_t:
|
||||
// we can't return it immediately from GetChar() when we read a Unicode
|
||||
// code point outside of the BMP, but we can't keep it in m_lastBytes
|
||||
// neither because it can't separately decoded, so we have a separate 1
|
||||
// wchar_t buffer just for this case.
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
wchar_t m_lastWChar;
|
||||
#endif // SIZEOF_WCHAR_T == 2
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
bool EatEOL(const wxChar &c);
|
||||
void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
|
||||
@@ -165,7 +174,13 @@ protected:
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
wxMBConv *m_conv;
|
||||
#endif
|
||||
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
// The first half of a surrogate character if one was passed to PutChar()
|
||||
// and couldn't be output when it was called the last time.
|
||||
wchar_t m_lastWChar;
|
||||
#endif // SIZEOF_WCHAR_T == 2
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxTextOutputStream);
|
||||
};
|
||||
|
Reference in New Issue
Block a user