Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StringUnescaper.php

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

StringUnescaper

Namespace

PHPStan\PhpDocParser\Parser

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal