function StringUnescaper::parseEscapeSequences
* Implementation based on https://github.com/nikic/PHP-Parser/blob/b0edd4c41111042d43bb45c6c657b2…
1 call to StringUnescaper::parseEscapeSequences()
- StringUnescaper::unescapeString in vendor/
phpstan/ phpdoc-parser/ src/ Parser/ StringUnescaper.php
File
-
vendor/
phpstan/ phpdoc-parser/ src/ Parser/ StringUnescaper.php, line 44
Class
Namespace
PHPStan\PhpDocParser\ParserCode
private static function parseEscapeSequences(string $str, string $quote) : string {
$str = str_replace('\\' . $quote, $quote, $str);
return preg_replace_callback('~\\\\([\\\\nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u\\{([0-9a-fA-F]+)\\})~', static function ($matches) {
$str = $matches[1];
if (isset(self::REPLACEMENTS[$str])) {
return self::REPLACEMENTS[$str];
}
if ($str[0] === 'x' || $str[0] === 'X') {
return chr((int) hexdec(substr($str, 1)));
}
if ($str[0] === 'u') {
if (!isset($matches[2])) {
throw new ShouldNotHappenException();
}
return self::codePointToUtf8((int) hexdec($matches[2]));
}
return chr((int) octdec($str));
}, $str);
}