[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Algo26\IdnaConvert\Punycode; 4 5 use Algo26\IdnaConvert\TranscodeUnicode\TranscodeUnicode; 6 7 abstract class AbstractPunycode 8 { 9 const punycodePrefix = 'xn--'; 10 const invalidUcs = 0x80000000; 11 const maxUcs = 0x10FFFF; 12 const base = 36; 13 const tMin = 1; 14 const tMax = 26; 15 const skew = 38; 16 const damp = 700; 17 const initialBias = 72; 18 const initialN = 0x80; 19 20 protected static $isMbStringOverload; 21 protected static $prefixAsArray; 22 protected static $prefixLength; 23 24 /** @var TranscodeUnicode */ 25 protected $unicodeTransCoder; 26 27 public function __construct() 28 { 29 $this->unicodeTransCoder = new TranscodeUnicode(); 30 31 // populate mbstring overloading cache if not set 32 if (self::$isMbStringOverload === null) { 33 self::$isMbStringOverload = (extension_loaded('mbstring') 34 && (ini_get('mbstring.func_overload') & 0x02) === 0x02); 35 } 36 37 if (self::$prefixAsArray === null) { 38 self::$prefixAsArray = $this->unicodeTransCoder->convert( 39 self::punycodePrefix, 40 $this->unicodeTransCoder::FORMAT_UTF8, 41 $this->unicodeTransCoder::FORMAT_UCS4_ARRAY 42 ); 43 self::$prefixLength = $this->byteLength(self::punycodePrefix); 44 } 45 } 46 47 public function getPunycodePrefix(): string 48 { 49 return self::punycodePrefix; 50 } 51 52 /** 53 * Gets the length of a string in bytes even if mbstring function 54 * overloading is turned on 55 * 56 * @param string $string the string for which to get the length. 57 * @return integer the length of the string in bytes. 58 */ 59 protected function byteLength($string): int 60 { 61 if (self::$isMbStringOverload) { 62 return mb_strlen($string, '8bit'); 63 } 64 65 return strlen((binary) $string); 66 } 67 68 69 /** 70 * Adapt the bias according to the current code point and position 71 * @param int $delta 72 * @param int $nPoints 73 * @param int $isFirst 74 * @return int 75 */ 76 protected function adapt($delta, $nPoints, $isFirst): int 77 { 78 $delta = intval($isFirst ? ($delta / self::damp) : ($delta / 2)); 79 $delta += intval($delta / $nPoints); 80 for ($k = 0; $delta > ((self::base - self::tMin) * self::tMax) / 2; $k += self::base) { 81 $delta = intval($delta / (self::base - self::tMin)); 82 } 83 84 return intval($k + (self::base - self::tMin + 1) * $delta / ($delta + self::skew)); 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |