From 1367ea75c3d6f544d5b6e7b1826c2c3888813580 Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 10 Nov 2025 13:39:32 +0000 Subject: [PATCH] Refactor `FormField`: replace `getInheritableFieldValueAsString` with `inheritable_string` method for clarity, consistency, and improved readability. --- libqpdf/QPDFFormFieldObjectHelper.cc | 15 +++++++-------- libqpdf/qpdf/FormField.hh | 9 ++++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index aea8cbc..ee5eb2c 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -107,15 +107,14 @@ FormField::inherited(std::string const& name, bool acroform) const std::string QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name) { - return m->getInheritableFieldValueAsString(name); + return m->inheritable_string(name); } std::string -FormField::getInheritableFieldValueAsString(std::string const& name) +FormField::inheritable_string(std::string const& name) const { - auto fv = inheritable_value(name); - if (fv.isString()) { - return fv.getUTF8Value(); + if (auto fv = inheritable_value(name)) { + return fv.utf8_value(); } return {}; } @@ -236,13 +235,13 @@ FormField::getValue() std::string QPDFFormFieldObjectHelper::getValueAsString() { - return getInheritableFieldValueAsString("/V"); + return m->getValueAsString(); } std::string FormField::getValueAsString() { - return getInheritableFieldValueAsString("/V"); + return inheritable_string("/V"); } QPDFObjectHandle @@ -266,7 +265,7 @@ QPDFFormFieldObjectHelper::getDefaultValueAsString() std::string FormField::getDefaultValueAsString() { - return getInheritableFieldValueAsString("/DV"); + return inheritable_string("/DV"); } QPDFObjectHandle diff --git a/libqpdf/qpdf/FormField.hh b/libqpdf/qpdf/FormField.hh index d85e692..de8b9f6 100644 --- a/libqpdf/qpdf/FormField.hh +++ b/libqpdf/qpdf/FormField.hh @@ -97,9 +97,12 @@ namespace qpdf::impl return {inherit ? inherited(name, acroform) : null_oh}; } - // Get an inherited field value as a string. If it is not a string, silently return the - // empty string. - std::string getInheritableFieldValueAsString(std::string const& name); + /// @brief Retrieves an inherited field string attribute as a string. + /// + /// @param name The name of the field for which the value is to be retrieved. + /// @return The inherited field value as a UTF-8 encoded string, or an empty string if the + /// value does not exist or is not of String type. + std::string inheritable_string(std::string const& name) const; // Get an inherited field value of type name as a string representing the name. If it is not // a name, silently return the empty string. -- libgit2 0.21.4