wp-user-avatar
/
third-party
/
vendor
/
symfony
/
css-selector
/
Parser
/
Tokenizer
/
TokenizerPatterns.php
wp-user-avatar
/
third-party
/
vendor
/
symfony
/
css-selector
/
Parser
/
Tokenizer
Last commit date
Tokenizer.php
2 months ago
TokenizerEscaping.php
2 months ago
TokenizerPatterns.php
2 months ago
TokenizerPatterns.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace ProfilePressVendor\Symfony\Component\CssSelector\Parser\Tokenizer; |
| 12 | |
| 13 | /** |
| 14 | * CSS selector tokenizer patterns builder. |
| 15 | * |
| 16 | * This component is a port of the Python cssselect library, |
| 17 | * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. |
| 18 | * |
| 19 | * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> |
| 20 | * |
| 21 | * @internal |
| 22 | */ |
| 23 | class TokenizerPatterns |
| 24 | { |
| 25 | private $unicodeEscapePattern; |
| 26 | private $simpleEscapePattern; |
| 27 | private $newLineEscapePattern; |
| 28 | private $escapePattern; |
| 29 | private $stringEscapePattern; |
| 30 | private $nonAsciiPattern; |
| 31 | private $nmCharPattern; |
| 32 | private $nmStartPattern; |
| 33 | private $identifierPattern; |
| 34 | private $hashPattern; |
| 35 | private $numberPattern; |
| 36 | private $quotedStringPattern; |
| 37 | public function __construct() |
| 38 | { |
| 39 | $this->unicodeEscapePattern = '\\\\([0-9a-f]{1,6})(?:\r\n|[ \n\r\t\f])?'; |
| 40 | $this->simpleEscapePattern = '\\\\(.)'; |
| 41 | $this->newLineEscapePattern = '\\\\(?:\n|\r\n|\r|\f)'; |
| 42 | $this->escapePattern = $this->unicodeEscapePattern . '|\\\\[^\n\r\f0-9a-f]'; |
| 43 | $this->stringEscapePattern = $this->newLineEscapePattern . '|' . $this->escapePattern; |
| 44 | $this->nonAsciiPattern = '[^\x00-\x7F]'; |
| 45 | $this->nmCharPattern = '[_a-z0-9-]|' . $this->escapePattern . '|' . $this->nonAsciiPattern; |
| 46 | $this->nmStartPattern = '[_a-z]|' . $this->escapePattern . '|' . $this->nonAsciiPattern; |
| 47 | $this->identifierPattern = '-?(?:' . $this->nmStartPattern . ')(?:' . $this->nmCharPattern . ')*'; |
| 48 | $this->hashPattern = '#((?:' . $this->nmCharPattern . ')+)'; |
| 49 | $this->numberPattern = '[+-]?(?:[0-9]*\.[0-9]+|[0-9]+)'; |
| 50 | $this->quotedStringPattern = '([^\n\r\f\\\\%s]|' . $this->stringEscapePattern . ')*'; |
| 51 | } |
| 52 | public function getNewLineEscapePattern(): string |
| 53 | { |
| 54 | return '~' . $this->newLineEscapePattern . '~'; |
| 55 | } |
| 56 | public function getSimpleEscapePattern(): string |
| 57 | { |
| 58 | return '~' . $this->simpleEscapePattern . '~'; |
| 59 | } |
| 60 | public function getUnicodeEscapePattern(): string |
| 61 | { |
| 62 | return '~' . $this->unicodeEscapePattern . '~i'; |
| 63 | } |
| 64 | public function getIdentifierPattern(): string |
| 65 | { |
| 66 | return '~^' . $this->identifierPattern . '~i'; |
| 67 | } |
| 68 | public function getHashPattern(): string |
| 69 | { |
| 70 | return '~^' . $this->hashPattern . '~i'; |
| 71 | } |
| 72 | public function getNumberPattern(): string |
| 73 | { |
| 74 | return '~^' . $this->numberPattern . '~'; |
| 75 | } |
| 76 | public function getQuotedStringPattern(string $quote): string |
| 77 | { |
| 78 | return '~^' . sprintf($this->quotedStringPattern, $quote) . '~i'; |
| 79 | } |
| 80 | } |
| 81 |