michael@0: // Common/StringConvert.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #include "StringConvert.h" michael@0: michael@0: #ifndef _WIN32 michael@0: #include michael@0: #endif michael@0: michael@0: #ifdef _WIN32 michael@0: UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) michael@0: { michael@0: UString resultString; michael@0: if(!srcString.IsEmpty()) michael@0: { michael@0: int numChars = MultiByteToWideChar(codePage, 0, srcString, michael@0: srcString.Length(), resultString.GetBuffer(srcString.Length()), michael@0: srcString.Length() + 1); michael@0: #ifndef _WIN32_WCE michael@0: if(numChars == 0) michael@0: throw 282228; michael@0: #endif michael@0: resultString.ReleaseBuffer(numChars); michael@0: } michael@0: return resultString; michael@0: } michael@0: michael@0: AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) michael@0: { michael@0: AString resultString; michael@0: if(!srcString.IsEmpty()) michael@0: { michael@0: int numRequiredBytes = srcString.Length() * 2; michael@0: int numChars = WideCharToMultiByte(codePage, 0, srcString, michael@0: srcString.Length(), resultString.GetBuffer(numRequiredBytes), michael@0: numRequiredBytes + 1, NULL, NULL); michael@0: #ifndef _WIN32_WCE michael@0: if(numChars == 0) michael@0: throw 282229; michael@0: #endif michael@0: resultString.ReleaseBuffer(numChars); michael@0: } michael@0: return resultString; michael@0: } michael@0: michael@0: #ifndef _WIN32_WCE michael@0: AString SystemStringToOemString(const CSysString &srcString) michael@0: { michael@0: AString result; michael@0: CharToOem(srcString, result.GetBuffer(srcString.Length() * 2)); michael@0: result.ReleaseBuffer(); michael@0: return result; michael@0: } michael@0: #endif michael@0: michael@0: #else michael@0: michael@0: UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) michael@0: { michael@0: UString resultString; michael@0: for (int i = 0; i < srcString.Length(); i++) michael@0: resultString += wchar_t(srcString[i]); michael@0: /* michael@0: if(!srcString.IsEmpty()) michael@0: { michael@0: int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1); michael@0: if (numChars < 0) throw "Your environment does not support UNICODE"; michael@0: resultString.ReleaseBuffer(numChars); michael@0: } michael@0: */ michael@0: return resultString; michael@0: } michael@0: michael@0: AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) michael@0: { michael@0: AString resultString; michael@0: for (int i = 0; i < srcString.Length(); i++) michael@0: resultString += char(srcString[i]); michael@0: /* michael@0: if(!srcString.IsEmpty()) michael@0: { michael@0: int numRequiredBytes = srcString.Length() * 6 + 1; michael@0: int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes); michael@0: if (numChars < 0) throw "Your environment does not support UNICODE"; michael@0: resultString.ReleaseBuffer(numChars); michael@0: } michael@0: */ michael@0: return resultString; michael@0: } michael@0: michael@0: #endif michael@0: