diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2018-02-11 13:20:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-02-16 15:04:47 (GMT) |
commit | 689eeb67cb87a9ed1d91a4971806488d00e68f42 (patch) | |
tree | 403880ec3c332705d11c5293940e143fa1a4aa9c /Source | |
parent | e24cda008e3ea1cbb22d17d29c5c39999facb4b7 (diff) | |
download | CMake-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')
-rw-r--r-- | Source/cmStringCommand.cxx | 25 | ||||
-rw-r--r-- | Source/cmStringCommand.h | 5 |
2 files changed, 28 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; diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index b287e37..569ed83 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <cstddef> #include <string> #include <vector> @@ -48,6 +49,7 @@ protected: bool HandleAppendCommand(std::vector<std::string> const& args); bool HandlePrependCommand(std::vector<std::string> const& args); bool HandleConcatCommand(std::vector<std::string> const& args); + bool HandleJoinCommand(std::vector<std::string> const& args); bool HandleStripCommand(std::vector<std::string> const& args); bool HandleRandomCommand(std::vector<std::string> const& args); bool HandleFindCommand(std::vector<std::string> const& args); @@ -56,6 +58,9 @@ protected: bool HandleGenexStripCommand(std::vector<std::string> const& args); bool HandleUuidCommand(std::vector<std::string> const& args); + bool joinImpl(std::vector<std::string> const& args, std::string const& glue, + size_t varIdx); + class RegexReplacement { public: |