Normalizes given path with given directory separator.
Default forced to Unix directory separator for substitutePaths to work properly in Windows.
@param string $path path to be normalized
@param string $ds directory separator
@return string
175031
public static function normalizePath($path, $ds = self::UNIX_DS): string
    {
        return rtrim(strtr($path, '/\\', $ds . $ds), $ds);
    }
1266805
public static function normalizePath($path){

		$segments = explode('/',$path);
		$segments = array_reverse($segments);

		$path = array();
		$path_len = 0;

		while( $segments ){
			$segment = array_pop($segments);
			switch( $segment ) {

				case '.':
				break;

				case '..':
					if( !$path_len || ( $path[$path_len-1] === '..') ){
						$path[] = $segment;
						$path_len++;
					}else{
						array_pop($path);
						$path_len--;
					}
				break;

				default:
					$path[] = $segment;
					$path_len++;
				break;
			}
		}

		return implode('/',$path);
	}
556400
public static function cleanFilePathname($path) {
		if (UString::isNotNull ( $path )) {
			if (\DS === "/")
				$path = \str_replace ( "\\", \DS, $path );
			else
				$path = \str_replace ( "/", \DS, $path );
			$path = \str_replace ( \DS . \DS, \DS, $path );
		}
		return $path;
	}
1030545
protected function _normalizePaths()
    {
        foreach ($this->_paths as &$path) {
            $ds = DIRECTORY_SEPARATOR;
            $path = $this->_normalizePath($path, $ds);
            $path = rtrim($path, $ds) . $ds;
        }
    }
798776
public static function fixPath($path)
    {
        // Detect which direction of slash is "wrong"
        switch (DIRECTORY_SEPARATOR) {
            case '\\':
                $wrongDirection = '/';
                break;

            case '/':
            default:
                $wrongDirection = '\\';
                break;
        }

        if (false !== stristr($path, $wrongDirection)) {
            $path = str_replace($wrongDirection, DIRECTORY_SEPARATOR, $path);

            // In case of mixed slashes we maybe need to cleanup
            if (stristr($path, '\\\\')) {
                $path = str_replace('\\\\', '\\', $path);
            } elseif (stristr($path, '//')) {
                $path = str_replace('//', '/', $path);
            }
        }

        // Return corrected path
        return $path;
    }
108646
protected function _abspath($path) {
		return $path == DIRECTORY_SEPARATOR ? $this->root : $this->root.DIRECTORY_SEPARATOR.$path;
	}
188526
public static function removeFileName($path)
    {
        $parts = explode(DIRECTORY_SEPARATOR, static::normalizePath($path));

        array_pop($parts);

        return implode(DIRECTORY_SEPARATOR, $parts);
    }
106916
public static function diskFullPath($path)
    {
        $path = self::diskPath($path);
        if (!Str::startsWith(root, $path)) {
            $path = root . DIRECTORY_SEPARATOR . ltrim($path, '\\/');
        }
        return $path;
    }
626702
public static function normalize(string $path):string
    {
        $path = str_replace('\\', '/', $path);
        $prefix = static::prefix($path);
        $path = substr($path, strlen($prefix));
        $parts = array_filter(explode('/', $path), 'strlen');
        $tokens = array();
        foreach ($parts as $part) {
            switch ($part) {
                case '.':
                    break;
                case '..':
                    if (0 !== count($tokens)) {
                        array_pop($tokens);
                    }

                    break;
                default:
                    $tokens[] = $part;
            }
        }
        return $prefix . implode('/', $tokens);
    }
961370
public static function normalizeRelativePath($path)
	{
		// Path remove self referring paths ("/./").
		$path = preg_replace('#/\.(?=/)|^\./|/\./?$#', '', $path);

		// Regex for resolving relative paths
		$regex = '#/*[^/\.]+/\.\.#Uu';

		while (preg_match($regex, $path))
		{
			$path = preg_replace($regex, '', $path);
		}

		return $path;
	}
1018486
public function normalizeDirectoryPath($path)
    {
        $path = $this->normalizePath($path);

        if (is_link($path)) {
            $path = realpath($path);
        }

        return $path;
    }
298983
public function normalizePath($path)
	{
		$path = rtrim($path, '/\\').DIRECTORY_SEPARATOR;
		$path = realpath($path).DIRECTORY_SEPARATOR;

		if ($this->root and strpos($path, $this->root) !== 0)
		{
			throw new \Exception('Cannot access path outside: '.$this->root.'. Trying to access: '.$path);
		}

		return $path;
	}
38645
protected function normalizePath($path)
    {
        $path = parent::normalizePath($path);
        return $this->getMultiRepositoryPath($path) ?: $path;
    }
1329812
protected function normalize_path( $path ) {

		$path = str_replace( '\\', '/', $path );
		$path = preg_replace( '|/+|','/', $path );

		return rtrim( $path, '/' );
	}
1344886
private String normalizePath(String path) {

		// remove leading and tailing whitespaces
		path = path.trim();

		// remove consecutive slashes & backslashes
		path = path.replace("\\", "/");
		path = path.replaceAll("/+", "/");

		// remove tailing separator
		if (path.endsWith(SEPARATOR) &&
				!path.equals(SEPARATOR) &&              // UNIX root path
				!WINDOWS_ROOT_DIR_REGEX.matcher(path).matches()) {  // Windows root path)

			// remove tailing slash
			path = path.substring(0, path.length() - SEPARATOR.length());
		}

		return 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;
    }
720758
public static function normalizeRelativePath($path)
    {
        $path = str_replace('\\', '/', $path);
        $path = static::removeFunkyWhiteSpace($path);

        $parts = [];

        foreach (explode('/', $path) as $part) {
            switch ($part) {
                case '':
                case '.':
                break;

            case '..':
                if (empty($parts)) {
                    throw new LogicException(
                        'Path is outside of the defined root, path: [' . $path . ']'
                    );
                }
                array_pop($parts);
                break;

            default:
                $parts[] = $part;
                break;
            }
        }

        return implode('/', $parts);
    }