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;
31 * @param string $source
33 public function __construct($source)
35 $this->source = $source;
36 $this->length = \strlen($source);
42 public function isEOF()
44 return $this->position >= $this->length;
50 public function getPosition()
52 return $this->position;
58 public function getRemainingLength()
60 return $this->length - $this->position;
69 public function getSubstring($length, $offset = 0)
71 return substr($this->source, $this->position + $offset, $length);
75 * @param string $string
79 public function getOffset($string)
81 $position = strpos($this->source, $string, $this->position);
83 return false === $position ? false : $position - $this->position;
87 * @param string $pattern
91 public function findPattern($pattern)
93 $source = substr($this->source, $this->position);
95 if (preg_match($pattern, $source, $matches)) {
105 public function moveForward($length)
107 $this->position += $length;
110 public function moveToEnd()
112 $this->position = $this->length;