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

Breadcrumb

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

function Idn::punycodeDecode

Parameters

string $input:

Return value

string

See also

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

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

File

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

Class

Idn
@internal

Namespace

Symfony\Polyfill\Intl\Idn

Code

private static function punycodeDecode($input) {
    $n = self::INITIAL_N;
    $out = 0;
    $i = 0;
    $bias = self::INITIAL_BIAS;
    $lastDelimIndex = strrpos($input, self::DELIMITER);
    $b = false === $lastDelimIndex ? 0 : $lastDelimIndex;
    $inputLength = \strlen($input);
    $output = [];
    $bytes = array_map('ord', str_split($input));
    for ($j = 0; $j < $b; ++$j) {
        if ($bytes[$j] > 0x7f) {
            throw new \Exception('Invalid input');
        }
        $output[$out++] = $input[$j];
    }
    if ($b > 0) {
        ++$b;
    }
    for ($in = $b; $in < $inputLength; ++$out) {
        $oldi = $i;
        $w = 1;
        for ($k = self::BASE;; $k += self::BASE) {
            if ($in >= $inputLength) {
                throw new \Exception('Invalid input');
            }
            $digit = self::$basicToDigit[$bytes[$in++] & 0xff];
            if ($digit < 0) {
                throw new \Exception('Invalid input');
            }
            if ($digit > intdiv(self::MAX_INT - $i, $w)) {
                throw new \Exception('Integer overflow');
            }
            $i += $digit * $w;
            if ($k <= $bias) {
                $t = self::TMIN;
            }
            elseif ($k >= $bias + self::TMAX) {
                $t = self::TMAX;
            }
            else {
                $t = $k - $bias;
            }
            if ($digit < $t) {
                break;
            }
            $baseMinusT = self::BASE - $t;
            if ($w > intdiv(self::MAX_INT, $baseMinusT)) {
                throw new \Exception('Integer overflow');
            }
            $w *= $baseMinusT;
        }
        $outPlusOne = $out + 1;
        $bias = self::adaptBias($i - $oldi, $outPlusOne, 0 === $oldi);
        if (intdiv($i, $outPlusOne) > self::MAX_INT - $n) {
            throw new \Exception('Integer overflow');
        }
        $n += intdiv($i, $outPlusOne);
        $i %= $outPlusOne;
        array_splice($output, $i++, 0, [
            mb_chr($n, 'utf-8'),
        ]);
    }
    return implode('', $output);
}

API Navigation

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