From d53e5dec3748e1d800dae595dcb78f2c4d55f788 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 9 Jun 2008 11:57:56 -0400 Subject: [PATCH] ENH: In find_* implementation centralize addition of trailing slashes - Create cmFindCommon::AddTrailingSlashes - Use it in cmFindBase and cmFindPackageCommand - Remove duplication from other find commands --- Source/cmFindBase.cxx | 4 ++++ Source/cmFindCommon.cxx | 15 +++++++++++++++ Source/cmFindCommon.h | 3 +++ Source/cmFindLibraryCommand.cxx | 10 ---------- Source/cmFindPackageCommand.cxx | 10 +--------- Source/cmFindPathCommand.cxx | 10 ---------- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 68e091baa..41e09f057 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -273,6 +273,10 @@ bool cmFindBase::ParseArguments(std::vector const& argsIn) // Handle search root stuff. this->RerootPaths(this->SearchPaths); + + // Add a trailing slash to all prefixes to aid the search process. + this->AddTrailingSlashes(this->SearchPaths); + return true; } diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index a82e6115e..d69fdce2e 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -417,3 +417,18 @@ void cmFindCommon::AddPathInternal(std::string const& in_path, this->SearchPaths.push_back(fullPath.c_str()); } } + +//---------------------------------------------------------------------------- +void cmFindCommon::AddTrailingSlashes(std::vector& paths) +{ + // Add a trailing slash to all paths to aid the search process. + for(std::vector::iterator i = paths.begin(); + i != paths.end(); ++i) + { + std::string& p = *i; + if(!p.empty() && p[p.size()-1] != '/') + { + p += "/"; + } + } +} diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index e141a08ea..a316b3387 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -44,6 +44,9 @@ protected: /** Place a set of search paths under the search roots. */ void RerootPaths(std::vector& paths); + /** Add trailing slashes to all search paths. */ + void AddTrailingSlashes(std::vector& paths); + /** Compute the current default root path mode. */ void SelectDefaultRootPathMode(); diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index ab6140176..2bf54b13d 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -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::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; for(std::vector::const_iterator p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 5cc172423..426d3df09 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1067,15 +1067,7 @@ void cmFindPackageCommand::ComputeFinalPrefixes() this->RerootPaths(prefixes); // Add a trailing slash to all prefixes to aid the search process. - for(std::vector::iterator i = prefixes.begin(); - i != prefixes.end(); ++i) - { - std::string& prefix = *i; - if(prefix[prefix.size()-1] != '/') - { - prefix += "/"; - } - } + this->AddTrailingSlashes(prefixes); } //---------------------------------------------------------------------------- diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index c04594ac6..e22b12200 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -102,16 +102,6 @@ bool cmFindPathCommand supportFrameworks = false; } std::string framework; - // Add a trailing slash to all paths to aid the search process. - for(std::vector::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. unsigned int k; std::string result;