Simplify wxMacConvertNewlines helper functions

One is not used at all, two are only used in one place. Make the remaining
two return a wxString instead of taking a wxString pointer parameter.
This commit is contained in:
Paul Cornett 2017-10-01 10:44:35 -07:00
parent 37e29d3451
commit 0b2ec56ae3
5 changed files with 29 additions and 61 deletions

View File

@ -26,12 +26,8 @@
class WXDLLIMPEXP_FWD_BASE wxString; class WXDLLIMPEXP_FWD_BASE wxString;
WXDLLIMPEXP_BASE void wxMacConvertNewlines13To10( wxString *data ) ; WXDLLIMPEXP_BASE wxString wxMacConvertNewlines13To10(const wxString& data);
WXDLLIMPEXP_BASE void wxMacConvertNewlines10To13( wxString *data ) ; WXDLLIMPEXP_BASE wxString wxMacConvertNewlines10To13(const wxString& data);
WXDLLIMPEXP_BASE void wxMacConvertNewlines13To10( char * data ) ;
WXDLLIMPEXP_BASE void wxMacConvertNewlines13To10( wxChar16 * data ) ;
WXDLLIMPEXP_BASE void wxMacConvertNewlines10To13( char * data ) ;
WXDLLIMPEXP_BASE wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ; WXDLLIMPEXP_BASE wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ;
WXDLLIMPEXP_BASE wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) ; WXDLLIMPEXP_BASE wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) ;

View File

@ -489,11 +489,15 @@ bool wxDataObject::GetFromPasteboard( void * pb )
if (dataFormat.GetType() == wxDF_TEXT) if (dataFormat.GetType() == wxDF_TEXT)
{ {
wxMacConvertNewlines13To10((char*) buf); for (char* p = static_cast<char*>(buf); *p; p++)
if (*p == '\r')
*p = '\n';
} }
else if (dataFormat.GetType() == wxDF_UNICODETEXT) else if (dataFormat.GetType() == wxDF_UNICODETEXT)
{ {
wxMacConvertNewlines13To10((wxChar16*) buf); for (wxChar16* p = static_cast<wxChar16*>(buf); *p; p++)
if (*p == '\r')
*p = '\n';
} }
SetData( flavorFormat, flavorDataSize, buf ); SetData( flavorFormat, flavorDataSize, buf );
transferred = true; transferred = true;

View File

@ -788,22 +788,22 @@ void wxNSTextViewControl::insertText(NSString* str, WXWidget slf, void *_cmd)
wxString wxNSTextViewControl::GetStringValue() const wxString wxNSTextViewControl::GetStringValue() const
{ {
wxString result;
if (m_textView) if (m_textView)
{ {
wxString result = wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding()); result = wxMacConvertNewlines13To10(
wxMacConvertNewlines13To10( &result ) ; wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding()));
return result;
} }
return wxEmptyString; return result;
} }
void wxNSTextViewControl::SetStringValue( const wxString &str) void wxNSTextViewControl::SetStringValue( const wxString &str)
{ {
wxString st = str;
wxMacConvertNewlines10To13( &st );
wxMacEditHelper helper(m_textView); wxMacEditHelper helper(m_textView);
if (m_textView) if (m_textView)
{ {
wxString st(wxMacConvertNewlines10To13(str));
[m_textView setString: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; [m_textView setString: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
if ( m_wxPeer->HasFlag(wxTE_AUTO_URL) ) if ( m_wxPeer->HasFlag(wxTE_AUTO_URL) )
{ {
@ -984,8 +984,7 @@ void wxNSTextViewControl::ShowPosition(long pos)
void wxNSTextViewControl::WriteText(const wxString& str) void wxNSTextViewControl::WriteText(const wxString& str)
{ {
wxString st = str; wxString st(wxMacConvertNewlines10To13(str));
wxMacConvertNewlines10To13( &st );
wxMacEditHelper helper(m_textView); wxMacEditHelper helper(m_textView);
NSEvent* formerEvent = m_lastKeyDownEvent; NSEvent* formerEvent = m_lastKeyDownEvent;
m_lastKeyDownEvent = nil; m_lastKeyDownEvent = nil;

View File

@ -24,46 +24,17 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
void wxMacConvertNewlines13To10( char * data )
{
char * buf = data ;
while( (buf=strchr(buf,0x0d)) != NULL )
{
*buf = 0x0a ;
buf++ ;
}
}
void wxMacConvertNewlines13To10( wxChar16 * data )
{
for ( ; *data; ++data )
{
if ( *data == 0x0d )
*data = 0x0a;
}
}
void wxMacConvertNewlines10To13( char * data )
{
char * buf = data ;
while( (buf=strchr(buf,0x0a)) != NULL )
{
*buf = 0x0d ;
buf++ ;
}
}
const wxString sCR((wxChar)13); const wxString sCR((wxChar)13);
const wxString sLF((wxChar)10); const wxString sLF((wxChar)10);
void wxMacConvertNewlines13To10( wxString * data ) wxString wxMacConvertNewlines13To10(const wxString& data)
{ {
data->Replace( sCR,sLF); return wxString(data)->Replace(sCR, sLF);
} }
void wxMacConvertNewlines10To13( wxString * data ) wxString wxMacConvertNewlines10To13(const wxString& data)
{ {
data->Replace( sLF,sCR); return wxString(data)->Replace(sLF, sCR);
} }
wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
@ -614,8 +585,7 @@ wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UN
} }
else else
{ {
wxString str = st ; wxString str(wxMacConvertNewlines13To10(st));
wxMacConvertNewlines13To10( &str ) ;
#if wxUSE_UNICODE #if wxUSE_UNICODE
#if wxUSE_UNICODE_WCHAR #if wxUSE_UNICODE_WCHAR
// native = wchar_t 4 bytes for us // native = wchar_t 4 bytes for us
@ -700,8 +670,7 @@ wxString wxCFStringRef::AsString( CFStringRef ref, wxFontEncoding WXUNUSED_IN_UN
#endif #endif
delete[] buf ; delete[] buf ;
wxMacConvertNewlines10To13( &result); return wxMacConvertNewlines10To13(result);
return result ;
} }
wxString wxCFStringRef::AsString(wxFontEncoding encoding) const wxString wxCFStringRef::AsString(wxFontEncoding encoding) const

View File

@ -336,23 +336,24 @@ bool wxUITextViewControl::CanFocus() const
wxString wxUITextViewControl::GetStringValue() const wxString wxUITextViewControl::GetStringValue() const
{ {
wxString result;
if (m_textView) if (m_textView)
{ {
wxString result = wxCFStringRef::AsString([m_textView text], m_wxPeer->GetFont().GetEncoding()); result = wxMacConvertNewlines13To10(
wxMacConvertNewlines13To10( &result ) ; wxCFStringRef::AsString([m_textView text], m_wxPeer->GetFont().GetEncoding()));
return result;
} }
return wxEmptyString; return result;
} }
void wxUITextViewControl::SetStringValue( const wxString &str) void wxUITextViewControl::SetStringValue( const wxString &str)
{ {
wxString st = str;
wxMacConvertNewlines10To13( &st );
wxMacEditHelper helper(m_textView); wxMacEditHelper helper(m_textView);
if (m_textView) if (m_textView)
{
wxString st(wxMacConvertNewlines10To13(str));
[m_textView setText: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; [m_textView setText: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
}
} }
void wxUITextViewControl::Copy() void wxUITextViewControl::Copy()
@ -419,8 +420,7 @@ void wxUITextViewControl::SetSelection( long from , long to )
void wxUITextViewControl::WriteText(const wxString& str) void wxUITextViewControl::WriteText(const wxString& str)
{ {
wxString st = str; wxString st(wxMacConvertNewlines10To13(str));
wxMacConvertNewlines10To13( &st );
wxMacEditHelper helper(m_textView); wxMacEditHelper helper(m_textView);
wxCFStringRef insert( st , m_wxPeer->GetFont().GetEncoding() ); wxCFStringRef insert( st , m_wxPeer->GetFont().GetEncoding() );