Parses a path component as it appears in a URL.

@param string $str
@throws \InvalidArgumentException
162011
public function parseComponent($str)
	{
		if (! is_string($str)) {
			throw new InvalidUrlException('Unexpected type.');
		}
		if (strpos($str, ' ') !== false) {
			throw new InvalidUrlException('Path contains whitespace.');
		}
		$p = explode('/', $str);
		foreach ($p as $i => $v) {
			$p[$i] = rawurldecode($v);
		}
		$decodedPath = join('/', $p);
		$this->path->set($decodedPath);
	}
816789
public function parseString($str) {
        if (!extension_loaded("SimpleXML"))
            throw new XmlParserException("SimpleXML extension not loaded, can not parse XML");
        
        libxml_use_internal_errors(true);
        $xml = simplexml_load_string($str);
        
        if ($xml === false) {
            $msg = "The following XML errors occurred while parsing:";
            foreach (libxml_get_errors() as $error)
                $msg .= "\n" . $error->message;
            throw new XmlParserException($msg);
        }

        $this->xml = $xml;
        $this->xmlString = $str;
        return $this;
    }
804488
public static function fromString($string)
    {
        $string = trim($string);
        if (!$string) {
            throw new \InvalidArgumentException('Empty attribute path');
        }

        $colonPos = strrpos($string, ':');
        if ($colonPos !== false) {
            $schema = substr($string, 0, $colonPos);
            $path = substr($string, $colonPos + 1);
        } else {
            $schema = null;
            $path = $string;
        }

        $parts = explode('.', $path);
        $attributePath = new static();
        $attributePath->schema = $schema;
        foreach ($parts as $part) {
            $attributePath->add($part);
        }

        return $attributePath;
    }
901857
private function filterString($str): ?string
    {
        if (null === $str) {
            return $str;
        }

        if (!is_scalar($str) && !method_exists($str, '__toString')) {
            throw new TypeError(sprintf('The component must be a string, a scalar or a stringable object %s given', gettype($str)));
        }

        $str = (string) $str;
        if (1 !== preg_match(self::REGEXP_INVALID_CHARS, $str)) {
            return $str;
        }

        throw new SyntaxError(sprintf('The component `%s` contains invalid characters', $str));
    }
1250499
protected function fromBinaryString($str){
		
		if(!(\is_string($str) && \preg_match('/^[01]+$/', $str))){
			throw new \InvalidArgumentException('$str is not a binary string');
		}
		
		for($i = 0, $l = \strlen($str); $i < $l; ++$i){
			$this->_List->pushFront($str[$i] === '1' ? true : false);
		}
		
	}
326481
protected function setPath($path)
    {
        if ($path !== '' && !$this->isValidPath($path)) {
            throw new \InvalidArgumentException("Invalid path '$path'");
        }
        
        $this->path = (string)$path;
    }
105303
public function endsWith(self $str, MStringComparison $cmp = null){
		
		if($str->isNullOrEmpty()){
			throw new \InvalidArgumentException('$str is empty');
		}
		
		if($str->count() > $this->count()){
			throw new \InvalidArgumentException('$str is longer than $this');
		}
		
		if($cmp === null || $cmp->Value === MStringComparison::CASE_SENSITIVE){
			return $this
					->substring($this->count() - $str->count(), $str->count())
					->_Value === $str->_Value;
		}
		else{
			return $this
					->substring($this->count() - $str->count(), $str->count())
					->toLower()->_Value === $str->toLower()->_Value;
		}
		
	}
1149695
protected function modifyPath(string $str): string
    {
        if ('' != $str && '/' !== $str[0]) {
            $str = '/'.$str;
        }

        if (0 === strpos($str, (string) $this->basepath)) {
            return $str;
        }

        return (string) $this->basepath->append($str);
    }
100499
function ParseStr($str) {
		$this->Clear();

		$this->modifyContent($str);

		$pos = strpos($str, '@');
		while ($pos !== false) {
			$start = $pos;
			$pos++;
			$media = '';
			$count = -1;

			while(true) {
				if ($str[$pos] == '{') {
					if ($count == -1) {
						$media = substr($str, $start, ($pos-$start));
						$count = 0;
					}
					$count++;
				}
				if ($str[$pos] == '}') $count--;

				if ($count == 0) {
					$end = $pos;

					$fullmedia = substr($str, $start, ($end-$start)+1);

					$subparse = substr($fullmedia, strpos($fullmedia, '{')+1);

					$subparse = substr($subparse, 0, -1);

					$cssparser = new Css($this->prefix);
					$cssparser->SetUrl($this->thisUrl);
					$cssparser->ParseStr($subparse);
					$codestr = $cssparser->GetCSS();

					$str = str_replace($fullmedia, '', $str);
					$this->Add($media, $codestr);
					$pos = 0;
					break;
				}
				$pos++;
				if ($pos == strlen($str)) break;
			}
			$pos = strpos($str, '@', $pos);
		}

		if (preg_match_all('#([^}]*){([^}]*)}#Sis', $str, $parts)) {
			foreach($parts[1] as $key => $keystr) {
				$codestr = trim($parts[2][$key]);
				$keys = explode(',', trim($keystr));
				if(count($keys)) {
					foreach($keys as $value) {
						$value = trim($value);
						if(strlen($value)) {
							$this->Add($value, $codestr);
						}
					}
				}
			}
		}
		return (count($this->css) > 0);
	}
369868
public function parse($str)
    {
        $this->removeBom($str);

        $data = $this->createM3uData();
        $lines = \explode("\n", $str);

        for ($i = 0, $l = \count($lines); $i < $l; ++$i) {
            $lineStr = \trim($lines[$i]);
            if ('' === $lineStr || $this->isComment($lineStr)) {
                continue;
            }

            if ($this->isExtM3u($lineStr)) {
                $tmp = \trim(\substr($lineStr, 7));
                if ($tmp) {
                    $data->initAttributes($tmp);
                }
                continue;
            }

            $data->append($this->parseLine($i, $lines));
        }

        return $data;
    }
1305867
public function parse( $string )
	{
		if( !is_string( $string ) )														//  no String given
			throw new InvalidArgumentException( 'Given argument is not a string' );		//  throw Exception

		$this->extendPossibleOptionsWithShortcuts();									//  realize Shortcuts

		$position	= 0;																//  initiate Sign Pointer
		$status		= self::STATUS_START;												//  initiate Status
		$buffer		= "";																//  initiate Argument Buffer
		$option		= "";																//  initiate Option Buffer

		while( isset( $string[$position] ) )											//  loop until End of String
		{
			$sign	= $string[$position];												//  get current Sign
			$position ++;																//  increase Sign Pointer

			switch( $status )															//  handle Sign depending on Status
			{
				case self::STATUS_START:												//  open for all Signs
					$this->onReady( $sign, $status, $buffer, $option );					//  handle Sign
					break;
				case self::STATUS_READ_OPTION_KEY:										//  open for Option Key Signs
					$this->onReadOptionKey( $sign, $status, $buffer, $option );			//  handle Sign
					break;
				case self::STATUS_READ_OPTION_VALUE:									//  open for Option Value Signs
					$this->onReadOptionValue( $sign, $status, $buffer, $option );		//  handle Sign
					break;
				case self::STATUS_READ_ARGUMENT:										//  open for Argument Signs
					$this->onReadArgument( $sign, $status, $buffer );					//  handle Sign
					break;
			}
		}
		$this->onEndOfLine( $status, $buffer, $option );								//  close open States
	}
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;
    }
397872
public static function fromString($url)
    {
        static $defaults = ['scheme' => null, 'host' => null,
            'path' => null, 'port' => null, 'query' => null,
            'user' => null, 'pass' => null, 'fragment' => null];

        if (false === ($parts = parse_url($url))) {
            throw new \InvalidArgumentException('Unable to parse malformed '
                . 'url: ' . $url);
        }

        $parts += $defaults;

        // Convert the query string into a Query object
        if ($parts['query'] || 0 !== strlen($parts['query'])) {
            $parts['query'] = Query::fromString($parts['query']);
        }

        return new static($parts['scheme'], $parts['host'], $parts['user'],
            $parts['pass'], $parts['port'], $parts['path'], $parts['query'],
            $parts['fragment']);
    }
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 . '_';
    }
146032
protected function modifyPath(string $str): string
    {
        return (string) $this->filterSegment($str)->withoutSegments($this->keys);
    }
1210476
public function loadString($str, $url = null)
    {
        $this->_str = $str;

        $this->_dom = new \DOMDocument();
        $this->_dom->strictErrorChecking = false;

        libxml_clear_errors();
        $old_use_internal_errors = libxml_use_internal_errors(true);
        $old_disable_entity_loader = libxml_disable_entity_loader(true);

        /** @noinspection SubStrUsedAsStrPosInspection */
        if (substr($str, 0, 5) === '<?xml') {
            $r = $this->_dom->loadXML($str);
        } else {
            $r = $this->_dom->loadHTML($str, LIBXML_HTML_NODEFDTD);
        }

        $this->_domErrors = libxml_get_errors();
        libxml_clear_errors();

        libxml_disable_entity_loader($old_disable_entity_loader);
        libxml_use_internal_errors($old_use_internal_errors);

        if (!$r) {
            throw new DocumentException('xx');
        }

        $this->_query = new Query($this->_dom);

        $this->_sourceUrl = $url;
        $this->_baseUrl = $this->_getBaseUrl() ?: $this->_sourceUrl;

        return $this;
    }
391867
protected function parseRoute($str) {
        $verbs=$path='';
        if (preg_match('/^\h*(\*|[\|\w]*)\h*(\H+)/',$str,$m)) {
            list(,$verbs,$path)=$m;
            if ($path[0]=='@')
                $path=\Base::instance()->get('ALIASES.'.substr($path,1));
        }
        if (!$verbs || $verbs=='*')
            $verbs=\Base::VERBS;
        return array(explode('|',$verbs),$path);
    }