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

Breadcrumb

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

function Normalizer::decompose

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

File

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

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 decompose($s, $c) {
    $result = '';
    $ASCII = self::$ASCII;
    $decompMap = self::$D;
    $combClass = self::$cC;
    $ulenMask = self::$ulenMask;
    if ($c) {
        $compatMap = self::$KD;
    }
    $c = [];
    $i = 0;
    $len = \strlen($s);
    while ($i < $len) {
        if ($s[$i] < "\x80") {
            // ASCII chars
            if ($c) {
                ksort($c);
                $result .= implode('', $c);
                $c = [];
            }
            $j = 1 + strspn($s, $ASCII, $i + 1);
            $result .= substr($s, $i, $j);
            $i += $j;
            continue;
        }
        $ulen = $ulenMask[$s[$i] & "\xf0"];
        $uchr = substr($s, $i, $ulen);
        $i += $ulen;
        if ($uchr < "가" || "힣" < $uchr) {
            // Table lookup
            if ($uchr !== ($j = $compatMap[$uchr] ?? $decompMap[$uchr] ?? $uchr)) {
                $uchr = $j;
                $j = \strlen($uchr);
                $ulen = $uchr[0] < "\x80" ? 1 : $ulenMask[$uchr[0] & "\xf0"];
                if ($ulen != $j) {
                    // Put trailing chars in $s
                    $j -= $ulen;
                    $i -= $j;
                    if (0 > $i) {
                        $s = str_repeat(' ', -$i) . $s;
                        $len -= $i;
                        $i = 0;
                    }
                    while ($j--) {
                        $s[$i + $j] = $uchr[$ulen + $j];
                    }
                    $uchr = substr($uchr, 0, $ulen);
                }
            }
            if (isset($combClass[$uchr])) {
                // Combining chars, for sorting
                if (!isset($c[$combClass[$uchr]])) {
                    $c[$combClass[$uchr]] = '';
                }
                $c[$combClass[$uchr]] .= $uchr;
                continue;
            }
        }
        else {
            // Hangul chars
            $uchr = unpack('C*', $uchr);
            $j = ($uchr[1] - 224 << 12) + ($uchr[2] - 128 << 6) + $uchr[3] - 0xac80;
            $uchr = "\xe1\x84" . \chr(0x80 + (int) ($j / 588)) . "\xe1\x85" . \chr(0xa1 + (int) ($j % 588 / 28));
            if ($j %= 28) {
                $uchr .= $j < 25 ? "\xe1\x86" . \chr(0xa7 + $j) : "\xe1\x87" . \chr(0x67 + $j);
            }
        }
        if ($c) {
            ksort($c);
            $result .= implode('', $c);
            $c = [];
        }
        $result .= $uchr;
    }
    if ($c) {
        ksort($c);
        $result .= implode('', $c);
    }
    return $result;
}

API Navigation

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