+ Fix path computation functions for Windows

This commit is contained in:
Kelson42 2014-05-14 18:33:11 +02:00
parent 457406b743
commit 1209e27e8c
1 changed files with 12 additions and 2 deletions

View File

@ -63,6 +63,14 @@ string computeRelativePath(const string path, const string absolutePath) {
} }
string relativePath; string relativePath;
#ifdef _WIN32
/* On Windows you have a token more because the root is represented
by a letter */
if (commonCount == 0) {
relativePath = "../"
}
#endif
for (unsigned int i = commonCount ; i < pathParts.size() ; i++) { for (unsigned int i = commonCount ; i < pathParts.size() ; i++) {
relativePath += "../"; relativePath += "../";
} }
@ -121,7 +129,9 @@ string removeLastPathElement(const string path, const bool removePreSeparator, c
string newPath = path; string newPath = path;
size_t offset = newPath.find_last_of(SEPARATOR); size_t offset = newPath.find_last_of(SEPARATOR);
if (removePreSeparator && if (removePreSeparator &&
#ifndef _WIN32
offset != newPath.find_first_of(SEPARATOR) && offset != newPath.find_first_of(SEPARATOR) &&
#endif
offset == newPath.length()-1) { offset == newPath.length()-1) {
newPath = newPath.substr(0, offset); newPath = newPath.substr(0, offset);
offset = newPath.find_last_of(SEPARATOR); offset = newPath.find_last_of(SEPARATOR);