Create empty wxCFStringRef and not null one if conversion fails

If the passed string cannot be represented in the target encoding in the
wxCFStringRef constructor, create a reference to an empty string instead of a
null ref. Most users of wxCFStringRef cannot handle a null wxCFStringRef.

Closes #17825.

(cherry picked from commit a2b04536d3)
This commit is contained in:
Tim Kosse
2017-03-20 10:37:01 +01:00
committed by Vadim Zeitlin
parent e4293e9e39
commit 8f12eaf980

View File

@@ -621,9 +621,16 @@ wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UN
#else
#error "unsupported Unicode representation"
#endif
reset( CFStringCreateWithBytes( kCFAllocatorDefault,
(const UInt8*)data, size, cfencoding, false /* no BOM */ ) );
CFStringref ref = CFStringCreateWithBytes( kCFAllocatorDefault,
(const UInt8*)data, size, cfencoding, false /* no BOM */ );
if (ref)
{
reset( ref );
}
else
{
reset( wxCFRetain( CFSTR("") ) );
}
#else // not wxUSE_UNICODE
reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
wxMacGetSystemEncFromFontEnc( encoding ) ) );