summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-03-22 13:10:24 +0100
committerm-holger <m-holger@kubitscheck.org>2023-03-23 21:23:37 +0100
commit0795b6952bdaf5b7f8ce7842ae26676d80286dab (patch)
tree2617100434aaab8644bbf38f222a176fa0de0c6c /include
parentf89196b6c898ac8fa7ce3fb477d0c4b03d0ece4f (diff)
downloadqpdf-0795b6952bdaf5b7f8ce7842ae26676d80286dab.tar.zst
Add new function QUtil::hex_decode_char
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/QUtil.hh17
1 files changed, 15 insertions, 2 deletions
diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh
index b42fe195..4d46f630 100644
--- a/include/qpdf/QUtil.hh
+++ b/include/qpdf/QUtil.hh
@@ -223,6 +223,11 @@ namespace QUtil
QPDF_DLL
std::string hex_decode(std::string const&);
+ // Decode a single hex digit into a char in the range 0 <= char < 16. Return
+ // a char >= 16 if digit is not a valid hex digit.
+ QPDF_DLL
+ inline constexpr char hex_decode_char(char digit) noexcept;
+
// Set stdin, stdout to binary mode
QPDF_DLL
void binary_stdout();
@@ -550,8 +555,7 @@ namespace QUtil
inline bool
QUtil::is_hex_digit(char ch)
{
- return ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f') ||
- ('A' <= ch && ch <= 'F');
+ return hex_decode_char(ch) < '\20';
}
inline bool
@@ -603,4 +607,13 @@ QUtil::hex_encode_char(char c)
'#', hexchars[static_cast<unsigned char>(c) >> 4], hexchars[c & 0x0f]};
}
+inline constexpr char
+QUtil::hex_decode_char(char digit) noexcept
+{
+ return digit <= '9' && digit >= '0'
+ ? char(digit - '0')
+ : (digit >= 'a' ? char(digit - 'a' + 10)
+ : (digit >= 'A' ? char(digit - 'A' + 10) : '\20'));
+}
+
#endif // QUTIL_HH