aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-01-04 12:17:01 +0100
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2023-01-07 00:42:12 +0100
commit942a2c3f689b46107538d49a67dbf74c76e672b8 (patch)
treead5b7294b726e99b14570dad8eb0414924728e20 /include
parent1326ff7f79a199ce7e9bbecb1a3dab5580d20815 (diff)
downloadqpdf-942a2c3f689b46107538d49a67dbf74c76e672b8.tar.zst
Add new function QUtil::hex_encode_char
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/QUtil.hh13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh
index 6d9d18ae..27521a70 100644
--- a/include/qpdf/QUtil.hh
+++ b/include/qpdf/QUtil.hh
@@ -210,6 +210,11 @@ namespace QUtil
QPDF_DLL
std::string hex_encode(std::string const&);
+ // Returns lower-case hex-encoded version of the char including a leading
+ // "#".
+ QPDF_DLL
+ inline std::string hex_encode_char(char);
+
// Returns a string that is the result of decoding the input
// string. The input string may consist of mixed case hexadecimal
// digits. Any characters that are not hexadecimal digits will be
@@ -583,4 +588,12 @@ QUtil::is_number(char const* p)
return found_digit;
}
+inline std::string
+QUtil::hex_encode_char(char c)
+{
+ static auto constexpr hexchars = "0123456789abcdef";
+ return {
+ '#', hexchars[static_cast<unsigned char>(c) >> 4], hexchars[c & 0x0f]};
+}
+
#endif // QUTIL_HH