- wxMBConvUTF16 converter ;
- size_t unicharbytes = converter.FromWChar( NULL , 0 , str.wc_str() , str.Length() ) ;
- wxASSERT( unicharbytes != wxCONV_FAILED );
- if ( unicharbytes == wxCONV_FAILED )
- {
- // create an empty string
- reset( wxCFRetain( CFSTR("") ) );
- }
- else
- {
- // unicharbytes: number of bytes needed for UTF-16 encoded string (without terminating null)
- // unichars: number of UTF-16 characters (without terminating null)
- size_t unichars = unicharbytes / sizeof(UniChar) ;
- UniChar *unibuf = new UniChar[ unichars ] ;
- converter.FromWChar( (char*)unibuf , unicharbytes , str.wc_str() , str.Length() ) ;
- reset( CFStringCreateWithCharacters( kCFAllocatorDefault , unibuf , unichars ) ) ;
- delete[] unibuf ;
- }