Parses an URL.

@param string $str
@throws InvalidUrlException
@return self
964995
public function parseUrl($str)
	{
		if (! is_string($str)) {
			throw new InvalidUrlException('Unexpected type.');
		}
		if ($str === '') {
			throw new InvalidUrlException('Empty URL.');
		}
		if (trim($str, ' ') === '') {
			throw new InvalidUrlException('Empty URL.');
		}
		$components = $this->parseUrlComponents($str);
		$components = array_replace([
			'scheme' => '',
			'host' => '',
			'port' => '',
			'user' => '',
			'pass' => '',
			'path' => '',
			'query' => '',
			'fragment' => ''
		], $components);
		$this->scheme->parseComponent($components['scheme']);
		$this->host->parseComponent($components['host']);
		$this->port->parseComponent(strval($components['port']));
		if (empty($components['user']) && empty($components['pass'])) {
			$this->credentials->username = null;
			$this->credentials->password = null;
		} else {
			$this->credentials->parseComponent($components['user'] . ':' . $components['pass']);
		}
		$this->path->parseComponent($components['path']);
		$this->query->parseComponent($components['query']);
		$this->fragment->parseComponent($components['fragment']);
		return $this;
	}
681320
protected function _replaceUrl($str) {
		if (!preg_match_all('/\[url(.*?)\](.*)\[\/url\]/', $str, $matches)) {
			return $str;
		}

		foreach ($matches[0] as $i => $find) {
			$opts = isset($matches[1][$i]) ? $this->_extractAttributes(trim($matches[1][$i])) : array();
			$full = (in_array('full', $opts) || (isset($opts['full']) && 'false' != $opts['full']));
			$replace = empty($matches[2][$i]) ? '' : $this->url(trim($matches[2][$i]), $full);
			$str = str_replace($find, $replace, $str);
		}

		return $str;
	}
900971
public static function parse( $url )
		{
			$uri = new phpUri( $url );

			/**
			 * CHANGE:
			 * @author Dominik Habichtsberg <Dominik.Habichtsberg@Hbg-IT.de>
			 * @since  24 Mai 2015 10:25 Uhr
			 * The base-url should always have a path
			 */
			if ( empty( $uri->path ) )
			{
				$uri->path = '/';
			}

			return $uri;
		}
152420
public static function parse_attrib_string($str)
    {
        $attrib = array();
        $html   = '<html>'
            . '<head><meta http-equiv="Content-Type" content="text/html; charset=' . RCUBE_CHARSET . '" /></head>'
            . '<body><div ' . rtrim($str, '/ ') . ' /></body>'
            . '</html>';

        $document = new DOMDocument('1.0', RCUBE_CHARSET);
        @$document->loadHTML($html);

        if ($node = $document->getElementsByTagName('div')->item(0)) {
            foreach ($node->attributes as $name => $attr) {
                $attrib[strtolower($name)] = $attr->nodeValue;
            }
        }

        return $attrib;
    }
264573
function parse($str) {
		preg_match_all('/(\w+|\*)\h*=\h*(?:\[(.+?)\]|(.+?))(?=,|$)/',
			$str,$pairs,PREG_SET_ORDER);
		$out=[];
		foreach ($pairs as $pair)
			if ($pair[2]) {
				$out[$pair[1]]=[];
				foreach (explode(',',$pair[2]) as $val)
					array_push($out[$pair[1]],$val);
			}
			else
				$out[$pair[1]]=trim($pair[3]);
		return $out;
	}
600067
public static function parse($str)
    {
        if (preg_match('#\{:.*?:\}#', $str) === 0) {
            return false;
        }

        $str = preg_replace('#' . self::$rearg . '#', '\\\$0', $str);
        return preg_replace_callback('#\\\{:.*?:\\\}#',
                    array( '\\' . get_called_class(), 'args' ), $str);
    }
82254
protected function parseCsvString($str)
    {
        if (! isset($this->optionsIndexMap) || ! is_array($this->optionsIndexMap) || empty($this->optionsIndexMap)) {
            throw new \InvalidArgumentException(sprintf(
                'Class %s is missing the `optionsIndexMap` property',
                get_class($this)
            ));
        }

        $options = explode(',', $str);
        $result  = array();
        foreach ($options as $k => $v) {
            if (! isset($this->optionsIndexMap[$k])) {
                throw new \InvalidArgumentException(sprintf(
                    'Class %s does not have the index %d configured in the `optionsIndexMap` property',
                    get_class($this),
                    $k
                ));
            }
            $result[$this->optionsIndexMap[$k]] = $v;
        }

        return $this->convertBooleanStrings($result);
    }
341129
public function validate($str)
    {
        if ($str === null) {
            throw new \InvalidArgumentException('Error: String must not be null');
        }
        if (! is_string($str)) {
            throw new \InvalidArgumentException(
                'Error: String must be of type string but is of type "'.gettype($str).'"'
            );
        }
        if ($str === '') {
            throw new \InvalidArgumentException('Error: String must not be empty');
        }
        if ($this->containsMultibyteChar($str)) {
            throw new \InvalidArgumentException('Error: String must not contain any multibyte characters');
        }
    }
1298930
public function parse()
    {
        if ($this->isParsed || $this->uriPattern === null || $this->uriPattern === '') {
            return;
        }
        $this->routeParts = [];
        $currentRoutePartIsOptional = false;
        if (substr($this->uriPattern, -1) === '/') {
            throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" ends with a slash, which is not allowed. You can put the trailing slash in brackets to make it optional.', 1234782997);
        }
        if ($this->uriPattern[0] === '/') {
            throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" starts with a slash, which is not allowed.', 1234782983);
        }

        $matches = [];
        preg_match_all(self::PATTERN_EXTRACTROUTEPARTS, $this->uriPattern, $matches, PREG_SET_ORDER);

        /** @var $lastRoutePart RoutePartInterface */
        $lastRoutePart = null;
        foreach ($matches as $match) {
            $routePartType = empty($match['dynamic']) ? self::ROUTEPART_TYPE_STATIC : self::ROUTEPART_TYPE_DYNAMIC;
            $routePartName = $match['content'];
            if (!empty($match['optionalStart'])) {
                if ($lastRoutePart !== null && $lastRoutePart->isOptional()) {
                    throw new InvalidUriPatternException('the URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains successive optional Route sections, which is not allowed.', 1234562050);
                }
                $currentRoutePartIsOptional = true;
            }
            $routePart = null;
            switch ($routePartType) {
                case self::ROUTEPART_TYPE_DYNAMIC:
                    if ($lastRoutePart instanceof DynamicRoutePartInterface) {
                        throw new InvalidUriPatternException('the URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains successive Dynamic Route Parts, which is not allowed.', 1218446975);
                    }
                    if (isset($this->routePartsConfiguration[$routePartName]['handler'])) {
                        $routePart = $this->objectManager->get($this->routePartsConfiguration[$routePartName]['handler']);
                        if (!$routePart instanceof DynamicRoutePartInterface) {
                            throw new InvalidRoutePartHandlerException(sprintf('routePart handlers must implement "%s" in route "%s"', DynamicRoutePartInterface::class, $this->getName()), 1218480972);
                        }
                    } elseif (isset($this->routePartsConfiguration[$routePartName]['objectType'])) {
                        $routePart = new IdentityRoutePart();
                        $routePart->setObjectType($this->routePartsConfiguration[$routePartName]['objectType']);
                        if (isset($this->routePartsConfiguration[$routePartName]['uriPattern'])) {
                            $routePart->setUriPattern($this->routePartsConfiguration[$routePartName]['uriPattern']);
                        }
                    } else {
                        $routePart = new DynamicRoutePart();
                    }
                    $routePartDefaultValue = ObjectAccess::getPropertyPath($this->defaults, $routePartName);
                    if ($routePartDefaultValue !== null) {
                        $routePart->setDefaultValue($routePartDefaultValue);
                    }
                    break;
                case self::ROUTEPART_TYPE_STATIC:
                    $routePart = new StaticRoutePart();
                    if ($lastRoutePart !== null && $lastRoutePart instanceof DynamicRoutePartInterface) {
                        /** @var DynamicRoutePartInterface $lastRoutePart */
                        $lastRoutePart->setSplitString($routePartName);
                    }
            }
            $routePart->setName($routePartName);
            if ($currentRoutePartIsOptional) {
                $routePart->setOptional(true);
                if ($routePart instanceof DynamicRoutePartInterface && !$routePart->hasDefaultValue()) {
                    throw new InvalidRouteSetupException(sprintf('There is no default value specified for the optional route part "{%s}" of route "%s", but all dynamic optional route parts need a default.', $routePartName, $this->getName()), 1477140679);
                }
            }
            $routePart->setLowerCase($this->lowerCase);
            if (isset($this->routePartsConfiguration[$routePartName]['options'])) {
                $routePart->setOptions($this->routePartsConfiguration[$routePartName]['options']);
            }
            if (isset($this->routePartsConfiguration[$routePartName]['toLowerCase'])) {
                $routePart->setLowerCase($this->routePartsConfiguration[$routePartName]['toLowerCase']);
            }

            $this->routeParts[] = $routePart;
            if (!empty($match['optionalEnd'])) {
                if (!$currentRoutePartIsOptional) {
                    throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unopened optional section.', 1234564495);
                }
                $currentRoutePartIsOptional = false;
            }
            $lastRoutePart = $routePart;
        }
        if ($currentRoutePartIsOptional) {
            throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unterminated optional section.', 1234563922);
        }
        $this->isParsed = true;
    }
658743
function ParseUrl($url) {
	    $content = null;

    	$this->Clear();

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

	    ob_start();
	    if (function_exists('curl_init')) {
		    //curl is the preferred function
		    $crl = curl_init();
		    curl_setopt($crl, CURLOPT_URL, $url);
		    curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
		    curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
		    curl_setopt($crl, CURLOPT_TIMEOUT, 20);
		    $FileData = curl_exec($crl);
		    $FileInfo = curl_getinfo($crl);
		    curl_close($crl);
		    if ($FileInfo['http_code'] != 200) {
			    throw new \HttpRequestException($FileInfo['http_code'] . ' error for file: ' . $url);
		    }
	    } else {
		    //see if we can use fopen to get file
		    $fopen_check = ini_get('allow_url_fopen');
		    if (!empty($fopen_check)) {
			    $content = file_get_contents($url);
		    } else {
			    throw new \RuntimeException('CURL_DISABLED');
		    }
	    }
	    ob_end_clean();

		if(strlen($content)) {
			$this->modifyContent($content);
			$this->ParseStr($content);
			return true;
		} else {
			return false;
		}
	}
516665
protected function setWebAppPrefix($str): void
    {
        $type = gettype($str);
        if (! is_string($str)) {
            throw StrictTypeException::cstrTypeError($str, 'WebApp Prefix');
        }
        $str = strtoupper(trim($str));
        if (strlen($str) < 3) {
            throw InvalidArgumentException::webappPrefixTooShort($str);
        }
        if (strlen($str) > 32) {
            throw InvalidArgumentException::webappPrefixTooLong($str);
        }
        if (preg_match('/[^A-Z0-9]/', $str) !== 0) {
            throw InvalidArgumentException::webappPrefixNotAlphaNumeric($str);
        }
        $this->webappPrefix = $str . '_';
    }
1318094
protected function _auto($str) {
		$self=$this;
		return preg_replace_callback(
			'/`.*?<(.+?)>.*?`|<(.+?)>/',
			function($expr) use($self) {
				if (empty($expr[1]) && parse_url($expr[2],PHP_URL_SCHEME)) {
					$expr[2]=$self->esc($expr[2]);
					return '<a href="'.$expr[2].'">'.$expr[2].'</a>';
				}
				return $expr[0];
			},
			$str
		);
	}
625297
public function fromString($uri)
    {
        if (is_numeric($uri)) { //Could be a valid url
            $uri = '' . $uri;
        }
        if (!is_string($uri)) {
            $uri = '';
        }
        $this->setRelative();
        if (0 === strpos($uri, '//')) {
            $this->setAbsolute();
        }
        $parsed_url = parse_url($uri);
        if (!$parsed_url) {
            return $this;
        }
        if (array_key_exists('scheme', $parsed_url)) {
            $this->setAbsolute();
        }
        foreach ($parsed_url as $urlPart => $value) {
            $method = 'set' . ucfirst($urlPart);
            if (method_exists($this, $method)) {
                $this->$method($value);
            }
        }
        return $this;
    }
1330790
public function parse( $str, $file_uri = null ){

		if( !$file_uri ){
			$uri_root = '';
			$filename = 'anonymous-file-'.Less_Parser::$next_id++.'.less';
		}else{
			$file_uri = self::WinPath($file_uri);
			$filename = $file_uri;
			$uri_root = dirname($file_uri);
		}

		$previousFileInfo = $this->env->currentFileInfo;
		$uri_root = self::WinPath($uri_root);
		$this->SetFileInfo($filename, $uri_root);

		$this->input = $str;
		$this->_parse();

		if( $previousFileInfo ){
			$this->env->currentFileInfo = $previousFileInfo;
		}

		return $this;
	}
1317925
static function parse(string $url, ?int $preferredFormat = self::ABSOLUTE)
    {
        $components = parse_url($url);

        if ($components === false) {
            throw new InvalidUrlException(sprintf('The given URL "%s" is invalid', $url));
        }

        $query = [];

        if (isset($components['query'])) {
            parse_str($components['query'], $query);
        }

        return new static(
            $components['scheme'] ?? null,
            $components['host'] ?? null,
            $components['port'] ?? null,
            $components['path'] ?? '',
            $query,
            $components['fragment'] ?? null,
            $preferredFormat
        );
    }
425922
public function parse($str)
    {
        /* Set the tree root back to a fresh DocumentElement. */
        $this->reset();

        $parent = $this->treeRoot;
        $tokenizer = new Tokenizer($str);

        while ($tokenizer->hasNext()) {
            $parent = $this->parseStartState($parent, $tokenizer);
            if ($parent->getCodeDefinition() && false ===
                $parent->getCodeDefinition()->parseContent()) {
                /* We're inside an element that does not allow its contents to be parseable. */
                $this->parseAsTextUntilClose($parent, $tokenizer);
                $parent = $parent->getParent();
            }
        }

        /* We parsed ignoring nest limits. Do an O(n) traversal to remove any elements that
         * are nested beyond their CodeDefinition's nest limit. */
        $this->removeOverNestedElements();

        return $this;
    }
690745
public function prepend($str)
    {
        $value = $this->val();
        $this->val($str . $value);

        return $this;
    }