Merge pull request #4036 from dokuwiki/issue4033
[dokuwiki.git] / _test / vendor / symfony / css-selector / Parser / Reader.php
blob4b43effed366791caf393fe27fcb7c86801be016
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector\Parser;
14 /**
15 * CSS selector reader.
17 * This component is a port of the Python cssselect library,
18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
20 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
22 * @internal
24 class Reader
26 private $source;
27 private $length;
28 private $position = 0;
30 public function __construct(string $source)
32 $this->source = $source;
33 $this->length = \strlen($source);
36 public function isEOF(): bool
38 return $this->position >= $this->length;
41 public function getPosition(): int
43 return $this->position;
46 public function getRemainingLength(): int
48 return $this->length - $this->position;
51 public function getSubstring(int $length, int $offset = 0): string
53 return substr($this->source, $this->position + $offset, $length);
56 public function getOffset(string $string)
58 $position = strpos($this->source, $string, $this->position);
60 return false === $position ? false : $position - $this->position;
63 /**
64 * @return array|false
66 public function findPattern(string $pattern)
68 $source = substr($this->source, $this->position);
70 if (preg_match($pattern, $source, $matches)) {
71 return $matches;
74 return false;
77 public function moveForward(int $length)
79 $this->position += $length;
82 public function moveToEnd()
84 $this->position = $this->length;