1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Common/StringConvert.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +// Common/StringConvert.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "StringConvert.h" 1.9 + 1.10 +#ifndef _WIN32 1.11 +#include <stdlib.h> 1.12 +#endif 1.13 + 1.14 +#ifdef _WIN32 1.15 +UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) 1.16 +{ 1.17 + UString resultString; 1.18 + if(!srcString.IsEmpty()) 1.19 + { 1.20 + int numChars = MultiByteToWideChar(codePage, 0, srcString, 1.21 + srcString.Length(), resultString.GetBuffer(srcString.Length()), 1.22 + srcString.Length() + 1); 1.23 + #ifndef _WIN32_WCE 1.24 + if(numChars == 0) 1.25 + throw 282228; 1.26 + #endif 1.27 + resultString.ReleaseBuffer(numChars); 1.28 + } 1.29 + return resultString; 1.30 +} 1.31 + 1.32 +AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) 1.33 +{ 1.34 + AString resultString; 1.35 + if(!srcString.IsEmpty()) 1.36 + { 1.37 + int numRequiredBytes = srcString.Length() * 2; 1.38 + int numChars = WideCharToMultiByte(codePage, 0, srcString, 1.39 + srcString.Length(), resultString.GetBuffer(numRequiredBytes), 1.40 + numRequiredBytes + 1, NULL, NULL); 1.41 + #ifndef _WIN32_WCE 1.42 + if(numChars == 0) 1.43 + throw 282229; 1.44 + #endif 1.45 + resultString.ReleaseBuffer(numChars); 1.46 + } 1.47 + return resultString; 1.48 +} 1.49 + 1.50 +#ifndef _WIN32_WCE 1.51 +AString SystemStringToOemString(const CSysString &srcString) 1.52 +{ 1.53 + AString result; 1.54 + CharToOem(srcString, result.GetBuffer(srcString.Length() * 2)); 1.55 + result.ReleaseBuffer(); 1.56 + return result; 1.57 +} 1.58 +#endif 1.59 + 1.60 +#else 1.61 + 1.62 +UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) 1.63 +{ 1.64 + UString resultString; 1.65 + for (int i = 0; i < srcString.Length(); i++) 1.66 + resultString += wchar_t(srcString[i]); 1.67 + /* 1.68 + if(!srcString.IsEmpty()) 1.69 + { 1.70 + int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1); 1.71 + if (numChars < 0) throw "Your environment does not support UNICODE"; 1.72 + resultString.ReleaseBuffer(numChars); 1.73 + } 1.74 + */ 1.75 + return resultString; 1.76 +} 1.77 + 1.78 +AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) 1.79 +{ 1.80 + AString resultString; 1.81 + for (int i = 0; i < srcString.Length(); i++) 1.82 + resultString += char(srcString[i]); 1.83 + /* 1.84 + if(!srcString.IsEmpty()) 1.85 + { 1.86 + int numRequiredBytes = srcString.Length() * 6 + 1; 1.87 + int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes); 1.88 + if (numChars < 0) throw "Your environment does not support UNICODE"; 1.89 + resultString.ReleaseBuffer(numChars); 1.90 + } 1.91 + */ 1.92 + return resultString; 1.93 +} 1.94 + 1.95 +#endif 1.96 +