Annotation of elwix/tools/oldlzma/SRC/Common/StringConvert.cpp, revision 1.1

1.1     ! misho       1: // Common/StringConvert.cpp
        !             2: 
        !             3: #include "StdAfx.h"
        !             4: 
        !             5: #include "StringConvert.h"
        !             6: 
        !             7: #ifndef _WIN32
        !             8: #include <stdlib.h>
        !             9: #endif
        !            10: 
        !            11: #ifdef _WIN32
        !            12: UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
        !            13: {
        !            14:   UString resultString;
        !            15:   if(!srcString.IsEmpty())
        !            16:   {
        !            17:     int numChars = MultiByteToWideChar(codePage, 0, srcString, 
        !            18:       srcString.Length(), resultString.GetBuffer(srcString.Length()), 
        !            19:       srcString.Length() + 1);
        !            20:     #ifndef _WIN32_WCE
        !            21:     if(numChars == 0)
        !            22:       throw 282228;
        !            23:     #endif
        !            24:     resultString.ReleaseBuffer(numChars);
        !            25:   }
        !            26:   return resultString;
        !            27: }
        !            28: 
        !            29: AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
        !            30: {
        !            31:   AString resultString;
        !            32:   if(!srcString.IsEmpty())
        !            33:   {
        !            34:     int numRequiredBytes = srcString.Length() * 2;
        !            35:     int numChars = WideCharToMultiByte(codePage, 0, srcString, 
        !            36:       srcString.Length(), resultString.GetBuffer(numRequiredBytes), 
        !            37:       numRequiredBytes + 1, NULL, NULL);
        !            38:     #ifndef _WIN32_WCE
        !            39:     if(numChars == 0)
        !            40:       throw 282229;
        !            41:     #endif
        !            42:     resultString.ReleaseBuffer(numChars);
        !            43:   }
        !            44:   return resultString;
        !            45: }
        !            46: 
        !            47: #ifndef _WIN32_WCE
        !            48: AString SystemStringToOemString(const CSysString &srcString)
        !            49: {
        !            50:   AString result;
        !            51:   CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));
        !            52:   result.ReleaseBuffer();
        !            53:   return result;
        !            54: }
        !            55: #endif
        !            56: 
        !            57: #else
        !            58: 
        !            59: UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
        !            60: {
        !            61:   UString resultString;
        !            62:   for (int i = 0; i < srcString.Length(); i++)
        !            63:     resultString += wchar_t(srcString[i]);
        !            64:   /*
        !            65:   if(!srcString.IsEmpty())
        !            66:   {
        !            67:     int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);
        !            68:     if (numChars < 0) throw "Your environment does not support UNICODE";
        !            69:     resultString.ReleaseBuffer(numChars);
        !            70:   }
        !            71:   */
        !            72:   return resultString;
        !            73: }
        !            74: 
        !            75: AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
        !            76: {
        !            77:   AString resultString;
        !            78:   for (int i = 0; i < srcString.Length(); i++)
        !            79:     resultString += char(srcString[i]);
        !            80:   /*
        !            81:   if(!srcString.IsEmpty())
        !            82:   {
        !            83:     int numRequiredBytes = srcString.Length() * 6 + 1;
        !            84:     int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);
        !            85:     if (numChars < 0) throw "Your environment does not support UNICODE";
        !            86:     resultString.ReleaseBuffer(numChars);
        !            87:   }
        !            88:   */
        !            89:   return resultString;
        !            90: }
        !            91: 
        !            92: #endif
        !            93: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>