From 1c443a1c3574706a57d71a0d066ef16280709383 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 20 Sep 2025 14:36:11 +0100 Subject: [PATCH] Refactor `QPDFJob::Selection` and `Inputs`: remove `Selection::password` member and replace it with a setter that directly sets `Input::password`, centralize password handling, simplify file processing, and adjust related logic in `handlePageSpecs`. --- libqpdf/QPDFJob.cc | 14 ++++++-------- libqpdf/QPDFJob_config.cc | 6 +----- libqpdf/qpdf/QPDFJob_private.hh | 8 +++----- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 65d0fd6..7412faf 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -2405,10 +2405,6 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) void QPDFJob::Inputs::process_all() { - for (auto& selection: selections) { - selection.process(*this); - } - if (!infile_name().empty()) { files.erase(""); } @@ -2479,7 +2475,7 @@ QPDFJob::Inputs::new_selection( std::string const& filename, std::string const& password, std::string const& range) { auto& selection = new_selection(filename); - selection.password = password; + selection.password(password); selection.range = range; } @@ -2501,11 +2497,13 @@ QPDFJob::Selection::filename() } void -QPDFJob::Selection::process(QPDFJob::Inputs& in) +QPDFJob::Selection::password(std::string password) { - if (!password.empty()) { - input().password = password; + auto& in = input(); + if (!in.password.empty()) { + usage("--password already specified for this file"); } + in.password = password; } // Handle all page specifications. diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index f94bd47..746b5be 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -1025,11 +1025,7 @@ QPDFJob::PagesConfig::password(std::string const& arg) if (config->o.m->inputs.selections.empty()) { usage("in --pages, --password must follow a file name"); } - auto& last = config->o.m->inputs.selections.back(); - if (!last.password.empty()) { - usage("--password already specified for this file"); - } - last.password = arg; + config->o.m->inputs.selections.back().password(arg); return this; } diff --git a/libqpdf/qpdf/QPDFJob_private.hh b/libqpdf/qpdf/QPDFJob_private.hh index 4c6231b..b77ab37 100644 --- a/libqpdf/qpdf/QPDFJob_private.hh +++ b/libqpdf/qpdf/QPDFJob_private.hh @@ -12,9 +12,9 @@ struct QPDFJob::Selection { Selection() = delete; - Selection(std::pair& entry); + Selection(std::pair& entry); - Selection(QPDFJob::Selection const& other, int page) : + Selection(Selection const& other, int page) : in_entry(other.in_entry), selected_pages({page}) { @@ -22,11 +22,9 @@ struct QPDFJob::Selection QPDFJob::Input& input(); std::string const& filename(); - - void process(Inputs& in); + void password(std::string password); std::pair* in_entry{nullptr}; - std::string password; std::string range; // An empty range means all pages. std::vector selected_pages; }; -- libgit2 0.21.4