mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-04 05:58:14 +02:00
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:
parent
f721c3bcc5
commit
dd0a4014b6
@ -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));
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user