Requests_IDNAEncoder::adapt() WordPress Method

The Requests_IDNAEncoder::adapt() method is a WordPress method that adapts IDNA-encoded domain names to the specified encoding. This is useful if you need to convert a domain name from one encoding to another.

Requests_IDNAEncoder::adapt( int $delta, int $numpoints, bool $firsttime ) #

Adapt the bias


Description

Top ↑

See also


Top ↑

Parameters

$delta

(int)(Required)

$numpoints

(int)(Required)

$firsttime

(bool)(Required)


Top ↑

Return

(int) New bias function adapt(delta,numpoints,firsttime):


Top ↑

Source

File: wp-includes/Requests/IDNAEncoder.php

	protected static function adapt($delta, $numpoints, $firsttime) {
		// if firsttime then let delta = delta div damp
		if ($firsttime) {
			$delta = floor($delta / self::BOOTSTRAP_DAMP);
		}
		// else let delta = delta div 2
		else {
			$delta = floor($delta / 2);
		}
		// let delta = delta + (delta div numpoints)
		$delta += floor($delta / $numpoints);
		// let k = 0
		$k = 0;
		// while delta > ((base - tmin) * tmax) div 2 do begin
		$max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2);
		while ($delta > $max) {
			// let delta = delta div (base - tmin)
			$delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN));
			// let k = k + base
			$k += self::BOOTSTRAP_BASE;
		} // end
		// return k + (((base - tmin + 1) * delta) div (delta + skew))
		return $k + floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN + 1) * $delta) / ($delta + self::BOOTSTRAP_SKEW));
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.