PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / vendor / symfony / css-selector / Parser / Tokenizer / TokenizerEscaping.php

TokenizerEscaping.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at vendor/symfony/css-selector/Parser/Tokenizer/TokenizerEscaping.php

64 lines 1.7 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 <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 escaping applier.
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 TokenizerEscaping
25 {
26 public function __construct(
27 private TokenizerPatterns $patterns,
28 ) {
29 }
30
31 public function escapeUnicode(string $value): string
32 {
33 $value = $this->replaceUnicodeSequences($value);
34
35 return preg_replace($this->patterns->getSimpleEscapePattern(), '$1', $value);
36 }
37
38 public function escapeUnicodeAndNewLine(string $value): string
39 {
40 $value = preg_replace($this->patterns->getNewLineEscapePattern(), '', $value);
41
42 return $this->escapeUnicode($value);
43 }
44
45 private function replaceUnicodeSequences(string $value): string
46 {
47 return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), static function ($match) {
48 $c = hexdec($match[1]);
49
50 if (0x80 > $c %= 0x200000) {
51 return \chr($c);
52 }
53 if (0x800 > $c) {
54 return \chr(0xC0 | $c >> 6).\chr(0x80 | $c & 0x3F);
55 }
56 if (0x10000 > $c) {
57 return \chr(0xE0 | $c >> 12).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
58 }
59
60 return '';
61 }, $value);
62 }
63 }
64