Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / css-selector / Parser / Tokenizer / TokenizerPatterns.php
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
12 namespace Symfony\Component\CssSelector\Parser\Tokenizer;
13
14 /**
15  * CSS selector tokenizer patterns builder.
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 TokenizerPatterns
25 {
26     private $unicodeEscapePattern;
27     private $simpleEscapePattern;
28     private $newLineEscapePattern;
29     private $escapePattern;
30     private $stringEscapePattern;
31     private $nonAsciiPattern;
32     private $nmCharPattern;
33     private $nmStartPattern;
34     private $identifierPattern;
35     private $hashPattern;
36     private $numberPattern;
37     private $quotedStringPattern;
38
39     public function __construct()
40     {
41         $this->unicodeEscapePattern = '\\\\([0-9a-f]{1,6})(?:\r\n|[ \n\r\t\f])?';
42         $this->simpleEscapePattern = '\\\\(.)';
43         $this->newLineEscapePattern = '\\\\(?:\n|\r\n|\r|\f)';
44         $this->escapePattern = $this->unicodeEscapePattern.'|\\\\[^\n\r\f0-9a-f]';
45         $this->stringEscapePattern = $this->newLineEscapePattern.'|'.$this->escapePattern;
46         $this->nonAsciiPattern = '[^\x00-\x7F]';
47         $this->nmCharPattern = '[_a-z0-9-]|'.$this->escapePattern.'|'.$this->nonAsciiPattern;
48         $this->nmStartPattern = '[_a-z]|'.$this->escapePattern.'|'.$this->nonAsciiPattern;
49         $this->identifierPattern = '-?(?:'.$this->nmStartPattern.')(?:'.$this->nmCharPattern.')*';
50         $this->hashPattern = '#((?:'.$this->nmCharPattern.')+)';
51         $this->numberPattern = '[+-]?(?:[0-9]*\.[0-9]+|[0-9]+)';
52         $this->quotedStringPattern = '([^\n\r\f%s]|'.$this->stringEscapePattern.')*';
53     }
54
55     /**
56      * @return string
57      */
58     public function getNewLineEscapePattern()
59     {
60         return '~^'.$this->newLineEscapePattern.'~';
61     }
62
63     /**
64      * @return string
65      */
66     public function getSimpleEscapePattern()
67     {
68         return '~^'.$this->simpleEscapePattern.'~';
69     }
70
71     /**
72      * @return string
73      */
74     public function getUnicodeEscapePattern()
75     {
76         return '~^'.$this->unicodeEscapePattern.'~i';
77     }
78
79     /**
80      * @return string
81      */
82     public function getIdentifierPattern()
83     {
84         return '~^'.$this->identifierPattern.'~i';
85     }
86
87     /**
88      * @return string
89      */
90     public function getHashPattern()
91     {
92         return '~^'.$this->hashPattern.'~i';
93     }
94
95     /**
96      * @return string
97      */
98     public function getNumberPattern()
99     {
100         return '~^'.$this->numberPattern.'~';
101     }
102
103     /**
104      * @param string $quote
105      *
106      * @return string
107      */
108     public function getQuotedStringPattern($quote)
109     {
110         return '~^'.sprintf($this->quotedStringPattern, $quote).'~i';
111     }
112 }