diff options
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r-- | Source/cmListCommand.cxx | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 1b01ea2..cbb1d3a 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -13,6 +13,9 @@ #include <stdio.h> #include <stdlib.h> // required for atoi #include <utility> +#include <vector> + +#include "cm_memory.hxx" #include "cmAlgorithms.h" #include "cmGeneratorExpression.h" @@ -20,6 +23,7 @@ #include "cmMessageType.h" #include "cmPolicies.h" #include "cmRange.h" +#include "cmStringAlgorithms.h" #include "cmStringReplaceHelper.h" #include "cmSystemTools.h" @@ -115,7 +119,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list, return true; } // expand the variable into a list - cmSystemTools::ExpandListArgument(listString, list, true); + cmExpandList(listString, list, true); // if no empty elements then just return if (std::find(list.begin(), list.end(), std::string()) == list.end()) { return true; @@ -128,7 +132,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list, // ExpandListArgument without the true which will remove // empty values list.clear(); - cmSystemTools::ExpandListArgument(listString, list); + cmExpandList(listString, list); std::string warn = cmPolicies::GetPolicyWarning(cmPolicies::CMP0007); warn += " List has value = ["; warn += listString; @@ -141,7 +145,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list, // ExpandListArgument without the true which will remove // empty values list.clear(); - cmSystemTools::ExpandListArgument(listString, list); + cmExpandList(listString, list); return true; case cmPolicies::NEW: return true; @@ -219,7 +223,7 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args) value += varArgsExpanded[item]; } - this->Makefile->AddDefinition(variableName, value.c_str()); + this->Makefile->AddDefinition(variableName, value); return true; } @@ -243,7 +247,7 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args) std::string::size_type(listString.empty() || args.empty()); listString += &";"[offset] + cmJoin(cmMakeRange(args).advance(2), ";"); - this->Makefile->AddDefinition(listName, listString.c_str()); + this->Makefile->AddDefinition(listName, listString); return true; } @@ -268,7 +272,7 @@ bool cmListCommand::HandlePrependCommand(std::vector<std::string> const& args) listString.insert(0, cmJoin(cmMakeRange(args).advance(2), ";") + &";"[offset]); - this->Makefile->AddDefinition(listName, listString.c_str()); + this->Makefile->AddDefinition(listName, listString); return true; } @@ -296,7 +300,7 @@ bool cmListCommand::HandlePopBackCommand(std::vector<std::string> const& args) // Ok, assign elements to be removed to the given variables for (; !varArgsExpanded.empty() && ai != args.cend(); ++ai) { assert(!ai->empty()); - this->Makefile->AddDefinition(*ai, varArgsExpanded.back().c_str()); + this->Makefile->AddDefinition(*ai, varArgsExpanded.back()); varArgsExpanded.pop_back(); } // Undefine the rest variables if the list gets empty earlier... @@ -305,8 +309,7 @@ bool cmListCommand::HandlePopBackCommand(std::vector<std::string> const& args) } } - this->Makefile->AddDefinition(listName, - cmJoin(varArgsExpanded, ";").c_str()); + this->Makefile->AddDefinition(listName, cmJoin(varArgsExpanded, ";")); } else if (ai != args.cend()) { // The list is empty, but some args were given @@ -344,7 +347,7 @@ bool cmListCommand::HandlePopFrontCommand(std::vector<std::string> const& args) auto vi = varArgsExpanded.begin(); for (; vi != varArgsExpanded.end() && ai != args.cend(); ++ai, ++vi) { assert(!ai->empty()); - this->Makefile->AddDefinition(*ai, vi->c_str()); + this->Makefile->AddDefinition(*ai, *vi); } varArgsExpanded.erase(varArgsExpanded.begin(), vi); // Undefine the rest variables if the list gets empty earlier... @@ -353,8 +356,7 @@ bool cmListCommand::HandlePopFrontCommand(std::vector<std::string> const& args) } } - this->Makefile->AddDefinition(listName, - cmJoin(varArgsExpanded, ";").c_str()); + this->Makefile->AddDefinition(listName, cmJoin(varArgsExpanded, ";")); } else if (ai != args.cend()) { // The list is empty, but some args were given @@ -388,7 +390,7 @@ bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args) if (it != varArgsExpanded.end()) { std::ostringstream indexStream; indexStream << std::distance(varArgsExpanded.begin(), it); - this->Makefile->AddDefinition(variableName, indexStream.str().c_str()); + this->Makefile->AddDefinition(variableName, indexStream.str()); return true; } @@ -434,7 +436,7 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args) args.end()); std::string value = cmJoin(varArgsExpanded, ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -462,7 +464,7 @@ bool cmListCommand::HandleJoinCommand(std::vector<std::string> const& args) std::string value = cmJoin(cmMakeRange(varArgsExpanded.begin(), varArgsExpanded.end()), glue); - this->Makefile->AddDefinition(variableName, value.c_str()); + this->Makefile->AddDefinition(variableName, value); return true; } @@ -491,7 +493,7 @@ bool cmListCommand::HandleRemoveItemCommand( cmRemoveMatching(varArgsExpanded, cmMakeRange(remBegin, remEnd)); std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -512,7 +514,7 @@ bool cmListCommand::HandleReverseCommand(std::vector<std::string> const& args) std::string value = cmJoin(cmReverseRange(varArgsExpanded), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -537,7 +539,7 @@ bool cmListCommand::HandleRemoveDuplicatesCommand( std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -853,7 +855,7 @@ bool cmListCommand::HandleTransformCommand( { "STRIP", 0, [&command](const std::string& s) -> std::string { if (command.Selector->InSelection(s)) { - return cmSystemTools::TrimWhitespace(s); + return cmTrimWhitespace(s); } return s; @@ -1088,7 +1090,7 @@ bool cmListCommand::HandleTransformCommand( } this->Makefile->AddDefinition(command.OutputName, - cmJoin(varArgsExpanded, ";").c_str()); + cmJoin(varArgsExpanded, ";")); return true; } @@ -1187,8 +1189,8 @@ bool cmListCommand::HandleSortCommand(std::vector<std::string> const& args) const std::string option = args[argumentIndex++]; if (option == "COMPARE") { if (sortCompare != cmStringSorter::Compare::UNINITIALIZED) { - std::string error = messageHint + "option \"" + option + - "\" has been specified multiple times."; + std::string error = cmStrCat(messageHint, "option \"", option, + "\" has been specified multiple times."); this->SetError(error); return false; } @@ -1199,23 +1201,22 @@ bool cmListCommand::HandleSortCommand(std::vector<std::string> const& args) } else if (argument == "FILE_BASENAME") { sortCompare = cmStringSorter::Compare::FILE_BASENAME; } else { - std::string error = messageHint + "value \"" + argument + - "\" for option \"" + option + "\" is invalid."; + std::string error = + cmStrCat(messageHint, "value \"", argument, "\" for option \"", + option, "\" is invalid."); this->SetError(error); return false; } } else { - std::string error = - messageHint + "missing argument for option \"" + option + "\"."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "missing argument for option \"", + option, "\".")); return false; } } else if (option == "CASE") { if (sortCaseSensitivity != cmStringSorter::CaseSensitivity::UNINITIALIZED) { - std::string error = messageHint + "option \"" + option + - "\" has been specified multiple times."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "option \"", option, + "\" has been specified multiple times.")); return false; } if (argumentIndex < args.size()) { @@ -1225,23 +1226,21 @@ bool cmListCommand::HandleSortCommand(std::vector<std::string> const& args) } else if (argument == "INSENSITIVE") { sortCaseSensitivity = cmStringSorter::CaseSensitivity::INSENSITIVE; } else { - std::string error = messageHint + "value \"" + argument + - "\" for option \"" + option + "\" is invalid."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "value \"", argument, + "\" for option \"", option, + "\" is invalid.")); return false; } } else { - std::string error = - messageHint + "missing argument for option \"" + option + "\"."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "missing argument for option \"", + option, "\".")); return false; } } else if (option == "ORDER") { if (sortOrder != cmStringSorter::Order::UNINITIALIZED) { - std::string error = messageHint + "option \"" + option + - "\" has been specified multiple times."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "option \"", option, + "\" has been specified multiple times.")); return false; } if (argumentIndex < args.size()) { @@ -1251,21 +1250,19 @@ bool cmListCommand::HandleSortCommand(std::vector<std::string> const& args) } else if (argument == "DESCENDING") { sortOrder = cmStringSorter::Order::DESCENDING; } else { - std::string error = messageHint + "value \"" + argument + - "\" for option \"" + option + "\" is invalid."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "value \"", argument, + "\" for option \"", option, + "\" is invalid.")); return false; } } else { - std::string error = - messageHint + "missing argument for option \"" + option + "\"."; - this->SetError(error); + this->SetError(cmStrCat(messageHint, "missing argument for option \"", + option, "\".")); return false; } } else { - std::string error = - messageHint + "option \"" + option + "\" is unknown."; - this->SetError(error); + this->SetError( + cmStrCat(messageHint, "option \"", option, "\" is unknown.")); return false; } } @@ -1297,7 +1294,7 @@ bool cmListCommand::HandleSortCommand(std::vector<std::string> const& args) } std::string value = cmJoin(varArgsExpanded, ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -1346,7 +1343,7 @@ bool cmListCommand::HandleSublistCommand(std::vector<std::string> const& args) : size_type(start + length); std::vector<std::string> sublist(varArgsExpanded.begin() + start, varArgsExpanded.begin() + end); - this->Makefile->AddDefinition(variableName, cmJoin(sublist, ";").c_str()); + this->Makefile->AddDefinition(variableName, cmJoin(sublist, ";")); return true; } @@ -1403,7 +1400,7 @@ bool cmListCommand::HandleRemoveAtCommand(std::vector<std::string> const& args) std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -1497,6 +1494,6 @@ bool cmListCommand::FilterRegex(std::vector<std::string> const& args, std::remove_if(argsBegin, argsEnd, MatchesRegex(regex, includeMatches)); std::string value = cmJoin(cmMakeRange(argsBegin, newArgsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } |