summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-03-21 18:34:32 (GMT)
committerBrad King <brad.king@kitware.com>2013-05-21 19:29:34 (GMT)
commit0ab50aea4c4d7099b339fb38b4459d0debbdbd85 (patch)
tree573c1c8fa48079f663c5c0a61d02c98040818627 /Source
parent272431a84ff13eb17cf04389428f57c7fe13e3a2 (diff)
downloadCMake-0ab50aea4c4d7099b339fb38b4459d0debbdbd85.zip
CMake-0ab50aea4c4d7099b339fb38b4459d0debbdbd85.tar.gz
CMake-0ab50aea4c4d7099b339fb38b4459d0debbdbd85.tar.bz2
string: Add MAKE_C_IDENTIFIER subcommand
Diffstat (limited to 'Source')
-rw-r--r--Source/cmStringCommand.cxx22
-rw-r--r--Source/cmStringCommand.h6
2 files changed, 27 insertions, 1 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index e49edd8..1fbde01 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -93,6 +93,10 @@ bool cmStringCommand
{
return this->HandleTimestampCommand(args);
}
+ else if(subCommand == "MAKE_C_IDENTIFIER")
+ {
+ return this->HandleMakeCIdentifierCommand(args);
+ }
std::string e = "does not recognize sub-command "+subCommand;
this->SetError(e.c_str());
@@ -755,6 +759,24 @@ bool cmStringCommand
}
//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleMakeCIdentifierCommand(std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+ {
+ this->SetError("sub-command MAKE_C_IDENTIFIER requires two arguments.");
+ return false;
+ }
+
+ const std::string& input = args[1];
+ const std::string& variableName = args[2];
+
+ this->Makefile->AddDefinition(variableName.c_str(),
+ cmSystemTools::MakeCidentifier(input.c_str()).c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
bool cmStringCommand::HandleStripCommand(
std::vector<std::string> const& args)
{
diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h
index 802e0b8..f584cfd 100644
--- a/Source/cmStringCommand.h
+++ b/Source/cmStringCommand.h
@@ -94,6 +94,7 @@ public:
" [RANDOM_SEED <seed>] <output variable>)\n"
" string(FIND <string> <substring> <output variable> [REVERSE])\n"
" string(TIMESTAMP <output variable> [<format string>] [UTC])\n"
+ " string(MAKE_C_IDENTIFIER <input string> <output variable>)\n"
"REGEX MATCH will match the regular expression once and store the "
"match in the output variable.\n"
"REGEX MATCHALL will match the regular expression as many times as "
@@ -176,7 +177,9 @@ public:
"and copied to the output as-is.\n"
"If no explicit <format string> is given it will default to:\n"
" %Y-%m-%dT%H:%M:%S for local time.\n"
- " %Y-%m-%dT%H:%M:%SZ for UTC.";
+ " %Y-%m-%dT%H:%M:%SZ for UTC.\n"
+ "MAKE_C_IDENTIFIER will write a string which can be used as an "
+ "identifier in C.";
}
cmTypeMacro(cmStringCommand, cmCommand);
@@ -200,6 +203,7 @@ protected:
bool HandleRandomCommand(std::vector<std::string> const& args);
bool HandleFindCommand(std::vector<std::string> const& args);
bool HandleTimestampCommand(std::vector<std::string> const& args);
+ bool HandleMakeCIdentifierCommand(std::vector<std::string> const& args);
class RegexReplacement
{