2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-05 21:07:50 +00:00

Tune unparsing of hex strings in QPDF_String::unparse

This commit is contained in:
m-holger 2022-09-21 20:21:17 +01:00 committed by Jay Berkenbilt
parent 92b3543e12
commit 033a66e9a5

View File

@ -113,7 +113,14 @@ QPDF_String::unparse(bool force_binary)
bool use_hexstring = force_binary || useHexString();
std::string result;
if (use_hexstring) {
result += "<" + QUtil::hex_encode(this->val) + ">";
static auto constexpr hexchars = "0123456789abcdef";
result.reserve(2 * this->val.length() + 2);
result += '<';
for (const char c: this->val) {
result += hexchars[static_cast<unsigned char>(c) >> 4];
result += hexchars[c & 0x0f];
}
result += '>';
} else {
result += "(";
for (unsigned int i = 0; i < this->val.length(); ++i) {