PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Libraries / Symfony / CssSelector / Parser / Tokenizer / Tokenizer.php

Tokenizer.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at back/Libraries/Symfony/CssSelector/Parser/Tokenizer/Tokenizer.php

74 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace AcyMailing\Libraries\Symfony\CssSelector\Parser\Tokenizer;
13
14 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Handler;
15 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Reader;
16 use AcyMailing\Libraries\Symfony\CssSelector\Parser\Token;
17 use AcyMailing\Libraries\Symfony\CssSelector\Parser\TokenStream;
18
19 /**
20 * CSS selector tokenizer.
21 *
22 * This component is a port of the Python cssselect library,
23 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
24 *
25 * @author Jean-François Simon <[email protected]>
26 *
27 * @internal
28 */
29 class Tokenizer
30 {
31 /**
32 * @var Handler\HandlerInterface[]
33 */
34 private $handlers;
35
36 public function __construct()
37 {
38 $patterns = new TokenizerPatterns();
39 $escaping = new TokenizerEscaping($patterns);
40
41 $this->handlers = [
42 new Handler\WhitespaceHandler(),
43 new Handler\IdentifierHandler($patterns, $escaping),
44 new Handler\HashHandler($patterns, $escaping),
45 new Handler\StringHandler($patterns, $escaping),
46 new Handler\NumberHandler($patterns),
47 new Handler\CommentHandler(),
48 ];
49 }
50
51 /**
52 * Tokenize selector source code.
53 */
54 public function tokenize(Reader $reader): TokenStream
55 {
56 $stream = new TokenStream();
57
58 while (!$reader->isEOF()) {
59 foreach ($this->handlers as $handler) {
60 if ($handler->handle($reader, $stream)) {
61 continue 2;
62 }
63 }
64
65 $stream->push(new Token(Token::TYPE_DELIMITER, $reader->getSubstring(1), $reader->getPosition()));
66 $reader->moveForward(1);
67 }
68
69 return $stream
70 ->push(new Token(Token::TYPE_FILE_END, null, $reader->getPosition()))
71 ->freeze();
72 }
73 }
74