From 32907fc14c663e95df0f7c62905b82389c0024a2 Mon Sep 17 00:00:00 2001 From: m-holger Date: Wed, 15 Feb 2023 10:11:38 +0000 Subject: Change type of QPDFValue::object_description to std::shared_ptr Also, name the type QPDFValue::Description. --- libqpdf/QPDFValue.cc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'libqpdf/QPDFValue.cc') diff --git a/libqpdf/QPDFValue.cc b/libqpdf/QPDFValue.cc index 19679df2..7c5b30a6 100644 --- a/libqpdf/QPDFValue.cc +++ b/libqpdf/QPDFValue.cc @@ -13,16 +13,28 @@ QPDFValue::do_create(QPDFValue* object) std::string QPDFValue::getDescription() { - auto description = object_description ? *object_description : ""; - if (auto pos = description.find("$OG"); pos != std::string::npos) { - description.replace(pos, 3, og.unparse(' ')); - } - if (auto pos = description.find("$PO"); pos != std::string::npos) { - qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2 - : (type_code == ::ot_array) ? 1 - : 0; + if (object_description) { + switch (object_description->index()) { + case 0: + { + auto description = std::get<0>(*object_description); + + if (auto pos = description.find("$OG"); + pos != std::string::npos) { + description.replace(pos, 3, og.unparse(' ')); + } + if (auto pos = description.find("$PO"); + pos != std::string::npos) { + qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2 + : (type_code == ::ot_array) ? 1 + : 0; - description.replace(pos, 3, std::to_string(parsed_offset + shift)); + description.replace( + pos, 3, std::to_string(parsed_offset + shift)); + } + return description; + } + } } - return description; + return {}; } -- cgit v1.2.3-70-g09d2