diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2023-04-01 15:31:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-01 15:31:28 +0200 |
commit | ef6f5a97f42a6d59abc9ca81ae4e9ab3b7168f55 (patch) | |
tree | 49a9071c15e3947d581cb33f2d5bfc129e1c9593 /include | |
parent | b62ad7ecc625963da9578d47d1ccb2809d6f0452 (diff) | |
parent | 5f4f553c3588f3ef3cb704c9d3c6db6bb78ccfa9 (diff) | |
download | qpdf-ef6f5a97f42a6d59abc9ca81ae4e9ab3b7168f55.tar.zst |
Merge pull request #936 from m-holger/hex
Refactor QUtil::hex_decode
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/QUtil.hh | 17 |
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 |