From a367a367d4626d2a70f566475800c76f10f1f315 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 1 Nov 2025 14:15:17 +0000 Subject: [PATCH] Refactor `QPDFObjectHandle::newUnicodeString`: remove `QPDF_String::create_utf16` and replace with `String::utf16`. --- libqpdf/QPDFObjectHandle.cc | 12 +++++++++++- libqpdf/QPDF_String.cc | 10 ---------- libqpdf/qpdf/QPDFObjectHandle_private.hh | 2 ++ libqpdf/qpdf/QPDFObject_private.hh | 1 - 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index b7bd526..7770df6 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1010,7 +1010,7 @@ QPDFObjectHandle::newString(std::string const& str) QPDFObjectHandle QPDFObjectHandle::newUnicodeString(std::string const& utf8_str) { - return {QPDF_String::create_utf16(utf8_str)}; + return {String::utf16(utf8_str).obj_sp()}; } String::String(std::string const& str) : @@ -1023,6 +1023,16 @@ String::String(std::string&& str) : { } +String +String::utf16(std::string const& utf8_str) +{ + std::string result; + if (QUtil::utf8_to_pdf_doc(utf8_str, result, '?')) { + return String(result); + } + return String(QUtil::utf8_to_utf16(utf8_str)); +} + std::string const& String::value() const { diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc index 235cd79..1f883fd 100644 --- a/libqpdf/QPDF_String.cc +++ b/libqpdf/QPDF_String.cc @@ -13,16 +13,6 @@ is_iso_latin1_printable(char ch) return (ch >= 32 && ch <= 126) || static_cast(ch) >= 160; } -std::shared_ptr -QPDF_String::create_utf16(std::string const& utf8_val) -{ - std::string result; - if (!QUtil::utf8_to_pdf_doc(utf8_val, result, '?')) { - result = QUtil::utf8_to_utf16(utf8_val); - } - return QPDFObject::create(result); -} - void QPDF_String::writeJSON(int json_version, JSON::Writer& p) { diff --git a/libqpdf/qpdf/QPDFObjectHandle_private.hh b/libqpdf/qpdf/QPDFObjectHandle_private.hh index 4b03f13..0f478a8 100644 --- a/libqpdf/qpdf/QPDFObjectHandle_private.hh +++ b/libqpdf/qpdf/QPDFObjectHandle_private.hh @@ -614,6 +614,8 @@ namespace qpdf { } + static String utf16(std::string const&); + // Return the string value. If the object is not a valid string, throw a // std::invalid_argument exception. operator std::string() const& diff --git a/libqpdf/qpdf/QPDFObject_private.hh b/libqpdf/qpdf/QPDFObject_private.hh index ecfcf7a..43ad341 100644 --- a/libqpdf/qpdf/QPDFObject_private.hh +++ b/libqpdf/qpdf/QPDFObject_private.hh @@ -266,7 +266,6 @@ class QPDF_String final friend class qpdf::impl::Writer; public: - static std::shared_ptr create_utf16(std::string const& utf8_val); std::string unparse(bool force_binary = false); void writeJSON(int json_version, JSON::Writer& p); -- libgit2 0.21.4