Removes dot segments from a path and returns the new path.

@param string $path

@return string
@link http://tools.ietf.org/html/rfc3986#section-5.2.4
556980
public static function removeDotSegments($path)
    {
        static $noopPaths = array('' => true, '/' => true, '*' => true);
        static $ignoreSegments = array('.' => true, '..' => true);

        if (isset($noopPaths[$path])) {
            return $path;
        }

        $results = array();
        $segments = explode('/', $path);
        foreach ($segments as $segment) {
            if ($segment == '..') {
                array_pop($results);
            } elseif (!isset($ignoreSegments[$segment])) {
                $results[] = $segment;
            }
        }

        $newPath = implode('/', $results);
        // Add the leading slash if necessary
        if (substr($path, 0, 1) === '/' &&
            substr($newPath, 0, 1) !== '/'
        ) {
            $newPath = '/' . $newPath;
        }

        // Add the trailing slash if necessary
        if ($newPath != '/' && isset($ignoreSegments[end($segments)])) {
            $newPath .= '/';
        }

        return $newPath;
    }
1071699
private function getPath($path)
    {
        return $this->root .
            ltrim(
                preg_replace(
                    sprintf('|%s{2,}|', preg_quote(DIRECTORY_SEPARATOR)),
                    DIRECTORY_SEPARATOR,
                    $path
                ),
                DIRECTORY_SEPARATOR
            );
    }
192660
protected function realPath( $path )
    {
        $path = trim( str_replace( '\\', '/', $path ), '/' );
        $path = str_replace( '/./', '/', $path );
        $path = preg_replace( '#[^/]+/\\.\\./#', '/', $path );
        $path = preg_replace( '#/?\\.\\.?/#', '', $path );
        $path = preg_replace( '#/+#', '/', $path );
        $path = trim( $path, '/' );

        if ( $path == '.' || $path == '..' )
        {
            $path = '';
        }

        return $path;
    }
324703
private function getCleanPath($path)
    {
        // remove the first slash for safety reasons [delimitor mapping] based on the web-server Rewrite
        if (mb_strpos($path, $this->delimiter) === 0) {
            $path = mb_substr($path, 1);
        }

        // if the last character is a delimiter remove it as well
        if (mb_strpos($path, $this->delimiter) == mb_strlen($path) - 1) {
            $path = mb_substr($path, 0, -1);
        }

        //remove the get parameter so it's clean
        if (($ppos = mb_strpos($path, '?')) && $ppos > 0) {
            $path = mb_substr($path, 0, $ppos);
        }

        unset($ppos);


        return $path;
    }
1055367
protected function cleanPath($path)
    {
        $lastchunk = strrchr($path, DS);
        if (strpos($lastchunk, ':') !== false) {
            $path = str_replace($lastchunk, '', $path);
        }

        return $path;
    }
1166055
private static function removeDotSegments(string $path)
    {
        $result = '';

        while (!\in_array($path, ['', '.', '..'], true)) {
            if ('.' === $path[0] && (0 === strpos($path, $p = '../') || 0 === strpos($path, $p = './'))) {
                $path = substr($path, \strlen($p));
            } elseif ('/.' === $path || 0 === strpos($path, '/./')) {
                $path = substr_replace($path, '/', 0, 3);
            } elseif ('/..' === $path || 0 === strpos($path, '/../')) {
                $i = strrpos($result, '/');
                $result = $i ? substr($result, 0, $i) : '';
                $path = substr_replace($path, '/', 0, 4);
            } else {
                $i = strpos($path, '/', 1) ?: \strlen($path);
                $result .= substr($path, 0, $i);
                $path = substr($path, $i);
            }
        }

        return $result;
    }
1002590
protected function newPath(/*# string */ $path)/*# : Path */
    {
        list($mnt, $remain) = $this->splitPath($path);
        return new Path($path, $remain, $this->getFilesystemAt($mnt));
    }
885525
public static function clean_up_path($path)
    {

        if (empty($path)) return '';
        if (strpos($path, '\\') !== false) {
            return str_replace("\\\\", "\\", $path);
        } else {
            return str_replace("//", "/", $path);
        }
    }
737527
private function normalizePipePath($path)
    {
        // Prepend slash if missing
        if (empty($path) || $path[0] !== '/') {
            $path = '/' . $path;
        }

        // Trim trailing slash if present
        if (strlen($path) > 1 && '/' === substr($path, -1)) {
            $path = rtrim($path, '/');
        }

        return $path;
    }
1091208
public static function stripExt($path) {
        if (mb_strpos($path, '.') !== false) {
            $path = mb_substr($path, 0, mb_strrpos($path, '.'));
        }

        return $path;
    }
347461
public static function normalizeFullPath($path)
    {
        $to = Folder::correctSlashFor($path);
        $from = ($to == '/' ? '\\' : '/');

        return str_replace($from, $to, $path);
    }
411308
public static function replaceRelativePathElements($path)
    {
        $pathSegments = explode('/', $path);
        $absolutePath = '';
        foreach ($pathSegments as $pathSegment) {
            switch ($pathSegment) {
                case '.':
                    continue 2;
                break;
                case '..':
                    $absolutePath = NodePaths::getParentPath($absolutePath);
                break;
                default:
                    $absolutePath = NodePaths::addNodePathSegment($absolutePath, $pathSegment);
                break;
            }
        }

        return $absolutePath;
    }
715595
private function get_new_path( $path ){
		if( preg_match( '/^(?:[a-zA-Z0-9]+\:|\/\/|\#)/', $path ) ){
			return $path;
		}

		$params = '';
		if( preg_match( '/^(.*?)([\?\#].*)$/', $path, $matched ) ){
			$path = $matched[1];
			$params = $matched[2];
		}

		$rewrite_direction = @$this->device_info->rewrite_direction;
		@preg_match('/^(.*)2(.*)$/', $rewrite_direction, $matched);
		$rewrite_from = @$matched[1];
		$rewrite_to   = @$matched[2];
		if( !strlen($rewrite_from) ){
			$rewrite_from = 'rewrited';
		}
		if( !strlen($rewrite_to) ){
			$rewrite_to = 'origin';
		}

		$type = 'relative';
		if( preg_match('/^\//', $path) ){
			$type = 'absolute';
		}elseif( preg_match('/^\.\//', $path) ){
			$type = 'relative_dotslash';
		}
		$is_slash_closed = false;
		if( preg_match('/\/$/', $path) ){
			$is_slash_closed = true;
			$path .= $this->px->get_directory_index_primary();
		}

		// ------------------

		$cd_origin = $this->px->fs()->normalize_path( $this->px->fs()->get_realpath( $this->path_original ) );
		$cd_origin = preg_replace( '/^(.*)(\/.*?)$/si', '$1', $cd_origin );
		if( !strlen($cd_origin) ){
			$cd_origin = '/';
		}

		$cd_rewrited = $this->px->fs()->normalize_path( $this->px->fs()->get_realpath( $this->path_rewrited ) );
		$cd_rewrited = preg_replace( '/^(.*)(\/.*?)$/si', '$1', $cd_rewrited );
		if( !strlen($cd_rewrited) ){
			$cd_rewrited = '/';
		}

		// ------------------

		$realpath_from = $cd_origin;
		$realpath_to = $this->px->fs()->normalize_path($this->px->fs()->get_realpath($path, $cd_origin));

		if( $rewrite_from == 'rewrited' ){
			$realpath_from = $cd_rewrited;
		}
		if( $rewrite_to == 'rewrited' ){
			$realpath_to = $this->path_rewriter->rewrite($realpath_to, $this->device_info->path_rewrite_rule);
			$realpath_to = $this->px->fs()->normalize_path($this->px->fs()->get_realpath($realpath_to, $cd_origin));
		}

		// ------------------

		if( $type == 'relative' || $type == 'relative_dotslash' ){
			$realpath_to = $this->px->fs()->normalize_path($this->px->fs()->get_relatedpath($realpath_to, $realpath_from));
			if( $type == 'relative' ){
				$realpath_to = preg_replace( '/^\.\//si', '', $realpath_to );
			}elseif( $type == 'relative_dotslash' ){
				$realpath_to = preg_replace( '/^(\.\/)?/si', './', $realpath_to );
			}
		}

		$realpath_to = $this->px->fs()->normalize_path($realpath_to);
		if( $is_slash_closed ){
			$realpath_to = preg_replace( '/'.$this->px->get_directory_index_preg_pattern().'$/', '', $realpath_to );
		}
		$realpath_to .= $params;

		return $realpath_to;
	}
428818
public function getRemainingPath($path)
	{
		$paths = explode('/', $path);
		
		$newPaths	= array();

		for($i = count(explode('/', $this->properties['path'])); $i < count($paths); $i++)
			$newPaths[]	= $paths[$i];

		return $this->properties['path'] != '' ? implode('/', $newPaths) : $path;
	}
833143
public function normalizePath($path)
    {
        $realpath = realpath($path);
        if ($realpath) {
            $path = $realpath;
        }

        $path = str_replace('\\', '/', $path);
        $path = rtrim($path, '/');
        if (substr($path, 1, 1) === ':') {
            $path = lcfirst($path);
        }

        return $path;
    }
220344
protected function sanitizePath($path)
    {
        $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);

        $path = preg_replace('/'.preg_quote('./', '/').'/', '', $path, 1);
        $path = trim($path, '/');

        return $path;
    }
928176
protected function formatPath(string $path): string
    {
        $path = $this->filterPath($path)->withoutDotSegments();
        if ('' !== $this->base_uri->getAuthority() && '' !== $path->__toString()) {
            $path = $path->withLeadingSlash();
        }

        return (string) $path;
    }