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

View File

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