#include <ctype.h>
#include <time.h>
+#include <cmTimestamp.h>
+
//----------------------------------------------------------------------------
bool cmStringCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
this->SetError("must be called with at least one argument.");
return false;
}
-
+
const std::string &subCommand = args[0];
if(subCommand == "REGEX")
{
{
return this->HandleFindCommand(args);
}
+ else if(subCommand == "TIMESTAMP")
+ {
+ return this->HandleTimestampCommand(args);
+ }
std::string e = "does not recognize sub-command "+subCommand;
this->SetError(e.c_str());
std::string outvar = args[2];
std::string output;
- if (toUpper)
+ if (toUpper)
{
output = cmSystemTools::UpperCase(args[1]);
- }
- else
+ }
+ else
{
output = cmSystemTools::LowerCase(args[1]);
}
}
return this->RegexReplace(args);
}
-
+
std::string e = "sub-command REGEX does not recognize mode "+mode;
this->SetError(e.c_str());
return false;
// <input> [<input>...])\n";
std::string regex = args[2];
std::string outvar = args[3];
-
+
// Concatenate all the last arguments together.
std::string input = args[4];
for(unsigned int i=5; i < args.size(); ++i)
{
input += args[i];
}
-
+
this->ClearMatches(this->Makefile);
// Compile the regular expression.
cmsys::RegularExpression re;
if(!re.compile(regex.c_str()))
{
- std::string e =
+ std::string e =
"sub-command REGEX, mode MATCH failed to compile regex \""+regex+"\".";
this->SetError(e.c_str());
return false;
}
-
+
// Scan through the input for all matches.
std::string output;
if(re.find(input.c_str()))
std::string::size_type r = re.end();
if(r-l == 0)
{
- std::string e =
+ std::string e =
"sub-command REGEX, mode MATCH regex \""+regex+
"\" matched an empty string.";
this->SetError(e.c_str());
}
output = input.substr(l, r-l);
}
-
+
// Store the output in the provided variable.
this->Makefile->AddDefinition(outvar.c_str(), output.c_str());
return true;
//----------------------------------------------------------------------------
bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
{
- //"STRING(REGEX MATCHALL <regular_expression> <output variable> <input>
+ //"STRING(REGEX MATCHALL <regular_expression> <output variable> <input>
// [<input>...])\n";
std::string regex = args[2];
std::string outvar = args[3];
-
+
// Concatenate all the last arguments together.
std::string input = args[4];
for(unsigned int i=5; i < args.size(); ++i)
{
input += args[i];
}
-
+
this->ClearMatches(this->Makefile);
// Compile the regular expression.
cmsys::RegularExpression re;
this->SetError(e.c_str());
return false;
}
-
+
// Scan through the input for all matches.
std::string output;
const char* p = input.c_str();
output += std::string(p+l, r-l);
p += r;
}
-
+
// Store the output in the provided variable.
this->Makefile->AddDefinition(outvar.c_str(), output.c_str());
return true;
//----------------------------------------------------------------------------
bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
{
- //"STRING(REGEX REPLACE <regular_expression> <replace_expression>
+ //"STRING(REGEX REPLACE <regular_expression> <replace_expression>
// <output variable> <input> [<input>...])\n"
std::string regex = args[2];
- std::string replace = args[3];
+ std::string replace = args[3];
std::string outvar = args[4];
-
+
// Pull apart the replace expression to find the escaped [0-9] values.
std::vector<RegexReplacement> replacement;
std::string::size_type l = 0;
}
l = r;
}
-
+
// Concatenate all the last arguments together.
std::string input = args[5];
for(unsigned int i=6; i < args.size(); ++i)
{
input += args[i];
}
-
+
this->ClearMatches(this->Makefile);
// Compile the regular expression.
cmsys::RegularExpression re;
if(!re.compile(regex.c_str()))
{
- std::string e =
+ std::string e =
"sub-command REGEX, mode REPLACE failed to compile regex \""+
regex+"\".";
this->SetError(e.c_str());
return false;
}
-
+
// Scan through the input for all matches.
std::string output;
std::string::size_type base = 0;
this->StoreMatches(this->Makefile, re);
std::string::size_type l2 = re.start();
std::string::size_type r = re.end();
-
+
// Concatenate the part of the input that was not matched.
output += input.substr(base, l2);
-
+
// Make sure the match had some text.
if(r-l2 == 0)
{
this->SetError(e.c_str());
return false;
}
-
+
// Concatenate the replacement for the match.
for(unsigned int i=0; i < replacement.size(); ++i)
{
}
}
}
-
+
// Move past the match.
base += r;
}
-
+
// Concatenate the text after the last match.
output += input.substr(base, input.length()-base);
-
+
// Store the output in the provided variable.
this->Makefile->AddDefinition(outvar.c_str(), output.c_str());
return true;
this->SetError(e.c_str());
return false;
}
-
+
const std::string& left = args[2];
- const std::string& right = args[3];
+ const std::string& right = args[3];
const std::string& outvar = args[4];
bool result;
if(mode == "LESS")
this->Makefile->AddDefinition(outvar.c_str(), "0");
}
return true;
- }
+ }
std::string e = "sub-command COMPARE does not recognize mode "+mode;
this->SetError(e.c_str());
return false;
input += args[i];
}
- cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(),
+ cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(),
replaceExpression.c_str());
this->Makefile->AddDefinition(variableName.c_str(), input.c_str());
}
//----------------------------------------------------------------------------
-bool cmStringCommand::HandleSubstringCommand(std::vector<std::string> const&
+bool cmStringCommand::HandleSubstringCommand(std::vector<std::string> const&
args)
{
if(args.size() != 5)
return false;
}
- this->Makefile->AddDefinition(variableName.c_str(),
+ this->Makefile->AddDefinition(variableName.c_str(),
stringValue.substr(begin, end).c_str());
return true;
}
size_t outLength = 0;
- // if the input string didn't contain any non-space characters, return
+ // if the input string didn't contain any non-space characters, return
// an empty string
if (startPos > inStringLength)
{
this->Makefile->AddDefinition(variableName.c_str(), &*result.begin());
return true;
}
+
+//----------------------------------------------------------------------------
+bool cmStringCommand
+::HandleTimestampCommand(std::vector<std::string> const& args)
+{
+ if(args.size() < 2)
+ {
+ this->SetError("sub-command TIMESTAMP requires at least one argument.");
+ return false;
+ }
+ else if(args.size() > 4)
+ {
+ this->SetError("sub-command TIMESTAMP takes at most three arguments.");
+ return false;
+ }
+
+ unsigned int argsIndex = 1;
+
+ const std::string &outputVariable = args[argsIndex++];
+
+ std::string formatString;
+ if(args.size() > argsIndex && args[argsIndex] != "UTC")
+ {
+ formatString = args[argsIndex++];
+ }
+
+ bool utcFlag = false;
+ if(args.size() > argsIndex)
+ {
+ if(args[argsIndex] == "UTC")
+ {
+ utcFlag = true;
+ }
+ else
+ {
+ std::string e = " TIMESTAMP sub-command does not recognize option " +
+ args[argsIndex] + ".";
+ this->SetError(e.c_str());
+ return false;
+ }
+ }
+
+ cmTimestamp timestamp;
+ std::string result = timestamp.CurrentTime(formatString, utcFlag);
+ this->Makefile->AddDefinition(outputVariable.c_str(), result.c_str());
+
+ return true;
+}