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

Breadcrumb

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

function Idn::punycodeEncode

Parameters

string $input:

Return value

string

See also

https://tools.ietf.org/html/rfc3492#section-6.3

1 call to Idn::punycodeEncode()
Idn::idn_to_ascii in vendor/symfony/polyfill-intl-idn/Idn.php

File

vendor/symfony/polyfill-intl-idn/Idn.php, line 668

Class

Idn
@internal

Namespace

Symfony\Polyfill\Intl\Idn

Code

private static function punycodeEncode($input) {
    $n = self::INITIAL_N;
    $delta = 0;
    $out = 0;
    $bias = self::INITIAL_BIAS;
    $inputLength = 0;
    $output = '';
    $iter = self::utf8Decode($input);
    foreach ($iter as $codePoint) {
        ++$inputLength;
        if ($codePoint < 0x80) {
            $output .= \chr($codePoint);
            ++$out;
        }
    }
    $h = $out;
    $b = $out;
    if ($b > 0) {
        $output .= self::DELIMITER;
        ++$out;
    }
    while ($h < $inputLength) {
        $m = self::MAX_INT;
        foreach ($iter as $codePoint) {
            if ($codePoint >= $n && $codePoint < $m) {
                $m = $codePoint;
            }
        }
        if ($m - $n > intdiv(self::MAX_INT - $delta, $h + 1)) {
            throw new \Exception('Integer overflow');
        }
        $delta += ($m - $n) * ($h + 1);
        $n = $m;
        foreach ($iter as $codePoint) {
            if ($codePoint < $n && 0 === ++$delta) {
                throw new \Exception('Integer overflow');
            }
            if ($codePoint === $n) {
                $q = $delta;
                for ($k = self::BASE;; $k += self::BASE) {
                    if ($k <= $bias) {
                        $t = self::TMIN;
                    }
                    elseif ($k >= $bias + self::TMAX) {
                        $t = self::TMAX;
                    }
                    else {
                        $t = $k - $bias;
                    }
                    if ($q < $t) {
                        break;
                    }
                    $qMinusT = $q - $t;
                    $baseMinusT = self::BASE - $t;
                    $output .= self::encodeDigit($t + $qMinusT % $baseMinusT, false);
                    ++$out;
                    $q = intdiv($qMinusT, $baseMinusT);
                }
                $output .= self::encodeDigit($q, false);
                ++$out;
                $bias = self::adaptBias($delta, $h + 1, $h === $b);
                $delta = 0;
                ++$h;
            }
        }
        ++$delta;
        ++$n;
    }
    return $output;
}

API Navigation

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