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>
39 private $position = 0;
42 * @param string $source
44 public function __construct($source)
46 $this->source = $source;
47 $this->length = strlen($source);
53 public function isEOF()
55 return $this->position >= $this->length;
61 public function getPosition()
63 return $this->position;
69 public function getRemainingLength()
71 return $this->length - $this->position;
80 public function getSubstring($length, $offset = 0)
82 return substr($this->source, $this->position + $offset, $length);
86 * @param string $string
90 public function getOffset($string)
92 $position = strpos($this->source, $string, $this->position);
94 return false === $position ? false : $position - $this->position;
98 * @param string $pattern
102 public function findPattern($pattern)
104 $source = substr($this->source, $this->position);
106 if (preg_match($pattern, $source, $matches)) {
116 public function moveForward($length)
118 $this->position += $length;
121 public function moveToEnd()
123 $this->position = $this->length;