Added: ChildPath function
This commit is contained in:
parent
dd3a6eff70
commit
d680b8c2a4
@ -73,7 +73,7 @@ type
|
|||||||
*}
|
*}
|
||||||
procedure Split(const ASource, ADelimiter: String; out ADest: TSplitArray);
|
procedure Split(const ASource, ADelimiter: String; out ADest: TSplitArray);
|
||||||
|
|
||||||
{** Appends string parts with a specified glue value
|
{** Appends string parts with a specified glue value.
|
||||||
*
|
*
|
||||||
* @param ASource the source parts
|
* @param ASource the source parts
|
||||||
* @param AGlue the string added between the parts
|
* @param AGlue the string added between the parts
|
||||||
@ -81,11 +81,24 @@ type
|
|||||||
*}
|
*}
|
||||||
function Join(const ASource: TSplitArray; const AGlue: String): String;
|
function Join(const ASource: TSplitArray; const AGlue: String): String;
|
||||||
|
|
||||||
|
{** Determines if one path is the child of another path.
|
||||||
|
*
|
||||||
|
* Matches the start of two normalized paths. Either of the path may contain
|
||||||
|
* parent-references (ex. 'some\..\..\path\'). Note that the file system is
|
||||||
|
* not actually accessed, all checks are performed on the strings only.
|
||||||
|
*
|
||||||
|
* @param AChild the path to check
|
||||||
|
* @param AParent the path which is supposed to be the parent
|
||||||
|
* @result True if the child is indeed a child of the parent,
|
||||||
|
* False otherwise.
|
||||||
|
*}
|
||||||
|
function ChildPath(const AChild, AParent: String): Boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
SysUtils;
|
SysUtils;
|
||||||
|
|
||||||
function FormatSize;
|
function FormatSize(const ABytes: Int64; AKeepBytes: Boolean = False): String;
|
||||||
const
|
const
|
||||||
KB = 1024;
|
KB = 1024;
|
||||||
MB = KB * 1024;
|
MB = KB * 1024;
|
||||||
@ -117,7 +130,8 @@ begin
|
|||||||
Result := FormatFloat(',0.##', dSize) + sExt;
|
Result := FormatFloat(',0.##', dSize) + sExt;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareTextL;
|
function CompareTextL(const AMatch, AAgainst: String;
|
||||||
|
const ALength: Integer): Integer;
|
||||||
var
|
var
|
||||||
sMatch: String;
|
sMatch: String;
|
||||||
sAgainst: String;
|
sAgainst: String;
|
||||||
@ -137,23 +151,24 @@ begin
|
|||||||
Result := CompareText(sMatch, sAgainst);
|
Result := CompareText(sMatch, sAgainst);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SameTextL;
|
function SameTextL(const AMatch, AAgainst: String;
|
||||||
|
const ALength: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := (CompareTextL(AMatch, AAgainst, ALength) = 0);
|
Result := (CompareTextL(AMatch, AAgainst, ALength) = 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareTextS;
|
function CompareTextS(const AMatch, AAgainst: String): Integer;
|
||||||
begin
|
begin
|
||||||
Result := CompareTextL(AMatch, AAgainst, Length(AAgainst));
|
Result := CompareTextL(AMatch, AAgainst, Length(AAgainst));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SameTextS;
|
function SameTextS(const AMatch, AAgainst: String): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := SameTextL(AMatch, AAgainst, Length(AAgainst));
|
Result := SameTextL(AMatch, AAgainst, Length(AAgainst));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure Split;
|
procedure Split(const ASource, ADelimiter: String; out ADest: TSplitArray);
|
||||||
// StrPos is slow. Sloooooow slow. This function may not be advanced or
|
// StrPos is slow. Sloooooow slow. This function may not be advanced or
|
||||||
// the fastest one around, but it sure kicks StrPos' ass.
|
// the fastest one around, but it sure kicks StrPos' ass.
|
||||||
// 11.5 vs 1.7 seconds on a 2.4 Ghz for 10.000 iterations, baby!
|
// 11.5 vs 1.7 seconds on a 2.4 Ghz for 10.000 iterations, baby!
|
||||||
@ -274,7 +289,7 @@ begin
|
|||||||
until False;
|
until False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Join;
|
function Join(const ASource: TSplitArray; const AGlue: String): String;
|
||||||
var
|
var
|
||||||
iGlue: Integer;
|
iGlue: Integer;
|
||||||
iHigh: Integer;
|
iHigh: Integer;
|
||||||
@ -321,5 +336,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function ChildPath(const AChild, AParent: String): Boolean;
|
||||||
|
var
|
||||||
|
sChild: String;
|
||||||
|
sParent: String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
sChild := IncludeTrailingPathDelimiter(ExpandFileName(AChild));
|
||||||
|
sParent := IncludeTrailingPathDelimiter(ExpandFileName(AParent));
|
||||||
|
Result := SameTextS(sChild, sParent);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user