From 980c35342199031740bba2b2ce34b61e781137cf Mon Sep 17 00:00:00 2001 From: ivost Date: Sat, 24 Apr 2010 21:05:05 +0000 Subject: [PATCH] * added function IncludeLeadingPathDelimiter: it adds a path delimiter in front of a path * added function ExcludeLeadingPathDelimiter: it removes a path delimiter in front of a path * added function ConcatPaths: it concats multiple path fragments, path delimiters are added if necessary git-svn-id: trunk@15167 - --- rtl/objpas/sysutils/fina.inc | 37 +++++++++++++++++++++++++++++++++++ rtl/objpas/sysutils/finah.inc | 3 +++ 2 files changed, 40 insertions(+) diff --git a/rtl/objpas/sysutils/fina.inc b/rtl/objpas/sysutils/fina.inc index a8f88aa36f..fee0882787 100644 --- a/rtl/objpas/sysutils/fina.inc +++ b/rtl/objpas/sysutils/fina.inc @@ -274,12 +274,49 @@ begin Result:=Copy(Path,1,L); end; +function IncludeLeadingPathDelimiter(Const Path : String) : String; + +Var + l : Integer; + +begin + Result:=Path; + l:=Length(Result); + If (L=0) or not(Result[1] in AllowDirectorySeparators) then + Result:=DirectorySeparator+Result; +end; + +function ExcludeLeadingPathDelimiter(Const Path: string): string; + +Var + L : Integer; + +begin + L:=Length(Path); + If (L>0) and (Path[1] in AllowDirectorySeparators) then + Dec(L); + Result:=Copy(Path,2,L); +end; + function IsPathDelimiter(Const Path: string; Index: Integer): Boolean; begin Result:=(Index>0) and (Index<=Length(Path)) and (Path[Index] in AllowDirectorySeparators); end; +function ConcatPaths(const Paths: array of String): String; +var + I: Integer; +begin + if Length(Paths) > 0 then + begin + Result := Paths[0]; + for I := 1 to Length(Paths) - 1 do + Result := IncludeTrailingPathDelimiter(Result) + ExcludeLeadingPathDelimiter(Paths[I]); + end else + Result := ''; +end; + Function GetFileHandle(var f : File):Longint; begin diff --git a/rtl/objpas/sysutils/finah.inc b/rtl/objpas/sysutils/finah.inc index b8961c8078..acbaf0737b 100644 --- a/rtl/objpas/sysutils/finah.inc +++ b/rtl/objpas/sysutils/finah.inc @@ -34,9 +34,12 @@ function IncludeTrailingPathDelimiter(Const Path : String) : String; function IncludeTrailingBackslash(Const Path : String) : String; function ExcludeTrailingBackslash(Const Path: string): string; function ExcludeTrailingPathDelimiter(Const Path: string): string; +function IncludeLeadingPathDelimiter(Const Path : String) : String; +function ExcludeLeadingPathDelimiter(Const Path: string): string; function IsPathDelimiter(Const Path: string; Index: Integer): Boolean; Procedure DoDirSeparators (Var FileName : String); Function SetDirSeparators (Const FileName : String) : String; Function GetDirs (Var DirName : String; Var Dirs : Array of pchar) : Longint; Function SameFileName(const S1, S2: string): Boolean; +function ConcatPaths(const Paths: array of String): String;