Skip to content

Commit

Permalink
TStr: +Capitalize, SplitStrToArrayEx, EnsureBounds, TrimENDL
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdp committed Oct 12, 2020
1 parent 03c488e commit 5d7a4ee
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions Base/JPL.TStr.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
interface

uses
{Windows, }SysUtils, {Classes,} Types,
SysUtils, Types,
JPL.Strings, JPL.Conversion;


type
const
ENDL = sLineBreak;


{ TStr }
type

TStr = record
private
Expand All @@ -39,6 +41,8 @@ TStr = record
class function PadRight(Text: string; Len: integer; PaddingChar: Char = ' '): string; overload; static;
class function PadRight(const x: integer; Len: integer; PaddingChar: Char = '0'): string; overload; static;

class function Capitalize(const s: string): string; static;

class function RemoveTrailingPathDelimiter(Dir: string): string; static;

class function RemoveSpaces(const s: string): string; static;
Expand All @@ -61,6 +65,11 @@ TStr = record
{$ENDIF}
class function SplitStr(const InStr: string; out LeftStr, RightStr: string; const Separator: string): Boolean; static;

// The SplitStrToArrayEx procedure uses the initial allocation of the size of the array and incrementing its size by the ArrDeltaSize value
// to avoid increasing the size of the array repeatedly by 1.
class procedure SplitStrToArrayEx(s: string; var Arr: TStringDynArray; const EndLineStr: string = sLineBreak; ArrDeltaSize: WORD = 100); static;

class function EnsureBounds(const s: string; LeftBound: string = '['; RightBound: string = ']'): string; static;
class function AddBounds(const s: string; LeftBound: string = '['; RightBound: string = ']'): string; static;
class function TrimBounds(s: string; LeftBound: string = '['; RightBound: string = ']'): string; static;
class function IsBoundedWith(const s: string; LeftBound: string = '['; RightBound: string = ']'; IgnoreCase: Boolean = False): Boolean; static;
Expand Down Expand Up @@ -92,6 +101,7 @@ TStr = record

class function TrimFromEnd(const s: string; const StringToCut: string): string; static;
class function TrimFromStart(const s: string; const StringToCut: string): string; static;
class function TrimENDL(const s: string): string; static;

class function CharCount(const s: string; const AChar: Char): integer; static;
class function FirstCharPos(const s: string; const AChar: Char): integer; static;
Expand Down Expand Up @@ -205,6 +215,11 @@ class procedure TStr.SplitStrToArray(s: string; var Arr: TArray<string>; const E
JPL.Strings.SplitStrToArray(s, Arr, EndLineStr);
end;

class procedure TStr.SplitStrToArrayEx(s: string; var Arr: TStringDynArray; const EndLineStr: string = sLineBreak; ArrDeltaSize: WORD = 100);
begin
JPL.Strings.SplitStrToArrayEx(s, Arr, EndLineStr, ArrDeltaSize);
end;

class function TStr.SplitStr(const InStr: string; out LeftStr, RightStr: string; const Separator: string): Boolean;
begin
Result := JPL.Strings.SplitStr(InStr, LeftStr, RightStr, Separator);
Expand All @@ -220,6 +235,11 @@ class function TStr.TrimBounds(s: string; LeftBound: string = '['; RightBound: s
Result := JPL.Strings.TrimBounds(s, LeftBound, RightBound);
end;

class function TStr.TrimENDL(const s: string): string;
begin
Result := JPL.Strings.TrimENDL(s);
end;

class function TStr.IsBoundedWith(const s: string; LeftBound: string = '['; RightBound: string = ']'; IgnoreCase: Boolean = False): Boolean;
begin
Result := JPL.Strings.IsBoundedWith(s, LeftBound, RightBound, IgnoreCase);
Expand Down Expand Up @@ -328,6 +348,11 @@ class function TStr.EndsWith(const SubStr, s: string; IgnoreCase: Boolean): Bool
else Result := TStr.EndsStr(SubStr, s);
end;

class function TStr.EnsureBounds(const s: string; LeftBound, RightBound: string): string;
begin
Result := JPL.Strings.EnsureBounds(s, LeftBound, RightBound);
end;

class function TStr.TrimFromEnd(const s: string; const StringToCut: string): string;
begin
Result := JPL.Strings.TrimFromEnd(s, StringToCut);
Expand All @@ -338,6 +363,11 @@ class function TStr.TrimFromStart(const s: string; const StringToCut: string): s
Result := JPL.Strings.TrimFromStart(s, StringToCut);
end;

class function TStr.Capitalize(const s: string): string;
begin
Result := JPL.Strings.Capitalize(s);
end;

class function TStr.CharCount(const s: string; const AChar: Char): integer;
var
i: integer;
Expand Down

0 comments on commit 5d7a4ee

Please sign in to comment.