$defaultEncoding
$defaultEncoding : string
The default encoding to use while reading.
A string reading utility that searches strings byte by byte.
peek(integer $length = null, integer $start = null) : string|null
Peeks one or multiple characters without moving the pointer forward.
The peeked length will be stored and can be consumed with consume()
later on.
integer | $length | the length to consume (default: 1). |
integer | $start | the offset to start on based on the current offset (default: 0). |
the peeked string or null if reading is finished.
match(string $pattern, string $modifiers = null, string $ignoredSuffixes = null) : boolean
Matches current input string against a regular expression.
The result length will be stored and can be consumed with consume()
later on.
Notice that ^ is automatically prepended to the pattern.
string | $pattern | the regular expression without slashes or modifiers. |
string | $modifiers | the modifiers for the regular expression. |
string | $ignoredSuffixes | characters that are scanned, but don't end up in the consume length. |
wether the expression matched or not.
consume(integer $length = null) : string
Consumes part of the input string and advances internal counters.
When no length is given, it will use the last peek()
or match()
length automatically.
Use this after successful peek()
or match()
-operations.
integer | $length | the length to consume (default: null) |
readWhile(callable $callback, integer $peekLength = null) : string|null
Reads part of a string until it doesn't match the given callback anymore.
The string part is consumed directly, no consume()
is required after read()
-operations.
callable | $callback | the callback to check string parts against. |
integer | $peekLength | the length to peek for each iteration. (default: 1) |
the result string or null if finished reading.
readUntil(callable $callback, integer $peekLength = null) : string|null
The opposite of `readWhile()`. Reads a string until the callback matches the string part.
callable | $callback | the callback to check string parts against. |
integer | $peekLength | the length to peek for each iteration. (default: 1) |
the result string or null if finished reading.
peekChars(string|array $chars) : boolean
Peeks one byte and checks if it equals the given characters.
You can pass the characters as a string containing them all or as an array.
string|array | $chars | the characters to check against. |
whether one of them match or not.
readIdentifier(string $prefix = null, array $allowedChars = null) : string|null
Reads an upcoming alpha-numeric identifier in a string.
Identifiers start with an alphabetical character and then follow with alpha-numeric characters.
string | $prefix | the prefix for an identifier (e.g. $, @, % etc., default: none) |
array | $allowedChars | additional chars to allow in the identifier (default: ['_']) |
the resulting identifier or null of none encountered.
readString(array $escapeSequences = null, boolean $raw = false) : string|null
Reads an enclosed string correctly.
Strings start with a quote and end with that same quote while other quotes inside it are ignored, including other kinds of expressions.
The quote itself is automatically passed as an escape sequence, so a '-enclosed string always knows \' as an escape expression.
array | $escapeSequences | |
boolean | $raw | whether to return the string raw, with quotes and keep escape sequences intact. |
the resulting string or null if none encountered.
readExpression(array $breaks = null, array $brackets = null) : string|null
Reads a code-expression that applies bracket counting correctly.
The expression reading stops on any string specified in the $breaks
-argument.
Breaks will be ignored if we are still in an open bracket.
Notice that this also validates brackets, if any bracket set doesn't match, this will throw an exception (e.g. "callMe(['demacia')]" would throw an exception)
array | $breaks | the break characters to use (Breaks on string end by default). |
array | $brackets | the brackets to allow (Defaulting to whatever is defined in Reader->expressionBrackets) |
the resulting expression or null, if none encountered.