diff --git a/Engine/source/core/stringBuffer.cpp b/Engine/source/core/stringBuffer.cpp index 2f05d1973..1706de9dc 100644 --- a/Engine/source/core/stringBuffer.cpp +++ b/Engine/source/core/stringBuffer.cpp @@ -359,7 +359,7 @@ void StringBuffer::getCopy8(UTF8 *buff, const U32 buffSize) const { incRequestCount8(); AssertFatal(mBuffer.last() == 0, "StringBuffer::get UTF8 - not a null terminated string!"); - convertUTF16toUTF8(mBuffer.address(), buff, buffSize); + convertUTF16toUTF8N(mBuffer.address(), buff, buffSize); } void StringBuffer::getCopy(UTF16 *buff, const U32 buffSize) const @@ -408,7 +408,7 @@ void StringBuffer::updateBuffer8() { U32 slackLen = getUTF8BufferSizeEstimate(); mBuffer8.setSize(slackLen); - U32 len = convertUTF16toUTF8(mBuffer.address(), mBuffer8.address(), slackLen); + U32 len = convertUTF16toUTF8N(mBuffer.address(), mBuffer8.address(), slackLen); mBuffer8.setSize(len+1); mBuffer8.compact(); mDirty8 = false; diff --git a/Engine/source/core/strings/unicode.cpp b/Engine/source/core/strings/unicode.cpp index 26bad63d2..ffc650fae 100644 --- a/Engine/source/core/strings/unicode.cpp +++ b/Engine/source/core/strings/unicode.cpp @@ -191,7 +191,7 @@ U32 convertUTF8toUTF16N(const UTF8 *unistring, UTF16 *outbuffer, U32 len) } //----------------------------------------------------------------------------- -U32 convertUTF16toUTF8( const UTF16 *unistring, UTF8 *outbuffer, U32 len) +U32 convertUTF16toUTF8N( const UTF16 *unistring, UTF8 *outbuffer, U32 len) { AssertFatal(len >= 1, "Buffer for unicode conversion must be large enough to hold at least the null terminator."); PROFILE_START(convertUTF16toUTF8); @@ -274,7 +274,7 @@ UTF8* convertUTF16toUTF8( const UTF16* unistring) FrameTemp buf(len); // perform conversion - nCodeunits = convertUTF16toUTF8( unistring, buf, len); + nCodeunits = convertUTF16toUTF8N( unistring, buf, len); // add 1 for the NULL terminator the converter promises it included. nCodeunits++; diff --git a/Engine/source/core/strings/unicode.h b/Engine/source/core/strings/unicode.h index 9a0c634eb..b5d332b40 100644 --- a/Engine/source/core/strings/unicode.h +++ b/Engine/source/core/strings/unicode.h @@ -81,7 +81,7 @@ UTF8* convertUTF16toUTF8( const UTF16 *unistring); /// - If the provided buffer is too small, the output will be truncated. U32 convertUTF8toUTF16N(const UTF8 *unistring, UTF16 *outbuffer, U32 len); -U32 convertUTF16toUTF8( const UTF16 *unistring, UTF8 *outbuffer, U32 len); +U32 convertUTF16toUTF8N( const UTF16 *unistring, UTF8 *outbuffer, U32 len); template inline U32 convertUTF8toUTF16(const UTF8 *unistring, UTF16 (&outbuffer)[N]) @@ -89,6 +89,12 @@ inline U32 convertUTF8toUTF16(const UTF8 *unistring, UTF16 (&outbuffer)[N]) return convertUTF8toUTF16N(unistring, outbuffer, (U32) N); } +template +inline U32 convertUTF16toUTF8(const UTF16 *unistring, UTF8 (&outbuffer)[N]) +{ + return convertUTF16toUTF8N(unistring, outbuffer, (U32) N); +} + //----------------------------------------------------------------------------- /// Functions that converts one unicode codepoint at a time /// - Since these functions are designed to be used in tight loops, they do not diff --git a/Engine/source/platformWin32/nativeDialogs/fileDialog.cpp b/Engine/source/platformWin32/nativeDialogs/fileDialog.cpp index 55e7912fc..1d64139ee 100644 --- a/Engine/source/platformWin32/nativeDialogs/fileDialog.cpp +++ b/Engine/source/platformWin32/nativeDialogs/fileDialog.cpp @@ -79,7 +79,7 @@ static LRESULT PASCAL OKBtnFolderHackProc(HWND hWnd, UINT uMsg, WPARAM wParam, L char *filePath; #ifdef UNICODE char fileBuf[MAX_PATH]; - convertUTF16toUTF8(ofn->lpstrFile, fileBuf, sizeof(fileBuf)); + convertUTF16toUTF8(ofn->lpstrFile, fileBuf); filePath = fileBuf; #else filePath = ofn->lpstrFile; @@ -140,7 +140,7 @@ static UINT_PTR CALLBACK FolderHookProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPA char filePath[MAX_PATH]; #ifdef UNICODE - convertUTF16toUTF8(buf, filePath, sizeof(filePath)); + convertUTF16toUTF8(buf, filePath); #else dStrcpy( filePath, buf ); #endif @@ -158,7 +158,7 @@ static UINT_PTR CALLBACK FolderHookProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPA #ifdef UNICODE char buf2[MAX_PATH]; - convertUTF16toUTF8(buf, buf2, sizeof(buf2)); + convertUTF16toUTF8(buf, buf2); #else char *buf2 = buf; #endif @@ -442,7 +442,7 @@ bool FileDialog::Execute() // Handle Result Properly for Unicode as well as ANSI #ifdef UNICODE if(pszFileTitle[0] || ! ( mData.mStyle & FileDialogData::FDS_OPEN && mData.mStyle & FileDialogData::FDS_MULTIPLEFILES )) - convertUTF16toUTF8( (UTF16*)pszFile, (UTF8*)pszResult, sizeof(pszResult)); + convertUTF16toUTF8( (UTF16*)pszFile, pszResult); else convertUTF16toUTF8DoubleNULL( (UTF16*)pszFile, (UTF8*)pszResult, sizeof(pszResult)); #else diff --git a/Engine/source/platformWin32/winDInputDevice.cpp b/Engine/source/platformWin32/winDInputDevice.cpp index 8d036352f..a88f9ff1d 100644 --- a/Engine/source/platformWin32/winDInputDevice.cpp +++ b/Engine/source/platformWin32/winDInputDevice.cpp @@ -588,7 +588,7 @@ const char* DInputDevice::getName() { #ifdef UNICODE static UTF8 buf[512]; - convertUTF16toUTF8(mDeviceInstance.tszInstanceName, buf, sizeof(buf)); + convertUTF16toUTF8(mDeviceInstance.tszInstanceName, buf); return (const char *)buf; #else return mDeviceInstance.tszInstanceName; @@ -600,7 +600,7 @@ const char* DInputDevice::getProductName() { #ifdef UNICODE static UTF8 buf[512]; - convertUTF16toUTF8(mDeviceInstance.tszProductName, buf, sizeof(buf)); + convertUTF16toUTF8(mDeviceInstance.tszProductName, buf); return (const char *)buf; #else return mDeviceInstance.tszProductName; diff --git a/Engine/source/platformWin32/winFileio.cpp b/Engine/source/platformWin32/winFileio.cpp index dff87f3b7..764eabe20 100644 --- a/Engine/source/platformWin32/winFileio.cpp +++ b/Engine/source/platformWin32/winFileio.cpp @@ -601,7 +601,7 @@ static bool recurseDumpPath(const char *path, const char *pattern, Vector& out_rVolumeI #ifdef UNICODE char buf[ sizeof( lpszFileSystem ) / sizeof( lpszFileSystem[ 0 ] ) * 3 + 1 ]; - convertUTF16toUTF8( lpszFileSystem, buf, sizeof( buf ) / sizeof( buf[ 0 ] ) ); + convertUTF16toUTF8( lpszFileSystem, buf ); info.FileSystem = StringTable->insert( buf ); - convertUTF16toUTF8( lpszVolumeName, buf, sizeof( buf ) / sizeof( buf[ 0 ] ) ); + convertUTF16toUTF8( lpszVolumeName ); info.Name = StringTable->insert( buf ); #else info.FileSystem = StringTable->insert( lpszFileSystem ); @@ -1276,7 +1276,7 @@ bool Platform::hasSubDirectory(const char *pPath) #ifdef UNICODE char fileName[ 1024 ]; - convertUTF16toUTF8( findData.cFileName, fileName, sizeof( fileName ) / sizeof( fileName[ 0 ] ) ); + convertUTF16toUTF8( findData.cFileName, fileName ); #else char* fileName = findData.cFileName; #endif @@ -1397,7 +1397,7 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve continue; #ifdef UNICODE - convertUTF16toUTF8( findData.cFileName, fileName, fileName.size ); + convertUTF16toUTF8N( findData.cFileName, fileName, fileName.size ); #else char* fileName = findData.cFileName; #endif @@ -1472,7 +1472,7 @@ StringTableEntry osGetTemporaryDirectory() #ifdef UNICODE TempAlloc< char > dirBuffer( len * 3 + 1 ); char* dir = dirBuffer; - convertUTF16toUTF8( buffer, dir, dirBuffer.size ); + convertUTF16toUTF8N( buffer, dir, dirBuffer.size ); #else char* dir = buf; #endif diff --git a/Engine/source/platformWin32/winFont.cpp b/Engine/source/platformWin32/winFont.cpp index ff179be5f..a67b096b3 100644 --- a/Engine/source/platformWin32/winFont.cpp +++ b/Engine/source/platformWin32/winFont.cpp @@ -104,7 +104,7 @@ BOOL CALLBACK EnumFamCallBack(LPLOGFONT logFont, LPNEWTEXTMETRIC textMetric, DWO const U32 len = dStrlen( logFont->lfFaceName ) * 3 + 1; FrameTemp buffer( len ); - convertUTF16toUTF8( logFont->lfFaceName, buffer, len ); + convertUTF16toUTF8N( logFont->lfFaceName, buffer, len ); fonts->push_back( StringTable->insert( buffer ) ); diff --git a/Engine/source/platformWin32/winUser.cpp b/Engine/source/platformWin32/winUser.cpp index c82a273a3..171dfff87 100644 --- a/Engine/source/platformWin32/winUser.cpp +++ b/Engine/source/platformWin32/winUser.cpp @@ -52,7 +52,7 @@ const char *Platform::getUserDataDirectory() #ifdef UNICODE char path[ MAX_PATH * 3 + 1 ]; - convertUTF16toUTF8( szBuffer, path, sizeof( path ) ); + convertUTF16toUTF8( szBuffer, path ); #else char* path = szBuffer; #endif @@ -78,7 +78,7 @@ const char *Platform::getUserHomeDirectory() #ifdef UNICODE char path[ MAX_PATH * 3 + 1 ]; - convertUTF16toUTF8( szBuffer, path, sizeof( path ) ); + convertUTF16toUTF8( szBuffer, path ); #else char* path = szBuffer; #endif diff --git a/Engine/source/platformWin32/winVolume.cpp b/Engine/source/platformWin32/winVolume.cpp index 04422d9eb..9f5eb3459 100644 --- a/Engine/source/platformWin32/winVolume.cpp +++ b/Engine/source/platformWin32/winVolume.cpp @@ -720,13 +720,13 @@ String Platform::FS::getAssetDir() { TCHAR buf[ 2048 ]; ::GetModuleFileNameW( NULL, buf, sizeof( buf ) ); - convertUTF16toUTF8( buf, cen_buf, sizeof( cen_buf ) ); + convertUTF16toUTF8( buf, cen_buf ); } else { TCHAR buf[ 2048 ]; GetCurrentDirectoryW( sizeof( buf ) / sizeof( buf[ 0 ] ), buf ); - convertUTF16toUTF8( buf, cen_buf, sizeof( cen_buf ) ); + convertUTF16toUTF8( buf, cen_buf ); return Path::CleanSeparators(cen_buf); } #else diff --git a/Engine/source/platformWin32/winWindow.cpp b/Engine/source/platformWin32/winWindow.cpp index f8417f2f1..bede84739 100644 --- a/Engine/source/platformWin32/winWindow.cpp +++ b/Engine/source/platformWin32/winWindow.cpp @@ -362,7 +362,7 @@ S32 WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32) { TCHAR buf[ moduleNameSize ]; GetModuleFileNameW( NULL, buf, moduleNameSize ); - convertUTF16toUTF8( buf, moduleName, moduleNameSize ); + convertUTF16toUTF8( buf, moduleName ); } #else GetModuleFileNameA(NULL, moduleName, moduleNameSize); @@ -440,7 +440,7 @@ S32 torque_winmain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32) { TCHAR buf[ moduleNameSize ]; GetModuleFileNameW( NULL, buf, moduleNameSize ); - convertUTF16toUTF8( buf, moduleName, moduleNameSize ); + convertUTF16toUTF8( buf, moduleName ); } #else GetModuleFileNameA(NULL, moduleName, moduleNameSize); @@ -541,7 +541,7 @@ bool Platform::openWebBrowser( const char* webAddress ) RegCloseKey( regKey ); sHaveKey = true; - convertUTF16toUTF8(sWebKey,utf8WebKey,512); + convertUTF16toUTF8(sWebKey,utf8WebKey); #ifdef UNICODE char *p = dStrstr((const char *)utf8WebKey, "%1");