• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/punycode.php
  • Класс: CBXPunycode
  • Вызов: CBXPunycode::DoDecodeUcs4
private function DoDecodeUcs4($input)
{
	$result = [];

	$input = array_slice($input, self::$punycodePrefixLength);
	$delimiterPosition = false;
	for ($i = count($input) - 1; $i >= 0; $i--)
	{
		if (array($input[$i]) == self::$hyphenUcs4)
		{
			$delimiterPosition = $i;
			break;
		}
	}

	if ($delimiterPosition !== false)
	{
		for ($i = 0; $i < $delimiterPosition; $i++)
			$result[] = $input[$i];
	}

	$resultLength = count($result);
	$inputLength = count($input);

	$isFirst = true;
	$bias = 72;
	$idx = 0;
	$char = 0x80;

	for ($inputIdx = ($delimiterPosition !== false) ? ($delimiterPosition + 1) : 0;
		$inputIdx < $inputLength;
		$resultLength++)
	{
		for ($oldIdx = $idx, $w = 1, $k = 36; 1; $k += 36)
		{
			$c = $input[$inputIdx++];
			$digit = ($c - 48 < 10) ? $c - 22 : (($c - 65 < 26) ? $c - 65 : (($c - 97 < 26) ? $c - 97 : 36));
			$idx += $digit * $w;
			$t = ($k <= $bias) ? 1 : (($k >= $bias + 26) ? 26 : ($k - $bias));
			if ($digit < $t)
				break;
			$w = (int) ($w * (36 - $t));
		}
		$bias = $this->Adapt($idx - $oldIdx, $resultLength + 1, $isFirst);
		$isFirst = false;
		$char += (int) ($idx / ($resultLength + 1));
		$idx %= ($resultLength + 1);
		if ($resultLength > 0)
		{
			for ($i = $resultLength; $i > $idx; $i--)
				$result[$i] = $result[($i - 1)];
		}
		$result[$idx++] = $char;
	}
	return $result;
}