in SharpGenTools.Sdk/Internal/Roslyn/PathUtilities.cs [201:264]
private static string GetWindowsRoot(string path)
{
// Windows
int length = path.Length;
if (length >= 1 && IsDirectorySeparator(path[0]))
{
if (length < 2 || !IsDirectorySeparator(path[1]))
{
// It was of the form:
// \
// \f
// in this case, just return \ as the root.
return path.Substring(0, 1);
}
// First consume all directory separators.
int i = 2;
i = ConsumeDirectorySeparators(path, length, i);
// We've got \\ so far. If we have a path of the form \\x\y\z
// then we want to return "\\x\y" as the root portion.
bool hitSeparator = false;
while (true)
{
if (i == length)
{
// We reached the end of the path. The entire path is
// considered the root.
return path;
}
if (!IsDirectorySeparator(path[i]))
{
// We got a non separator character. Just keep consuming.
i++;
continue;
}
if (!hitSeparator)
{
// This is the first separator group we've hit after some server path.
// Consume them and keep going.
hitSeparator = true;
i = ConsumeDirectorySeparators(path, length, i);
continue;
}
// We hit the second separator. The root is the path up to this point.
return path.Substring(0, i);
}
}
else if (length >= 2 && path[1] == VolumeSeparatorChar)
{
// handles c: and c:\
return length >= 3 && IsDirectorySeparator(path[2])
? path.Substring(0, 3)
: path.Substring(0, 2);
}
else
{
// No path root.
return "";
}
}