Fix Path Separator

@param string $path
@param bool   $useCleanPrefix
@return string
551636
public static function fixDirectorySeparator(string $path, $useCleanPrefix = false) : string
    {
        /**
         * Trimming path string
         */
        if (($path = trim($path)) == '') {
            return $path;
        }

        $path = preg_replace('`(\/|\\\)+`', DIRECTORY_SEPARATOR, $path);
        if ($useCleanPrefix) {
            $path = DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
        }

        return $path;
    }
1270031
public static String clean(final String path) {
        return clean(path.replace(WINDOWS_SEPARATOR, UNIX_SEPARATOR), true);
    }
661695
function removePathPrefix($path)
    {
        if (strpos($path, $this->getPathPrefix()) === false) {
            return basename($path);
        }

        return parent::removePathPrefix($path);
    }
1277754
private function fixPath($path)
    {
        $helper = $this->getAssets();

        if ($helper === null) {
            return $path;
        }

        $url = $helper->getUrl($path);

        if (substr($path, -1) === '/' && ($position = strpos($url, '?')) !== false) {
            $url = substr($url, 0, $position);
        }

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

        return $path;
    }
372801
protected function fixPath($path)
    {
        $len = strlen($this->front);

        if (substr($path, 0, $len) == $this->front) {
            $path = substr($path, $len);
        }

        return '/' . ltrim($path, '/');
    }
26951
public static function normalizePath($path, $endSlash = true)
    {
        $path = rtrim($path, '/') . DIRECTORY_SEPARATOR;
        $path = rtrim($path, DIRECTORY_SEPARATOR);

        $path = $endSlash ? $path . DIRECTORY_SEPARATOR : $path;

        return $path;
    }
36557
public static String fixFilePath(String source, String separator)
    {
    	if (source == null)
    		return null;
        StringBuilder dest = new StringBuilder(DBConstants.BLANK);
        for (int i = 0; i < source.length(); i++)
        {
            if (source.charAt(i) == '/')
            	dest.append(separator);
            else
            	dest.append(source.charAt(i));
        }
        return dest.toString();
    }
1289185
public static function formatPath($path)
    {
        if ($path == DIRECTORY_SEPARATOR) {
            return $path;
        }
        return trim($path) ? rtrim(trim($path), DIRECTORY_SEPARATOR) : '';
    }
421893
protected function fixTarPath($path)
    {
        if (OsUtil::isWindows()) {
            $path = preg_replace_callback(
                '#^([A-Z]):/#i',
                function (array $matches) {
                    return '/' . strtolower($matches[1]) . '/';
                },
                str_replace('\\', '/', $path)
            );
        }

        return $path;
    }
146089
protected function normalizePath($path, $sep='/')
    {
        $path = $this->normalizeSlashes($path, $sep);
        $out = [];
        foreach (explode($sep, $path) as $i => $fold) {
            if ($fold == '..' && $i > 0 && end($out) != '..') array_pop($out);
            $fold = preg_replace('/\.{2,}/', '.', $fold);
            if ($fold == '' || $fold == '.') continue;
            else $out[] = $fold;
        }
        return ($path[0] == $sep ? $sep : '') . join($sep, $out);
    }
1112309
protected function normalize($path, $returnString = false)
    {
        // Clean the Directory separator
        $path = $this->clean($path);

        // Extract to array
        $path = $this->extract($path);

        // Remove dots from path
        $path = $this->removeDots($path);

        // If set to return string, compact it.
        if ($returnString == true) {
            $path = $this->compact($path);
        }

        return $path;
    }
1090027
public function removePrefixPath($prefix, $path = null)
    {
        $prefix = $this->_formatPrefix($prefix);
        if ($this->_useStaticRegistry) {
            $registry =& self::$_staticPrefixToPaths[$this->_useStaticRegistry];
        } else {
            $registry =& $this->_prefixToPaths;
        }

        if (!isset($registry[$prefix])) {

            throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' was not found in the PluginLoader.');
        }

        if ($path != null) {
            $pos = array_search($path, $registry[$prefix]);
            if (false === $pos) {

                throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' / Path ' . $path . ' was not found in the PluginLoader.');
            }
            unset($registry[$prefix][$pos]);
        } else {
            unset($registry[$prefix]);
        }

        return $this;
    }
20630
public function normalizePath($path)
    {
        $path = trim($path);

        $path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path);

        if (ends_with($path, DIRECTORY_SEPARATOR)) {
            $path = substr($path, 0, -1);
        }

        return $path;
    }
735445
protected function canonicalize($path)
    {
        $parts = array_filter(explode('/', $path));
        $canonicalized = array();

        foreach ($parts as $part) {
            if ('.' == $part) {
                continue;
            }

            if ('..' == $part) {
                array_pop($canonicalized);
            } else {
                $canonicalized[] = $part;
            }
        }

        return implode('/', $canonicalized);
    }
774056
public static function resolve_path_with_dots($path) {

		if(!is_null($path) && is_string($path) && strlen($path)) {
			while(preg_match('/\/\//', $path)) {
				$path = preg_replace('/\/\//', '/', $path);
			}
			$retval = $path;
			if(preg_match('/\./', $path)) {

				$isAbsolute = FALSE;
				if(preg_match('/^\//', $path)) {
					$isAbsolute = TRUE;
					$path = preg_replace('/^\//', '', $path);
				}
				$pieces = explode('/', $path);

				$finalPieces = array();
				for($i=0; $i < count($pieces); $i++) {
					$dirName = $pieces[$i];
					if($dirName == '.') {
						//do nothing; don't bother appending.
					}
					elseif($dirName == '..') {
						array_pop($finalPieces);
					}
					else {
						$finalPieces[] = $dirName;
					}
				}

				//$retval = cs_global::string_from_array($finalPieces, NULL, '/');
				$retval = implode('/', $finalPieces);
				if($isAbsolute) {
					$retval = '/'. $retval;
				}
			}
		}
		else {
			throw new \InvalidArgumentException(__METHOD__ .": invalid path (". $path .")");
		}

		if(is_null($retval)) {
			throw new \LogicException(__METHOD__ .": returning NULL for path (". $path .")");
		}
		return($retval);
	}
1081521
public static function fixPath(string $path): string
    {
        if (false !== strpos($path, '\\')) {
            $path = str_replace('\\', '/', $path);
        }
        while (false !== strpos($path, '//')) {
            $path = str_replace('//', '/', $path);
        }
        if (strlen($path)) {
            if ('/' === substr($path, 0, 1)) {
                $path = ltrim($path, '/');
            }
            if ('/' === substr($path, -1, 1)) {
                $path = rtrim($path, '/');
            }
        }

        return $path;
    }