aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QUtil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-01-14 15:04:13 +0100
committerJay Berkenbilt <ejb@ql.org>2018-01-14 15:04:13 +0100
commit3e306ae64cc3d160034f27d72ad27bee03a65aa5 (patch)
treed60ce6f228328e1560e51cf494bc93b7ff2bd03e /libqpdf/QUtil.cc
parent68572df2bf0c6d1d7756ff05a96e01d7e2f69c09 (diff)
downloadqpdf-3e306ae64cc3d160034f27d72ad27bee03a65aa5.tar.zst
Add QUtil::hex_decode
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()
{