diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-02-20 16:51:39 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-02-20 16:51:51 (GMT) |
commit | 1f44c5ed65a1192c508cfef46ccb5985d63830d3 (patch) | |
tree | d4b9fa8047cdf8acf2c87ef7d962da8c9d5855fd /Source | |
parent | 907ffbf52eb08ea4899ab8aa86427264b20203f5 (diff) | |
parent | 97b639d3f17ab826986c06bb8ea7f9f534b1d3ee (diff) | |
download | CMake-1f44c5ed65a1192c508cfef46ccb5985d63830d3.zip CMake-1f44c5ed65a1192c508cfef46ccb5985d63830d3.tar.gz CMake-1f44c5ed65a1192c508cfef46ccb5985d63830d3.tar.bz2 |
Merge topic 'string-hex'
97b639d3f1 Help: Make note that file(READ ... HEX) produces lowercase letters
5395bf05eb string: Add new HEX sub-command
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4373
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmStringCommand.cxx | 22 |
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 }, |