mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 23:59:10 +02:00
LazFileUtils: ComapareFileExt for CaseInsensitive comparing when Ext contains lowercase unicode charaters.
git-svn-id: trunk@41357 -
This commit is contained in:
parent
cb33ec967a
commit
46d203865a
@ -171,62 +171,37 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareFileExt(const Filename, Ext: string;
|
function CompareFileExt(const Filename, Ext: string; CaseSensitive: boolean): integer;
|
||||||
CaseSensitive: boolean): integer;
|
// Ext can contain a point or not
|
||||||
var
|
var
|
||||||
|
n, e : AnsiString;
|
||||||
FileLen, FilePos, ExtLen, ExtPos: integer;
|
FileLen, FilePos, ExtLen, ExtPos: integer;
|
||||||
FileChar, ExtChar: char;
|
|
||||||
begin
|
begin
|
||||||
FileLen:=length(Filename);
|
FileLen := length(Filename);
|
||||||
ExtLen:=length(Ext);
|
ExtLen := length(Ext);
|
||||||
FilePos:=FileLen;
|
FilePos := FileLen;
|
||||||
while (FilePos>=1) and (Filename[FilePos]<>'.') do dec(FilePos);
|
while (FilePos>=1) and (Filename[FilePos]<>'.') do dec(FilePos);
|
||||||
if FilePos<1 then begin
|
if FilePos < 1 then begin
|
||||||
// no extension in filename
|
// no extension in filename
|
||||||
Result:=1;
|
Result:=1;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
// skip point
|
// skip point
|
||||||
inc(FilePos);
|
inc(FilePos);
|
||||||
ExtPos:=1;
|
ExtPos := 1;
|
||||||
if (ExtPos<=ExtLen) and (Ext[1]='.') then inc(ExtPos);
|
if (ExtPos <= ExtLen) and (Ext[1] = '.') then inc(ExtPos);
|
||||||
|
|
||||||
// compare extensions
|
// compare extensions
|
||||||
while true do begin
|
n := Copy(Filename, FilePos, length(FileName));
|
||||||
if FilePos<=FileLen then begin
|
e := Copy(Ext, ExtPos, length(Ext));
|
||||||
if ExtPos<=ExtLen then begin
|
if CaseSensitive then
|
||||||
FileChar:=Filename[FilePos];
|
Result := CompareStr(n, e)
|
||||||
ExtChar:=Ext[ExtPos];
|
else
|
||||||
if not CaseSensitive then begin
|
Result := UTF8CompareText(n, e);
|
||||||
FileChar:=FPUpChars[FileChar];
|
if Result < 0
|
||||||
ExtChar:=FPUpChars[ExtChar];
|
then Result := -1
|
||||||
end;
|
else
|
||||||
if FileChar=ExtChar then begin
|
if Result > 0 then Result := 1;
|
||||||
inc(FilePos);
|
|
||||||
inc(ExtPos);
|
|
||||||
end else if FileChar>ExtChar then begin
|
|
||||||
Result:=1;
|
|
||||||
exit;
|
|
||||||
end else begin
|
|
||||||
Result:=-1;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end else begin
|
|
||||||
// fileext longer than ext
|
|
||||||
Result:=1;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end else begin
|
|
||||||
if ExtPos<=ExtLen then begin
|
|
||||||
// fileext shorter than ext
|
|
||||||
Result:=-1;
|
|
||||||
exit;
|
|
||||||
end else begin
|
|
||||||
// equal
|
|
||||||
Result:=0;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FileIsExecutable(const AFilename: string): boolean;
|
function FileIsExecutable(const AFilename: string): boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user