X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5185263fc5f0729ea1b926f9c2dcdc0153f6384e..de6185e212ebc37ff11ff70278e3c4f68419b097:/src/mac/corefoundation/cfstring.cpp diff --git a/src/mac/corefoundation/cfstring.cpp b/src/mac/corefoundation/cfstring.cpp index 0bb09db851..078df1e308 100644 --- a/src/mac/corefoundation/cfstring.cpp +++ b/src/mac/corefoundation/cfstring.cpp @@ -107,6 +107,10 @@ wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) encoding = wxLocale::GetSystemEncoding() ; #endif } + if ( encoding == wxFONTENCODING_SYSTEM ) + { + enc = CFStringGetSystemEncoding(); + } switch( encoding) { @@ -629,27 +633,34 @@ wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) // converts this string into a carbon foundation string with optional pc 2 mac encoding void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding ) { - Release() ; - - wxString str = st ; - wxMacConvertNewlines13To10( &str ) ; + Release() ; + if (st.IsEmpty()) + { + m_cfs = CFSTR("") ; + CFRetain( m_cfs ) ; + } + else + { + wxString str = st ; + wxMacConvertNewlines13To10( &str ) ; #if wxUSE_UNICODE #if SIZEOF_WCHAR_T == 2 - m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault, - (UniChar*)str.wc_str() , str.Len() ); + m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault, + (UniChar*)str.wc_str() , str.Len() ); #else - wxMBConvUTF16BE converter ; - size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; - UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ; - converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ; - m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault , - unibuf , unicharlen / sizeof(UniChar) ) ; - delete[] unibuf ; + wxMBConvUTF16 converter ; + size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; + UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ; + converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ; + m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault , + unibuf , unicharlen / sizeof(UniChar) ) ; + delete[] unibuf ; #endif #else // not wxUSE_UNICODE - m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , - wxMacGetSystemEncFromFontEnc( encoding ) ) ; + m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , + wxMacGetSystemEncFromFontEnc( encoding ) ) ; #endif + } m_release = true ; } @@ -668,10 +679,12 @@ wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding) UniChar* unibuf = new UniChar[ cflen + 1 ] ; CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ; unibuf[cflen] = 0 ; - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ; + wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); buf = new wxChar[ noChars + 1 ] ; - converter.MB2WC( buf , (const char*)unibuf , noChars ) ; + noChars = converter.MB2WC( buf , (const char*)unibuf , noChars + 1 ) ; + wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); delete[] unibuf ; #endif #else