cmAlgorithms: Add cmWrap.
Port some existing cmJoin to use it. cmJoin is cumbersome to use in cases where the objective is to somehow 'quote' each item and then join it with a separator. In that case, the joiner string is harder to read and reason about. cmWrap aims to solve that. Provide an overload taking char wrappers to simplify the case of surrounding every element in quotes without needing to escape the quote character.
This commit is contained in:
parent
a281809384
commit
37b88d348a
|
@ -278,4 +278,21 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r)
|
||||||
return cmRemoveIndices(r, indices);
|
return cmRemoveIndices(r, indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Range>
|
||||||
|
std::string cmWrap(std::string prefix, Range const& r, std::string suffix,
|
||||||
|
std::string sep)
|
||||||
|
{
|
||||||
|
if (r.empty())
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
return prefix + cmJoin(r, (suffix + sep + prefix).c_str()) + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Range>
|
||||||
|
std::string cmWrap(char prefix, Range const& r, char suffix, std::string sep)
|
||||||
|
{
|
||||||
|
return cmWrap(std::string(1, prefix), r, std::string(1, suffix), sep);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2296,14 +2296,7 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
|
||||||
if (!componentsSet->empty())
|
if (!componentsSet->empty())
|
||||||
{
|
{
|
||||||
ostr << "Available install components are: ";
|
ostr << "Available install components are: ";
|
||||||
std::set<std::string>::iterator it;
|
ostr << cmWrap('"', *componentsSet, '"', " ");
|
||||||
for (
|
|
||||||
it = componentsSet->begin();
|
|
||||||
it != componentsSet->end();
|
|
||||||
++ it )
|
|
||||||
{
|
|
||||||
ostr << " \"" << *it << "\"";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -724,12 +724,7 @@ cmLocalUnixMakefileGenerator3
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the list of commands.
|
// Write the list of commands.
|
||||||
for(std::vector<std::string>::const_iterator i = commands.begin();
|
os << cmWrap("\t", commands, "", "\n") << "\n";
|
||||||
i != commands.end(); ++i)
|
|
||||||
{
|
|
||||||
replace = *i;
|
|
||||||
os << "\t" << replace << "\n";
|
|
||||||
}
|
|
||||||
if(symbolic && !this->WatcomWMake)
|
if(symbolic && !this->WatcomWMake)
|
||||||
{
|
{
|
||||||
os << ".PHONY : " << cmMakeSafe(tgt) << "\n";
|
os << ".PHONY : " << cmMakeSafe(tgt) << "\n";
|
||||||
|
|
|
@ -835,7 +835,7 @@ cmSystemTools::PrintSingleCommand(std::vector<std::string> const& command)
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "\"" + cmJoin(command, "\" \"") + "\"";
|
return cmWrap('"', command, '"', " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmSystemTools::DoesFileExistWithExtensions(
|
bool cmSystemTools::DoesFileExistWithExtensions(
|
||||||
|
|
|
@ -450,9 +450,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string command = "\"";
|
std::string command = cmWrap('"', cmRange(args).advance(3), '"', " ");
|
||||||
command += cmJoin(cmRange(args).advance(3), "\" \"");
|
|
||||||
command += "\"";
|
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
|
if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
|
||||||
|
|
Loading…
Reference in New Issue