From 2f5cc6afa1f9561783193c4541bf1149b3f63fa8 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Sun, 18 Aug 2024 17:35:32 +1000 Subject: [PATCH] cmParseArgumentsCommand: Use cmStrCat() for string concatenation --- Source/cmParseArgumentsCommand.cxx | 45 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index f193ed9624..9b1e76bb60 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -79,13 +78,13 @@ static void PassParsedArguments( const options_set& keywordsMissingValues, bool parseFromArgV) { for (auto const& iter : options) { - makefile.AddDefinition(prefix + iter.first, + makefile.AddDefinition(cmStrCat(prefix, iter.first), iter.second ? "TRUE" : "FALSE"); } for (auto const& iter : singleValArgs) { if (!iter.second.empty()) { - makefile.AddDefinition(prefix + iter.first, iter.second); + makefile.AddDefinition(cmStrCat(prefix, iter.first), iter.second); } else { makefile.RemoveDefinition(prefix + iter.first); } @@ -93,26 +92,26 @@ static void PassParsedArguments( for (auto const& iter : multiValArgs) { if (!iter.second.empty()) { - makefile.AddDefinition(prefix + iter.first, + makefile.AddDefinition(cmStrCat(prefix, iter.first), JoinList(iter.second, parseFromArgV)); } else { - makefile.RemoveDefinition(prefix + iter.first); + makefile.RemoveDefinition(cmStrCat(prefix, iter.first)); } } if (!unparsed.empty()) { - makefile.AddDefinition(prefix + "UNPARSED_ARGUMENTS", + makefile.AddDefinition(cmStrCat(prefix, "UNPARSED_ARGUMENTS"), JoinList(unparsed, parseFromArgV)); } else { - makefile.RemoveDefinition(prefix + "UNPARSED_ARGUMENTS"); + makefile.RemoveDefinition(cmStrCat(prefix, "UNPARSED_ARGUMENTS")); } if (!keywordsMissingValues.empty()) { makefile.AddDefinition( - prefix + "KEYWORDS_MISSING_VALUES", + cmStrCat(prefix, "KEYWORDS_MISSING_VALUES"), cmList::to_string(cmMakeRange(keywordsMissingValues))); } else { - makefile.RemoveDefinition(prefix + "KEYWORDS_MISSING_VALUES"); + makefile.RemoveDefinition(cmStrCat(prefix, "KEYWORDS_MISSING_VALUES")); } } @@ -143,9 +142,10 @@ bool cmParseArgumentsCommand(std::vector const& args, parseFromArgV = true; argIter++; // move past PARSE_ARGV if (!cmStrToULong(*argIter, &argvStart)) { - status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, - "PARSE_ARGV index '" + *argIter + - "' is not an unsigned integer"); + status.GetMakefile().IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("PARSE_ARGV index '", *argIter, + "' is not an unsigned integer")); cmSystemTools::SetFatalErrorOccurred(); return true; } @@ -167,7 +167,7 @@ bool cmParseArgumentsCommand(std::vector const& args, auto const duplicateKey = [&status](std::string const& key) { status.GetMakefile().IssueMessage( - MessageType::WARNING, "keyword defined more than once: " + key); + MessageType::WARNING, cmStrCat("keyword defined more than once: ", key)); }; // the second argument is a (cmake) list of options without argument @@ -194,21 +194,20 @@ bool cmParseArgumentsCommand(std::vector const& args, std::string argc = status.GetMakefile().GetSafeDefinition("ARGC"); unsigned long count; if (!cmStrToULong(argc, &count)) { - status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, - "PARSE_ARGV called with ARGC='" + - argc + - "' that is not an unsigned integer"); + status.GetMakefile().IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("PARSE_ARGV called with ARGC='", argc, + "' that is not an unsigned integer")); cmSystemTools::SetFatalErrorOccurred(); return true; } for (unsigned long i = argvStart; i < count; ++i) { - std::ostringstream argName; - argName << "ARGV" << i; - cmValue arg = status.GetMakefile().GetDefinition(argName.str()); + const std::string argName{ cmStrCat("ARGV", i) }; + cmValue arg = status.GetMakefile().GetDefinition(argName); if (!arg) { - status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, - "PARSE_ARGV called with " + - argName.str() + " not set"); + status.GetMakefile().IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("PARSE_ARGV called with ", argName, " not set")); cmSystemTools::SetFatalErrorOccurred(); return true; }