Skip to content

Instantly share code, notes, and snippets.

Why Comments Are Stupid, a Real Example 3
public class DirectoryFileSplitter
{
private readonly string validatedFullPath;
private int length;
private int rootLength;
public DirectoryFileSplitter(string validatedFullPath)
{
this.validatedFullPath = validatedFullPath;
}
public void Split(out string directory, out string file)
{
directory = null;
file = null;
if (validatedFullPath != null)
{
length = validatedFullPath.Length;
rootLength = GetRootLength(validatedFullPath);
IgnoreTrailingSlash();
// find the pivot index between end of string and root
for (int pivot = length - 1; pivot >= rootLength; pivot--)
{
if (IsDirectorySeparator(validatedFullPath[pivot]))
{
directory = validatedFullPath.Substring(0, pivot);
file = validatedFullPath.Substring(pivot + 1, length - pivot - 1);
return;
}
}
// no pivot, return just the trimmed directory
directory = validatedFullPath.Substring(0, length);
}
return;
}
private void IgnoreTrailingSlash()
{
if (length > rootLength && EndsInDirectorySeparator(validatedFullPath))
length--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment