| OLD | NEW |
| (Empty) |
| 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 &s, UINT codePage, char defaultCh
ar, bool &defaultCharWasUsed) | |
| 30 { | |
| 31 AString dest; | |
| 32 defaultCharWasUsed = false; | |
| 33 if (!s.IsEmpty()) | |
| 34 { | |
| 35 int numRequiredBytes = s.Length() * 2; | |
| 36 BOOL defUsed; | |
| 37 int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(), | |
| 38 dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1, | |
| 39 &defaultChar, &defUsed); | |
| 40 defaultCharWasUsed = (defUsed != FALSE); | |
| 41 #ifndef _WIN32_WCE | |
| 42 if (numChars == 0) | |
| 43 throw 282229; | |
| 44 #endif | |
| 45 dest.ReleaseBuffer(numChars); | |
| 46 } | |
| 47 return dest; | |
| 48 } | |
| 49 | |
| 50 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) | |
| 51 { | |
| 52 bool defaultCharWasUsed; | |
| 53 return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed); | |
| 54 } | |
| 55 | |
| 56 #ifndef _WIN32_WCE | |
| 57 AString SystemStringToOemString(const CSysString &srcString) | |
| 58 { | |
| 59 AString result; | |
| 60 CharToOem(srcString, result.GetBuffer(srcString.Length() * 2)); | |
| 61 result.ReleaseBuffer(); | |
| 62 return result; | |
| 63 } | |
| 64 #endif | |
| 65 | |
| 66 #else | |
| 67 | |
| 68 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) | |
| 69 { | |
| 70 UString resultString; | |
| 71 for (int i = 0; i < srcString.Length(); i++) | |
| 72 resultString += wchar_t(srcString[i]); | |
| 73 /* | |
| 74 if (!srcString.IsEmpty()) | |
| 75 { | |
| 76 int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcStrin
g, srcString.Length() + 1); | |
| 77 if (numChars < 0) throw "Your environment does not support UNICODE"; | |
| 78 resultString.ReleaseBuffer(numChars); | |
| 79 } | |
| 80 */ | |
| 81 return resultString; | |
| 82 } | |
| 83 | |
| 84 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) | |
| 85 { | |
| 86 AString resultString; | |
| 87 for (int i = 0; i < srcString.Length(); i++) | |
| 88 resultString += char(srcString[i]); | |
| 89 /* | |
| 90 if (!srcString.IsEmpty()) | |
| 91 { | |
| 92 int numRequiredBytes = srcString.Length() * 6 + 1; | |
| 93 int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString,
numRequiredBytes); | |
| 94 if (numChars < 0) throw "Your environment does not support UNICODE"; | |
| 95 resultString.ReleaseBuffer(numChars); | |
| 96 } | |
| 97 */ | |
| 98 return resultString; | |
| 99 } | |
| 100 | |
| 101 #endif | |
| 102 | |
| OLD | NEW |