X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/939fba6c17da245488a77a3f58e983180fc5de91..3ef37e7f4ec5f0688a4fb47e530ca2d30a6bb3ed:/src/mac/utils.cpp?ds=inline diff --git a/src/mac/utils.cpp b/src/mac/utils.cpp index 16f91e18e3..0a0735d4a7 100644 --- a/src/mac/utils.cpp +++ b/src/mac/utils.cpp @@ -46,9 +46,7 @@ #include "TextCommon.h" #include "TextEncodingConverter.h" -#if defined(__WXMAC__) - #include "wx/mac/private.h" // includes mac headers -#endif +#include "wx/mac/private.h" // includes mac headers #if defined(__MWERKS__) && wxUSE_UNICODE #include @@ -751,8 +749,10 @@ wxString wxMacMakeStringFromPascal( ConstStringPtr from ) #if TARGET_CARBON // converts this string into a carbon foundation string with optional pc 2 mac encoding -void wxMacCFStringHolder::Assign( const wxString &str ) +void wxMacCFStringHolder::Assign( const wxString &st ) { + wxString str = st ; + wxMacConvertNewlines13To10( &str ) ; #if wxUSE_UNICODE m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault, (const unsigned short*)str.wc_str(), str.Len() ); @@ -774,12 +774,83 @@ wxString wxMacCFStringHolder::AsString() CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ; #endif buf[len] = 0 ; + wxMacConvertNewlines10To13( buf ) ; result.UngetWriteBuf() ; return result ; } #endif //TARGET_CARBON +void wxMacConvertNewlines13To10( char * data ) +{ + char * buf = data ; + while( (buf=strchr(buf,0x0d)) != NULL ) + { + *buf = 0x0a ; + buf++ ; + } +} + +void wxMacConvertNewlines10To13( char * data ) +{ + char * buf = data ; + while( (buf=strchr(buf,0x0a)) != NULL ) + { + *buf = 0x0d ; + buf++ ; + } +} + +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 ) ; +} + +void wxMacConvertNewlines10To13( wxString * data ) +{ + size_t len = data->Length() ; + + if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL) + return ; + + wxString temp(*data) ; + wxStringBuffer buf(*data,len ) ; + memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; + wxMacConvertNewlines10To13( buf ) ; +} + + +#if wxUSE_UNICODE +void wxMacConvertNewlines13To10( wxChar * data ) +{ + wxChar * buf = data ; + while( (buf=wxStrchr(buf,0x0d)) != NULL ) + { + *buf = 0x0a ; + buf++ ; + } +} + +void wxMacConvertNewlines10To13( wxChar * data ) +{ + wxChar * buf = data ; + while( (buf=wxStrchr(buf,0x0a)) != NULL ) + { + *buf = 0x0d ; + buf++ ; + } +} +#endif + // ---------------------------------------------------------------------------- // debugging support // ----------------------------------------------------------------------------