add self return to TStringRange.popFront + add TStringRange.popFrontN

This commit is contained in:
Basile Burg 2016-08-29 11:24:33 +02:00
parent 7d0f3212c1
commit 0b8c3bf093
4 changed files with 18 additions and 12 deletions

View File

@ -294,9 +294,7 @@ begin
end;
with TStringRange.create(pge) do while not empty do
begin
popUntil('"');
popFront;
fList.Add(takeUntil('"').yield);
fList.Add(popUntil('"')^.popFront^.takeUntil('"').yield);
popFront;
end;
cbb.Items.clear;

View File

@ -2536,11 +2536,10 @@ begin
rng.init(firstLineFlags);
if rng.startsWith('#!') then
begin
rng.popFront;
rng.popFront;
rng.popWhile([' ', #9]);
rng.popUntil([' ', #9, ':']);
rng.popWhile([' ', #9, ':']);
rng.popFrontN(2)^
.popWhile([' ', #9])^
.popUntil([' ', #9, ':'])^
.popWhile([' ', #9, ':']);
firstlineFlags := rng.takeUntil(#0).yield;
firstlineFlags := fSymStringExpander.expand(firstlineFlags);
lst := TStringList.Create;

View File

@ -43,7 +43,9 @@ type
function init(const pchr: PChar; length: integer): PStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances.
procedure popFront; {$IFNDEF DEBUG}inline;{$ENDIF}
function popFront: PStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances N times
function popFrontN(n: integer): PStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// returns the current element.
function front: char; {$IFNDEF DEBUG}inline;{$ENDIF}
// indicates wether the range is consumed.
@ -125,9 +127,16 @@ begin
Result := @self;
end;
procedure TStringRange.popFront;
function TStringRange.popFront: PStringRange;
begin
pos += 1;
Result := @self;
end;
function TStringRange.popFrontN(n: integer): PStringRange;
begin
pos += n;
Result := @self;
end;
function TStringRange.front: char;

View File

@ -269,8 +269,8 @@ begin
Result += rng.takeUntil('<').yield;
if not rng.empty and (rng.front = '<') then
begin
rng.popFront;
sym := rng.takeUntil('>').yield;
;
sym := rng.popFront^.takeUntil('>').yield;
if not rng.empty and (rng.front = '>') then
begin
rng.popFront;