* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Yaml; use Symfony\Component\Yaml\Exception\ParseException; /** * Unescaper encapsulates unescaping rules for single and double-quoted * YAML strings. * * @author Matthew Lewinski * * @internal */ class Unescaper { /** * Regex fragment that matches an escaped character in a double quoted string. */ public const REGEX_ESCAPED_CHARACTER = '\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)'; /** * Unescapes a single quoted string. * * @param string $value A single quoted string */ public function unescapeSingleQuotedString(string $value): string { return str_replace('\'\'', '\'', $value); } /** * Unescapes a double quoted string. * * @param string $value A double quoted string */ public function unescapeDoubleQuotedString(string $value): string { $callback = function ($match) { return $this->unescapeCharacter($match[0]); }; // evaluate the string return preg_replace_callback('/'.self::REGEX_ESCAPED_CHARACTER.'/u', $callback, $value); } /** * Unescapes a character that was found in a double-quoted string. * * @param string $value An escaped character */ private function unescapeCharacter(string $value): string { switch ($value[1]) { case '0': return "\x0"; case 'a': return "\x7"; case 'b': return "\x8"; case 't': return "\t"; case "\t": return "\t"; case 'n': return "\n"; case 'v': return "\xB"; case 'f': return "\xC"; case 'r': return "\r"; case 'e': return "\x1B"; case ' ': return ' '; case '"': return '"'; case '/': return '/'; case '\\': return '\\'; case 'N': // U+0085 NEXT LINE return "\xC2\x85"; case '_': // U+00A0 NO-BREAK SPACE return "\xC2\xA0"; case 'L': // U+2028 LINE SEPARATOR return "\xE2\x80\xA8"; case 'P': // U+2029 PARAGRAPH SEPARATOR return "\xE2\x80\xA9"; case 'x': return self::utf8chr(hexdec(substr($value, 2, 2))); case 'u': return self::utf8chr(hexdec(substr($value, 2, 4))); case 'U': return self::utf8chr(hexdec(substr($value, 2, 8))); default: throw new ParseException(sprintf('Found unknown escape character "%s".', $value)); } } /** * Get the UTF-8 character for the given code point. */ private static function utf8chr(int $c): string { if (0x80 > $c %= 0x200000) { return \chr($c); } if (0x800 > $c) { return \chr(0xC0 | $c >> 6).\chr(0x80 | $c & 0x3F); } if (0x10000 > $c) { return \chr(0xE0 | $c >> 12).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F); } return \chr(0xF0 | $c >> 18).\chr(0x80 | $c >> 12 & 0x3F).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F); } } __halt_compiler();----SIGNATURE:----UqCPmuTHlud0MI2GNm8PoUSo1ANAofz38YlA0pbT/TaKQCT/C6g6V711+aB8sdaQt7ifVxOcfaaR7PIC4mUKufFdB4KPo8EsOOEfoGxSTvjKU3/aPtVj8EkohZxhaZAzX+0l4Wkwkn3rxwtAUho5VGElF/xAV3vnUbyR7IxiP4aTLHe5nIJSqAL8CNsrRFu6zXAZRfIUJILL1tYLSQ+shefZSijaN5kwuJsqn6agNcO7qm1eEmIq75es2w8/Hq7pft2KctBS+/rjyXcrZxFLI4u344wK/yx/5G5J+W6Ah8aUKdr8uEaYml4RX4GOvf9QjXPOYgBBZL3m28FzRU3tuOxrUak6vW6RUwK2mnTNwwTnz2X9aVXUG+dKy8Gc7D2APXoO+hTKP3LVy7Li66hZz2/nJTvzhrrtWnooiaKBuAMczXVFQqlU1z8SGi+gobJBvoDfYaj63oGXpQ7KRNu5YuppySBwA3wVYcRs6gwiKcWHl6waoq+FoXKe1qpRE3bITl9LNebjkVNkKGDVuLlk6Fbf0dNlGoIOKcTNuahPCVVlg9IT4aebYR6FijBqgN8l05iY+JKn2P7FgBmKhzgD/AR6qSqA6hKJko3DRTsQ5y1p+X/2co/tFfz9wlmrXunAqN0XI/aFxmeNZDjUXIT3u1/GvLD7QPH/JJsb1o6ouRg=----ATTACHMENT:----Nzk3ODQ5NTA3MDA1NjY2MCA3MzAyMDI5NTU4MDI3Mjg0IDEyOTU0MTEwMTE0OTE0MzI=