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
;
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>
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
;
66 public function findPattern(string $pattern)
68 $source = substr($this->source
, $this->position
);
70 if (preg_match($pattern, $source, $matches)) {
77 public function moveForward(int $length)
79 $this->position +
= $length;
82 public function moveToEnd()
84 $this->position
= $this->length
;