Commit cb5a5f4ed050fd36461bcc768cd5ea6198e2299d
1 parent
1c443a1c
Refactor `handlePageSpecs`: adjust logic to process selections specific to each …
…input, centralize page range parsing, and simplify page processing.
Showing
1 changed file
with
20 additions
and
17 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -2368,6 +2368,7 @@ QPDFJob::Inputs::infile_name(std::string const& name) |
| 2368 | 2368 | } |
| 2369 | 2369 | } |
| 2370 | 2370 | |
| 2371 | + | |
| 2371 | 2372 | void |
| 2372 | 2373 | QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) |
| 2373 | 2374 | { |
| ... | ... | @@ -2424,25 +2425,27 @@ QPDFJob::Inputs::process_all() |
| 2424 | 2425 | if (!input.qpdf) { |
| 2425 | 2426 | process(filename, input); |
| 2426 | 2427 | } |
| 2427 | - } | |
| 2428 | 2428 | |
| 2429 | - for (auto& selection: selections) { | |
| 2430 | - // Read original pages from the PDF, and parse the page range associated with this | |
| 2431 | - // occurrence of the file. | |
| 2432 | - auto const& input = selection.input(); | |
| 2433 | - if (selection.range.empty()) { | |
| 2434 | - selection.selected_pages.reserve(static_cast<size_t>(input.n_pages)); | |
| 2435 | - for (int i = 1; i <= input.n_pages; ++i) { | |
| 2436 | - selection.selected_pages.push_back(i); | |
| 2429 | + for (auto& selection: selections) { | |
| 2430 | + if (&selection.input() != &input) { | |
| 2431 | + continue; | |
| 2432 | + } | |
| 2433 | + // Read original pages from the PDF, and parse the page range associated with this | |
| 2434 | + // occurrence of the file. | |
| 2435 | + if (selection.range.empty()) { | |
| 2436 | + selection.selected_pages.reserve(static_cast<size_t>(input.n_pages)); | |
| 2437 | + for (int i = 1; i <= input.n_pages; ++i) { | |
| 2438 | + selection.selected_pages.push_back(i); | |
| 2439 | + } | |
| 2440 | + continue; | |
| 2441 | + } | |
| 2442 | + try { | |
| 2443 | + selection.selected_pages = | |
| 2444 | + QUtil::parse_numrange(selection.range.data(), selection.input().n_pages); | |
| 2445 | + } catch (std::runtime_error& e) { | |
| 2446 | + throw std::runtime_error( | |
| 2447 | + "parsing numeric range for " + selection.filename() + ": " + e.what()); | |
| 2437 | 2448 | } |
| 2438 | - continue; | |
| 2439 | - } | |
| 2440 | - try { | |
| 2441 | - selection.selected_pages = | |
| 2442 | - QUtil::parse_numrange(selection.range.data(), selection.input().n_pages); | |
| 2443 | - } catch (std::runtime_error& e) { | |
| 2444 | - throw std::runtime_error( | |
| 2445 | - "parsing numeric range for " + selection.filename() + ": " + e.what()); | |
| 2446 | 2449 | } |
| 2447 | 2450 | } |
| 2448 | 2451 | } | ... | ... |