summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2003-07-10 17:25:54 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2003-07-10 17:25:54 (GMT)
commitc4275f54c7d958349ea66458b6da46ae755bf324 (patch)
treeda79dd9f34ae722c3f2b7b582c50de1e843a2da0 /Source
parenta6fd6a0bae63c72b482d3a54342c7f92bc4d5917 (diff)
downloadCMake-c4275f54c7d958349ea66458b6da46ae755bf324.zip
CMake-c4275f54c7d958349ea66458b6da46ae755bf324.tar.gz
CMake-c4275f54c7d958349ea66458b6da46ae755bf324.tar.bz2
ENH: Add upper and lower case support. Close Bug #79 - STRING TOUPPER and TOLOWER
Diffstat (limited to 'Source')
-rw-r--r--Source/cmStringCommand.cxx40
-rw-r--r--Source/cmStringCommand.h6
2 files changed, 44 insertions, 2 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 1e13592..f41d582 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -18,6 +18,7 @@
#include <cmsys/RegularExpression.hxx>
#include <stdlib.h> // required for atoi
+#include <ctype.h>
//----------------------------------------------------------------------------
bool cmStringCommand::InitialPass(std::vector<std::string> const& args)
{
@@ -31,7 +32,15 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args)
if(subCommand == "REGEX")
{
return this->HandleRegexCommand(args);
- }
+ }
+ else if(subCommand == "TOLOWER")
+ {
+ return this->HandleToUpperLowerCommand(args, false);
+ }
+ else if(subCommand == "TOUPPER")
+ {
+ return this->HandleToUpperLowerCommand(args, true);
+ }
else if(subCommand == "COMPARE")
{
return this->HandleCompareCommand(args);
@@ -47,6 +56,35 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args)
}
//----------------------------------------------------------------------------
+bool cmStringCommand::HandleToUpperLowerCommand(
+ std::vector<std::string> const& args, bool toUpper)
+{
+ if ( args.size() <= 1 )
+ {
+ this->SetError("no output variable specified");
+ return false;
+ }
+
+ std::string outvar = args[2];
+ std::string output;
+
+ bool first = true;
+
+ if (toUpper)
+ {
+ output = cmSystemTools::UpperCase(args[1]);
+ }
+ else
+ {
+ output = cmSystemTools::LowerCase(args[1]);
+ }
+
+ // Store the output in the provided variable.
+ m_Makefile->AddDefinition(outvar.c_str(), output.c_str());
+ return true;
+}
+
+//----------------------------------------------------------------------------
bool cmStringCommand::HandleAsciiCommand(std::vector<std::string> const& args)
{
if ( args.size() <= 1 )
diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h
index 4968d5a..74dbf2b 100644
--- a/Source/cmStringCommand.h
+++ b/Source/cmStringCommand.h
@@ -78,6 +78,8 @@ public:
" STRING(COMPARE LESS <string1> <string2> <output variable>)\n"
" STRING(COMPARE GREATER <string1> <string2> <output variable>)\n"
" STRING(ASCII <number> [<number> ...] <output variable>)\n"
+ " STRING(TOUPPER <string1> <output variable>)\n"
+ " STRING(TOLOWER <string1> <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 "
@@ -87,7 +89,8 @@ public:
"in the output.\n"
"COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and "
"store true or false in the output variable.\n"
- "ASCII will convert all numbers into corresponding ASCII characters.";
+ "ASCII will convert all numbers into corresponding ASCII characters.\n"
+ "TOUPPER/TOLOWER will convert string to upper/lower characters.";
}
cmTypeMacro(cmStringCommand, cmCommand);
@@ -97,6 +100,7 @@ protected:
bool RegexMatch(std::vector<std::string> const& args);
bool RegexMatchAll(std::vector<std::string> const& args);
bool RegexReplace(std::vector<std::string> const& args);
+ bool HandleToUpperLowerCommand(std::vector<std::string> const& args, bool toUpper);
bool HandleCompareCommand(std::vector<std::string> const& args);
class RegexReplacement