1 // Common/StringConvert.cpp
5 #include "StringConvert.h"
12 UString
MultiByteToUnicodeString(const AString
&srcString
, UINT codePage
)
15 if(!srcString
.IsEmpty())
17 int numChars
= MultiByteToWideChar(codePage
, 0, srcString
,
18 srcString
.Length(), resultString
.GetBuffer(srcString
.Length()),
19 srcString
.Length() + 1);
24 resultString
.ReleaseBuffer(numChars
);
29 AString
UnicodeStringToMultiByte(const UString
&srcString
, UINT codePage
)
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
);
42 resultString
.ReleaseBuffer(numChars
);
48 AString
SystemStringToOemString(const CSysString
&srcString
)
51 CharToOem(srcString
, result
.GetBuffer(srcString
.Length() * 2));
52 result
.ReleaseBuffer();
59 UString
MultiByteToUnicodeString(const AString
&srcString
, UINT codePage
)
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);
75 AString
UnicodeStringToMultiByte(const UString
&srcString
, UINT codePage
)
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);