fix string range, startsWith

+ disable inlining in dbg mode
This commit is contained in:
Basile Burg 2016-03-20 18:45:54 +01:00
parent 930d3577e5
commit 9e873f6aec
1 changed files with 26 additions and 22 deletions

View File

@ -38,45 +38,49 @@ type
class function create(const pchr: PChar; length: integer): TStringRange; static; class function create(const pchr: PChar; length: integer): TStringRange; static;
// initializes the range with a string. // initializes the range with a string.
function init(const str: string): PStringRange; inline; function init(const str: string): PStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// initialized the range from a pointer. // initialized the range from a pointer.
function init(const pchr: PChar; length: integer): PStringRange; inline; function init(const pchr: PChar; length: integer): PStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances. // advances.
procedure popFront; inline; procedure popFront; {$IFNDEF DEBUG}inline;{$ENDIF}
// returns the current element. // returns the current element.
function front: char; inline; function front: char; {$IFNDEF DEBUG}inline;{$ENDIF}
// indicates wether the range is consumed. // indicates wether the range is consumed.
function empty: boolean; inline; function empty: boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
// yields the state of the range to a string. // yields the state of the range to a string.
function yield: string; inline; function yield: string; {$IFNDEF DEBUG}inline;{$ENDIF}
// returns a copy. // returns a copy.
function save: TStringRange; inline; function save: TStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// resets the range. // resets the range.
function reset: PStringRange; inline; function reset: PStringRange; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances the range while the front is in value, returns a copy. // advances the range while the front is in value, returns a copy.
function takeWhile(value: TSysCharSet): TStringRange; overload; inline; function takeWhile(value: TSysCharSet): TStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
function takeWhile(value: Char): TStringRange; overload; inline; // advances the range while the front is equal to value, returns a copy.
function takeWhile(value: Char): TStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances the range until the front is in value, returns a copy. // advances the range until the front is in value, returns a copy.
function takeUntil(value: TSysCharSet): TStringRange; overload; inline; function takeUntil(value: TSysCharSet): TStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
function takeUntil(value: Char): TStringRange; overload; inline; // advances the range until the front is equal to value, returns a copy.
function takeUntil(value: Char): TStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances the range while the front is in value. // advances the range while the front is in value.
function popWhile(value: TSysCharSet): PStringRange; overload; inline; function popWhile(value: TSysCharSet): PStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
function popWhile(value: Char): PStringRange; overload; inline; // advances the range while the front is equal to value.
function popWhile(value: Char): PStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
// advances the range until the front is in value. // advances the range until the front is in value.
function popUntil(value: TSysCharSet): PStringRange; overload; inline; function popUntil(value: TSysCharSet): PStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
function popUntil(value: Char): PStringRange; overload; inline; // advances the range until the front is equal to value.
function popUntil(value: Char): PStringRange; overload; {$IFNDEF DEBUG}inline;{$ENDIF}
// returns the next word. // returns the next word.
function nextWord: string; inline; function nextWord: string; {$IFNDEF DEBUG}inline;{$ENDIF}
// returns the next line. // returns the next line.
function nextLine: string; inline; function nextLine: string; {$IFNDEF DEBUG}inline;{$ENDIF}
// indicates wether the range starts with value. // indicates wether the range starts with value.
function startsWith(const value: string): boolean; inline; function startsWith(const value: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
// indicates wether the range starts with value. // indicates wether the range starts with value.
function startsWith(var value: TStringRange): boolean; inline; function startsWith(var value: TStringRange): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
end; end;
implementation implementation
@ -266,8 +270,8 @@ end;
function TStringRange.startsWith(const value: string): boolean; function TStringRange.startsWith(const value: string): boolean;
begin begin
Result := false; Result := false;
if len - pos <= length(value) then if len - pos >= length(value) then
Result := ptr[pos .. pos + length(value)] = value; Result := ptr[pos .. pos + length(value)-1] = value;
end; end;
function TStringRange.startsWith(var value: TStringRange): boolean; function TStringRange.startsWith(var value: TStringRange): boolean;