예제 #1
0
wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UNICODE(encoding) )
{
    if (st.IsEmpty())
    {
        reset( wxCFRetain( CFSTR("") ) );
    }
    else
    {
        wxString str = st ;
        wxMacConvertNewlines13To10( &str ) ;
#if wxUSE_UNICODE
#if wxUSE_UNICODE_WCHAR
        // native = wchar_t 4 bytes for us
        const wchar_t * const data = str.wc_str();
        const size_t size = str.length()*sizeof(wchar_t);
        CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF32Native;
#elif wxUSE_UNICODE_UTF8
        // native = utf8
        const char * const data = str.utf8_str();
        const size_t size = str.utf8_length();
        CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF8;
#else
    #error "unsupported Unicode representation"
#endif

        reset( CFStringCreateWithBytes( kCFAllocatorDefault,
            (const UInt8*)data, size, cfencoding, false /* no BOM */ ) );
#else // not wxUSE_UNICODE
        reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
            wxMacGetSystemEncFromFontEnc( encoding ) ) );
#endif
    }
}
예제 #2
0
파일: cfstring.cpp 프로젝트: gitrider/wxsj2
// converts this string into a carbon foundation string with optional pc 2 mac encoding
void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
{
    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() );
#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 ;
#endif
#else // not wxUSE_UNICODE
        m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
            wxMacGetSystemEncFromFontEnc( encoding ) ) ;
#endif
    }
    m_release = true ;
}
예제 #3
0
파일: cfstring.cpp 프로젝트: EdgarTx/wx
void wxMacConvertNewlines13To10( wxString * data )
{
    size_t len = data->Length() ;

    if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
        return ;

    wxString temp(*data) ;
    wxStringBuffer buf(*data,len ) ;
    memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;

    wxMacConvertNewlines13To10( buf ) ;
}
예제 #4
0
파일: cfstring.cpp 프로젝트: EdgarTx/wx
// converts this string into a carbon foundation string with optional pc 2 mac encoding
void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
{
    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() );
#else
        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
            m_cfs = CFSTR("") ;
            CFRetain( m_cfs ) ;
        }
        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() ) ;
            m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault , unibuf , unichars ) ;
            delete[] unibuf ;
        }
#endif
#else // not wxUSE_UNICODE
        m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
            wxMacGetSystemEncFromFontEnc( encoding ) ) ;
#endif
    }
    m_release = true ;
}