FileIsText: only exit False if an "illegal" char is found, don't require a NewLine char being present. Resolves #0036679.

git-svn-id: trunk@62787 -
This commit is contained in:
bart 2020-03-21 12:40:35 +00:00
parent 96225c4159
commit 4ff199e1d7

View File

@ -572,10 +572,11 @@ function FileIsText(const AFilename: string; out FileReadable: boolean): boolean
var var
Buf: string; Buf: string;
Len: integer; Len: integer;
NewLine: boolean;
p: PChar; p: PChar;
ZeroAllowed: Boolean; ZeroAllowed: Boolean;
fHandle: THandle; fHandle: THandle;
const
BufSize = 2048;
begin begin
Result:=false; Result:=false;
FileReadable:=true; FileReadable:=true;
@ -583,7 +584,7 @@ begin
if (THandle(fHandle) <> feInvalidHandle) then if (THandle(fHandle) <> feInvalidHandle) then
begin begin
try try
Len:=1024; Len:=BufSize;
SetLength(Buf,Len+1); SetLength(Buf,Len+1);
Len := FileRead(fHandle,Buf[1],Len); Len := FileRead(fHandle,Buf[1],Len);
@ -603,7 +604,6 @@ begin
inc(p,2); inc(p,2);
ZeroAllowed:=true; ZeroAllowed:=true;
end; end;
NewLine:=false;
while true do begin while true do begin
case p^ of case p^ of
#0: #0:
@ -615,11 +615,9 @@ begin
// #12: form feed // #12: form feed
// #26: end of file // #26: end of file
#1..#8,#11,#14..#25,#27..#31: exit; #1..#8,#11,#14..#25,#27..#31: exit;
#10,#13: NewLine:=true;
end; end;
inc(p); inc(p);
end; end;
if NewLine or (Len<1024) then
Result:=true; Result:=true;
end else end else
Result:=true; Result:=true;