- // in Unicode mode we might not be able to write the last byte
- size_t len = size / sizeof(wxChar);
+ const char *p = static_cast<const char *>(buffer);
+
+#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
+ // we get the rest (and also take into account the part which we might have
+ // left unconverted before)
+ const char *src;
+ size_t srcLen;
+ if ( m_unconv.GetDataLen() )
+ {
+ // append the new data to the data remaining since the last time
+ m_unconv.AppendData(p, size);
+ src = m_unconv;
+ srcLen = m_unconv.GetDataLen();
+ }
+ else // no unconverted data left, avoid extra copy
+ {
+ src = p;
+ srcLen = size;
+ }