验证是否有合法的ipv4地址

@param string $string   被搜索的 字符串
@param array $matches   会被搜索的结果,默认为array()
@param boolean $ifAll   是否进行全局正则表达式匹配，默认为false即仅进行一次匹配
@return boolean 如果匹配成功返回true，否则返回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);
	}
193112
protected function matchIp(/*# string */ $ip, array $patterns)/*# : bool */
    {
        $num = ip2long($ip);
        foreach ($patterns as $pat) {
            if (($num & $pat[1]) == $pat[0]) {
                return true;
            }
        }
        return false;
    }
687460
@Override
	protected boolean hasNoStringCache() {
		if(stringCache == null) {
			synchronized(this) {
				if(stringCache == null) {
					stringCache = new IPv6StringCache();
					return true;
				}
			}
		}
		return false;
	}
908290
public static function endsWith($string, $substrings)
    {
        if (is_array($substrings)) {
            foreach ((array) $substrings as $substring) {
                if ((string) $substring === static::subString($string, -static::length($substring))) {
                    return true;
                }
            }
        } elseif (is_string($substrings)) {
            if ((string) $substring === static::subString($string, -static::length($substring))) {
                return true;
            }
        }

        return false;
    }
894177
public static function stringContainsWildcardKeyword(string $pattern, string $string): bool
    {
        $pattern = '#\b' . self::wildcardToRegex($pattern) . '\b#i';

        return (bool) preg_match($pattern, $string);
    }
167906
public function compareUrlToProtocols(IUrl $url, array $protocols) {
        if (count($protocols) == 0) {
            return true;
        }

        return array_contains($protocols, $url->getProtocol());
    }
441672
public function containsAll(array $matches = []) {
        foreach($matches as $match) {
            if(!StringUtils::contains($this->string, $match)) {
                return FALSE;
            }
        }

        return TRUE;
    }
202273
protected function _doAnchors_inline_callback($matches) {
		$whole_match	=  $matches[1];
		$link_text		=  $this->runSpanGamut($matches[2]);
		$url			=  $matches[3] == '' ? $matches[4] : $matches[3];
		$title			=& $matches[7];
		$attr  = $this->doExtraAttributes("a", $dummy =& $matches[8]);

		// if the URL was of the form <s p a c e s> it got caught by the HTML
		// tag parser and hashed. Need to reverse the process before using the URL.
		$unhashed = $this->unhash($url);
		if ($unhashed != $url)
			$url = preg_replace('/^<(.*)>$/', '\1', $unhashed);

		$url = $this->encodeURLAttribute($url);

		$result = "<a href=\"$url\"";
		if (isset($title)) {
			$title = $this->encodeAttribute($title);
			$result .=  " title=\"$title\"";
		}
		$result .= $attr;
		
		$link_text = $this->runSpanGamut($link_text);
		$result .= ">$link_text</a>";

		return $this->hashPart($result);
	}
831740
private static function quickTempCallback($matches)
	{
		for ($i=1, $count=\count($matches); $i<$count; $i++) {
			if (\strlen($matches[$i])) {
				$key = $matches[$i];
				break;
			}
		}
		$return = null;
		if (\substr($matches[0], 0, 1) == '\\') {
			$return = \ltrim($matches[0], '\\');
		} elseif (\is_array(self::$temp)) {
			$arrayUtil = new ArrayUtil();
			$return = $arrayUtil->path(self::$temp, $key);
		} elseif (\is_object(self::$temp) && isset(self::$temp->$key)) {
			$return = self::$temp->$key;
		}
		if ($return === null) {
			#$this->debug->log('try lookup func');
			$regex = '/^(\S+?)(?:'	// key
					.'\((.+)\)|'	// (param1, ...)
					.'\s+((?:[\'"\$]|array|true|false|null).*)$'	// params not inside parens
				.')/s';
			if (\preg_match($regex, $key, $matches)) {
				#$this->debug->log('func()');
				$args = !empty($matches[2])
					? $matches[2]
					: $matches[3];
				$key = $matches[1];
				$parsed = @eval('$args = array('.$args.');');
				if ($parsed === false) {
					// workaround for PHP "Bug" that sends a 500 response when an eval doesn't parse
					$code = !empty($_SERVER['REDIRECT_STATUS'])
						? $_SERVER['REDIRECT_STATUS']
						: 200;
					\header('Status:', true, $code);
				}
			} else {
				#$this->debug->log('unquoted string arg');
				$args	= \explode(' ', $key, 2);
				$key	= \array_shift($args);
			}
			#$this->debug->log('args', $args);
			if (is_object(self::$temp) && method_exists(self::$temp, 'get'.\ucfirst($key))) {
				$method = 'get'.\ucfirst($key);
				#$this->debug->info('method exists', $method);
				$return = \call_user_func_array(array(self::$temp, $method), $args);
			} elseif (\function_exists('get_'.$key) && !\in_array($key, array('class'))) {
				$return = \call_user_func_array('get_'.$key, $args);
			} else {
				#$this->debug->warn('no method or get_ function');
			}
		}
		#$this->debug->info('return', $return);
		return $return;
	}
879324
function isUrl(string){
    if (typeof string !== 'string') {
      return false;
    }

    var match = string.match(protocolAndDomainRE);
    if (!match) {
      return false;
    }

    var everythingAfterProtocol = match[1];
    if (!everythingAfterProtocol) {
      return false;
    }

    return localhostDomainRE.test(everythingAfterProtocol) ||
        nonLocalhostDomainRE.test(everythingAfterProtocol);
  }
181788
private function findCommand($i, array $matches)
    {
        $match = $matches[0][$i];
        $cmd = isset($matches['function'][$i]) ? $matches['function'][$i] : '';

        return [$match, $cmd];
    }
430191
protected function matchRangeToken($i, $match, array &$matches, &$special, &$replace)
    {
        if (' - ' === $match) {
            $matches[$i - 1] = '>='.str_replace(array('*', 'x', 'X'), '0', $matches[$i - 1]);

            if (false !== strpos($matches[$i + 1], '.') && false === strpos($matches[$i + 1], '*')
                    && false === strpos($matches[$i + 1], 'x') && false === strpos($matches[$i + 1], 'X')) {
                $matches[$i] = ',<=';
            } else {
                $matches[$i] = ',<';
                $special = ',<~';
            }
        } else {
            $this->matchRangeTokenStep2($i, $match, $matches, $special, $replace);
        }
    }
737688
public static boolean handleIfMatch(final String ifMatch, final List<ETag> etags, boolean allowWeak) {
        if (ifMatch == null) {
            return true;
        }
        if (ifMatch.equals("*")) {
            return true; //todo: how to tell if there is a current entity for the request
        }
        List<ETag> parts = parseETagList(ifMatch);
        for (ETag part : parts) {
            if (part.isWeak() && !allowWeak) {
                continue;
            }
            for (ETag tag : etags) {
                if (tag != null) {
                    if (tag.isWeak() && !allowWeak) {
                        continue;
                    }
                    if (tag.getTag().equals(part.getTag())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
1323761
private function checkByline($node, $matchString)
    {
        if (!$this->configuration->getArticleByLine()) {
            return false;
        }

        /*
         * Check if the byline is already set
         */
        if ($this->getAuthor()) {
            return false;
        }

        $rel = $node->getAttribute('rel');

        if ($rel === 'author' || preg_match(NodeUtility::$regexps['byline'], $matchString) && $this->isValidByline($node->getTextContent())) {
            $this->logger->info(sprintf('[Metadata] Found article author: \'%s\'', $node->getTextContent()));
            $this->setAuthor(trim($node->getTextContent()));

            return true;
        }

        return false;
    }
775281
private function matchStripHostsPatterns($url)
    {
        if (Filesystem::isLocalPath($url)) {
            return true;
        }

        if (is_array($this->stripHosts)) {
            $url = trim(parse_url($url, PHP_URL_HOST), '[]');

            if (false !== filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
                $urltype = 'ipv4';
            } elseif (false !== filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
                $urltype = 'ipv6';
            } else {
                $urltype = 'name';
            }

            if ('ipv4' === $urltype || 'ipv6' === $urltype) {
                $urlunpack = unpack('N*', @inet_pton($url));
            }

            foreach ($this->stripHosts as $pattern) {
                @list($type, $host, $mask) = $pattern;

                if ('/local' === $type) {
                    if ('name' === $urltype && 'localhost' === strtolower($url)
                        || ('ipv4' === $urltype || 'ipv6' === $urltype)
                        && false === filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)
                    ) {
                        return true;
                    }
                } elseif ('/private' === $type) {
                    if (('ipv4' === $urltype || 'ipv6' === $urltype)
                        && false === filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)
                    ) {
                        return true;
                    }
                } elseif ('ipv4' === $type || 'ipv6' === $type) {
                    if ($urltype === $type && $this->matchAddr($urlunpack, $host, $mask)) {
                        return true;
                    }
                } elseif ('name' === $type) {
                    if ('name' === $urltype && preg_match($host, $url)) {
                        return true;
                    }
                }
            }
        }
    }
74631
public static function loop(array $array, $string, $betweenStrings = PHP_EOL)
    {
        $output = [];

        foreach ($array as $key => $value) {
            // Flatten the array with dots and parse it
            $output[] = static::parseString($string, array_map('addslashes', static::array_dot($value)));
        }

        return implode($betweenStrings, $output);
    }
580580
private function detectRouteForWithIdentifierPattern(array $matches): ?Route
    {
        $actions = [
            'GET' => 'singleAction',
            'PUT' => 'editAction',
            'DELETE' => 'destroyAction'
        ];

        if (!isset($actions[$this->request->getMethod()])) {
            return null;
        }

        $controllerName = implode('', array_map('ucfirst', explode('-', $matches['controller'])));
        $controller = $this->configuration->getControllerNamespace() . $controllerName . 'Controller';

        return (new Route())
            ->setController($controller)
            ->setAction($actions[$this->request->getMethod()])
            ->setActionParams([$matches['id']]);
    }