aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QUtil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r--libqpdf/QUtil.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 93374568..1cc5449a 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -290,6 +290,50 @@ QUtil::hex_encode(std::string const& input)
return result;
}
+std::string
+QUtil::hex_decode(std::string const& input)
+{
+ std::string result;
+ size_t pos = 0;
+ for (std::string::const_iterator p = input.begin(); p != input.end(); ++p)
+ {
+ char ch = *p;
+ bool skip = false;
+ if ((*p >= 'A') && (*p <= 'F'))
+ {
+ ch -= 'A';
+ ch += 10;
+ }
+ else if ((*p >= 'a') && (*p <= 'f'))
+ {
+ ch -= 'a';
+ ch += 10;
+ }
+ else if ((*p >= '0') && (*p <= '9'))
+ {
+ ch -= '0';
+ }
+ else
+ {
+ skip = true;
+ }
+ if (! skip)
+ {
+ if (pos == 0)
+ {
+ result.push_back(ch << 4);
+ pos = 1;
+ }
+ else
+ {
+ result.back() += ch;
+ pos = 0;
+ }
+ }
+ }
+ return result;
+}
+
void
QUtil::binary_stdout()
{