Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String NormalizePath(const String& path)
- {
- Int first, last, length, i;
- length = path.length();
- // Locate the first directory separator
- for(i = 0; i < length; ++i)
- {
- Char letter = path[i];
- if((letter == '/') || (letter == '\\'))
- {
- first = last = i;
- break;
- }
- }
- // Locate the last directory separator
- for(++i; i < length; ++i)
- {
- Char letter = path[i];
- if((letter == '/') || (letter == '\\'))
- {
- last = i;
- break;
- }
- }
- // Exit if the path is already normalized
- if(first == last) { return path; }
- Int filenameLength = length - last;
- Char normalized[MAX_PATH];
- ZeroMemory(normalized, MAX_PATH);
- // Copy the characters into the normalized string
- // Front
- for(i = 0; i < first; ++i)
- {
- normalized[i] = path[i];
- }
- // Back
- for(i = 0; i < filenameLength; ++i)
- {
- normalized[first + i] = path[last + i];
- }
- return normalized;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement