Commit 09ac645b05133c304108916f3c48196ef83a52f4
1 parent
8dc8e8c3
Refactor `String::utf8_value`: inline `QPDF_String::getUTF8Val`, remove redundant implementation.
Showing
3 changed files
with
9 additions
and
16 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -1040,7 +1040,15 @@ String::utf8_value() const |
| 1040 | 1040 | if (!s) { |
| 1041 | 1041 | throw invalid_error("String"); |
| 1042 | 1042 | } |
| 1043 | - return s->getUTF8Val(); | |
| 1043 | + if (util::is_utf16(s->val)) { | |
| 1044 | + return QUtil::utf16_to_utf8(s->val); | |
| 1045 | + } | |
| 1046 | + if (util::is_explicit_utf8(s->val)) { | |
| 1047 | + // PDF 2.0 allows UTF-8 strings when explicitly prefixed with the three-byte representation | |
| 1048 | + // of U+FEFF. | |
| 1049 | + return s->val.substr(3); | |
| 1050 | + } | |
| 1051 | + return QUtil::pdf_doc_to_utf8(s->val); | |
| 1044 | 1052 | } |
| 1045 | 1053 | |
| 1046 | 1054 | std::string | ... | ... |
libqpdf/QPDF_String.cc
| ... | ... | @@ -150,17 +150,3 @@ QPDF_String::unparse(bool force_binary) |
| 150 | 150 | |
| 151 | 151 | return result; |
| 152 | 152 | } |
| 153 | - | |
| 154 | -std::string | |
| 155 | -QPDF_String::getUTF8Val() const | |
| 156 | -{ | |
| 157 | - if (util::is_utf16(val)) { | |
| 158 | - return QUtil::utf16_to_utf8(val); | |
| 159 | - } | |
| 160 | - if (util::is_explicit_utf8(val)) { | |
| 161 | - // PDF 2.0 allows UTF-8 strings when explicitly prefixed with the three-byte representation | |
| 162 | - // of U+FEFF. | |
| 163 | - return val.substr(3); | |
| 164 | - } | |
| 165 | - return QUtil::pdf_doc_to_utf8(val); | |
| 166 | -} | ... | ... |
libqpdf/qpdf/QPDFObject_private.hh
| ... | ... | @@ -269,7 +269,6 @@ class QPDF_String final |
| 269 | 269 | static std::shared_ptr<QPDFObject> create_utf16(std::string const& utf8_val); |
| 270 | 270 | std::string unparse(bool force_binary = false); |
| 271 | 271 | void writeJSON(int json_version, JSON::Writer& p); |
| 272 | - std::string getUTF8Val() const; | |
| 273 | 272 | |
| 274 | 273 | private: |
| 275 | 274 | QPDF_String(std::string const& val) : | ... | ... |