namespace ICSharpCode.SharpZipLib.Core
{
///
/// WindowsPathUtils provides simple utilities for handling windows paths.
///
public abstract class WindowsPathUtils
{
///
/// Initializes a new instance of the class.
///
internal WindowsPathUtils()
{
}
///
/// Remove any path root present in the path
///
/// A containing path information.
/// The path with the root removed if it was present; path otherwise.
/// Unlike the class the path isnt otherwise checked for validity.
public static string DropPathRoot(string path)
{
string result = path;
if (!string.IsNullOrEmpty(path))
{
if ((path[0] == '\\') || (path[0] == '/'))
{
// UNC name ?
if ((path.Length > 1) && ((path[1] == '\\') || (path[1] == '/')))
{
int index = 2;
int elements = 2;
// Scan for two separate elements \\machine\share\restofpath
while ((index <= path.Length) &&
(((path[index] != '\\') && (path[index] != '/')) || (--elements > 0)))
{
index++;
}
index++;
if (index < path.Length)
{
result = path.Substring(index);
}
else
{
result = "";
}
}
}
else if ((path.Length > 1) && (path[1] == ':'))
{
int dropCount = 2;
if ((path.Length > 2) && ((path[2] == '\\') || (path[2] == '/')))
{
dropCount = 3;
}
result = result.Remove(0, dropCount);
}
}
return result;
}
}
}