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

Breadcrumb

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

function Normalizer::recompose

1 call to Normalizer::recompose()
Normalizer::normalize in vendor/symfony/polyfill-intl-normalizer/Normalizer.php

File

vendor/symfony/polyfill-intl-normalizer/Normalizer.php, line 113

Class

Normalizer
Normalizer is a PHP fallback implementation of the Normalizer class provided by the intl extension.

Namespace

Symfony\Polyfill\Intl\Normalizer

Code

private static function recompose($s) {
    $ASCII = self::$ASCII;
    $compMap = self::$C;
    $combClass = self::$cC;
    $ulenMask = self::$ulenMask;
    $result = $tail = '';
    $i = $s[0] < "\x80" ? 1 : $ulenMask[$s[0] & "\xf0"];
    $len = \strlen($s);
    $lastUchr = substr($s, 0, $i);
    $lastUcls = isset($combClass[$lastUchr]) ? 256 : 0;
    while ($i < $len) {
        if ($s[$i] < "\x80") {
            // ASCII chars
            if ($tail) {
                $lastUchr .= $tail;
                $tail = '';
            }
            if ($j = strspn($s, $ASCII, $i + 1)) {
                $lastUchr .= substr($s, $i, $j);
                $i += $j;
            }
            $result .= $lastUchr;
            $lastUchr = $s[$i];
            $lastUcls = 0;
            ++$i;
            continue;
        }
        $ulen = $ulenMask[$s[$i] & "\xf0"];
        $uchr = substr($s, $i, $ulen);
        if ($lastUchr < "ᄀ" || "ᄒ" < $lastUchr || $uchr < "ᅡ" || "ᅵ" < $uchr || $lastUcls) {
            // Table lookup and combining chars composition
            $ucls = $combClass[$uchr] ?? 0;
            if (isset($compMap[$lastUchr . $uchr]) && (!$lastUcls || $lastUcls < $ucls)) {
                $lastUchr = $compMap[$lastUchr . $uchr];
            }
            elseif ($lastUcls = $ucls) {
                $tail .= $uchr;
            }
            else {
                if ($tail) {
                    $lastUchr .= $tail;
                    $tail = '';
                }
                $result .= $lastUchr;
                $lastUchr = $uchr;
            }
        }
        else {
            // Hangul chars
            $L = \ord($lastUchr[2]) - 0x80;
            $V = \ord($uchr[2]) - 0xa1;
            $T = 0;
            $uchr = substr($s, $i + $ulen, 3);
            if ("ᆧ" <= $uchr && $uchr <= "ᇂ") {
                $T = \ord($uchr[2]) - 0xa7;
                0 > $T && ($T += 0x40);
                $ulen += 3;
            }
            $L = 0xac00 + ($L * 21 + $V) * 28 + $T;
            $lastUchr = \chr(0xe0 | $L >> 12) . \chr(0x80 | $L >> 6 & 0x3f) . \chr(0x80 | $L & 0x3f);
        }
        $i += $ulen;
    }
    return $result . $lastUchr . $tail;
}

API Navigation

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