ENH: Added JoinPath overload that accepts an iterator range.

This commit is contained in:
Brad King 2006-08-17 12:02:18 -04:00
parent 006b61be35
commit 3a44f2a47e
2 changed files with 25 additions and 6 deletions

View File

@ -2813,20 +2813,36 @@ void SystemTools::SplitPath(const char* p,
kwsys_stl::string kwsys_stl::string
SystemTools::JoinPath(const kwsys_stl::vector<kwsys_stl::string>& components) SystemTools::JoinPath(const kwsys_stl::vector<kwsys_stl::string>& components)
{ {
return SystemTools::JoinPath(components.begin(), components.end());
}
//----------------------------------------------------------------------------
kwsys_stl::string
SystemTools
::JoinPath(kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
kwsys_stl::vector<kwsys_stl::string>::const_iterator last)
{
// Construct result in a single string.
kwsys_stl::string result; kwsys_stl::string result;
if(components.size() > 0)
// The first two components do not add a slash.
if(first != last)
{ {
result += components[0]; result += *first++;
} }
if(components.size() > 1) if(first != last)
{ {
result += components[1]; result += *first++;
} }
for(unsigned int i=2; i < components.size(); ++i)
// All remaining components are always separated with a slash.
while(first != last)
{ {
result += "/"; result += "/";
result += components[i]; result += *first++;
} }
// Return the concatenated result.
return result; return result;
} }

View File

@ -364,6 +364,9 @@ public:
*/ */
static kwsys_stl::string JoinPath( static kwsys_stl::string JoinPath(
const kwsys_stl::vector<kwsys_stl::string>& components); const kwsys_stl::vector<kwsys_stl::string>& components);
static kwsys_stl::string JoinPath(
kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
kwsys_stl::vector<kwsys_stl::string>::const_iterator last);
/** /**
* Compare a path or components of a path. * Compare a path or components of a path.