Commit a367a367d4626d2a70f566475800c76f10f1f315

Authored by m-holger
1 parent 09ac645b

Refactor `QPDFObjectHandle::newUnicodeString`: remove `QPDF_String::create_utf16…

…` and replace with `String::utf16`.
libqpdf/QPDFObjectHandle.cc
@@ -1010,7 +1010,7 @@ QPDFObjectHandle::newString(std::string const& str) @@ -1010,7 +1010,7 @@ QPDFObjectHandle::newString(std::string const& str)
1010 QPDFObjectHandle 1010 QPDFObjectHandle
1011 QPDFObjectHandle::newUnicodeString(std::string const& utf8_str) 1011 QPDFObjectHandle::newUnicodeString(std::string const& utf8_str)
1012 { 1012 {
1013 - return {QPDF_String::create_utf16(utf8_str)}; 1013 + return {String::utf16(utf8_str).obj_sp()};
1014 } 1014 }
1015 1015
1016 String::String(std::string const& str) : 1016 String::String(std::string const& str) :
@@ -1023,6 +1023,16 @@ String::String(std::string&& str) : @@ -1023,6 +1023,16 @@ String::String(std::string&& str) :
1023 { 1023 {
1024 } 1024 }
1025 1025
  1026 +String
  1027 +String::utf16(std::string const& utf8_str)
  1028 +{
  1029 + std::string result;
  1030 + if (QUtil::utf8_to_pdf_doc(utf8_str, result, '?')) {
  1031 + return String(result);
  1032 + }
  1033 + return String(QUtil::utf8_to_utf16(utf8_str));
  1034 +}
  1035 +
1026 std::string const& 1036 std::string const&
1027 String::value() const 1037 String::value() const
1028 { 1038 {
libqpdf/QPDF_String.cc
@@ -13,16 +13,6 @@ is_iso_latin1_printable(char ch) @@ -13,16 +13,6 @@ is_iso_latin1_printable(char ch)
13 return (ch >= 32 && ch <= 126) || static_cast<unsigned char>(ch) >= 160; 13 return (ch >= 32 && ch <= 126) || static_cast<unsigned char>(ch) >= 160;
14 } 14 }
15 15
16 -std::shared_ptr<QPDFObject>  
17 -QPDF_String::create_utf16(std::string const& utf8_val)  
18 -{  
19 - std::string result;  
20 - if (!QUtil::utf8_to_pdf_doc(utf8_val, result, '?')) {  
21 - result = QUtil::utf8_to_utf16(utf8_val);  
22 - }  
23 - return QPDFObject::create<QPDF_String>(result);  
24 -}  
25 -  
26 void 16 void
27 QPDF_String::writeJSON(int json_version, JSON::Writer& p) 17 QPDF_String::writeJSON(int json_version, JSON::Writer& p)
28 { 18 {
libqpdf/qpdf/QPDFObjectHandle_private.hh
@@ -614,6 +614,8 @@ namespace qpdf @@ -614,6 +614,8 @@ namespace qpdf
614 { 614 {
615 } 615 }
616 616
  617 + static String utf16(std::string const&);
  618 +
617 // Return the string value. If the object is not a valid string, throw a 619 // Return the string value. If the object is not a valid string, throw a
618 // std::invalid_argument exception. 620 // std::invalid_argument exception.
619 operator std::string() const& 621 operator std::string() const&
libqpdf/qpdf/QPDFObject_private.hh
@@ -266,7 +266,6 @@ class QPDF_String final @@ -266,7 +266,6 @@ class QPDF_String final
266 friend class qpdf::impl::Writer; 266 friend class qpdf::impl::Writer;
267 267
268 public: 268 public:
269 - static std::shared_ptr<QPDFObject> create_utf16(std::string const& utf8_val);  
270 std::string unparse(bool force_binary = false); 269 std::string unparse(bool force_binary = false);
271 void writeJSON(int json_version, JSON::Writer& p); 270 void writeJSON(int json_version, JSON::Writer& p);
272 271