add more stringrange functions

This commit is contained in:
Basile Burg 2018-02-06 14:09:42 +01:00
parent 382ae6c7bd
commit eda6ec6e81
1 changed files with 19 additions and 0 deletions

View File

@ -86,6 +86,12 @@ type
function startsWith(const value: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
// indicates wether the range starts with value.
function startsWith(var value: TStringRange): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
// indicates wether the range ends with value.
function endsWith(const value: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
// read-only position
function position: integer;
end;
implementation
@ -122,6 +128,11 @@ begin
len := length(str);
end;
function TStringRange.position: integer;
begin
Result := pos;
end;
function TStringRange.init(const pchr: PChar; length: integer): PStringRange;
begin
ptr := pchr;
@ -320,5 +331,13 @@ begin
value.pos := p1;
end;
function TStringRange.endsWith(const value: string): boolean;
begin
if empty then
Result := false
else
Result := ptr[pos .. length(value)-1] = value;
end;
end.