Cursor
in package
Table of Contents
- INDENT_LEVEL = 4
- $charCache : array<int, string>
- $column : int
- $currentPosition : int
- $indent : int
- $isMultibyte : bool
- $length : int
- $line : string
- $lineContainsTabs : bool
- $nextNonSpaceCache : int|null
- $partiallyConsumedTab : bool
- $previousPosition : int
- __construct() : mixed
- advance() : void
- Move the cursor forwards
- advanceBy() : void
- Move the cursor forwards
- advanceBySpaceOrTab() : bool
- Advances the cursor by a single space or tab, if present
- advanceToEnd() : int
- Move the position to the very end of the line
- advanceToNextNonSpaceOrNewline() : int
- Parse zero or more space characters, including at most one newline.
- advanceToNextNonSpaceOrTab() : int
- Parse zero or more space/tab characters
- getCharacter() : string|null
- getColumn() : int
- getIndent() : int
- Calculates the current indent (number of spaces after current position)
- getLine() : string
- getNextNonSpaceCharacter() : string
- Returns the next character which isn't a space (or tab)
- getNextNonSpacePosition() : int
- Returns the position of the next character which is not a space (or tab)
- getPosition() : int
- getPreviousText() : string
- getRemainder() : string
- getSubstring() : string
- isAtEnd() : bool
- isBlank() : bool
- Whether the remainder is blank
- isIndented() : bool
- Whether the cursor is indented to INDENT_LEVEL
- match() : string|null
- Try to match a regular expression
- peek() : string|null
- Returns the next character (or null, if none) without advancing forwards
- restoreState() : void
- Restore the cursor to a previous state.
- saveState() : array<string|int, mixed>
- Encapsulates the current state of this cursor in case you need to rollback later.
Constants
INDENT_LEVEL
public
mixed
INDENT_LEVEL
= 4
Properties
$charCache
private
array<int, string>
$charCache
= []
$column
private
int
$column
= 0
$currentPosition
private
int
$currentPosition
= 0
$indent
private
int
$indent
= 0
$isMultibyte
private
bool
$isMultibyte
$length
private
int
$length
$line
private
string
$line
$lineContainsTabs
private
bool
$lineContainsTabs
$nextNonSpaceCache
private
int|null
$nextNonSpaceCache
$partiallyConsumedTab
private
bool
$partiallyConsumedTab
= false
$previousPosition
private
int
$previousPosition
= 0
Methods
__construct()
public
__construct(string $line) : mixed
Parameters
- $line : string
-
The line being parsed (ASCII or UTF-8)
Return values
mixed —advance()
Move the cursor forwards
public
advance() : void
Return values
void —advanceBy()
Move the cursor forwards
public
advanceBy(int $characters[, bool $advanceByColumns = false ]) : void
Parameters
- $characters : int
-
Number of characters to advance by
- $advanceByColumns : bool = false
-
Whether to advance by columns instead of spaces
Return values
void —advanceBySpaceOrTab()
Advances the cursor by a single space or tab, if present
public
advanceBySpaceOrTab() : bool
Return values
bool —advanceToEnd()
Move the position to the very end of the line
public
advanceToEnd() : int
Return values
int —The number of characters moved
advanceToNextNonSpaceOrNewline()
Parse zero or more space characters, including at most one newline.
public
advanceToNextNonSpaceOrNewline() : int
Tab characters are not parsed with this function.
Return values
int —Number of positions moved
advanceToNextNonSpaceOrTab()
Parse zero or more space/tab characters
public
advanceToNextNonSpaceOrTab() : int
Return values
int —Number of positions moved
getCharacter()
public
getCharacter([int|null $index = null ]) : string|null
Parameters
- $index : int|null = null
Return values
string|null —getColumn()
public
getColumn() : int
Return values
int —getIndent()
Calculates the current indent (number of spaces after current position)
public
getIndent() : int
Return values
int —getLine()
public
getLine() : string
Return values
string —getNextNonSpaceCharacter()
Returns the next character which isn't a space (or tab)
public
getNextNonSpaceCharacter() : string
Return values
string —getNextNonSpacePosition()
Returns the position of the next character which is not a space (or tab)
public
getNextNonSpacePosition() : int
Return values
int —getPosition()
public
getPosition() : int
Return values
int —getPreviousText()
public
getPreviousText() : string
Return values
string —getRemainder()
public
getRemainder() : string
Return values
string —getSubstring()
public
getSubstring(int $start[, int|null $length = null ]) : string
Parameters
- $start : int
- $length : int|null = null
Return values
string —isAtEnd()
public
isAtEnd() : bool
Return values
bool —isBlank()
Whether the remainder is blank
public
isBlank() : bool
Return values
bool —isIndented()
Whether the cursor is indented to INDENT_LEVEL
public
isIndented() : bool
Return values
bool —match()
Try to match a regular expression
public
match(string $regex) : string|null
Returns the matching text and advances to the end of that match
Parameters
- $regex : string
Return values
string|null —peek()
Returns the next character (or null, if none) without advancing forwards
public
peek([int $offset = 1 ]) : string|null
Parameters
- $offset : int = 1
Return values
string|null —restoreState()
Restore the cursor to a previous state.
public
restoreState(array<string|int, mixed> $state) : void
Pass in the value previously obtained by calling saveState().
Parameters
- $state : array<string|int, mixed>
Return values
void —saveState()
Encapsulates the current state of this cursor in case you need to rollback later.
public
saveState() : array<string|int, mixed>
WARNING: Do not parse or use the return value for ANYTHING except for passing it back into restoreState(), as the number of values and their contents may change in any future release without warning.