Commit 3d29a0533c6c15628daddd6afa7637faad36dba4

Authored by m-holger
1 parent ef14676b

Refactor `QPDFFormFieldObjectHelper`: simplify return logic, use direct returns …

…for improved readability, and remove redundant variables.
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -88,23 +88,21 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) @@ -88,23 +88,21 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
88 std::string 88 std::string
89 QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name) 89 QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name)
90 { 90 {
91 - QPDFObjectHandle fv = getInheritableFieldValue(name);  
92 - std::string result; 91 + auto fv = getInheritableFieldValue(name);
93 if (fv.isString()) { 92 if (fv.isString()) {
94 - result = fv.getUTF8Value(); 93 + return fv.getUTF8Value();
95 } 94 }
96 - return result; 95 + return {};
97 } 96 }
98 97
99 std::string 98 std::string
100 QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name) 99 QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name)
101 { 100 {
102 - QPDFObjectHandle fv = getInheritableFieldValue(name);  
103 - std::string result; 101 + auto fv = getInheritableFieldValue(name);
104 if (fv.isName()) { 102 if (fv.isName()) {
105 - result = fv.getName(); 103 + return fv.getName();
106 } 104 }
107 - return result; 105 + return {};
108 } 106 }
109 107
110 std::string 108 std::string
@@ -203,12 +201,11 @@ QPDFFormFieldObjectHelper::getDefaultAppearance() @@ -203,12 +201,11 @@ QPDFFormFieldObjectHelper::getDefaultAppearance()
203 value = getFieldFromAcroForm("/DA"); 201 value = getFieldFromAcroForm("/DA");
204 looked_in_acroform = true; 202 looked_in_acroform = true;
205 } 203 }
206 - std::string result;  
207 if (value.isString()) { 204 if (value.isString()) {
208 QTC::TC("qpdf", "QPDFFormFieldObjectHelper DA present", looked_in_acroform ? 0 : 1); 205 QTC::TC("qpdf", "QPDFFormFieldObjectHelper DA present", looked_in_acroform ? 0 : 1);
209 - result = value.getUTF8Value(); 206 + return value.getUTF8Value();
210 } 207 }
211 - return result; 208 + return {};
212 } 209 }
213 210
214 int 211 int
@@ -220,12 +217,11 @@ QPDFFormFieldObjectHelper::getQuadding() @@ -220,12 +217,11 @@ QPDFFormFieldObjectHelper::getQuadding()
220 fv = getFieldFromAcroForm("/Q"); 217 fv = getFieldFromAcroForm("/Q");
221 looked_in_acroform = true; 218 looked_in_acroform = true;
222 } 219 }
223 - int result = 0;  
224 if (fv.isInteger()) { 220 if (fv.isInteger()) {
225 QTC::TC("qpdf", "QPDFFormFieldObjectHelper Q present", looked_in_acroform ? 0 : 1); 221 QTC::TC("qpdf", "QPDFFormFieldObjectHelper Q present", looked_in_acroform ? 0 : 1);
226 - result = QIntC::to_int(fv.getIntValue()); 222 + return QIntC::to_int(fv.getIntValue());
227 } 223 }
228 - return result; 224 + return 0;
229 } 225 }
230 226
231 int 227 int
@@ -238,46 +234,46 @@ QPDFFormFieldObjectHelper::getFlags() @@ -238,46 +234,46 @@ QPDFFormFieldObjectHelper::getFlags()
238 bool 234 bool
239 QPDFFormFieldObjectHelper::isText() 235 QPDFFormFieldObjectHelper::isText()
240 { 236 {
241 - return (getFieldType() == "/Tx"); 237 + return getFieldType() == "/Tx";
242 } 238 }
243 239
244 bool 240 bool
245 QPDFFormFieldObjectHelper::isCheckbox() 241 QPDFFormFieldObjectHelper::isCheckbox()
246 { 242 {
247 - return ((getFieldType() == "/Btn") && ((getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0)); 243 + return getFieldType() == "/Btn" && (getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0;
248 } 244 }
249 245
250 bool 246 bool
251 QPDFFormFieldObjectHelper::isChecked() 247 QPDFFormFieldObjectHelper::isChecked()
252 { 248 {
253 - return isCheckbox() && getValue().isName() && (getValue().getName() != "/Off"); 249 + return isCheckbox() && getValue().isName() && getValue().getName() != "/Off";
254 } 250 }
255 251
256 bool 252 bool
257 QPDFFormFieldObjectHelper::isRadioButton() 253 QPDFFormFieldObjectHelper::isRadioButton()
258 { 254 {
259 - return ((getFieldType() == "/Btn") && ((getFlags() & ff_btn_radio) == ff_btn_radio)); 255 + return getFieldType() == "/Btn" && (getFlags() & ff_btn_radio) == ff_btn_radio;
260 } 256 }
261 257
262 bool 258 bool
263 QPDFFormFieldObjectHelper::isPushbutton() 259 QPDFFormFieldObjectHelper::isPushbutton()
264 { 260 {
265 - return ((getFieldType() == "/Btn") && ((getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton)); 261 + return getFieldType() == "/Btn" && (getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton;
266 } 262 }
267 263
268 bool 264 bool
269 QPDFFormFieldObjectHelper::isChoice() 265 QPDFFormFieldObjectHelper::isChoice()
270 { 266 {
271 - return (getFieldType() == "/Ch"); 267 + return getFieldType() == "/Ch";
272 } 268 }
273 269
274 std::vector<std::string> 270 std::vector<std::string>
275 QPDFFormFieldObjectHelper::getChoices() 271 QPDFFormFieldObjectHelper::getChoices()
276 { 272 {
277 - std::vector<std::string> result;  
278 if (!isChoice()) { 273 if (!isChoice()) {
279 - return result; 274 + return {};
280 } 275 }
  276 + std::vector<std::string> result;
281 for (auto const& item: getInheritableFieldValue("/Opt").as_array()) { 277 for (auto const& item: getInheritableFieldValue("/Opt").as_array()) {
282 if (item.isString()) { 278 if (item.isString()) {
283 result.emplace_back(item.getUTF8Value()); 279 result.emplace_back(item.getUTF8Value());