Computes the lower and upper bounds of the IPv4 range by parsing the
range string.
@param string $range The IPv4 range as a string.
545557
private function computeLowerAndUpperBounds($range)
    {
        if (strpos($range, '/') !== false) {
            // support CIDR notation
            list($this->lowerInt, $this->upperInt) = $this->parseCidrRange($range);
        } elseif (strpos($range, '-') !== false) {
            // support for IP ranges like '10.0.0.0-10.0.0.255'
            list($this->lowerInt, $this->upperInt) = $this->parseHyphenRange($range);
        } elseif (($pos = strpos($range, '*')) !== false) {
            // support for IP ranges like '10.0.*'
            list($this->lowerInt, $this->upperInt) = $this->parseWildcardRange($range, $pos);
        } else {
            // assume we have a single address
            $this->lowerInt = ip2long($range);
            $this->upperInt = $this->lowerInt;
        }
    }
443392
public static function inRange(string $ip, string $range): bool
	{
		if(strpos($range, '/') === false)
		{
			$netmask = 128;
		}
		else
		{
			[$range, $netmask] = explode('/', $range, 2);

			if($netmask < 1 || $netmask > 128)
			{
				return false;
			}
		}

		$binNetmask = str_repeat('f', $netmask / 4);

		switch($netmask % 4)
		{
			case 1:
				$binNetmask .= '8';
				break;
			case 2:
				$binNetmask .= 'c';
				break;
			case 3:
				$binNetmask .= 'e';
				break;
		}

		$binNetmask = pack('H*', str_pad($binNetmask, 32, '0'));

		try
		{
			return (inet_pton($ip) & $binNetmask) === inet_pton($range);
		}
		catch(Throwable $e)
		{
			return false;
		}
	}
964749
public static function hasIpv4($string, &$matches = array(), $ifAll = false) {
		return 0 < self::validateByRegExp('/((25[0-5]|2[0-4]\d|1\d{2}|0?[1-9]\d|0?0?\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|0?[1-9]\d|0?0?\d)/', $string, $matches, $ifAll);
	}
207436
private function isIpv4InUnroutableRange(IPv4 $ip): bool
    {
        foreach ($this->unrouteableRanges as $ipRange) {
            if ($ip->matches(new Subnet($ipRange))) {
                return true;
            }
        }

        return false;
    }
709216
public static function reset($range =  '')
    {
        $range = $range ? : self::$range;
        true === $range ? self::$config = [] : self::$config[$range] = [];
    }
982977
public static function fromString($range)
    {
        $result = null;
        if (is_string($range)) {
            $parts = explode('/', $range);
            if (count($parts) === 2) {
                $address = Factory::addressFromString($parts[0]);
                if ($address !== null) {
                    if (preg_match('/^[0-9]{1,9}$/', $parts[1])) {
                        $networkPrefix = (int) $parts[1];
                        if ($networkPrefix >= 0) {
                            $addressBytes = $address->getBytes();
                            $totalBytes = count($addressBytes);
                            $numDifferentBits = $totalBytes * 8 - $networkPrefix;
                            if ($numDifferentBits >= 0) {
                                $numSameBytes = $networkPrefix >> 3;
                                $sameBytes = array_slice($addressBytes, 0, $numSameBytes);
                                $differentBytesStart = ($totalBytes === $numSameBytes) ? array() : array_fill(0, $totalBytes - $numSameBytes, 0);
                                $differentBytesEnd = ($totalBytes === $numSameBytes) ? array() : array_fill(0, $totalBytes - $numSameBytes, 255);
                                $startSameBits = $networkPrefix % 8;
                                if ($startSameBits !== 0) {
                                    $varyingByte = $addressBytes[$numSameBytes];
                                    $differentBytesStart[0] = $varyingByte & bindec(str_pad(str_repeat('1', $startSameBits), 8, '0', STR_PAD_RIGHT));
                                    $differentBytesEnd[0] = $differentBytesStart[0] + bindec(str_repeat('1', 8 - $startSameBits));
                                }
                                $result = new static(
                                    Factory::addressFromBytes(array_merge($sameBytes, $differentBytesStart)),
                                    Factory::addressFromBytes(array_merge($sameBytes, $differentBytesEnd)),
                                    $networkPrefix
                                );
                            }
                        }
                    }
                }
            }
        }

        return $result;
    }
1330569
final void parseRange(String range) {
		if (range == null) {
			throw new IllegalArgumentException("Invalid IP range");
		}
		
		int index = range.indexOf('/');
		String subnetStr = null;
		if (index == -1) {
			ipAddress = new IPAddress(range);
		} else {
			ipAddress = new IPAddress(range.substring(0, index));
			subnetStr = range.substring(index + 1);
		}
		
		// try to convert the remaining part of the range into a decimal
		// value.
		try {
			if (subnetStr != null) {
				extendedNetworkPrefix = Integer.parseInt(subnetStr);
				if ((extendedNetworkPrefix < 0) || (extendedNetworkPrefix > 32)) {
					throw new IllegalArgumentException("Invalid IP range [" + range + "]");
				}
				ipSubnetMask = computeMaskFromNetworkPrefix(extendedNetworkPrefix);
			}
		} catch (NumberFormatException ex) {
			
			// the remaining part is not a valid decimal value.
			// Check if it's a decimal-dotted notation.
			ipSubnetMask = new IPAddress(subnetStr);
			
			// create the corresponding subnet decimal
			extendedNetworkPrefix = computeNetworkPrefixFromMask(ipSubnetMask);
			if (extendedNetworkPrefix == -1) {
				throw new IllegalArgumentException("Invalid IP range [" + range + "]", ex);
			}
		}
	}
236059
public static function getIPRangeBounds($ipRange)
    {
        if (strpos($ipRange, '/') === false) {
            $ipRange = self::sanitizeIpRange($ipRange);

            if ($ipRange === null) {
                return null;
            }
        }
        $pos = strpos($ipRange, '/');

        $bits = substr($ipRange, $pos + 1);
        $range = substr($ipRange, 0, $pos);
        $high = $low = @inet_pton($range);
        if ($low === false) {
            return null;
        }

        $lowLen = strlen($low);
        $i = $lowLen - 1;
        $bits = $lowLen * 8 - $bits;

        for ($n = (int)($bits / 8); $n > 0; $n--, $i--) {
            $low[$i] = chr(0);
            $high[$i] = chr(255);
        }

        $n = $bits % 8;
        if ($n) {
            $low[$i] = chr(ord($low[$i]) & ~((1 << $n) - 1));
            $high[$i] = chr(ord($high[$i]) | ((1 << $n) - 1));
        }

        return array($low, $high);
    }
901295
public function searchRange(Range $range)
    {
        $iterator = $this->getIterator();
        
        // find start
        $start = null;
        $binarySearch = new BinarySearch($this);
        $startHint = $binarySearch->search($range->getMin());
        if ($startHint == null) {
            return new RangeIterator($iterator, Range::getEmptyRange());
            
        }
        $iterator->setOffset($startHint->getOffset(), Parser::HINT_RESULT_BOUNDARY);

        if (! $range->contains($startHint->getKey()) && $startHint->getKey() <= $range->getMin()) {
            // shift $startHint higher
            
            foreach ($iterator as $result) {
                if ($range->contains($result->getKey())) {
                    $start = $result;
                    break;
                    
                }
            }
            
        } else {
            // shift $startHint lower
            
            if ($range->contains($startHint->getKey())) {
                $start = $startHint;
                
            }
            $iterator->setDirection(KeyReader::DIRECTION_BACKWARD);
            foreach ($iterator as $result) {
                // Skip everything which is too big
                if (! $range->contains($result->getKey() && $result->getKey() >= $range->getMax())) {
                    continue;
                    
                }
                
                // shift the start left until no more key is included
                if ($range->contains($result->getKey())) {
                    $start = $result;
                    
                } else {
                    break;
                    
                }
            }
            
        }
        if (is_null($start)) {
            return new RangeIterator($iterator, Range::getEmptyRange());

        }
        
        $iterator = $this->getIterator();
        $iterator->setOffset($start->getOffset(), Parser::HINT_RESULT_BOUNDARY);
        return new RangeIterator($iterator, $range);
    }
320762
public function setRange($pRange = '')
    {
        // Uppercase coordinate
        $cellAddress = explode('!', strtoupper($pRange));
        if (count($cellAddress) > 1) {
            list($worksheet, $pRange) = $cellAddress;
        }

        if (strpos($pRange, ':') !== false) {
            $this->range = $pRange;
        } elseif (empty($pRange)) {
            $this->range = '';
        } else {
            throw new PHPExcel_Exception('Autofilter must be set on a range of cells.');
        }

        if (empty($pRange)) {
            //    Discard all column rules
            $this->columns = array();
        } else {
            //    Discard any column rules that are no longer valid within this range
            list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($this->range);
            foreach ($this->columns as $key => $value) {
                $colIndex = PHPExcel_Cell::columnIndexFromString($key);
                if (($rangeStart[0] > $colIndex) || ($rangeEnd[0] < $colIndex)) {
                    unset($this->columns[$key]);
                }
            }
        }

        return $this;
    }
382677
public function filterRange($range)
    {
        if (is_int($range)) {
            $level = $range;
            $depth = 0;
        } else {
            reset($range);
            $level = key($range);
            $depth = current($range);
        }

        if (1 === $level) {
            $nodeList = $this->xp->query('/descendant-or-self::*[ name() = "ul" and count( ancestor-or-self::ul ) >= '.$level.'  ]')->item(0);
        } else {
            $nodeList = $this->xp->query('/descendant-or-self::*[ name() = "ul" and count( ancestor-or-self::ul ) >= '.$level.' and ( descendant-or-self::*[ contains(@class, "open") or contains(@class, "active") ] or ancestor-or-self::*[ contains(@class, "open")  or contains(@class, "active") ] ) ]')->item(0);
        }

        if (!$nodeList) {
            return false;
        }

        if (false === $depth) {
            return $nodeList;
        }

        $depthNodelist = $this->xp->query('./descendant::*[ name() = "ul" and count( ancestor-or-self::ul ) > '.($level + $depth).' ]', $nodeList);

        foreach ($depthNodelist as $node) {
            $node->parentNode->removeChild($node);
        }

        if ($nodeList) {
            return $nodeList;
        } else {
            return false;
        }
    }
350707
public function range($val, $lower, $upper, $id, $name = null) {
        if ($val < $lower || $val > $upper) {
            if (is_null($name))
                $name = ucwords($id);
            $this->add($id, "$name must be between $lower and $upper.");
            return false;
        }

        return true;
    }
49838
protected function parseDefaults()
    {
        if (isset($this->ipv4) && !is_int($this->ipv4)) {
            $this->ipv4 = ip2long($this->ipv4);
        }
    }
1327991
private function validateReservedRange(string $value = ''): bool
    {
        $isValid = true;
        if ($this->options['allow-reserved-range'] === false) {
            $flags = FILTER_FLAG_NO_RES_RANGE;
            $isValid = \filter_var($value, FILTER_VALIDATE_IP, ['flags' => $flags]) !== false ? true : false;
        }
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_IP_RESERVED_RANGE_NOT_ALLOWED);
        }

        return $isValid;
    }
86465
private function cidrMatch($ip, $range) {
        if ($this->isIPv6($ip)) {
            return $this->cidr6Match($ip, $range);
        } else {
            return $this->cidr4Match($ip, $range);
        }
    }
42850
private function range($value, $range)
    {
        if (is_string($value)) {
            $value = strlen($value);
        }

        return $value >= $range[0] && $value <= $range[1]; // 如果是数字，则需要是一个数组,例array(5,22)
    }
612636
private function splitRanges(string $ranges): void
    {
        $matches = [];
        if (!preg_match('#^[\-|\+]{1}([0-9]+),([0-9]+) [\-\+]{1}([0-9]+),([0-9]+)$#', $ranges, $matches)) {
            throw new \RuntimeException('invalid ranges: ' . $ranges);
        }
        $this->pre  = ['from' => (int)$matches[1], 'to' => (int)$matches[2]];
        $this->post = ['from' => (int)$matches[3], 'to' => (int)$matches[4]];
    }