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:
parent
89780d353a
commit
0ecf5033e2
|
@ -1161,3 +1161,37 @@ std::string UIDouble2Str( double aValue )
|
||||||
|
|
||||||
return std::string( buf, len );
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -105,17 +105,15 @@
|
||||||
#define TO_STR(x) TO_STR2(x)
|
#define TO_STR(x) TO_STR2(x)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
|
* Convert an expected UTF8 encoded C string to a wxString.
|
||||||
|
* If fails, tray to convert using current locale
|
||||||
|
* If still fails, return an empty wxString
|
||||||
|
* This macro is obsolete. Replaced by
|
||||||
|
* wxString From_UTF8( const char* cstring )
|
||||||
|
* (and also wxString From_UTF8( const std::string& aString ) )
|
||||||
*/
|
*/
|
||||||
static inline wxString FROM_UTF8( const char* cstring )
|
wxString From_UTF8( const char* cstring );
|
||||||
{
|
#define FROM_UTF8(x) From_UTF8(x)
|
||||||
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
|
|
||||||
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define UNIMPLEMENTED_FOR( type ) \
|
#define UNIMPLEMENTED_FOR( type ) \
|
||||||
wxFAIL_MSG( wxString::Format( wxT( "%s: unimplemented for %s" ), __FUNCTION__, type ) )
|
wxFAIL_MSG( wxString::Format( wxT( "%s: unimplemented for %s" ), __FUNCTION__, type ) )
|
||||||
|
|
|
@ -366,4 +366,12 @@ std::string UIDouble2Str( double aValue );
|
||||||
*/
|
*/
|
||||||
std::string FormatDouble2Str( double aValue );
|
std::string FormatDouble2Str( double aValue );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert an expected UTF8 encoded std::string to a wxString.
|
||||||
|
* If fails, tray to convert using current locale
|
||||||
|
* If still fails, return the initial string (can be already a converted string)
|
||||||
|
*/
|
||||||
|
wxString From_UTF8( const std::string& aString );
|
||||||
|
wxString From_UTF8( const char* cstring );
|
||||||
|
|
||||||
#endif // STRING_UTILS_H
|
#endif // STRING_UTILS_H
|
||||||
|
|
Loading…
Reference in New Issue