Commit 03fcdc63c84e92d53deb75dced39948916a48727
1 parent
4a4b9456
Refactor QPDFJob::checkConfiguration code to improve readability and consistency
Replaced `else if` chains with standalone `if` statements for clarity. Updated conditional checks with modern coding practices, such as using `.contains()` instead of `.count()`. These changes enhance code maintainability and ensure better style consistency.
Showing
1 changed file
with
17 additions
and
12 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -606,32 +606,37 @@ QPDFJob::checkConfiguration() |
| 606 | 606 | // Check for --empty appears later after we have checked m->infilename. |
| 607 | 607 | if (m->outfilename) { |
| 608 | 608 | usage("--replace-input may not be used when an output file is specified"); |
| 609 | - } else if (m->split_pages) { | |
| 609 | + } | |
| 610 | + if (m->split_pages) { | |
| 610 | 611 | usage("--split-pages may not be used with --replace-input"); |
| 611 | - } else if (m->json_version) { | |
| 612 | + } | |
| 613 | + if (m->json_version) { | |
| 612 | 614 | usage("--json may not be used with --replace-input"); |
| 613 | 615 | } |
| 614 | 616 | } |
| 615 | - if (m->json_version && (m->outfilename == nullptr)) { | |
| 617 | + if (m->json_version && !m->outfilename) { | |
| 616 | 618 | // The output file is optional with --json for backward compatibility and defaults to |
| 617 | 619 | // standard output. |
| 618 | 620 | m->outfilename = QUtil::make_shared_cstr("-"); |
| 619 | 621 | } |
| 620 | - if (m->infilename == nullptr) { | |
| 622 | + if (!m->infilename) { | |
| 621 | 623 | usage("an input file name is required"); |
| 622 | - } else if (m->replace_input && (strlen(m->infilename.get()) == 0)) { | |
| 624 | + } | |
| 625 | + if (m->replace_input && (strlen(m->infilename.get()) == 0)) { | |
| 623 | 626 | usage("--replace-input may not be used with --empty"); |
| 624 | - } else if (m->require_outfile && (m->outfilename == nullptr) && (!m->replace_input)) { | |
| 627 | + } | |
| 628 | + if (m->require_outfile && (m->outfilename == nullptr) && (!m->replace_input)) { | |
| 625 | 629 | usage("an output file name is required; use - for standard output"); |
| 626 | - } else if ((!m->require_outfile) && ((m->outfilename != nullptr) || m->replace_input)) { | |
| 630 | + } | |
| 631 | + if ((!m->require_outfile) && ((m->outfilename != nullptr) || m->replace_input)) { | |
| 627 | 632 | usage("no output file may be given for this option"); |
| 628 | 633 | } |
| 629 | 634 | if (m->check_requires_password && m->check_is_encrypted) { |
| 630 | 635 | usage("--requires-password and --is-encrypted may not be given together"); |
| 631 | 636 | } |
| 632 | 637 | |
| 633 | - if (m->encrypt && (!m->allow_insecure) && | |
| 634 | - (m->owner_password.empty() && (!m->user_password.empty()) && (m->keylen == 256))) { | |
| 638 | + if (m->encrypt && !m->allow_insecure && m->owner_password.empty() && | |
| 639 | + !m->user_password.empty() && m->keylen == 256) { | |
| 635 | 640 | // Note that empty owner passwords for R < 5 are copied from the user password, so this lack |
| 636 | 641 | // of security is not an issue for those files. Also we are consider only the ability to |
| 637 | 642 | // open the file without a password to be insecure. We are not concerned about whether the |
| ... | ... | @@ -656,7 +661,7 @@ QPDFJob::checkConfiguration() |
| 656 | 661 | if (save_to_stdout) { |
| 657 | 662 | m->log->saveToStandardOutput(true); |
| 658 | 663 | } |
| 659 | - if ((!m->split_pages) && QUtil::same_file(m->infilename.get(), m->outfilename.get())) { | |
| 664 | + if (!m->split_pages && QUtil::same_file(m->infilename.get(), m->outfilename.get())) { | |
| 660 | 665 | QTC::TC("qpdf", "QPDFJob same file error"); |
| 661 | 666 | usage( |
| 662 | 667 | "input file and output file are the same; use --replace-input to intentionally " |
| ... | ... | @@ -664,11 +669,11 @@ QPDFJob::checkConfiguration() |
| 664 | 669 | } |
| 665 | 670 | |
| 666 | 671 | if (m->json_version == 1) { |
| 667 | - if (m->json_keys.count("qpdf")) { | |
| 672 | + if (m->json_keys.contains("qpdf")) { | |
| 668 | 673 | usage("json key \"qpdf\" is only valid for json version > 1"); |
| 669 | 674 | } |
| 670 | 675 | } else { |
| 671 | - if (m->json_keys.count("objectinfo") || m->json_keys.count("objects")) { | |
| 676 | + if (m->json_keys.contains("objectinfo") || m->json_keys.count("objects")) { | |
| 672 | 677 | usage("json keys \"objects\" and \"objectinfo\" are only valid for json version 1"); |
| 673 | 678 | } |
| 674 | 679 | } | ... | ... |