Convert loops populating maybe-empty content into the common pattern.

This commit is contained in:
Stephen Kelly 2015-01-17 17:36:19 +01:00
parent 7ee56f0399
commit 7b8725bf84
3 changed files with 30 additions and 17 deletions

View File

@ -254,14 +254,18 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
// expand the variable // expand the variable
std::string listString; std::string listString;
this->GetListString(listString, listName); this->GetListString(listString, listName);
size_t cc;
for ( cc = 2; cc < args.size(); ++ cc ) if(!listString.empty() && !args.empty())
{
if(!listString.empty())
{ {
listString += ";"; listString += ";";
} }
const char* sep = "";
size_t cc;
for ( cc = 2; cc < args.size(); ++ cc )
{
listString += sep;
listString += args[cc]; listString += args[cc];
sep = ";";
} }
this->Makefile->AddDefinition(listName, listString.c_str()); this->Makefile->AddDefinition(listName, listString.c_str());

View File

@ -3011,13 +3011,17 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
// trailing slash in the input then the last iteration of the loop // trailing slash in the input then the last iteration of the loop
// will add a slash followed by an empty string which will preserve // will add a slash followed by an empty string which will preserve
// the trailing slash in the output. // the trailing slash in the output.
for(unsigned int i=common; i < remote.size(); ++i)
{ if(!relative.empty() && !remote.empty())
if(!relative.empty())
{ {
relative += "/"; relative += "/";
} }
const char* sep = "";
for(unsigned int i=common; i < remote.size(); ++i)
{
relative += sep;
relative += remote[i]; relative += remote[i];
sep = "/";
} }
// Finally return the path. // Finally return the path.

View File

@ -166,15 +166,17 @@ bool cmMacroHelperCommand::InvokeInitialPass
{ {
if (expandedArgs.size() > this->Args.size() - 1) if (expandedArgs.size() > this->Args.size() - 1)
{ {
std::vector<std::string>::const_iterator eit if (!argnDef.empty() && !expandedArgs.empty())
= expandedArgs.begin() + (this->Args.size() - 1);
for( ; eit != expandedArgs.end(); ++eit)
{
if (!argnDef.empty())
{ {
argnDef += ";"; argnDef += ";";
} }
argnDef += *eit; std::vector<std::string>::const_iterator eit
= expandedArgs.begin() + (this->Args.size() - 1);
const char* sep = "";
for( ; eit != expandedArgs.end(); ++eit)
{
argnDef += sep + *eit;
sep = ";";
} }
} }
argnDefInitialized = true; argnDefInitialized = true;
@ -191,14 +193,17 @@ bool cmMacroHelperCommand::InvokeInitialPass
// repleace ARGV, compute it only once // repleace ARGV, compute it only once
if (!argvDefInitialized) if (!argvDefInitialized)
{ {
std::vector<std::string>::const_iterator eit; if (!argvDef.empty() && !expandedArgs.empty())
for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
{
if (!argvDef.empty())
{ {
argvDef += ";"; argvDef += ";";
} }
const char* sep = "";
std::vector<std::string>::const_iterator eit;
for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
{
argvDef += sep;
argvDef += *eit; argvDef += *eit;
sep = ";";
} }
argvDefInitialized = true; argvDefInitialized = true;
} }