Handler
2 years ago
Shortcut
2 years ago
Tokenizer
2 years ago
Parser.php
2 years ago
ParserInterface.php
2 years ago
Reader.php
2 years ago
Token.php
2 years ago
TokenStream.php
2 years ago
index.php
2 years ago
Reader.php
52 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Parser; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class Reader |
| 5 | { |
| 6 | private $source; |
| 7 | private $length; |
| 8 | private $position = 0; |
| 9 | public function __construct(string $source) |
| 10 | { |
| 11 | $this->source = $source; |
| 12 | $this->length = \strlen($source); |
| 13 | } |
| 14 | public function isEOF() : bool |
| 15 | { |
| 16 | return $this->position >= $this->length; |
| 17 | } |
| 18 | public function getPosition() : int |
| 19 | { |
| 20 | return $this->position; |
| 21 | } |
| 22 | public function getRemainingLength() : int |
| 23 | { |
| 24 | return $this->length - $this->position; |
| 25 | } |
| 26 | public function getSubstring(int $length, int $offset = 0) : string |
| 27 | { |
| 28 | return \substr($this->source, $this->position + $offset, $length); |
| 29 | } |
| 30 | public function getOffset(string $string) |
| 31 | { |
| 32 | $position = \strpos($this->source, $string, $this->position); |
| 33 | return \false === $position ? \false : $position - $this->position; |
| 34 | } |
| 35 | public function findPattern(string $pattern) |
| 36 | { |
| 37 | $source = \substr($this->source, $this->position); |
| 38 | if (\preg_match($pattern, $source, $matches)) { |
| 39 | return $matches; |
| 40 | } |
| 41 | return \false; |
| 42 | } |
| 43 | public function moveForward(int $length) |
| 44 | { |
| 45 | $this->position += $length; |
| 46 | } |
| 47 | public function moveToEnd() |
| 48 | { |
| 49 | $this->position = $this->length; |
| 50 | } |
| 51 | } |
| 52 |