diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-10-17 13:10:20 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-10-17 13:10:20 (GMT) |
commit | 6e5cdd6de72de0d9d8f91c9971f0c13e10511c73 (patch) | |
tree | 03b8912732fb9070de978fc883cfb8e70ade305d /Source/cmStringCommand.cxx | |
parent | 33ac18891ff73863b088ca3f373eb90620637c11 (diff) | |
download | CMake-6e5cdd6de72de0d9d8f91c9971f0c13e10511c73.zip CMake-6e5cdd6de72de0d9d8f91c9971f0c13e10511c73.tar.gz CMake-6e5cdd6de72de0d9d8f91c9971f0c13e10511c73.tar.bz2 |
ENH: Add regular string replace (not regex), and relative path command. Also add tests
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r-- | Source/cmStringCommand.cxx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 76d60e0..dc592ba 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -16,6 +16,7 @@ =========================================================================*/ #include "cmStringCommand.h" #include <cmsys/RegularExpression.hxx> +#include <cmsys/SystemTools.hxx> #include <stdlib.h> // required for atoi #include <ctype.h> @@ -33,6 +34,10 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args) { return this->HandleRegexCommand(args); } + else if(subCommand == "REPLACE") + { + return this->HandleReplaceCommand(args); + } else if(subCommand == "TOLOWER") { return this->HandleToUpperLowerCommand(args, false); @@ -492,3 +497,28 @@ bool cmStringCommand::HandleCompareCommand(std::vector<std::string> const& args) this->SetError(e.c_str()); return false; } + +//---------------------------------------------------------------------------- +bool cmStringCommand::HandleReplaceCommand(std::vector<std::string> const& args) +{ + if(args.size() < 5) + { + this->SetError("sub-command REPLACE requires four arguments."); + return false; + } + + const std::string& matchExpression = args[1]; + const std::string& replaceExpression = args[2]; + const std::string& variableName = args[3]; + + std::string input = args[4]; + for(unsigned int i=5; i < args.size(); ++i) + { + input += args[i]; + } + + cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(), replaceExpression.c_str()); + + m_Makefile->AddDefinition(variableName.c_str(), input.c_str()); + return true; +} |