From 8910224950a2b723e0d4fd7c21a326af7fb2e050 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 14 Jan 2015 21:31:46 +0100 Subject: [PATCH] Replace common loop pattern with cmJoin --- Source/cmFindPackageCommand.cxx | 19 ++---------------- Source/cmFunctionCommand.cxx | 8 ++------ Source/cmGetCMakePropertyCommand.cxx | 20 ++----------------- Source/cmMacroCommand.cxx | 9 +-------- Source/cmMakefile.cxx | 30 +++------------------------- Source/cmOptionCommand.cxx | 6 +----- 6 files changed, 11 insertions(+), 81 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 7746980d4..fd9b236a8 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1064,26 +1064,11 @@ void cmFindPackageCommand::AppendToFoundProperty(bool found) } - std::string tmp; - const char* sep =""; - for(size_t i=0; iMakefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND", tmp.c_str()); - tmp = ""; - sep = ""; - for(size_t i=0; iMakefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND", tmp.c_str()); } diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index c33048c81..b44e228a0 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -193,12 +193,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, if (!this->Depth) { std::string name = this->Args[0]; - std::vector::size_type cc; - name += "("; - for ( cc = 0; cc < this->Args.size(); cc ++ ) - { - name += " " + this->Args[cc]; - } + name += "( "; + name += cmJoin(this->Args, " "); name += " )"; // create a new command and add it to cmake diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx index c0e4683a2..84c00bac4 100644 --- a/Source/cmGetCMakePropertyCommand.cxx +++ b/Source/cmGetCMakePropertyCommand.cxx @@ -34,15 +34,7 @@ bool cmGetCMakePropertyCommand std::vector vars = this->Makefile->GetDefinitions(cacheonly); if (!vars.empty()) { - output = ""; - const char* sep = ""; - std::vector::size_type cc; - for ( cc = 0; cc < vars.size(); ++cc ) - { - output += sep; - output += vars[cc]; - sep = ";"; - } + output = cmJoin(vars, ";"); } } else if ( args[1] == "MACROS" ) @@ -54,15 +46,7 @@ bool cmGetCMakePropertyCommand const std::set* components = this->Makefile->GetLocalGenerator()->GetGlobalGenerator() ->GetInstallComponents(); - std::set::const_iterator compIt; - output = ""; - const char* sep = ""; - for (compIt = components->begin(); compIt != components->end(); ++compIt) - { - output += sep; - output += *compIt; - sep = ";"; - } + output = cmJoin(*components, ";"); } else { diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 81aaf3ec1..676e082bf 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -197,14 +197,7 @@ bool cmMacroHelperCommand::InvokeInitialPass { argvDef += ";"; } - const char* sep = ""; - std::vector::const_iterator eit; - for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit) - { - argvDef += sep; - argvDef += *eit; - sep = ";"; - } + argvDef += cmJoin(expandedArgs, ";"); argvDefInitialized = true; } cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str()); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index aca4413a2..ac5fec9c3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4202,15 +4202,7 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "LISTFILE_STACK") { - const char* sep = ""; - for (std::deque::const_iterator - i = this->ListFileStack.begin(); - i != this->ListFileStack.end(); ++i) - { - output += sep; - output += *i; - sep = ";"; - } + output = cmJoin(this->ListFileStack, ";"); return output.c_str(); } else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES") @@ -4220,14 +4212,7 @@ const char *cmMakefile::GetProperty(const std::string& prop, { cacheonly = 1; } - std::vector vars = this->GetDefinitions(cacheonly); - const char* sep = ""; - for (unsigned int cc = 0; cc < vars.size(); cc ++ ) - { - output += sep; - output += vars[cc]; - sep = ";"; - } + output = cmJoin(this->GetDefinitions(cacheonly), ";"); return output.c_str(); } else if (prop == "MACROS") @@ -4242,16 +4227,7 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "LINK_DIRECTORIES") { - const char* sep = ""; - for (std::vector::const_iterator - it = this->GetLinkDirectories().begin(); - it != this->GetLinkDirectories().end(); - ++ it ) - { - output += sep; - output += *it; - sep = ";"; - } + output = cmJoin(this->GetLinkDirectories(), ";"); return output.c_str(); } else if (prop == "INCLUDE_DIRECTORIES") diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index e505440e8..60728eaea 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -34,11 +34,7 @@ bool cmOptionCommand if(argError) { std::string m = "called with incorrect number of arguments: "; - for(size_t i =0; i < args.size(); ++i) - { - m += args[i]; - m += " "; - } + m += cmJoin(args, " "); this->SetError(m); return false; }