Browse Source

* 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 -

ivost 15 years ago
parent
commit
980c353421
2 changed files with 40 additions and 0 deletions
  1. 37 0
      rtl/objpas/sysutils/fina.inc
  2. 3 0
      rtl/objpas/sysutils/finah.inc

+ 37 - 0
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

+ 3 - 0
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;