/**
* Function to strip additional / or \ in a path name.
*
* @param string $path The path to clean.
* @param string $ds Directory separator (optional).
*
* @return string The cleaned path.
*
* @throws \UnexpectedValueException
* @since 1.7.0
*/
public static function clean($path, $ds = DIRECTORY_SEPARATOR)
{
if (!\is_string($path) && !empty($path)) {
throw new \UnexpectedValueException(sprintf('%s() - $path is not a string', __METHOD__));
}
$path = trim($path);
if (empty($path)) {
$path = JPATH_ROOT;
} elseif ($ds === '\\' && substr($path, 0, 2) === '\\\\') {
$path = "\\" . preg_replace('#[/\\\\]+#', $ds, $path);
} else {
$path = preg_replace('#[/\\\\]+#', $ds, $path);
}
return $path;
}