Object TStringView

Unit

Declaration

type TStringView = object(TPcharView)

Description

A string view representing a subsequence of a string

See TPCharView and TPointerView for the general concept. TStringView keeps a reference to the original string, so it is fully memory safe.

For example, if you have a string '(123)', and want to convert the number between the parentheses to an integer, you can do:

var
  v: TStringView;
  number: integer;
  ok: boolean;
begin
  v := '(123)'.view;
  ok := v.rightOfFind('(');
  ok := ok and v.leftOfFind(')');
  ok := ok and v.toIntDecimalTry(number);

Hierarchy

Overview

Nested Types

Published TSplitOptions = (...);
Public TStringViewArray = array of TStringView;

Methods

Public procedure init(const buffer: string); reintroduce;
Public function viewLeftWith(newLast: pchar): TStringView; reintroduce;
Public function viewLeftOf(newEnd: pchar): TStringView; reintroduce;
Public function viewRightWith(newStart: pchar): TStringView; reintroduce;
Public function viewRightOf(newStartSkip: pchar): TStringView; reintroduce;
Public function splitAt(out before: TStringView; element: PChar; out behind: TStringView): boolean;
Public function splitLeftOf(element: PChar; out behind: TStringView): boolean;
Public function splitRightOf(out before: TStringView; element: PChar): boolean;
Public function splitAtFind(out before: TStringView; searched: pchar; searchedLength: SizeInt; out behind: TStringView): boolean;
Public function splitLeftOfFind(searched: pchar; searchedLength: SizeInt; out behind: TStringView): boolean;
Public function splitRightOfFind(out before: TStringView; searched: pchar; searchedLength: SizeInt): boolean;
Public function splitAtFind(out before: TStringView; const searched: string; out behind: TStringView): boolean;
Public function splitLeftOfFind(const searched: string; out behind: TStringView): boolean;
Public function splitRightOfFind(out before: TStringView; const searched: string): boolean;
Public function splitFindToArray(const sep: string; options: TSplitOptions = soNone): TStringViewArray;

Description

Nested Types

Published TSplitOptions = (...);
 
Values
  • soNone
  • soExcludeEmpty
  • soExcludeLastEmpty
Public TStringViewArray = array of TStringView;
 

Methods

Public procedure init(const buffer: string); reintroduce;

Creates a view for a string.

Public function viewLeftWith(newLast: pchar): TStringView; reintroduce;

copy and leftWith.

Public function viewLeftOf(newEnd: pchar): TStringView; reintroduce;

copy and leftOf.

Public function viewRightWith(newStart: pchar): TStringView; reintroduce;

copy and rightWith.

Public function viewRightOf(newStartSkip: pchar): TStringView; reintroduce;

copy and rightOf.

Public function splitAt(out before: TStringView; element: PChar; out behind: TStringView): boolean;

Splits the view at element. Everything before element is returned in before, everything behind it in behind. self is unchanged.

Public function splitLeftOf(element: PChar; out behind: TStringView): boolean;

Splits the view at element. Everything before element is returned in self, everything behind it in behind.

Public function splitRightOf(out before: TStringView; element: PChar): boolean;

Splits the view at element. Everything before element is returned in before, everything behind it in self.

Public function splitAtFind(out before: TStringView; searched: pchar; searchedLength: SizeInt; out behind: TStringView): boolean;

Splits the view at the first occurrence of searched. Everything before searched is returned in before, everything behind (searched+searchedLength) in behind. Self is unchanged.

Public function splitLeftOfFind(searched: pchar; searchedLength: SizeInt; out behind: TStringView): boolean;

Splits the view at the first occurrence of searched. Everything before searched is returned in self, everything behind (searched+searchedLength) in behind.

Public function splitRightOfFind(out before: TStringView; searched: pchar; searchedLength: SizeInt): boolean;

Splits the view at the first occurrence of searched. Everything before searched is returned in before, everything behind (searched+searchedLength) in self.

Public function splitAtFind(out before: TStringView; const searched: string; out behind: TStringView): boolean;

Splits the view at the first occurrence of searched. Everything before searched is returned in before, everything behind (searched+searchedLength) in behind. Self is unchanged.

Public function splitLeftOfFind(const searched: string; out behind: TStringView): boolean;

Splits the view at the first occurrence of searched. Everything before searched is returned in self, everything behind searched in behind.

Public function splitRightOfFind(out before: TStringView; const searched: string): boolean;

Splits the view at the first occurrence of searched. Everything before searched is returned in before, everything behind searched in self.

Public function splitFindToArray(const sep: string; options: TSplitOptions = soNone): TStringViewArray;
 

Generated by PasDoc 0.16.0.