string_utils: Add From_UTF8( const char* cstring ) and From_UTF8( const std::string aString ),

mainly because we now use std::string in a lot of function using previously char*
FROM_UTF8(const char* cstring) now calls From_UTF8(const char* cstring)
This commit is contained in:
jean-pierre charras
2023-07-16 08:21:43 +02:00
parent 89780d353a
commit 0ecf5033e2
3 changed files with 50 additions and 10 deletions
+34
View File
@@ -1161,3 +1161,37 @@ std::string UIDouble2Str( double aValue )
return std::string( buf, len );
}
wxString From_UTF8( const char* cstring )
{
// Convert an expected UTF8 encoded C string to a wxString
wxString line = wxString::FromUTF8( cstring );
if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
{
line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
if( line.IsEmpty() )
line = wxString::From8BitData( cstring ); // try to use native string
}
return line;
}
wxString From_UTF8( const std::string& aString )
{
// Convert an expected UTF8 encoded std::string to a wxString
wxString line = wxString::FromUTF8( aString );
if( line.IsEmpty() ) // happens when aString is not a valid UTF8 sequence
{
line = wxConvCurrent->cMB2WC( aString.c_str() ); // try to use locale conversion
if( line.IsEmpty() )
line = wxString::From8BitData( aString.c_str() ); // try to use native string
}
return line;
}