mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add new function QUtil::hex_encode_char
This commit is contained in:
parent
1326ff7f79
commit
942a2c3f68
@ -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
|
||||
|
@ -38,7 +38,7 @@ QPDF_Name::normalizeName(std::string const& name)
|
||||
// invalid #.
|
||||
result += "#";
|
||||
} else if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126)) {
|
||||
result += "#" + QUtil::hex_encode(std::string(&ch, 1));
|
||||
result += QUtil::hex_encode_char(ch);
|
||||
} else {
|
||||
result += ch;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user