+ if ( srcLen == 0 )
+ {
+ // there is nothing left except the BOM so we'd return 0 below but
+ // this is unexpected: decoding a non-empty string must either fail
+ // or return something non-empty, in particular this would break
+ // the code in wxTextInputStream::NextChar()
+ //
+ // so still return an error as we need some more data to be able to
+ // decode it
+ return wxCONV_FAILED;
+ }
+ }
+
+ // try to convert using the auto-detected encoding
+ size_t rc = m_conv->ToWChar(dst, dstLen, src, srcLen);
+ if ( rc == wxCONV_FAILED && m_bomType == BOM_None )
+ {
+ // if the conversion failed but we didn't really detect anything and
+ // simply tried UTF-8 by default, retry it using the fall-back
+ if ( m_encDefault != wxFONTENCODING_MAX )
+ {
+ if ( m_ownsConv )
+ delete m_conv;
+
+ self->m_conv = new wxCSConv(m_encDefault == wxFONTENCODING_DEFAULT
+ ? GetFallbackEncoding()
+ : m_encDefault);
+ self->m_ownsConv = true;
+
+ rc = m_conv->ToWChar(dst, dstLen, src, srcLen);
+ }