public function normalize_path($path, $slash_it = true)
{
$path_original = $path;
$s = DIRECTORY_SEPARATOR;
$path = preg_replace('/[\\/\\\\]/', $s, $path);
$path = str_replace($s . $s, $s, $path);
if (strval($path) == '') {
$path = $path_original;
}
if ($slash_it == false) {
$path = rtrim($path, DIRECTORY_SEPARATOR);
} else {
$path .= DIRECTORY_SEPARATOR;
$path = rtrim($path, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
}
if (strval(trim($path)) == '' or strval(trim($path)) == '/') {
$path = $path_original;
}
if ($slash_it == false) {
} else {
$path = $path . DIRECTORY_SEPARATOR;
$path = $this->reduce_double_slashes($path);
}
return $path;
}