LazUtils: LConvEncoding fix for CP936 and other DBCS codepages. Issue #36492, patch from CudaText man.

git-svn-id: trunk@62467 -
This commit is contained in:
juha 2019-12-29 23:18:57 +00:00
parent f721c3bcc5
commit dd0a4014b6
2 changed files with 49 additions and 5 deletions

View File

@ -46,6 +46,20 @@ begin
begin begin
l:=UnicodeToUTF8Inline(code,Dest); l:=UnicodeToUTF8Inline(code,Dest);
inc(Dest,l); inc(Dest,l);
end
else
case ConvertEncodingErrorMode of
ceemSkip:
begin end;
ceemException:
raise EConvertError.Create('Cannot convert DBCS code page to UTF8');
ceemReplace:
begin
Dest^:='?';
Inc(Dest);
end;
ceemReturmEmpty:
Exit('');
end; end;
end; end;
until false; until false;
@ -209,8 +223,19 @@ begin
Inc(Dest); Inc(Dest);
end end
else else
if ConvertEncodingFromUtf8RaisesException then case ConvertEncodingErrorMode of
ceemSkip:
begin end;
ceemException:
raise EConvertError.Create('Cannot convert UTF8 to DBCS code page'); raise EConvertError.Create('Cannot convert UTF8 to DBCS code page');
ceemReplace:
begin
Dest^ := '?';
Inc(Dest);
end;
ceemReturmEmpty:
Exit('');
end;
end; end;
until false; until false;
//SetLength(Result, Dest - PChar(Result)); //SetLength(Result, Dest - PChar(Result));

View File

@ -31,8 +31,16 @@ uses
SysUtils, Classes, dos, LazUTF8 SysUtils, Classes, dos, LazUTF8
{$IFDEF EnableIconvEnc},iconvenc{$ENDIF}; {$IFDEF EnableIconvEnc},iconvenc{$ENDIF};
type
TConvertEncodingErrorMode = (
ceemSkip,
ceemException,
ceemReplace,
ceemReturmEmpty
);
var var
ConvertEncodingFromUtf8RaisesException: boolean = False; ConvertEncodingErrorMode: TConvertEncodingErrorMode = ceemSkip;
//encoding names //encoding names
const const
@ -2105,8 +2113,19 @@ begin
inc(Dest); inc(Dest);
end end
else else
if ConvertEncodingFromUtf8RaisesException then case ConvertEncodingErrorMode of
ceemSkip:
begin end;
ceemException:
raise EConvertError.Create('Cannot convert UTF8 to single byte'); raise EConvertError.Create('Cannot convert UTF8 to single byte');
ceemReplace:
begin
Dest^:='?';
inc(Dest);
end;
ceemReturmEmpty:
Exit('');
end;
end; end;
end; end;
SetLength(Result,Dest-PChar(Result)); SetLength(Result,Dest-PChar(Result));