UTF8: Correct MSW issue with previous commit

Linux does not handle the resize command with wide-character extended
table UTF-8.  The solution did not work for W7-32bit.  This is a
compromise, attempting first the preferred, previous solution and
falling back to the secondary solution.
This commit is contained in:
Seth Hillbrand 2018-10-17 07:31:11 -07:00
parent b37bc69476
commit 6106210c87
2 changed files with 31 additions and 5 deletions

View File

@ -201,9 +201,20 @@ bool IsUTF8( const char* aString )
UTF8::UTF8( const wchar_t* txt )
{
wxCharBuffer charbuf = wxSafeConvertWX2MB( txt );
try
{
size_t len = wcslen( txt ) * 4 + 1;
char temp[len];
wxConvUTF8.WC2MB( temp, txt, len );
m_s.assign( temp );
}
catch(...)
{
auto string = wxSafeConvertWX2MB( txt );
m_s.assign( string );
}
m_s.assign( charbuf.data() );
m_s.shrink_to_fit();
}

View File

@ -15,13 +15,13 @@ void callee( const wxString& aString )
int main( int argc, char** argv )
{
UTF8 bozo = "ü";
UTF8 bozo = "This is a test of UTF-8: ü‱☺😕😱";
callee( bozo );
wxString s = bozo;
wxString b = bozo;
UTF8 b = s;
if( s.IsEmpty() )
{
@ -30,8 +30,23 @@ int main( int argc, char** argv )
if( s != bozo.wx_str() )
{
printf( "string miscompare\n" );
printf( "wxString conversion error\n" );
}
if( b != bozo )
{
printf( "From string conversion error\n" );
}
auto pos = bozo.begin();
auto end = bozo.end();
while( pos != end )
{
printf( "%c", *pos++ );
}
printf("\n");
return 0;
}