From 1255f3fd741833211c24b62744b1b960da100230 Mon Sep 17 00:00:00 2001 From: shinydoofy Date: Sat, 4 Apr 2009 09:05:00 +0000 Subject: [PATCH] fixed NULLbytes for win32 for now by reverting my changes --- changelog.txt | 1 + src/utils/xstring.cpp | 35 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/changelog.txt b/changelog.txt index c6ba88c8..5f52e3b4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,4 @@ +04-apr-2009 - shinydoofy - Reverted UTF8<->UTF32 code changes to fix up the win32 build for now 01-apr-2009 - adelikat - Beginning 2.1.1 ---version 2.1.0 released--- 29-mar-2009 - adelikat - Win32 - reverted acmlm's /dll folder change diff --git a/src/utils/xstring.cpp b/src/utils/xstring.cpp index 6b138914..c33d84dd 100644 --- a/src/utils/xstring.cpp +++ b/src/utils/xstring.cpp @@ -585,35 +585,38 @@ namespace UtfConverter size_t widesize = utf8string.length(); if (sizeof(wchar_t) == 2) { - std::wstring resultstring; - resultstring.resize(widesize+1, L'\0'); + wchar_t* widestringnative = new wchar_t[widesize+1]; const UTF8* sourcestart = reinterpret_cast(utf8string.c_str()); const UTF8* sourceend = sourcestart + widesize; - UTF16* targetstart = reinterpret_cast(&resultstring[0]); - UTF16* targetend = targetstart + widesize; + UTF16* targetstart = reinterpret_cast(widestringnative); + UTF16* targetend = targetstart + widesize+1; ConversionResult res = ConvertUTF8toUTF16(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) { + delete [] widestringnative; throw std::exception(); } *targetstart = 0; + std::wstring resultstring(widestringnative); + delete [] widestringnative; return resultstring; } else if (sizeof(wchar_t) == 4) { - std::wstring resultstring; - resultstring.resize(widesize+1, L'\0'); + wchar_t* widestringnative = new wchar_t[widesize]; const UTF8* sourcestart = reinterpret_cast(utf8string.c_str()); const UTF8* sourceend = sourcestart + widesize; - UTF32* targetstart = reinterpret_cast(&resultstring[0]); + UTF32* targetstart = reinterpret_cast(widestringnative); UTF32* targetend = targetstart + widesize; ConversionResult res = ConvertUTF8toUTF32(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) { + delete [] widestringnative; throw std::exception(); } *targetstart = 0; - resultstring = resultstring.substr(0, 23); + std::wstring resultstring(widestringnative); + delete [] widestringnative; return resultstring; } else @@ -630,35 +633,39 @@ namespace UtfConverter if (sizeof(wchar_t) == 2) { size_t utf8size = 3 * widesize + 1; - std::string resultstring; - resultstring.resize(utf8size, '\0'); + char* utf8stringnative = new char[utf8size]; const UTF16* sourcestart = reinterpret_cast(widestring.c_str()); const UTF16* sourceend = sourcestart + widesize; - UTF8* targetstart = reinterpret_cast(&resultstring[0]); + UTF8* targetstart = reinterpret_cast(utf8stringnative); UTF8* targetend = targetstart + utf8size; ConversionResult res = ConvertUTF16toUTF8(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) { + delete [] utf8stringnative; throw std::exception(); } *targetstart = 0; + std::string resultstring(utf8stringnative); + delete [] utf8stringnative; return resultstring; } else if (sizeof(wchar_t) == 4) { size_t utf8size = 4 * widesize + 1; - std::string resultstring; - resultstring.resize(utf8size, '\0'); + char* utf8stringnative = new char[utf8size]; const UTF32* sourcestart = reinterpret_cast(widestring.c_str()); const UTF32* sourceend = sourcestart + widesize; - UTF8* targetstart = reinterpret_cast(&resultstring[0]); + UTF8* targetstart = reinterpret_cast(utf8stringnative); UTF8* targetend = targetstart + utf8size; ConversionResult res = ConvertUTF32toUTF8(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) { + delete [] utf8stringnative; throw std::exception(); } *targetstart = 0; + std::string resultstring(utf8stringnative); + delete [] utf8stringnative; return resultstring; } else