From 6244ac6f06a9723ac7d14545d3336b9dbb68bd9c Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Wed, 1 Jan 2003 17:34:47 -0500 Subject: [PATCH] Add a way to convert ascii to string --- Source/cmStringCommand.cxx | 38 +++++++++++++++++++++++++++++++++++++- Source/cmStringCommand.h | 5 ++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index f6e473a6d..a4d55181b 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -33,13 +33,49 @@ bool cmStringCommand::InitialPass(std::vector const& args) else if(subCommand == "COMPARE") { return this->HandleCompareCommand(args); - } + } + else if(subCommand == "ASCII") + { + return this->HandleAsciiCommand(args); + } std::string e = "does not recognize sub-command "+subCommand; this->SetError(e.c_str()); return false; } +//---------------------------------------------------------------------------- +bool cmStringCommand::HandleAsciiCommand(std::vector const& args) +{ + if ( args.size() <= 1 ) + { + this->SetError("No output variable specified"); + return false; + } + std::string::size_type cc; + std::string outvar = args[args.size()-1]; + std::string output = ""; + for ( cc = 1; cc < args.size()-1; cc ++ ) + { + int ch = atoi(args[cc].c_str()); + if ( ch > 0 && ch < 256 ) + { + output += static_cast(ch); + } + else + { + std::string error = "Character with code "; + error += ch; + error += " does not exist."; + this->SetError(error.c_str()); + return false; + } + } + // Store the output in the provided variable. + m_Makefile->AddDefinition(outvar.c_str(), output.c_str()); + return true; +} + //---------------------------------------------------------------------------- bool cmStringCommand::HandleRegexCommand(std::vector const& args) { diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index c78f3ac3e..298d730b3 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -67,16 +67,19 @@ public: "STRING(COMPARE NOTEQUAL )\n" "STRING(COMPARE LESS )\n" "STRING(COMPARE GREATER )\n" + "STRING(ASCII [ ...] )\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 possible and store the matches\n" " in the output variable as a list.\n" "REGEX REPLACE will match the regular expression as many times as possible and substitute the\n" " replacement expression for the match in the output.\n" - "COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and store true or false in the output variable.\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.\n"; } cmTypeMacro(cmStringCommand, cmCommand); protected: + bool HandleAsciiCommand(std::vector const& args); bool HandleRegexCommand(std::vector const& args); bool RegexMatch(std::vector const& args); bool RegexMatchAll(std::vector const& args);