CommentHandler.php
2 years ago
HandlerInterface.php
2 years ago
HashHandler.php
2 years ago
IdentifierHandler.php
2 years ago
NumberHandler.php
2 years ago
StringHandler.php
2 years ago
WhitespaceHandler.php
2 years ago
index.php
2 years ago
StringHandler.php
45 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Parser\Handler; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\CssSelector\Exception\InternalErrorException; |
| 5 | use MailPoetVendor\Symfony\Component\CssSelector\Exception\SyntaxErrorException; |
| 6 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Reader; |
| 7 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Token; |
| 8 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping; |
| 9 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns; |
| 10 | use MailPoetVendor\Symfony\Component\CssSelector\Parser\TokenStream; |
| 11 | class StringHandler implements HandlerInterface |
| 12 | { |
| 13 | private $patterns; |
| 14 | private $escaping; |
| 15 | public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping) |
| 16 | { |
| 17 | $this->patterns = $patterns; |
| 18 | $this->escaping = $escaping; |
| 19 | } |
| 20 | public function handle(Reader $reader, TokenStream $stream) : bool |
| 21 | { |
| 22 | $quote = $reader->getSubstring(1); |
| 23 | if (!\in_array($quote, ["'", '"'])) { |
| 24 | return \false; |
| 25 | } |
| 26 | $reader->moveForward(1); |
| 27 | $match = $reader->findPattern($this->patterns->getQuotedStringPattern($quote)); |
| 28 | if (!$match) { |
| 29 | throw new InternalErrorException(\sprintf('Should have found at least an empty match at %d.', $reader->getPosition())); |
| 30 | } |
| 31 | // check unclosed strings |
| 32 | if (\strlen($match[0]) === $reader->getRemainingLength()) { |
| 33 | throw SyntaxErrorException::unclosedString($reader->getPosition() - 1); |
| 34 | } |
| 35 | // check quotes pairs validity |
| 36 | if ($quote !== $reader->getSubstring(1, \strlen($match[0]))) { |
| 37 | throw SyntaxErrorException::unclosedString($reader->getPosition() - 1); |
| 38 | } |
| 39 | $string = $this->escaping->escapeUnicodeAndNewLine($match[0]); |
| 40 | $stream->push(new Token(Token::TYPE_STRING, $string, $reader->getPosition())); |
| 41 | $reader->moveForward(\strlen($match[0]) + 1); |
| 42 | return \true; |
| 43 | } |
| 44 | } |
| 45 |