@@ -15,65 +15,11 @@ static const char k_DefultChar = '_';
1515
1616#ifdef _WIN32
1717
18- /*
19- MultiByteToWideChar(CodePage, DWORD dwFlags,
20- LPCSTR lpMultiByteStr, int cbMultiByte,
21- LPWSTR lpWideCharStr, int cchWideChar)
22-
23- if (cbMultiByte == 0)
24- return: 0. ERR: ERROR_INVALID_PARAMETER
25-
26- if (cchWideChar == 0)
27- return: the required buffer size in characters.
28-
29- if (supplied buffer size was not large enough)
30- return: 0. ERR: ERROR_INSUFFICIENT_BUFFER
31- The number of filled characters in lpWideCharStr can be smaller than cchWideChar (if last character is complex)
32-
33- If there are illegal characters:
34- if MB_ERR_INVALID_CHARS is set in dwFlags:
35- - the function stops conversion on illegal character.
36- - Return: 0. ERR: ERROR_NO_UNICODE_TRANSLATION.
37-
38- if MB_ERR_INVALID_CHARS is NOT set in dwFlags:
39- before Vista: illegal character is dropped (skipped). WinXP-64: GetLastError() returns 0.
40- in Vista+: illegal character is not dropped (MSDN). Undocumented: illegal
41- character is converted to U+FFFD, which is REPLACEMENT CHARACTER.
42- */
43-
44-
4518void MultiByteToUnicodeString2 (UString &dest, const AString &src, UINT codePage)
4619{
4720 dest.Empty ();
48- if (src.IsEmpty ())
49- return ;
21+ if (!src.IsEmpty ())
5022 {
51- /*
52- wchar_t *d = dest.GetBuf(src.Len());
53- const char *s = (const char *)src;
54- unsigned i;
55-
56- for (i = 0;;)
57- {
58- Byte c = (Byte)s[i];
59- if (c >= 0x80 || c == 0)
60- break;
61- d[i++] = (wchar_t)c;
62- }
63-
64- if (i != src.Len())
65- {
66- unsigned len = MultiByteToWideChar(codePage, 0, s + i,
67- src.Len() - i, d + i,
68- src.Len() + 1 - i);
69- if (len == 0)
70- throw 282228;
71- i += len;
72- }
73-
74- d[i] = 0;
75- dest.ReleaseBuf_SetLen(i);
76- */
7723 Cube::Encoding::Conversion::Initialize ();
7824 auto code = Cube::Encoding::Conversion::Guess ((const char *)src);
7925 auto cvt = code != Cube::Encoding::Unknown ?
@@ -83,94 +29,12 @@ void MultiByteToUnicodeString2(UString &dest, const AString &src, UINT codePage)
8329 }
8430}
8531
86- /*
87- int WideCharToMultiByte(
88- UINT CodePage, DWORD dwFlags,
89- LPCWSTR lpWideCharStr, int cchWideChar,
90- LPSTR lpMultiByteStr, int cbMultiByte,
91- LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
92-
93- if (lpDefaultChar == NULL),
94- - it uses system default value.
95-
96- if (CodePage == CP_UTF7 || CodePage == CP_UTF8)
97- if (lpDefaultChar != NULL || lpUsedDefaultChar != NULL)
98- return: 0. ERR: ERROR_INVALID_PARAMETER.
99-
100- The function operates most efficiently, if (lpDefaultChar == NULL && lpUsedDefaultChar == NULL)
101-
102- */
103-
10432static void UnicodeStringToMultiByte2 (AString &dest, const UString &src, UINT codePage, char defaultChar, bool &defaultCharWasUsed)
10533{
10634 dest.Empty ();
10735 defaultCharWasUsed = false ;
108- if (src.IsEmpty ())
109- return ;
36+ if (!src.IsEmpty ())
11037 {
111- /*
112- unsigned numRequiredBytes = src.Len() * 2;
113- char *d = dest.GetBuf(numRequiredBytes);
114- const wchar_t *s = (const wchar_t *)src;
115- unsigned i;
116-
117- for (i = 0;;)
118- {
119- wchar_t c = s[i];
120- if (c >= 0x80 || c == 0)
121- break;
122- d[i++] = (char)c;
123- }
124-
125- if (i != src.Len())
126- {
127- BOOL defUsed = FALSE;
128- defaultChar = defaultChar;
129-
130- bool isUtf = (codePage == CP_UTF8 || codePage == CP_UTF7);
131- unsigned len = WideCharToMultiByte(codePage, 0, s + i, src.Len() - i,
132- d + i, numRequiredBytes + 1 - i,
133- (isUtf ? NULL : &defaultChar),
134- (isUtf ? NULL : &defUsed));
135- defaultCharWasUsed = (defUsed != FALSE);
136- if (len == 0)
137- throw 282229;
138- i += len;
139- }
140-
141- d[i] = 0;
142- dest.ReleaseBuf_SetLen(i);
143- */
144-
145- /*
146- if (codePage != CP_UTF7)
147- {
148- const wchar_t *s = (const wchar_t *)src;
149- unsigned i;
150- for (i = 0;; i++)
151- {
152- wchar_t c = s[i];
153- if (c >= 0x80 || c == 0)
154- break;
155- }
156-
157- if (s[i] == 0)
158- {
159- char *d = dest.GetBuf(src.Len());
160- for (i = 0;;)
161- {
162- wchar_t c = s[i];
163- if (c == 0)
164- break;
165- d[i++] = (char)c;
166- }
167- d[i] = 0;
168- dest.ReleaseBuf_SetLen(i);
169- return;
170- }
171- }
172- */
173-
17438 Cube::Encoding::Conversion::Initialize ();
17539 auto utf8 = codePage == CP_UTF7 ||
17640 codePage == CP_UTF8 ||
@@ -182,19 +46,6 @@ static void UnicodeStringToMultiByte2(AString &dest, const UString &src, UINT co
18246 }
18347}
18448
185- /*
186- #ifndef UNDER_CE
187- AString SystemStringToOemString(const CSysString &src)
188- {
189- AString dest;
190- const unsigned len = src.Len() * 2;
191- CharToOem(src, dest.GetBuf(len));
192- dest.ReleaseBuf_CalcLen(len);
193- return dest;
194- }
195- #endif
196- */
197-
19849#else
19950
20051void MultiByteToUnicodeString2 (UString &dest, const AString &src, UINT /* codePage */ )
0 commit comments