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;
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>
26 const TYPE_FILE_END = 'eof';
27 const TYPE_DELIMITER = 'delimiter';
28 const TYPE_WHITESPACE = 'whitespace';
29 const TYPE_IDENTIFIER = 'identifier';
30 const TYPE_HASH = 'hash';
31 const TYPE_NUMBER = 'number';
32 const TYPE_STRING = 'string';
51 * @param string $value
52 * @param int $position
54 public function __construct($type, $value, $position)
57 $this->value = $value;
58 $this->position = $position;
64 public function getType()
72 public function getValue()
80 public function getPosition()
82 return $this->position;
88 public function isFileEnd()
90 return self::TYPE_FILE_END === $this->type;
94 * @param array $values
98 public function isDelimiter(array $values = array())
100 if (self::TYPE_DELIMITER !== $this->type) {
104 if (empty($values)) {
108 return in_array($this->value, $values);
114 public function isWhitespace()
116 return self::TYPE_WHITESPACE === $this->type;
122 public function isIdentifier()
124 return self::TYPE_IDENTIFIER === $this->type;
130 public function isHash()
132 return self::TYPE_HASH === $this->type;
138 public function isNumber()
140 return self::TYPE_NUMBER === $this->type;
146 public function isString()
148 return self::TYPE_STRING === $this->type;
154 public function __toString()
157 return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);
160 return sprintf('<%s at %s>', $this->type, $this->position);