Cursor
in package
Table of Contents
Constants
- INDENT_LEVEL = 4
Properties
- $charCache : array<int, string>
- $column : int
- $currentPosition : int
- $indent : int
- $isMultibyte : bool
- $lastTabPosition : int|false
- $length : int
- $line : string
- $nextNonSpaceCache : int|null
- $partiallyConsumedTab : bool
- $previousPosition : int
Methods
- __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
- getCurrentCharacter() : string|null
- Slightly-optimized version of getCurrent(null)
- getIndent() : int
- Calculates the current indent (number of spaces after current position)
- getLine() : string
- getNextNonSpaceCharacter() : string|null
- 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() : CursorState
- 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
It's possible for this to be 1 char past the end, meaning we've parsed all chars and have reached the end. In this state, any character-returning method MUST return null.
$indent
private
int
$indent
= 0
$isMultibyte
private
bool
$isMultibyte
Tags
$lastTabPosition
private
int|false
$lastTabPosition
Tags
$length
private
int
$length
Tags
$line
private
string
$line
Tags
$nextNonSpaceCache
private
int|null
$nextNonSpaceCache
= null
$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)
advance()
Move the cursor forwards
public
advance() : 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
advanceBySpaceOrTab()
Advances the cursor by a single space or tab, if present
public
advanceBySpaceOrTab() : bool
Return values
booladvanceToEnd()
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|nullgetColumn()
public
getColumn() : int
Return values
intgetCurrentCharacter()
Slightly-optimized version of getCurrent(null)
public
getCurrentCharacter() : string|null
Return values
string|nullgetIndent()
Calculates the current indent (number of spaces after current position)
public
getIndent() : int
Return values
intgetLine()
public
getLine() : string
Return values
stringgetNextNonSpaceCharacter()
Returns the next character which isn't a space (or tab)
public
getNextNonSpaceCharacter() : string|null
Return values
string|nullgetNextNonSpacePosition()
Returns the position of the next character which is not a space (or tab)
public
getNextNonSpacePosition() : int
Return values
intgetPosition()
public
getPosition() : int
Return values
intgetPreviousText()
public
getPreviousText() : string
Return values
stringgetRemainder()
public
getRemainder() : string
Return values
stringgetSubstring()
public
getSubstring(int $start[, int|null $length = null ]) : string
Parameters
- $start : int
- $length : int|null = null
Return values
stringisAtEnd()
public
isAtEnd() : bool
Return values
boolisBlank()
Whether the remainder is blank
public
isBlank() : bool
Return values
boolisIndented()
Whether the cursor is indented to INDENT_LEVEL
public
isIndented() : bool
Return values
boolmatch()
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
Tags
Return values
string|nullpeek()
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|nullrestoreState()
Restore the cursor to a previous state.
public
restoreState(CursorState $state) : void
Pass in the value previously obtained by calling saveState().
Parameters
- $state : CursorState
saveState()
Encapsulates the current state of this cursor in case you need to rollback later.
public
saveState() : CursorState
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.