summaryrefslogtreecommitdiffstats
path: root/Source/cmStringCommand.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-02-18 15:49:02 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-02-19 14:11:05 (GMT)
commit5395bf05ebaa122400a2bd9f0b0547cf760aa43c (patch)
tree5ba56ea071815b63403b535f53622dc3f9dde2a4 /Source/cmStringCommand.cxx
parent952945813c091c4267590e80bd8e5421fe64508b (diff)
downloadCMake-5395bf05ebaa122400a2bd9f0b0547cf760aa43c.zip
CMake-5395bf05ebaa122400a2bd9f0b0547cf760aa43c.tar.gz
CMake-5395bf05ebaa122400a2bd9f0b0547cf760aa43c.tar.bz2
string: Add new HEX sub-command
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r--Source/cmStringCommand.cxx22
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 9212195..7662204 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -124,6 +124,27 @@ bool HandleAsciiCommand(std::vector<std::string> const& args,
return true;
}
+bool HandleHexCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ if (args.size() != 3) {
+ status.SetError("Incorrect number of arguments");
+ return false;
+ }
+ auto const& instr = args[1];
+ auto const& outvar = args[2];
+ std::string output(instr.size() * 2, ' ');
+
+ std::string::size_type hexIndex = 0;
+ for (auto const& c : instr) {
+ sprintf(&output[hexIndex], "%.2x", static_cast<unsigned char>(c) & 0xFF);
+ hexIndex += 2;
+ }
+
+ status.GetMakefile().AddDefinition(outvar, output);
+ return true;
+}
+
bool HandleConfigureCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
@@ -936,6 +957,7 @@ bool cmStringCommand(std::vector<std::string> const& args,
{ "TOUPPER"_s, HandleToUpperCommand },
{ "COMPARE"_s, HandleCompareCommand },
{ "ASCII"_s, HandleAsciiCommand },
+ { "HEX"_s, HandleHexCommand },
{ "CONFIGURE"_s, HandleConfigureCommand },
{ "LENGTH"_s, HandleLengthCommand },
{ "APPEND"_s, HandleAppendCommand },