Skip to content

Commit

Permalink
[commons] CombinePaths method
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Oct 22, 2020
1 parent 010ce06 commit 43c58e7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Quick.Commons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Kike Pérez
Version : 2.0
Created : 14/07/2017
Modified : 14/07/2020
Modified : 06/08/2020
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand Down Expand Up @@ -304,6 +304,8 @@ EShellError = class(Exception);
function GetComputerName : string;
//Changes incorrect delims in path
function NormalizePathDelim(const cPath : string; const Delim : Char) : string;
//combine paths normalized with delim
function CombinePaths(const aFirstPath, aSecondPath: string; aDelim : Char): string;
//Removes last segment of a path
function RemoveLastPathSegment(cDir : string) : string;
//returns path delimiter if found
Expand Down Expand Up @@ -386,6 +388,8 @@ EShellError = class(Exception);

var
path : TEnvironmentPath;
//Enabled if QuickService is defined
IsQuickServiceApp : Boolean;

implementation

Expand Down Expand Up @@ -985,6 +989,22 @@ function NormalizePathDelim(const cPath : string; const Delim : Char) : string;
else Result := StringReplace(cPath,'\',Delim,[rfReplaceAll]);
end;

function CombinePaths(const aFirstPath, aSecondPath: string; aDelim : Char): string;
begin
var path1 := NormalizePathDelim(aFirstPath,aDelim);
var path2 := NormalizePathDelim(aSecondPath,aDelim);
if path1.EndsWith(aDelim) then
begin
if path2.StartsWith(aDelim) then Result := path1 + path2.Substring(1)
else Result := path1 + path2;
end
else
begin
if path2.StartsWith(aDelim) then Result := path1 + path2
else result := path1 + aDelim + path2;
end;
end;

function RemoveLastPathSegment(cDir : string) : string;
var
posi : Integer;
Expand Down

0 comments on commit 43c58e7

Please sign in to comment.