Created
July 20, 2016 03:50
Why Comments Are Stupid, a Real Example 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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