diff options
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r-- | libqpdf/QUtil.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 3cdfdc49..faccaee7 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -2,6 +2,7 @@ #include <qpdf/qpdf-config.h> #include <qpdf/QUtil.hh> +#include <qpdf/PointerHolder.hh> #include <stdio.h> #include <errno.h> @@ -163,6 +164,21 @@ QUtil::copy_string(std::string const& str) return result; } +std::string +QUtil::hex_encode(std::string const& input) +{ + size_t input_size = input.length(); + size_t hex_size = 1 + (2 * input_size); + PointerHolder<char> bufp(true, new char[hex_size]); + char* buf = bufp.getPointer(); + buf[hex_size - 1] = '\0'; + for (unsigned int i = 0; i < input_size; ++i) + { + sprintf(buf + i * 2, "%02x", (unsigned char)input[i]); + } + return buf; +} + void QUtil::binary_stdout() { |