From fcf52fb5e0d6e00ab5998af68081c4a16d1a53e6 Mon Sep 17 00:00:00 2001 From: Ben Payne Date: Fri, 23 Jan 2015 16:09:01 -0500 Subject: [PATCH] Rename the memory allocating versions to make prev error less likely The behavior is different enough that these shouldn't be overloaded with the non-allocating verions. Also makes it more obvious what is going on to the caller. --- Engine/source/core/stringBuffer.cpp | 6 +++--- Engine/source/core/strings/unicode.cpp | 4 ++-- Engine/source/core/strings/unicode.h | 4 ++-- Engine/source/core/util/str.cpp | 4 ++-- Engine/source/core/util/test/strTest.cpp | 2 +- Engine/source/gui/controls/guiTextEditCtrl.cpp | 2 +- Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp | 4 ++-- Engine/source/platformWin32/winFileio.cpp | 6 +++--- Engine/source/windowManager/win32/win32CursorController.cpp | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Engine/source/core/stringBuffer.cpp b/Engine/source/core/stringBuffer.cpp index 1706de9dc..3d15a6183 100644 --- a/Engine/source/core/stringBuffer.cpp +++ b/Engine/source/core/stringBuffer.cpp @@ -186,7 +186,7 @@ void StringBuffer::append(const UTF8* in) // convert to UTF16, because that's our internal format. // if the conversion fails, exit. - UTF16* tmp = convertUTF8toUTF16(in); + UTF16* tmp = createUTF16string(in); AssertFatal(tmp, "StringBuffer::append(UTF8) - could not convert UTF8 string!"); if(!tmp) return; @@ -231,7 +231,7 @@ void StringBuffer::insert(const U32 charOffset, const UTF8* in) // convert to UTF16, because that's our internal format. // if the conversion fails, exit. - UTF16* tmp = convertUTF8toUTF16(in); + UTF16* tmp = createUTF16string(in); AssertFatal(tmp, "StringBuffer::insert(UTF8) - could not convert UTF8 string!"); if(!tmp) return; @@ -377,7 +377,7 @@ UTF8* StringBuffer::createCopy8() const incRequestCount8(); // convert will create a buffer of the appropriate size for a null terminated // input string. - UTF8* out = convertUTF16toUTF8(mBuffer.address()); + UTF8* out = createUTF8string(mBuffer.address()); return out; } diff --git a/Engine/source/core/strings/unicode.cpp b/Engine/source/core/strings/unicode.cpp index 3db038aa3..984168653 100644 --- a/Engine/source/core/strings/unicode.cpp +++ b/Engine/source/core/strings/unicode.cpp @@ -242,7 +242,7 @@ U32 convertUTF16toUTF8DoubleNULL( const UTF16 *unistring, UTF8 *outbuffer, U32 //----------------------------------------------------------------------------- // Functions that convert buffers of unicode code points //----------------------------------------------------------------------------- -UTF16* convertUTF8toUTF16( const UTF8* unistring) +UTF16* createUTF16string( const UTF8* unistring) { PROFILE_SCOPE(convertUTF8toUTF16_create); @@ -264,7 +264,7 @@ UTF16* convertUTF8toUTF16( const UTF8* unistring) } //----------------------------------------------------------------------------- -UTF8* convertUTF16toUTF8( const UTF16* unistring) +UTF8* createUTF8string( const UTF16* unistring) { PROFILE_SCOPE(convertUTF16toUTF8_create); diff --git a/Engine/source/core/strings/unicode.h b/Engine/source/core/strings/unicode.h index 737a8c500..ec26d1c91 100644 --- a/Engine/source/core/strings/unicode.h +++ b/Engine/source/core/strings/unicode.h @@ -62,9 +62,9 @@ /// calling delete[] on these buffers. /// - Because they allocate memory, do not use these functions in a tight loop. /// - These are useful when you need a new long term copy of a string. -UTF16* convertUTF8toUTF16( const UTF8 *unistring); +UTF16* createUTF16string( const UTF8 *unistring); -UTF8* convertUTF16toUTF8( const UTF16 *unistring); +UTF8* createUTF8string( const UTF16 *unistring); //----------------------------------------------------------------------------- /// Functions that convert buffers of unicode code points, into a provided buffer. diff --git a/Engine/source/core/util/str.cpp b/Engine/source/core/util/str.cpp index 3f4f3d8f9..d9d3c3ec7 100644 --- a/Engine/source/core/util/str.cpp +++ b/Engine/source/core/util/str.cpp @@ -346,7 +346,7 @@ class String::StringData : protected StringDataImpl { // Do this atomically to protect interned strings. - UTF16* utf16 = convertUTF8toUTF16( mData ); + UTF16* utf16 = createUTF16string( mData ); if( !dCompareAndSwap( mUTF16,( UTF16* ) NULL, utf16 ) ) delete [] utf16; } @@ -580,7 +580,7 @@ String::String(const UTF16 *str) if( str && str[ 0 ] ) { - UTF8* utf8 = convertUTF16toUTF8( str ); + UTF8* utf8 = createUTF8string( str ); U32 len = dStrlen( utf8 ); _string = new ( len ) StringData( utf8 ); delete [] utf8; diff --git a/Engine/source/core/util/test/strTest.cpp b/Engine/source/core/util/test/strTest.cpp index 3bb381d56..5658f2aa0 100644 --- a/Engine/source/core/util/test/strTest.cpp +++ b/Engine/source/core/util/test/strTest.cpp @@ -44,7 +44,7 @@ protected: : mData( str ), mLength( str ? dStrlen( str ) : 0 ), mUTF16( NULL ) { if( str ) - mUTF16 = convertUTF8toUTF16( mData ); + mUTF16 = createUTF16string( mData ); } ~StrTest() { diff --git a/Engine/source/gui/controls/guiTextEditCtrl.cpp b/Engine/source/gui/controls/guiTextEditCtrl.cpp index c451400b7..450be5280 100644 --- a/Engine/source/gui/controls/guiTextEditCtrl.cpp +++ b/Engine/source/gui/controls/guiTextEditCtrl.cpp @@ -279,7 +279,7 @@ void GuiTextEditCtrl::setText( const UTF16* txt) { if(txt && txt[0] != 0) { - UTF8* txt8 = convertUTF16toUTF8( txt ); + UTF8* txt8 = createUTF8string( txt ); Parent::setText( txt8 ); delete[] txt8; mTextBuffer.set( txt ); diff --git a/Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp b/Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp index 9fb6948f8..422800415 100644 --- a/Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp +++ b/Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp @@ -101,8 +101,8 @@ S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons butto pWindow->setCursorVisible(true); #ifdef UNICODE - const UTF16 *msg = convertUTF8toUTF16(message); - const UTF16 *t = convertUTF8toUTF16(title); + const UTF16 *msg = createUTF16string(message); + const UTF16 *t = createUTF16string(title); #else const UTF8 *msg = message; const UTF8 *t = title; diff --git a/Engine/source/platformWin32/winFileio.cpp b/Engine/source/platformWin32/winFileio.cpp index 81b6142df..36900cd15 100644 --- a/Engine/source/platformWin32/winFileio.cpp +++ b/Engine/source/platformWin32/winFileio.cpp @@ -802,7 +802,7 @@ StringTableEntry Platform::getCurrentDirectory() forwardslash( buf ); #ifdef UNICODE - char* utf8 = convertUTF16toUTF8( buf ); + char* utf8 = createUTF8string( buf ); StringTableEntry result = StringTable->insert( utf8 ); SAFE_DELETE_ARRAY( utf8 ); return result; @@ -847,8 +847,8 @@ static void getExecutableInfo( StringTableEntry* path, StringTableEntry* exe ) if( delimiter ) *delimiter = '\0'; - char* pathBuf = convertUTF16toUTF8( cen_buf ); - char* exeBuf = convertUTF16toUTF8( delimiter + 1 ); + char* pathBuf = createUTF8string( cen_buf ); + char* exeBuf = createUTF8string( delimiter + 1 ); pathEntry = StringTable->insert( pathBuf ); exeEntry = StringTable->insert( exeBuf ); diff --git a/Engine/source/windowManager/win32/win32CursorController.cpp b/Engine/source/windowManager/win32/win32CursorController.cpp index 9b1b1eb3f..ca8a12563 100644 --- a/Engine/source/windowManager/win32/win32CursorController.cpp +++ b/Engine/source/windowManager/win32/win32CursorController.cpp @@ -150,7 +150,7 @@ static HCURSOR gCursorShape = NULL; void Win32CursorController::setCursorShape( const UTF8 *fileName, bool reload ) { #ifdef UNICODE - const UTF16 *lFileName = convertUTF8toUTF16( fileName ); + const UTF16 *lFileName = createUTF16string( fileName ); #else const UTF8 *lFileName = fileName; #endif