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);