ENH: better comments and variable names
This commit is contained in:
parent
e60b8b87eb
commit
89d35bc8fb
|
@ -1218,7 +1218,7 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
|
||||||
}
|
}
|
||||||
if(!cmSystemTools::FileIsFullPath(remote))
|
if(!cmSystemTools::FileIsFullPath(remote))
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("RelativePath must be passed a full path to local: ", remote);
|
cmSystemTools::Error("RelativePath must be passed a full path to remote: ", remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for driveletter: as the start of the path
|
// check for driveletter: as the start of the path
|
||||||
|
@ -1230,54 +1230,55 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
|
||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string relativePath; // result string
|
|
||||||
// split up both paths into arrays of strings using / as a separator
|
// split up both paths into arrays of strings using / as a separator
|
||||||
std::string localString = local;
|
std::string localString = local;
|
||||||
std::vector<cmStdString> fileSplit = cmSystemTools::SplitString(local, '/', true);
|
std::vector<cmStdString> localSplit = cmSystemTools::SplitString(local, '/', true);
|
||||||
std::vector<cmStdString> relativeSplit = cmSystemTools::SplitString(remote, '/', true);
|
std::vector<cmStdString> remoteSplit = cmSystemTools::SplitString(remote, '/', true);
|
||||||
std::vector<cmStdString> commonPath;
|
std::vector<cmStdString> commonPath; // store shared parts of path in this array
|
||||||
std::vector<cmStdString> finalPath;
|
std::vector<cmStdString> finalPath; // store the final relative path here
|
||||||
// count up how many matching directory names there are from the start
|
// count up how many matching directory names there are from the start
|
||||||
unsigned int sameCount = 0;
|
unsigned int sameCount = 0;
|
||||||
while(
|
while(
|
||||||
((sameCount <= (fileSplit.size()-1)) && (sameCount <= (relativeSplit.size()-1)))
|
((sameCount <= (localSplit.size()-1)) && (sameCount <= (remoteSplit.size()-1)))
|
||||||
&&
|
&&
|
||||||
// for windows and apple do a case insensitive string compare
|
// for windows and apple do a case insensitive string compare
|
||||||
#if defined(_WIN32) || defined(__APPLE__)
|
#if defined(_WIN32) || defined(__APPLE__)
|
||||||
cmSystemTools::Strucmp(fileSplit[sameCount].c_str(),
|
cmSystemTools::Strucmp(localSplit[sameCount].c_str(),
|
||||||
relativeSplit[sameCount].c_str()) == 0
|
remoteSplit[sameCount].c_str()) == 0
|
||||||
#else
|
#else
|
||||||
fileSplit[sameCount] == relativeSplit[sameCount]
|
localSplit[sameCount] == remoteSplit[sameCount]
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// put the common parts of the path into the commonPath array
|
// put the common parts of the path into the commonPath array
|
||||||
commonPath.push_back(fileSplit[sameCount]);
|
commonPath.push_back(localSplit[sameCount]);
|
||||||
// erase the common parts of the path from the original path arrays
|
// erase the common parts of the path from the original path arrays
|
||||||
fileSplit[sameCount] = "";
|
localSplit[sameCount] = "";
|
||||||
relativeSplit[sameCount] = "";
|
remoteSplit[sameCount] = "";
|
||||||
sameCount++;
|
sameCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each entry that is not common in the local or file path
|
// for each entry that is not common in the local path
|
||||||
// add a ../ to the finalpath array
|
// add a ../ to the finalpath array, this gets us out of the local
|
||||||
for(unsigned int i = 0; i < fileSplit.size(); ++i)
|
// path into the remote dir
|
||||||
|
for(unsigned int i = 0; i < localSplit.size(); ++i)
|
||||||
{
|
{
|
||||||
if(fileSplit[i].size())
|
if(localSplit[i].size())
|
||||||
{
|
{
|
||||||
finalPath.push_back("../");
|
finalPath.push_back("../");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for each entry that is not common in the remote path add it
|
// for each entry that is not common in the remote path add it
|
||||||
// to the final path
|
// to the final path.
|
||||||
for(std::vector<cmStdString>::iterator i = relativeSplit.begin();
|
for(std::vector<cmStdString>::iterator i = remoteSplit.begin();
|
||||||
i != relativeSplit.end(); ++i)
|
i != remoteSplit.end(); ++i)
|
||||||
{
|
{
|
||||||
if(i->size())
|
if(i->size())
|
||||||
{
|
{
|
||||||
finalPath.push_back(*i);
|
finalPath.push_back(*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::string relativePath; // result string
|
||||||
// now turn the array of directories into a unix path by puttint /
|
// now turn the array of directories into a unix path by puttint /
|
||||||
// between each entry that does not already have one
|
// between each entry that does not already have one
|
||||||
for(std::vector<cmStdString>::iterator i = finalPath.begin();
|
for(std::vector<cmStdString>::iterator i = finalPath.begin();
|
||||||
|
|
Loading…
Reference in New Issue