You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

3 years ago
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\CssSelector\Parser\Handler;
  11. use Symfony\Component\CssSelector\Parser\Reader;
  12. use Symfony\Component\CssSelector\Parser\Token;
  13. use Symfony\Component\CssSelector\Parser\TokenStream;
  14. /**
  15. * CSS selector whitespace handler.
  16. *
  17. * This component is a port of the Python cssselect library,
  18. * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
  19. *
  20. * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
  21. *
  22. * @internal
  23. */
  24. class WhitespaceHandler implements HandlerInterface
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function handle(Reader $reader, TokenStream $stream): bool
  30. {
  31. $match = $reader->findPattern('~^[ \t\r\n\f]+~');
  32. if (false === $match) {
  33. return false;
  34. }
  35. $stream->push(new Token(Token::TYPE_WHITESPACE, $match[0], $reader->getPosition()));
  36. $reader->moveForward(\strlen($match[0]));
  37. return true;
  38. }
  39. }