@@ -15,65 +15,11 @@ static const char k_DefultChar = '_';
15
15
16
16
#ifdef _WIN32
17
17
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
-
45
18
void MultiByteToUnicodeString2 (UString &dest, const AString &src, UINT codePage)
46
19
{
47
20
dest.Empty ();
48
- if (src.IsEmpty ())
49
- return ;
21
+ if (!src.IsEmpty ())
50
22
{
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
- */
77
23
Cube::Encoding::Conversion::Initialize ();
78
24
auto code = Cube::Encoding::Conversion::Guess ((const char *)src);
79
25
auto cvt = code != Cube::Encoding::Unknown ?
@@ -83,94 +29,12 @@ void MultiByteToUnicodeString2(UString &dest, const AString &src, UINT codePage)
83
29
}
84
30
}
85
31
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
-
104
32
static void UnicodeStringToMultiByte2 (AString &dest, const UString &src, UINT codePage, char defaultChar, bool &defaultCharWasUsed)
105
33
{
106
34
dest.Empty ();
107
35
defaultCharWasUsed = false ;
108
- if (src.IsEmpty ())
109
- return ;
36
+ if (!src.IsEmpty ())
110
37
{
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
-
174
38
Cube::Encoding::Conversion::Initialize ();
175
39
auto utf8 = codePage == CP_UTF7 ||
176
40
codePage == CP_UTF8 ||
@@ -182,19 +46,6 @@ static void UnicodeStringToMultiByte2(AString &dest, const UString &src, UINT co
182
46
}
183
47
}
184
48
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
-
198
49
#else
199
50
200
51
void MultiByteToUnicodeString2 (UString &dest, const AString &src, UINT /* codePage */ )
0 commit comments