summaryrefslogtreecommitdiffstats
path: root/Source/cmStringCommand.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2018-02-11 13:20:57 (GMT)
committerBrad King <brad.king@kitware.com>2018-02-16 15:04:47 (GMT)
commit689eeb67cb87a9ed1d91a4971806488d00e68f42 (patch)
tree403880ec3c332705d11c5293940e143fa1a4aa9c /Source/cmStringCommand.cxx
parente24cda008e3ea1cbb22d17d29c5c39999facb4b7 (diff)
downloadCMake-689eeb67cb87a9ed1d91a4971806488d00e68f42.zip
CMake-689eeb67cb87a9ed1d91a4971806488d00e68f42.tar.gz
CMake-689eeb67cb87a9ed1d91a4971806488d00e68f42.tar.bz2
string: Add JOIN subcommand
This is just like CONCAT but accepts a glue string to put between each value. `JOIN ""` is equivalent to `CONCAT`.
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r--Source/cmStringCommand.cxx25
1 files changed, 23 insertions, 2 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 55af078..9631912 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -68,6 +68,9 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args,
if (subCommand == "CONCAT") {
return this->HandleConcatCommand(args);
}
+ if (subCommand == "JOIN") {
+ return this->HandleJoinCommand(args);
+ }
if (subCommand == "SUBSTRING") {
return this->HandleSubstringCommand(args);
}
@@ -677,8 +680,26 @@ bool cmStringCommand::HandleConcatCommand(std::vector<std::string> const& args)
return false;
}
- std::string const& variableName = args[1];
- std::string value = cmJoin(cmMakeRange(args).advance(2), std::string());
+ return this->joinImpl(args, std::string(), 1);
+}
+
+bool cmStringCommand::HandleJoinCommand(std::vector<std::string> const& args)
+{
+ if (args.size() < 3) {
+ this->SetError("sub-command JOIN requires at least two arguments.");
+ return false;
+ }
+
+ return this->joinImpl(args, args[1], 2);
+}
+
+bool cmStringCommand::joinImpl(std::vector<std::string> const& args,
+ std::string const& glue, const size_t varIdx)
+{
+ std::string const& variableName = args[varIdx];
+ // NOTE Items to concat/join placed right after the variable for
+ // both `CONCAT` and `JOIN` sub-commands.
+ std::string value = cmJoin(cmMakeRange(args).advance(varIdx + 1), glue);
this->Makefile->AddDefinition(variableName, value.c_str());
return true;