Commit 1367ea75c3d6f544d5b6e7b1826c2c3888813580

Authored by m-holger
1 parent 91ae1494

Refactor `FormField`: replace `getInheritableFieldValueAsString` with `inheritab…

…le_string` method for clarity, consistency, and improved readability.
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -107,15 +107,14 @@ FormField::inherited(std::string const& name, bool acroform) const @@ -107,15 +107,14 @@ FormField::inherited(std::string const& name, bool acroform) const
107 std::string 107 std::string
108 QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name) 108 QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name)
109 { 109 {
110 - return m->getInheritableFieldValueAsString(name); 110 + return m->inheritable_string(name);
111 } 111 }
112 112
113 std::string 113 std::string
114 -FormField::getInheritableFieldValueAsString(std::string const& name) 114 +FormField::inheritable_string(std::string const& name) const
115 { 115 {
116 - auto fv = inheritable_value<QPDFObjectHandle>(name);  
117 - if (fv.isString()) {  
118 - return fv.getUTF8Value(); 116 + if (auto fv = inheritable_value<String>(name)) {
  117 + return fv.utf8_value();
119 } 118 }
120 return {}; 119 return {};
121 } 120 }
@@ -236,13 +235,13 @@ FormField::getValue() @@ -236,13 +235,13 @@ FormField::getValue()
236 std::string 235 std::string
237 QPDFFormFieldObjectHelper::getValueAsString() 236 QPDFFormFieldObjectHelper::getValueAsString()
238 { 237 {
239 - return getInheritableFieldValueAsString("/V"); 238 + return m->getValueAsString();
240 } 239 }
241 240
242 std::string 241 std::string
243 FormField::getValueAsString() 242 FormField::getValueAsString()
244 { 243 {
245 - return getInheritableFieldValueAsString("/V"); 244 + return inheritable_string("/V");
246 } 245 }
247 246
248 QPDFObjectHandle 247 QPDFObjectHandle
@@ -266,7 +265,7 @@ QPDFFormFieldObjectHelper::getDefaultValueAsString() @@ -266,7 +265,7 @@ QPDFFormFieldObjectHelper::getDefaultValueAsString()
266 std::string 265 std::string
267 FormField::getDefaultValueAsString() 266 FormField::getDefaultValueAsString()
268 { 267 {
269 - return getInheritableFieldValueAsString("/DV"); 268 + return inheritable_string("/DV");
270 } 269 }
271 270
272 QPDFObjectHandle 271 QPDFObjectHandle
libqpdf/qpdf/FormField.hh
@@ -97,9 +97,12 @@ namespace qpdf::impl @@ -97,9 +97,12 @@ namespace qpdf::impl
97 return {inherit ? inherited(name, acroform) : null_oh}; 97 return {inherit ? inherited(name, acroform) : null_oh};
98 } 98 }
99 99
100 - // Get an inherited field value as a string. If it is not a string, silently return the  
101 - // empty string.  
102 - std::string getInheritableFieldValueAsString(std::string const& name); 100 + /// @brief Retrieves an inherited field string attribute as a string.
  101 + ///
  102 + /// @param name The name of the field for which the value is to be retrieved.
  103 + /// @return The inherited field value as a UTF-8 encoded string, or an empty string if the
  104 + /// value does not exist or is not of String type.
  105 + std::string inheritable_string(std::string const& name) const;
103 106
104 // Get an inherited field value of type name as a string representing the name. If it is not 107 // Get an inherited field value of type name as a string representing the name. If it is not
105 // a name, silently return the empty string. 108 // a name, silently return the empty string.