synedit: implemented non UTF-8 characters are shown as ?

git-svn-id: trunk@15347 -
This commit is contained in:
mattias 2008-06-07 00:39:15 +00:00
parent fff34bfe63
commit e8e615a9b1
2 changed files with 31 additions and 9 deletions

View File

@ -3267,9 +3267,9 @@ var
procedure ExpandSpecialChars(var p: PChar; var Count: integer; procedure ExpandSpecialChars(var p: PChar; var Count: integer;
PhysicalStartPos: integer); PhysicalStartPos: integer);
// if there are no tabs: keep p and Count untouched // if there are no tabs or special chars: keep p and Count untouched
// if there are tabs: copy p into ExpandedPaintToken buffer, // if there are special chars: copy p into ExpandedPaintToken buffer,
// convert tabs to spaces, and return the buffer // convert tabs to spaces, and return the buffer
var var
i: integer; i: integer;
TabCount, LengthNeeded: Integer; TabCount, LengthNeeded: Integer;
@ -3284,8 +3284,10 @@ var
TabCount:=0; TabCount:=0;
for i:=0 to Count-1 do for i:=0 to Count-1 do
if p[i]=#9 then inc(TabCount); if p[i]=#9 then inc(TabCount);
if TabCount=0 then exit; if (TabCount=0)
LengthNeeded:=Count+TabCount*8; and (FindInvalidUTF8Character(p,Count)<0) then
exit;
LengthNeeded:=Count+TabCount*TabWidth;
if length(ExpandedPaintToken)<LengthNeeded then if length(ExpandedPaintToken)<LengthNeeded then
SetLength(ExpandedPaintToken,LengthNeeded+CharsInWindow); SetLength(ExpandedPaintToken,LengthNeeded+CharsInWindow);
SrcPos:=0; SrcPos:=0;
@ -3295,13 +3297,28 @@ var
while SrcPos<Count do begin while SrcPos<Count do begin
c:=p[SrcPos]; c:=p[SrcPos];
case c of case c of
#128..#195:
begin
if UseUTF8 then
Dest[DestPos]:='?' // non UTF-8 character
else
Dest[DestPos]:=p[SrcPos]; // normal char
inc(DestPos);
inc(SrcPos);
inc(ScreenPos);
end;
#196..#255: #196..#255:
begin begin
// could be UTF8 char // could be UTF8 char
if UseUTF8 then if UseUTF8 then begin
CharLen:=UTF8CharacterLength(@p[SrcPos]) CharLen:=UTF8CharacterStrictLength(@p[SrcPos]);
else if CharLen=0 then begin
Dest[DestPos]:='?';
inc(DestPos);
inc(SrcPos);
end;
end else
CharLen:=1; CharLen:=1;
for i:=1 to CharLen do begin for i:=1 to CharLen do begin
Dest[DestPos]:=p[SrcPos]; Dest[DestPos]:=p[SrcPos];

View File

@ -4137,7 +4137,12 @@ begin
inc(p); inc(p);
end else begin end else begin
i:=UTF8CharacterStrictLength(@s[p]); i:=UTF8CharacterStrictLength(@s[p]);
if i=0 then break; if i=0 then begin
{$IFDEF VerboseIDEEncoding}
DebugLn(['GuessEncoding non UTF-8 found at ',p,' ',dbgstr(copy(s,p-10,20))]);
{$ENDIF}
break;
end;
inc(p); inc(p);
end; end;
end; end;