mirror of https://github.com/kiwix/libkiwix.git
Use the correct separator when computing relativePath.
This commit is contained in:
parent
802df71410
commit
d4ecda40ff
|
@ -35,9 +35,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define SEPARATOR "\\"
|
const std::string SEPARATOR("\\");
|
||||||
#else
|
#else
|
||||||
#define SEPARATOR "/"
|
const std::string SEPARATOR("/");
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -66,28 +66,25 @@ string computeRelativePath(const string path, const string absolutePath)
|
||||||
while (commonCount < pathParts.size()
|
while (commonCount < pathParts.size()
|
||||||
&& commonCount < absolutePathParts.size()
|
&& commonCount < absolutePathParts.size()
|
||||||
&& pathParts[commonCount] == absolutePathParts[commonCount]) {
|
&& pathParts[commonCount] == absolutePathParts[commonCount]) {
|
||||||
if (!pathParts[commonCount].empty()) {
|
|
||||||
commonCount++;
|
commonCount++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
string relativePath;
|
string relativePath;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* On Windows you have a token more because the root is represented
|
/* On Windows you have a token more because the root is represented
|
||||||
by a letter */
|
by a letter */
|
||||||
if (commonCount == 0) {
|
if (commonCount == 0) {
|
||||||
relativePath = "../";
|
relativePath = ".." + SEPARATOR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (unsigned int i = commonCount; i < pathParts.size(); i++) {
|
for (unsigned int i = commonCount; i < pathParts.size(); i++) {
|
||||||
relativePath += "../";
|
relativePath += ".." + SEPARATOR;
|
||||||
}
|
}
|
||||||
for (unsigned int i = commonCount; i < absolutePathParts.size(); i++) {
|
for (unsigned int i = commonCount; i < absolutePathParts.size(); i++) {
|
||||||
relativePath += absolutePathParts[i];
|
relativePath += absolutePathParts[i];
|
||||||
relativePath += i + 1 < absolutePathParts.size() ? "/" : "";
|
relativePath += i + 1 < absolutePathParts.size() ? SEPARATOR : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return relativePath;
|
return relativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue