KWSys: Use SplitPath in GetActualCaseForPath

Avoid using the old SplitString method in favor of the more robust
SplitPath method.
This commit is contained in:
Brad King 2010-08-27 10:46:35 -04:00
parent 3bf1869c93
commit 735a8c26d7
1 changed files with 12 additions and 7 deletions

View File

@ -3063,30 +3063,35 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot
static int GetCasePathName(const kwsys_stl::string & pathIn, static int GetCasePathName(const kwsys_stl::string & pathIn,
kwsys_stl::string & casePath) kwsys_stl::string & casePath)
{ {
kwsys_stl::vector<kwsys::String> path_components = kwsys_stl::vector<kwsys_stl::string> path_components;
SystemTools::SplitString(pathIn.c_str(), '/', true); SystemTools::SplitPath(pathIn.c_str(), path_components);
if(path_components.empty()) if(path_components[0].empty()) // First component always exists.
{ {
// Relative paths cannot be converted.
casePath = ""; casePath = "";
return 0; return 0;
} }
// Start with root component.
kwsys_stl::vector<kwsys_stl::string>::size_type idx = 0; kwsys_stl::vector<kwsys_stl::string>::size_type idx = 0;
// assume always absolute path, so just take first
casePath = path_components[idx++]; casePath = path_components[idx++];
const char* sep = "";
// If network path, fill casePath with server/share so FindFirstFile // If network path, fill casePath with server/share so FindFirstFile
// will work after that. Maybe someday call other APIs to get // will work after that. Maybe someday call other APIs to get
// actual case of servers and shares. // actual case of servers and shares.
if(path_components.size() > 2 && pathIn.size() >= 2 && if(path_components.size() > 2 && path_components[0] == "//")
pathIn[0] == '/' && pathIn[1] == '/')
{ {
casePath += path_components[idx++]; casePath += path_components[idx++];
casePath += "/"; casePath += "/";
casePath += path_components[idx++]; casePath += path_components[idx++];
sep = "/";
} }
for(; idx < path_components.size(); idx++) for(; idx < path_components.size(); idx++)
{ {
casePath += "/"; casePath += sep;
sep = "/";
kwsys_stl::string test_str = casePath; kwsys_stl::string test_str = casePath;
test_str += path_components[idx]; test_str += path_components[idx];