Răsfoiți Sursa

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.
Ben Payne 10 ani în urmă
părinte
comite
fcf52fb5e0

+ 3 - 3
Engine/source/core/stringBuffer.cpp

@@ -186,7 +186,7 @@ void StringBuffer::append(const UTF8* in)
    
    
    // convert to UTF16, because that's our internal format.
    // convert to UTF16, because that's our internal format.
    // if the conversion fails, exit.
    // if the conversion fails, exit.
-   UTF16* tmp = convertUTF8toUTF16(in);
+   UTF16* tmp = createUTF16string(in);
    AssertFatal(tmp, "StringBuffer::append(UTF8) - could not convert UTF8 string!");
    AssertFatal(tmp, "StringBuffer::append(UTF8) - could not convert UTF8 string!");
    if(!tmp)
    if(!tmp)
       return;
       return;
@@ -231,7 +231,7 @@ void StringBuffer::insert(const U32 charOffset, const UTF8* in)
    
    
    // convert to UTF16, because that's our internal format.
    // convert to UTF16, because that's our internal format.
    // if the conversion fails, exit.
    // if the conversion fails, exit.
-   UTF16* tmp = convertUTF8toUTF16(in);
+   UTF16* tmp = createUTF16string(in);
    AssertFatal(tmp, "StringBuffer::insert(UTF8) - could not convert UTF8 string!");
    AssertFatal(tmp, "StringBuffer::insert(UTF8) - could not convert UTF8 string!");
    if(!tmp)
    if(!tmp)
       return;
       return;
@@ -377,7 +377,7 @@ UTF8* StringBuffer::createCopy8() const
    incRequestCount8();
    incRequestCount8();
    // convert will create a buffer of the appropriate size for a null terminated
    // convert will create a buffer of the appropriate size for a null terminated
    // input string.
    // input string.
-   UTF8* out = convertUTF16toUTF8(mBuffer.address());
+   UTF8* out = createUTF8string(mBuffer.address());
    return out;
    return out;
 }
 }
 
 

+ 2 - 2
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
 // Functions that convert buffers of unicode code points
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-UTF16* convertUTF8toUTF16( const UTF8* unistring)
+UTF16* createUTF16string( const UTF8* unistring)
 {
 {
    PROFILE_SCOPE(convertUTF8toUTF16_create);
    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);
    PROFILE_SCOPE(convertUTF16toUTF8_create);
 
 

+ 2 - 2
Engine/source/core/strings/unicode.h

@@ -62,9 +62,9 @@
 ///   calling delete[] on these buffers.
 ///   calling delete[] on these buffers.
 /// - Because they allocate memory, do not use these functions in a tight loop.
 /// - 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.
 /// - 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.
 /// Functions that convert buffers of unicode code points, into a provided buffer.

+ 2 - 2
Engine/source/core/util/str.cpp

@@ -346,7 +346,7 @@ class String::StringData : protected StringDataImpl
          {
          {
             // Do this atomically to protect interned strings.
             // Do this atomically to protect interned strings.
             
             
-            UTF16* utf16 = convertUTF8toUTF16( mData );
+            UTF16* utf16 = createUTF16string( mData );
             if( !dCompareAndSwap( mUTF16,( UTF16* ) NULL, utf16 ) )
             if( !dCompareAndSwap( mUTF16,( UTF16* ) NULL, utf16 ) )
                delete [] utf16;
                delete [] utf16;
          }
          }
@@ -580,7 +580,7 @@ String::String(const UTF16 *str)
 
 
    if( str && str[ 0 ] )
    if( str && str[ 0 ] )
    {
    {
-      UTF8* utf8 = convertUTF16toUTF8( str );
+      UTF8* utf8 = createUTF8string( str );
       U32 len = dStrlen( utf8 );
       U32 len = dStrlen( utf8 );
       _string = new ( len ) StringData( utf8 );
       _string = new ( len ) StringData( utf8 );
       delete [] utf8;
       delete [] utf8;

+ 1 - 1
Engine/source/core/util/test/strTest.cpp

@@ -44,7 +44,7 @@ protected:
          : mData( str ), mLength( str ? dStrlen( str ) : 0 ), mUTF16( NULL )
          : mData( str ), mLength( str ? dStrlen( str ) : 0 ), mUTF16( NULL )
       {
       {
          if( str )
          if( str )
-            mUTF16 = convertUTF8toUTF16( mData );
+            mUTF16 = createUTF16string( mData );
       }
       }
       ~StrTest()
       ~StrTest()
       {
       {

+ 1 - 1
Engine/source/gui/controls/guiTextEditCtrl.cpp

@@ -279,7 +279,7 @@ void GuiTextEditCtrl::setText( const UTF16* txt)
 {
 {
    if(txt && txt[0] != 0)
    if(txt && txt[0] != 0)
    {
    {
-      UTF8* txt8 = convertUTF16toUTF8( txt );
+      UTF8* txt8 = createUTF8string( txt );
       Parent::setText( txt8 );
       Parent::setText( txt8 );
       delete[] txt8;
       delete[] txt8;
       mTextBuffer.set( txt );
       mTextBuffer.set( txt );

+ 2 - 2
Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp

@@ -101,8 +101,8 @@ S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons butto
       pWindow->setCursorVisible(true);
       pWindow->setCursorVisible(true);
 
 
 #ifdef UNICODE
 #ifdef UNICODE
-   const UTF16 *msg = convertUTF8toUTF16(message);
-   const UTF16 *t = convertUTF8toUTF16(title);
+   const UTF16 *msg = createUTF16string(message);
+   const UTF16 *t = createUTF16string(title);
 #else
 #else
    const UTF8 *msg = message;
    const UTF8 *msg = message;
    const UTF8 *t = title;
    const UTF8 *t = title;

+ 3 - 3
Engine/source/platformWin32/winFileio.cpp

@@ -802,7 +802,7 @@ StringTableEntry Platform::getCurrentDirectory()
    forwardslash( buf );
    forwardslash( buf );
 
 
 #ifdef UNICODE
 #ifdef UNICODE
-   char* utf8 = convertUTF16toUTF8( buf );
+   char* utf8 = createUTF8string( buf );
    StringTableEntry result = StringTable->insert( utf8 );
    StringTableEntry result = StringTable->insert( utf8 );
    SAFE_DELETE_ARRAY( utf8 );
    SAFE_DELETE_ARRAY( utf8 );
    return result;
    return result;
@@ -847,8 +847,8 @@ static void getExecutableInfo( StringTableEntry* path, StringTableEntry* exe )
          if( delimiter )
          if( delimiter )
             *delimiter = '\0';
             *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 );
          pathEntry = StringTable->insert( pathBuf );
          exeEntry = StringTable->insert( exeBuf );
          exeEntry = StringTable->insert( exeBuf );

+ 1 - 1
Engine/source/windowManager/win32/win32CursorController.cpp

@@ -150,7 +150,7 @@ static HCURSOR gCursorShape = NULL;
 void Win32CursorController::setCursorShape( const UTF8 *fileName, bool reload )
 void Win32CursorController::setCursorShape( const UTF8 *fileName, bool reload )
 {
 {
 #ifdef UNICODE
 #ifdef UNICODE
-   const UTF16 *lFileName = convertUTF8toUTF16( fileName );
+   const UTF16 *lFileName = createUTF16string( fileName );
 #else
 #else
    const UTF8  *lFileName = fileName;
    const UTF8  *lFileName = fileName;
 #endif
 #endif