LazUtils: Move FileSearchUtf8 to LazFileUtils (and inline it in FileUtil).

Part of the ongoing restructuring of LazFileUtils/FileUtil.

git-svn-id: trunk@41568 -
This commit is contained in:
bart 2013-06-06 21:29:50 +00:00
parent 05b0c79893
commit 8df292bbb6
3 changed files with 33 additions and 33 deletions

View File

@ -1234,36 +1234,8 @@ end;
function FileSearchUTF8(const Name, DirList: String): String;
------------------------------------------------------------------------------}
function FileSearchUTF8(const Name, DirList: String; ImplicitCurrentDir : Boolean = True): String;
Var
I : longint;
Temp : String;
begin
Result:=Name;
temp:=SetDirSeparators(DirList);
// Start with checking the file in the current directory
If ImplicitCurrentDir and (Result <> '') and FileExistsUTF8(Result) Then
exit;
while True do begin
If Temp = '' then
Break; // No more directories to search - fail
I:=pos(PathSeparator,Temp);
If I<>0 then
begin
Result:=Copy (Temp,1,i-1);
system.Delete(Temp,1,I);
end
else
begin
Result:=Temp;
Temp:='';
end;
If Result<>'' then
Result:=AppendPathDelim(Result)+Name;
If (Result <> '') and FileExistsUTF8(Result) Then
exit;
end;
Result:='';
Result := LazFileUtils.FileSearchUTF8(Name, DirList, ImplicitCurrentDir);
end;
{------------------------------------------------------------------------------

View File

@ -249,7 +249,7 @@ function FileGetAttrUTF8(const FileName: String): Longint; inline;
function FileSetAttrUTF8(const Filename: String; Attr: longint): Longint; inline;
function DeleteFileUTF8(const FileName: String): Boolean; inline;
function RenameFileUTF8(const OldName, NewName: String): Boolean; inline;
function FileSearchUTF8(const Name, DirList : String; ImplicitCurrentDir : Boolean = True): String;
function FileSearchUTF8(const Name, DirList : String; ImplicitCurrentDir : Boolean = True): String; inline;
function FileIsReadOnlyUTF8(const FileName: String): Boolean; inline;
function GetCurrentDirUTF8: String; inline;
function SetCurrentDirUTF8(const NewDir: String): Boolean; inline;

View File

@ -84,7 +84,7 @@ function FileGetAttrUTF8(const FileName: String): Longint;
function FileSetAttrUTF8(const Filename: String; Attr: longint): Longint;
function DeleteFileUTF8(const FileName: String): Boolean;
function RenameFileUTF8(const OldName, NewName: String): Boolean;
function FileSearchUTF8(const Name, DirList : String): String;
function FileSearchUTF8(const Name, DirList : String; ImplicitCurrentDir : Boolean = True): String;
function FileIsReadOnlyUTF8(const FileName: String): Boolean;
function GetCurrentDirUTF8: String;
function SetCurrentDirUTF8(const NewDir: String): Boolean;
@ -845,9 +845,37 @@ end;
function FileSearchUTF8(const Name, DirList: String): String;
function FileSearchUTF8(const Name, DirList: String; ImplicitCurrentDir : Boolean = True): String;
Var
I : longint;
Temp : String;
begin
Result:=SysToUTF8(SysUtils.FileSearch(UTF8ToSys(Name),UTF8ToSys(DirList)));
Result:=Name;
temp:=SetDirSeparators(DirList);
// Start with checking the file in the current directory
If ImplicitCurrentDir and (Result <> '') and FileExistsUTF8(Result) Then
exit;
while True do begin
If Temp = '' then
Break; // No more directories to search - fail
I:=pos(PathSeparator,Temp);
If I<>0 then
begin
Result:=Copy (Temp,1,i-1);
system.Delete(Temp,1,I);
end
else
begin
Result:=Temp;
Temp:='';
end;
If Result<>'' then
Result:=AppendPathDelim(Result)+Name;
If (Result <> '') and FileExistsUTF8(Result) Then
exit;
end;
Result:='';
end;
function FileIsReadOnlyUTF8(const FileName: String): Boolean;