Skip to content

Commit b7eec74

Browse files
author
Arnaud Bouchez
committed
core: fixed some (Chinese) encoding on Windows
1 parent eea8a3e commit b7eec74

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/core/mormot.core.os.windows.inc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,36 @@ end;
177177
const
178178
DefaultCharVar: AnsiChar = '?';
179179

180+
function FullCodePage(CodePage: cardinal): boolean; {$ifdef HASINLINE} inline; {$endif}
181+
begin
182+
case CodePage of
183+
50220 .. 50229, 54936, 57002 .. 57011, 65000, CP_UTF8:
184+
result := true; // as required by the Windows API
185+
else
186+
result := false;
187+
end;
188+
end;
189+
180190
function Unicode_AnsiToWide(A: PAnsiChar; W: PWideChar; LA, LW, CodePage: PtrInt): integer;
191+
var
192+
flags: cardinal;
181193
begin
182-
result := MultiByteToWideChar(CodePage, MB_PRECOMPOSED, A, LA, W, LW);
194+
if FullCodePage(CodePage) then
195+
flags := 0
196+
else
197+
flags := MB_PRECOMPOSED;
198+
result := MultiByteToWideChar(CodePage, flags, A, LA, W, LW);
183199
end;
184200

185201
function Unicode_WideToAnsi(W: PWideChar; A: PAnsiChar; LW, LA, CodePage: PtrInt): integer;
202+
var
203+
defchar: PAnsiChar;
186204
begin
187-
result := WideCharToMultiByte(CodePage, 0, W, LW, A, LA, @DefaultCharVar, nil);
205+
if FullCodePage(CodePage) then
206+
defchar := nil
207+
else
208+
defchar := @DefaultCharVar;
209+
result := WideCharToMultiByte(CodePage, 0, W, LW, A, LA, defchar, nil);
188210
end;
189211

190212
function Win32Utf8ToAnsi(P: pointer; L, CP: integer; var A: RawByteString): boolean;

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.3.9541'
1+
'2.3.9542'

0 commit comments

Comments
 (0)