summaryrefslogtreecommitdiffstats
path: root/Source/cmStringCommand.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r--Source/cmStringCommand.cxx30
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;
+}