ENH: In find_* implementation centralize addition of trailing slashes
- Create cmFindCommon::AddTrailingSlashes - Use it in cmFindBase and cmFindPackageCommand - Remove duplication from other find commands
This commit is contained in:
parent
3446bab75e
commit
d53e5dec37
|
@ -273,6 +273,10 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
||||||
|
|
||||||
// Handle search root stuff.
|
// Handle search root stuff.
|
||||||
this->RerootPaths(this->SearchPaths);
|
this->RerootPaths(this->SearchPaths);
|
||||||
|
|
||||||
|
// Add a trailing slash to all prefixes to aid the search process.
|
||||||
|
this->AddTrailingSlashes(this->SearchPaths);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -417,3 +417,18 @@ void cmFindCommon::AddPathInternal(std::string const& in_path,
|
||||||
this->SearchPaths.push_back(fullPath.c_str());
|
this->SearchPaths.push_back(fullPath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmFindCommon::AddTrailingSlashes(std::vector<std::string>& paths)
|
||||||
|
{
|
||||||
|
// Add a trailing slash to all paths to aid the search process.
|
||||||
|
for(std::vector<std::string>::iterator i = paths.begin();
|
||||||
|
i != paths.end(); ++i)
|
||||||
|
{
|
||||||
|
std::string& p = *i;
|
||||||
|
if(!p.empty() && p[p.size()-1] != '/')
|
||||||
|
{
|
||||||
|
p += "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,9 @@ protected:
|
||||||
/** Place a set of search paths under the search roots. */
|
/** Place a set of search paths under the search roots. */
|
||||||
void RerootPaths(std::vector<std::string>& paths);
|
void RerootPaths(std::vector<std::string>& paths);
|
||||||
|
|
||||||
|
/** Add trailing slashes to all search paths. */
|
||||||
|
void AddTrailingSlashes(std::vector<std::string>& paths);
|
||||||
|
|
||||||
/** Compute the current default root path mode. */
|
/** Compute the current default root path mode. */
|
||||||
void SelectDefaultRootPathMode();
|
void SelectDefaultRootPathMode();
|
||||||
|
|
||||||
|
|
|
@ -252,16 +252,6 @@ std::string cmFindLibraryCommand::FindLibrary(const char* name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a trailing slash to all paths to aid the search process.
|
|
||||||
for(std::vector<std::string>::iterator i = this->SearchPaths.begin();
|
|
||||||
i != this->SearchPaths.end(); ++i)
|
|
||||||
{
|
|
||||||
std::string& p = *i;
|
|
||||||
if(p.empty() || p[p.size()-1] != '/')
|
|
||||||
{
|
|
||||||
p += "/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::string tryPath;
|
std::string tryPath;
|
||||||
for(std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
|
for(std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
|
||||||
p != this->SearchPaths.end(); ++p)
|
p != this->SearchPaths.end(); ++p)
|
||||||
|
|
|
@ -1067,15 +1067,7 @@ void cmFindPackageCommand::ComputeFinalPrefixes()
|
||||||
this->RerootPaths(prefixes);
|
this->RerootPaths(prefixes);
|
||||||
|
|
||||||
// Add a trailing slash to all prefixes to aid the search process.
|
// Add a trailing slash to all prefixes to aid the search process.
|
||||||
for(std::vector<std::string>::iterator i = prefixes.begin();
|
this->AddTrailingSlashes(prefixes);
|
||||||
i != prefixes.end(); ++i)
|
|
||||||
{
|
|
||||||
std::string& prefix = *i;
|
|
||||||
if(prefix[prefix.size()-1] != '/')
|
|
||||||
{
|
|
||||||
prefix += "/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -102,16 +102,6 @@ bool cmFindPathCommand
|
||||||
supportFrameworks = false;
|
supportFrameworks = false;
|
||||||
}
|
}
|
||||||
std::string framework;
|
std::string framework;
|
||||||
// Add a trailing slash to all paths to aid the search process.
|
|
||||||
for(std::vector<std::string>::iterator i = this->SearchPaths.begin();
|
|
||||||
i != this->SearchPaths.end(); ++i)
|
|
||||||
{
|
|
||||||
std::string& p = *i;
|
|
||||||
if(p.empty() || p[p.size()-1] != '/')
|
|
||||||
{
|
|
||||||
p += "/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Use the search path to find the file.
|
// Use the search path to find the file.
|
||||||
unsigned int k;
|
unsigned int k;
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
Loading…
Reference in New Issue