[cmake-commits] andy committed cmStringCommand.cxx 1.22 1.23 cmStringCommand.h 1.19 1.20

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Apr 26 21:50:54 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv10367/Source

Modified Files:
	cmStringCommand.cxx cmStringCommand.h 
Log Message:
ENH: Add STRING STRIP command


Index: cmStringCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmStringCommand.cxx,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cmStringCommand.cxx	23 Apr 2007 20:48:56 -0000	1.22
+++ cmStringCommand.cxx	27 Apr 2007 01:50:52 -0000	1.23
@@ -68,6 +68,10 @@
     {
     return this->HandleSubstringCommand(args);
     }
+  else if(subCommand == "STRIP")
+    {
+    return this->HandleStripCommand(args);
+    }
   else if(subCommand == "RANDOM")
     {
     return this->HandleRandomCommand(args);
@@ -614,6 +618,43 @@
 }
 
 //----------------------------------------------------------------------------
+bool cmStringCommand::HandleStripCommand(
+  std::vector<std::string> const& args)
+{
+ if(args.size() != 3)
+    {
+    this->SetError("sub-command LENGTH requires two arguments.");
+    return false;
+    }
+
+  const std::string& stringValue = args[1];
+  const std::string& variableName = args[2];
+  size_t inStringLength = stringValue.size();
+  size_t startPos = inStringLength + 1;
+  size_t endPos = 0;
+  const char* ptr = stringValue.c_str();
+  size_t cc;
+  for ( cc = 0; cc < inStringLength; ++ cc )
+    {
+    if ( !isspace(*ptr) )
+      {
+      if ( startPos > inStringLength )
+        {
+        startPos = cc;
+        }
+      endPos = cc;
+      }
+    ++ ptr;
+    }
+
+  size_t outLength = endPos - startPos + 1;
+ 
+  this->Makefile->AddDefinition(variableName.c_str(),
+    stringValue.substr(startPos, outLength).c_str());
+  return true;
+}
+
+//----------------------------------------------------------------------------
 bool cmStringCommand
 ::HandleRandomCommand(std::vector<std::string> const& args)
 {

Index: cmStringCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmStringCommand.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cmStringCommand.h	25 Apr 2007 21:48:51 -0000	1.19
+++ cmStringCommand.h	27 Apr 2007 01:50:52 -0000	1.20
@@ -85,6 +85,7 @@
       "  STRING(TOLOWER <string1> <output variable>)\n"
       "  STRING(LENGTH <string> <output variable>)\n"
       "  STRING(SUBSTRING <string> <begin> <length> <output variable>)\n"
+      "  STRING(STRIP <string> <output variable>)\n"
       "  STRING(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]\n"
       "         <output variable>)\n"
       "REGEX MATCH will match the regular expression once and store the "
@@ -111,6 +112,8 @@
       "TOUPPER/TOLOWER will convert string to upper/lower characters.\n"
       "LENGTH will return a given string's length.\n"
       "SUBSTRING will return a substring of a given string.\n"
+      "STRIP will return a substring of a given string with leading "
+      "and trailing spaces removed.\n"
       "RANDOM will return a random string of given length consisting of "
       "characters from the given alphabet. Default length is 5 "
       "characters and default alphabet is all numbers and upper and "
@@ -131,6 +134,7 @@
   bool HandleReplaceCommand(std::vector<std::string> const& args);
   bool HandleLengthCommand(std::vector<std::string> const& args);
   bool HandleSubstringCommand(std::vector<std::string> const& args);
+  bool HandleStripCommand(std::vector<std::string> const& args);
   bool HandleRandomCommand(std::vector<std::string> const& args);
   
   class RegexReplacement



More information about the Cmake-commits mailing list