Object TPCharView
Unit
Declaration
type TPCharView = object(specialize TPointerView<char>)
Description
A string view representing a subsequence of a string or pchar or char array.
See TPointerView for the general concept. TPCharView
extends TPointerView with methods for string inputs.
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: TPCharView; number: integer; ok: boolean; begin v := '(123)'.pcharView; ok := v.rightOfFind('('); ok := ok and v.leftOfFind(')'); ok := ok and v.toIntDecimalTry(number);
The integer is returned in the variable number and the variable ok returns whether the parentheses exist and the conversion was successful.
This is fast (zero allocations) and safe (no out-of-bound access or overflow is possible).
(although you need to make sure the string is not destroyed while using the TPcharView
. For truly safe operations, use TStringView)
Hierarchy
- TObject
- TPointerView
- TPCharView
Overview
Methods
![]() |
procedure init(const buffer: string); overload; |
![]() |
procedure init(const buffer: TBytes); overload; |
![]() |
function ToString: string; |
![]() |
function length: SizeInt; reintroduce; |
![]() |
function contains(const s: string): boolean; inline; |
![]() |
function beginsWith(const s: string): boolean; inline; |
![]() |
function endsWith(const expectedEnd: string): boolean; inline; |
![]() |
function find(searched: pchar; searchedLength: SizeInt): pchar; |
![]() |
function find(const s: string): pchar; |
![]() |
function findLast(searched: pchar; searchedLength: SizeInt): pchar; |
![]() |
function findLast(const s: string): pchar; |
![]() |
function rightWithFind(const s: string): boolean; |
![]() |
function rightOfFind(const s: string): boolean; |
![]() |
function rightWithFindLast(const s: string): boolean; |
![]() |
function rightOfFindLast(const s: string): boolean; |
![]() |
function findLineBreak: pchar; |
![]() |
function rightWithLineBreak: boolean; |
![]() |
function rightOfLineBreak: boolean; |
![]() |
function leftOfFind(const s: string): boolean; |
![]() |
function leftWithFind(const s: string): boolean; |
![]() |
function leftOfFindLast(const s: string): boolean; |
![]() |
function leftWithFindLast(const s: string): boolean; |
![]() |
procedure trim(const trimCharacters: TCharSet = [#0..' ']); |
![]() |
procedure trimLeft(const trimCharacters: TCharSet = [#0..' ']); |
![]() |
procedure trimRight(const trimCharacters: TCharSet = [#0..' ']); |
![]() |
procedure trim(trimChar: char); |
![]() |
procedure trimLeft(trimChar: char); |
![]() |
procedure trimRight(trimChar: char); |
![]() |
function toIntDecimalTry(out v: Int64): boolean; |
![]() |
function toIntDecimalTry(out v: Int32): boolean; |
![]() |
function toUIntDecimalTry(out v: UInt64): boolean; |
![]() |
function toUIntDecimalTry(out v: UInt32): boolean; |
![]() |
function viewLeftWith(newLast: pchar): TPCharView; reintroduce; |
![]() |
function viewLeftOf(newEnd: pchar): TPCharView; reintroduce; |
![]() |
function viewRightWith(newStart: pchar): TPCharView; reintroduce; |
![]() |
function viewRightOf(newStartSkip: pchar): TPCharView; reintroduce; |
![]() |
function splitAt(out before: TPCharView; element: PChar; out behind: TPCharView): boolean; |
![]() |
function splitLeftOf(element: PChar; out behind: TPCharView): boolean; |
![]() |
function splitRightOf(out before: TPCharView; element: PChar): boolean; |
![]() |
function splitAtFind(out before: TPCharView; searched: pchar; searchedLength: SizeInt; out behind: TPCharView): boolean; |
![]() |
function splitLeftOfFind(searched: pchar; searchedLength: SizeInt; out behind: TPCharView): boolean; |
![]() |
function splitRightOfFind(out before: TPCharView; searched: pchar; searchedLength: SizeInt): boolean; |
![]() |
function splitAtFind(out before: TPCharView; const searched: string; out behind: TPCharView): boolean; |
![]() |
function splitLeftOfFind(const searched: string; out behind: TPCharView): boolean; |
![]() |
function splitRightOfFind(out before: TPCharView; const searched: string): boolean; |
Description
Methods
![]() |
procedure init(const buffer: string); overload; |
Creates a view for a string. |
![]() |
procedure init(const buffer: TBytes); overload; |
Creates a view for a byte array. |
![]() |
function ToString: string; |
Converts the view to a string. |
![]() |
function length: SizeInt; reintroduce; |
|
![]() |
function contains(const s: string): boolean; inline; |
Tests whether the view |
![]() |
function beginsWith(const s: string): boolean; inline; |
Tests whether the view starts with a string. |
![]() |
function endsWith(const expectedEnd: string): boolean; inline; |
Tests whether the view ends with a string. |
![]() |
function find(searched: pchar; searchedLength: SizeInt): pchar; |
![]() |
function find(const s: string): pchar; |
![]() |
function findLast(searched: pchar; searchedLength: SizeInt): pchar; |
![]() |
function findLast(const s: string): pchar; |
![]() |
function rightWithFind(const s: string): boolean; |
Removes all characters before the first occurrence of a string s (keeps s itself). Keeps the view unchanged if it does not contain s. |
![]() |
function rightOfFind(const s: string): boolean; |
Removes all characters before the first occurrence of a string s (removes s, too). Keeps the view unchanged if it does not contain s. |
![]() |
function rightWithFindLast(const s: string): boolean; |
Removes all characters before the last occurrence of a string s (keeps s itself). Keeps the view unchanged if it does not contain s. |
![]() |
function rightOfFindLast(const s: string): boolean; |
Removes all characters before the last occurrence of a string s (removes s, too). Keeps the view unchanged if it does not contain s. |
![]() |
function findLineBreak: pchar; |
finds #13 or #10 (implicit #13#10) |
![]() |
function rightWithLineBreak: boolean; |
Remves everything before the first line break (exclusive). |
![]() |
function rightOfLineBreak: boolean; |
Remves everything before the first line break (inclusive). |
![]() |
function leftOfFind(const s: string): boolean; |
Removes all characters after the first occurrence of a string (removes s, too). Keeps the view unchanged if it does not contain s. |
![]() |
function leftWithFind(const s: string): boolean; |
Removes all characters after the first occurrence of a string (keeps s itself). Keeps the view unchanged if it does not contain s. |
![]() |
function leftOfFindLast(const s: string): boolean; |
Removes all characters after the last occurrence of a string (removes s, too). Keeps the view unchanged if it does not contain s. |
![]() |
function leftWithFindLast(const s: string): boolean; |
Removes all characters after the last occurrence of a string (keeps s itself). Keeps the view unchanged if it does not contain s. |
![]() |
procedure trim(const trimCharacters: TCharSet = [#0..' ']); |
Removes all whitespace characters from the left and right side. |
![]() |
procedure trimLeft(const trimCharacters: TCharSet = [#0..' ']); |
Removes all whitespace characters from the left side. |
![]() |
procedure trimRight(const trimCharacters: TCharSet = [#0..' ']); |
Removes all whitespace characters from the right side. |
![]() |
procedure trim(trimChar: char); |
Removes all whitespace characters trimChar from the left and right side. |
![]() |
procedure trimLeft(trimChar: char); |
Removes all whitespace characters trimChar from the left side. |
![]() |
procedure trimRight(trimChar: char); |
Removes all whitespace characters trimChar from the right side. |
![]() |
function toIntDecimalTry(out v: Int64): boolean; |
Converts the view to a signed integer. Returns true if it matches -?[0-9]+ and does not overflow. |
![]() |
function toIntDecimalTry(out v: Int32): boolean; |
Converts the view to a signed integer. Returns true if it matches -?[0-9]+ and does not overflow. |
![]() |
function toUIntDecimalTry(out v: UInt64): boolean; |
Converts the view to an unsigned integer. Returns true if it matches [0-9]+ and does not overflow. |
![]() |
function toUIntDecimalTry(out v: UInt32): boolean; |
Converts the view to an unsigned integer. Returns true if it matches [0-9]+ and does not overflow. |
![]() |
function viewLeftWith(newLast: pchar): TPCharView; reintroduce; |
copy and leftWith. |
![]() |
function viewLeftOf(newEnd: pchar): TPCharView; reintroduce; |
copy and leftOf. |
![]() |
function viewRightWith(newStart: pchar): TPCharView; reintroduce; |
copy and rightWith. |
![]() |
function viewRightOf(newStartSkip: pchar): TPCharView; reintroduce; |
copy and rightOf. |
![]() |
function splitAt(out before: TPCharView; element: PChar; out behind: TPCharView): boolean; |
Splits the view at element. Everything before element is returned in before, everything behind it in behind. self is unchanged. |
![]() |
function splitLeftOf(element: PChar; out behind: TPCharView): boolean; |
Splits the view at element. Everything before element is returned in self, everything behind it in behind. |
![]() |
function splitRightOf(out before: TPCharView; element: PChar): boolean; |
Splits the view at element. Everything before element is returned in before, everything behind it in self. |
![]() |
function splitAtFind(out before: TPCharView; searched: pchar; searchedLength: SizeInt; out behind: TPCharView): 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. |
![]() |
function splitLeftOfFind(searched: pchar; searchedLength: SizeInt; out behind: TPCharView): boolean; |
Splits the view at the first occurrence of searched. Everything before searched is returned in self, everything behind (searched+searchedLength) in behind. |
![]() |
function splitRightOfFind(out before: TPCharView; 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. |
![]() |
function splitAtFind(out before: TPCharView; const searched: string; out behind: TPCharView): 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. |
![]() |
function splitLeftOfFind(const searched: string; out behind: TPCharView): boolean; |
Splits the view at the first occurrence of searched. Everything before searched is returned in self, everything behind searched in behind. |
![]() |
function splitRightOfFind(out before: TPCharView; 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. |
Generated by PasDoc 0.16.0.