Commit 033a66e9a5f859798cfc1920eb3129b40fdaa842
Committed by
Jay Berkenbilt
1 parent
92b3543e
Tune unparsing of hex strings in QPDF_String::unparse
Showing
1 changed file
with
8 additions
and
1 deletions
libqpdf/QPDF_String.cc
| ... | ... | @@ -113,7 +113,14 @@ QPDF_String::unparse(bool force_binary) |
| 113 | 113 | bool use_hexstring = force_binary || useHexString(); |
| 114 | 114 | std::string result; |
| 115 | 115 | if (use_hexstring) { |
| 116 | - result += "<" + QUtil::hex_encode(this->val) + ">"; | |
| 116 | + static auto constexpr hexchars = "0123456789abcdef"; | |
| 117 | + result.reserve(2 * this->val.length() + 2); | |
| 118 | + result += '<'; | |
| 119 | + for (const char c: this->val) { | |
| 120 | + result += hexchars[static_cast<unsigned char>(c) >> 4]; | |
| 121 | + result += hexchars[c & 0x0f]; | |
| 122 | + } | |
| 123 | + result += '>'; | |
| 117 | 124 | } else { |
| 118 | 125 | result += "("; |
| 119 | 126 | for (unsigned int i = 0; i < this->val.length(); ++i) { | ... | ... |