CoreFiles by mySites.guru
AbstractPunycode.php58 lines, 1,679 bytes, from Joomla_6.2.0-Stable-Full_Package.zip
Raw History Compare with 6.1.4
md5
168c56f5c76a12337fc68f07351d3f92
sha1
03461d0da5519b5391b9be347556e0590313c938
sha256
598af37337db508cbcbac6f5254c48733fabba1961bd2584a109d1837cdd5f18
<?php

declare(strict_types=1);

namespace Algo26\IdnaConvert\Punycode;

use Algo26\IdnaConvert\TranscodeUnicode\ByteLengthTrait;
use Algo26\IdnaConvert\TranscodeUnicode\TranscodeUnicode;

abstract class AbstractPunycode
{
    const PUNYCODE_PREFIX = 'xn--';
    const MAX_UCS = 0x10FFFF;
    const BASE = 36;
    const T_MIN = 1;
    const T_MAX = 26;
    const SKEW = 38;
    const DAMP = 700;
    const INITIAL_BIAS = 72;
    const INITIAL_N = 0x80;

    protected static ?array $prefixAsArray = null;
    protected static int $prefixLength;

    protected TranscodeUnicode $unicodeTransCoder;

    use ByteLengthTrait;

    public function __construct()
    {
        $this->unicodeTransCoder = new TranscodeUnicode();

        if (self::$prefixAsArray === null) {
            self::$prefixAsArray = $this->unicodeTransCoder->convert(
                self::PUNYCODE_PREFIX,
                $this->unicodeTransCoder::FORMAT_UTF8,
                $this->unicodeTransCoder::FORMAT_UCS4_ARRAY
            );
            self::$prefixLength = $this->getByteLength(self::PUNYCODE_PREFIX);
        }
    }

    public function getPunycodePrefix(): string
    {
        return self::PUNYCODE_PREFIX;
    }

    protected function adapt(int $delta, int $nPoints, bool $isFirst): int
    {
        $delta = intval($isFirst ? ($delta / self::DAMP) : ($delta / 2));
        $delta += intval($delta / $nPoints);
        for ($k = 0; $delta > ((self::BASE - self::T_MIN) * self::T_MAX) / 2; $k += self::BASE) {
            $delta = intval($delta / (self::BASE - self::T_MIN));
        }

        return intval($k + (self::BASE - self::T_MIN + 1) * $delta / ($delta + self::SKEW));
    }
}

The same content is in 49 releases, Joomla 6.0.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.