mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 21:42:51 +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
|
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));
|
||||||
|
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user