BCM WL 6.30.102.9 (r366174)
[tomato.git] / release / src-rt / linux / linux-2.6 / scripts / squashfs / lzma / C / Common / StringConvert.cpp
blob4b5913ade7b493319c811e7363997c841210ce78
1 // Common/StringConvert.cpp
3 #include "StdAfx.h"
5 #include "StringConvert.h"
7 #ifndef _WIN32
8 #include <stdlib.h>
9 #endif
11 #ifdef _WIN32
12 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
14 UString resultString;
15 if(!srcString.IsEmpty())
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);
26 return resultString;
29 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
31 AString resultString;
32 if(!srcString.IsEmpty())
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);
44 return resultString;
47 #ifndef _WIN32_WCE
48 AString SystemStringToOemString(const CSysString &srcString)
50 AString result;
51 CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));
52 result.ReleaseBuffer();
53 return result;
55 #endif
57 #else
59 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
61 UString resultString;
62 for (int i = 0; i < srcString.Length(); i++)
63 resultString += wchar_t(srcString[i]);
65 if(!srcString.IsEmpty())
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);
72 return resultString;
75 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
77 AString resultString;
78 for (int i = 0; i < srcString.Length(); i++)
79 resultString += char(srcString[i]);
81 if(!srcString.IsEmpty())
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);
89 return resultString;
92 #endif