Tokenizer.php
2 years ago
TokenizerEscaping.php
2 years ago
TokenizerPatterns.php
2 years ago
index.php
2 years ago
TokenizerEscaping.php
38 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Parser\Tokenizer; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class TokenizerEscaping |
| 5 | { |
| 6 | private $patterns; |
| 7 | public function __construct(TokenizerPatterns $patterns) |
| 8 | { |
| 9 | $this->patterns = $patterns; |
| 10 | } |
| 11 | public function escapeUnicode(string $value) : string |
| 12 | { |
| 13 | $value = $this->replaceUnicodeSequences($value); |
| 14 | return \preg_replace($this->patterns->getSimpleEscapePattern(), '$1', $value); |
| 15 | } |
| 16 | public function escapeUnicodeAndNewLine(string $value) : string |
| 17 | { |
| 18 | $value = \preg_replace($this->patterns->getNewLineEscapePattern(), '', $value); |
| 19 | return $this->escapeUnicode($value); |
| 20 | } |
| 21 | private function replaceUnicodeSequences(string $value) : string |
| 22 | { |
| 23 | return \preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function ($match) { |
| 24 | $c = \hexdec($match[1]); |
| 25 | if (0x80 > ($c %= 0x200000)) { |
| 26 | return \chr($c); |
| 27 | } |
| 28 | if (0x800 > $c) { |
| 29 | return \chr(0xc0 | $c >> 6) . \chr(0x80 | $c & 0x3f); |
| 30 | } |
| 31 | if (0x10000 > $c) { |
| 32 | return \chr(0xe0 | $c >> 12) . \chr(0x80 | $c >> 6 & 0x3f) . \chr(0x80 | $c & 0x3f); |
| 33 | } |
| 34 | return ''; |
| 35 | }, $value); |
| 36 | } |
| 37 | } |
| 38 |