Commit 1d7ebddb58b0919b92f2008b004beefaaf6a0054

Authored by m-holger
1 parent 28aa951f

Replace `count()` with `contains()` for cleaner and more efficient checks

Converted multiple occurrences of `count()` to `contains()` throughout the codebase where the goal was to check key existence in containers. This improves code readability and aligns with modern C++ practices, particularly with C++20, making the intent more explicit and potentially aiding performance.
examples/pdf-bookmarks.cc
... ... @@ -104,7 +104,7 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers)
104 104 QPDFObjectHandle dest_page = outline.getDestPage();
105 105 if (!dest_page.isNull()) {
106 106 QTC::TC("examples", "pdf-bookmarks dest");
107   - if (page_map.count(dest_page)) {
  107 + if (page_map.contains(dest_page)) {
108 108 target = std::to_string(page_map[dest_page]);
109 109 }
110 110 }
... ...
examples/pdf-custom-filter.cc
... ... @@ -276,7 +276,7 @@ StreamReplacer::registerStream(
276 276 // We don't need to process a stream more than once. In this example, we are just iterating
277 277 // through objects, but if we were doing something like iterating through images on pages, we
278 278 // might realistically encounter the same stream more than once.
279   - if (this->copied_streams.count(og) > 0) {
  279 + if (this->copied_streams.contains(og)) {
280 280 return;
281 281 }
282 282 // Store something in copied_streams so that we don't double-process even in the negative case.
... ...
examples/pdf-invert-images.cc
... ... @@ -52,7 +52,7 @@ ImageInverter::registerImage(
52 52 // Store information about the images based on the object and generation number. Recall that a
53 53 // single image object may be used more than once, so no need to update the same stream multiple
54 54 // times.
55   - if (this->copied_images.count(og) > 0) {
  55 + if (copied_images.contains(og)) {
56 56 return;
57 57 }
58 58 this->copied_images[og] = image.copyStream();
... ...
include/qpdf/QPDFObjGen.hh
... ... @@ -110,7 +110,7 @@ class QPDFObjGen
110 110 add(QPDFObjGen og)
111 111 {
112 112 if (og.isIndirect()) {
113   - if (count(og) > 0) {
  113 + if (count(og)) {
114 114 return false;
115 115 }
116 116 emplace(og);
... ...
libqpdf/JSON.cc
... ... @@ -516,11 +516,11 @@ JSON::checkSchemaInternal(
516 516 }
517 517 }
518 518 }
519   - for (auto const& [key, val]: this_dict->members) {
520   - if (!sch_dict->members.contains(key)) {
  519 + for (auto const& item: this_dict->members) {
  520 + if (!sch_dict->members.contains(item.first)) {
521 521 QTC::TC("libtests", "JSON key extra in object");
522 522 errors.emplace_back(
523   - err_prefix + ": key \"" + key +
  523 + err_prefix + ": key \"" + item.first +
524 524 "\" is not present in schema but appears in object");
525 525 }
526 526 }
... ...
libqpdf/QPDF.cc
... ... @@ -564,7 +564,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
564 564 obj_copier.to_copy.clear();
565 565  
566 566 auto og = foreign.getObjGen();
567   - if (!obj_copier.object_map.count(og)) {
  567 + if (!obj_copier.object_map.contains(og)) {
568 568 warn(damagedPDF(
569 569 other.getFilename() + " object " + og.unparse(' '),
570 570 foreign.getParsedOffset(),
... ... @@ -594,7 +594,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
594 594 QTC::TC("qpdf", "QPDF loop reserving objects");
595 595 return;
596 596 }
597   - if (obj_copier.object_map.count(foreign_og) > 0) {
  597 + if (obj_copier.object_map.contains(foreign_og)) {
598 598 QTC::TC("qpdf", "QPDF already reserved object");
599 599 if (!(top && foreign.isPageObject() && obj_copier.object_map[foreign_og].isNull())) {
600 600 obj_copier.visiting.erase(foreign);
... ...
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -85,7 +85,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(std::vector<QPDFObjectHandle>
85 85 // this field's /T is always at the end of the fully qualified name, appending to /T
86 86 // has the effect of appending the same thing to the fully qualified name.
87 87 std::string old_name = QPDFFormFieldObjectHelper(obj).getFullyQualifiedName();
88   - if (renames.count(old_name) == 0) {
  88 + if (!renames.contains(old_name)) {
89 89 std::string new_name = old_name;
90 90 int suffix = 0;
91 91 std::string append;
... ... @@ -145,7 +145,7 @@ QPDFAcroFormDocumentHelper::removeFormFields(std::set<QPDFObjGen> const& to_remo
145 145 int i = 0;
146 146 while (i < fields.getArrayNItems()) {
147 147 auto field = fields.getArrayItem(i);
148   - if (to_remove.count(field.getObjGen())) {
  148 + if (to_remove.contains(field.getObjGen())) {
149 149 fields.eraseItem(i);
150 150 } else {
151 151 ++i;
... ... @@ -191,7 +191,7 @@ QPDFAcroFormDocumentHelper::getAnnotationsForField(QPDFFormFieldObjectHelper h)
191 191 analyze();
192 192 std::vector<QPDFAnnotationObjectHelper> result;
193 193 QPDFObjGen og(h.getObjectHandle().getObjGen());
194   - if (m->field_to_annotations.count(og)) {
  194 + if (m->field_to_annotations.contains(og)) {
195 195 result = m->field_to_annotations[og];
196 196 }
197 197 return result;
... ... @@ -228,7 +228,7 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h)
228 228 }
229 229 analyze();
230 230 QPDFObjGen og(oh.getObjGen());
231   - if (m->annotation_to_field.count(og)) {
  231 + if (m->annotation_to_field.contains(og)) {
232 232 result = m->annotation_to_field[og];
233 233 }
234 234 return result;
... ... @@ -271,7 +271,7 @@ QPDFAcroFormDocumentHelper::analyze()
271 271 for (auto const& iter: getWidgetAnnotationsForPage(ph)) {
272 272 QPDFObjectHandle annot(iter.getObjectHandle());
273 273 QPDFObjGen og(annot.getObjGen());
274   - if (m->annotation_to_field.count(og) == 0) {
  274 + if (!m->annotation_to_field.contains(og)) {
275 275 QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget");
276 276 // This is not supposed to happen, but it's easy enough for us to handle this case.
277 277 // Treat the annotation as its own field. This could allow qpdf to sensibly handle a
... ... @@ -542,7 +542,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const&amp; token)
542 542 bool wrote = false;
543 543 if (token.getType() == QPDFTokenizer::tt_name) {
544 544 std::string name = QPDFObjectHandle::newName(token.getValue()).getName();
545   - if (to_replace.count(name) && to_replace[name].count(offset)) {
  545 + if (to_replace.contains(name) && to_replace[name].contains(offset)) {
546 546 QTC::TC("qpdf", "QPDFAcroFormDocumentHelper replaced DA token");
547 547 write(to_replace[name][offset]);
548 548 wrote = true;
... ... @@ -807,7 +807,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
807 807 std::map<QPDFObjGen, QPDFObjectHandle> orig_to_copy;
808 808 auto maybe_copy_object = [&](QPDFObjectHandle& to_copy) {
809 809 auto og = to_copy.getObjGen();
810   - if (orig_to_copy.count(og)) {
  810 + if (orig_to_copy.contains(og)) {
811 811 to_copy = orig_to_copy[og];
812 812 return false;
813 813 } else {
... ... @@ -893,7 +893,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
893 893 auto parent = obj.getKey("/Parent");
894 894 if (parent.isIndirect()) {
895 895 auto parent_og = parent.getObjGen();
896   - if (orig_to_copy.count(parent_og)) {
  896 + if (orig_to_copy.contains(parent_og)) {
897 897 obj.replaceKey("/Parent", orig_to_copy[parent_og]);
898 898 } else {
899 899 parent.warnIfPossible(
... ...
libqpdf/QPDFArgParser.cc
... ... @@ -71,7 +71,7 @@ QPDFArgParser::selectOptionTable(std::string const&amp; name)
71 71 void
72 72 QPDFArgParser::registerOptionTable(std::string const& name, bare_arg_handler_t end_handler)
73 73 {
74   - if (0 != m->option_tables.count(name)) {
  74 + if (m->option_tables.contains(name)) {
75 75 QTC::TC("libtests", "QPDFArgParser register registered table");
76 76 throw std::logic_error(
77 77 "QPDFArgParser: registering already registered option table " + name);
... ... @@ -84,7 +84,7 @@ QPDFArgParser::registerOptionTable(std::string const&amp; name, bare_arg_handler_t e
84 84 QPDFArgParser::OptionEntry&
85 85 QPDFArgParser::registerArg(std::string const& arg)
86 86 {
87   - if (0 != m->option_table->count(arg)) {
  87 + if (m->option_table->contains(arg)) {
88 88 QTC::TC("libtests", "QPDFArgParser duplicate handler");
89 89 throw std::logic_error(
90 90 "QPDFArgParser: adding a duplicate handler for option " + arg + " in " +
... ... @@ -481,7 +481,7 @@ QPDFArgParser::parseArgs()
481 481 }
482 482  
483 483 if ((!m->bash_completion) && (m->argc == 2) && (m->cur_arg == 1) &&
484   - m->help_option_table.count(arg_s)) {
  484 + m->help_option_table.contains(arg_s)) {
485 485 // Handle help option, which is only valid as the sole option.
486 486 QTC::TC("libtests", "QPDFArgParser help option");
487 487 oep = m->help_option_table.find(arg_s);
... ... @@ -508,8 +508,8 @@ QPDFArgParser::parseArgs()
508 508 }
509 509  
510 510 OptionEntry& oe = oep->second;
511   - if ((oe.parameter_needed && (!have_parameter)) ||
512   - ((!oe.choices.empty() && have_parameter && (0 == oe.choices.count(parameter))))) {
  511 + if ((oe.parameter_needed && !have_parameter) ||
  512 + (!oe.choices.empty() && have_parameter && !oe.choices.contains(parameter))) {
513 513 std::string message = "--" + arg_s + " must be given as --" + arg_s + "=";
514 514 if (oe.invalid_choice_handler) {
515 515 oe.invalid_choice_handler(parameter);
... ... @@ -584,7 +584,7 @@ void
584 584 QPDFArgParser::addChoicesToCompletions(
585 585 option_table_t& option_table, std::string const& option, std::string const& extra_prefix)
586 586 {
587   - if (option_table.count(option) != 0) {
  587 + if (option_table.contains(option)) {
588 588 OptionEntry& oe = option_table[option];
589 589 for (auto const& choice: oe.choices) {
590 590 QTC::TC("libtests", "QPDFArgParser complete choices");
... ... @@ -690,7 +690,7 @@ QPDFArgParser::addHelpTopic(
690 690 QTC::TC("libtests", "QPDFArgParser bad topic for help");
691 691 throw std::logic_error("QPDFArgParser: help topics must not start with -");
692 692 }
693   - if (m->help_topics.count(topic)) {
  693 + if (m->help_topics.contains(topic)) {
694 694 QTC::TC("libtests", "QPDFArgParser add existing topic");
695 695 throw std::logic_error("QPDFArgParser: topic " + topic + " has already been added");
696 696 }
... ... @@ -710,7 +710,7 @@ QPDFArgParser::addOptionHelp(
710 710 QTC::TC("libtests", "QPDFArgParser bad option for help");
711 711 throw std::logic_error("QPDFArgParser: options for help must start with --");
712 712 }
713   - if (m->option_help.count(option_name)) {
  713 + if (m->option_help.contains(option_name)) {
714 714 QTC::TC("libtests", "QPDFArgParser duplicate option help");
715 715 throw std::logic_error("QPDFArgParser: option " + option_name + " already has help");
716 716 }
... ... @@ -782,9 +782,9 @@ QPDFArgParser::getHelp(std::string const&amp; arg)
782 782 } else {
783 783 if (arg == "all") {
784 784 getAllHelp(msg);
785   - } else if (m->option_help.count(arg)) {
  785 + } else if (m->option_help.contains(arg)) {
786 786 getTopicHelp(arg, m->option_help[arg], msg);
787   - } else if (m->help_topics.count(arg)) {
  787 + } else if (m->help_topics.contains(arg)) {
788 788 getTopicHelp(arg, m->help_topics[arg], msg);
789 789 } else {
790 790 // should not be possible
... ...
libqpdf/QPDFCryptoProvider.cc
... ... @@ -88,7 +88,7 @@ QPDFCryptoProvider::registerImpl_internal(std::string const&amp; name, provider_fn f
88 88 void
89 89 QPDFCryptoProvider::setDefaultProvider_internal(std::string const& name)
90 90 {
91   - if (!m->providers.count(name)) {
  91 + if (!m->providers.contains(name)) {
92 92 throw std::logic_error(
93 93 "QPDFCryptoProvider: request to set default provider to unknown implementation \"" +
94 94 name + "\"");
... ...
libqpdf/QPDFJob.cc
... ... @@ -673,7 +673,7 @@ QPDFJob::checkConfiguration()
673 673 usage("json key \"qpdf\" is only valid for json version > 1");
674 674 }
675 675 } else {
676   - if (m->json_keys.contains("objectinfo") || m->json_keys.count("objects")) {
  676 + if (m->json_keys.contains("objectinfo") || m->json_keys.contains("objects")) {
677 677 usage("json keys \"objects\" and \"objectinfo\" are only valid for json version 1");
678 678 }
679 679 }
... ... @@ -1007,13 +1007,13 @@ QPDFJob::doJSONObjects(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1007 1007 for (auto& obj: pdf.getAllObjects()) {
1008 1008 std::string key = obj.unparse();
1009 1009  
1010   - if (all_objects || wanted_og.count(obj.getObjGen())) {
  1010 + if (all_objects || wanted_og.contains(obj.getObjGen())) {
1011 1011 JSON::writeDictionaryKey(p, first_object, obj.unparse(), 2);
1012 1012 obj.writeJSON(1, p, true, 2);
1013 1013 first_object = false;
1014 1014 }
1015 1015 }
1016   - if (all_objects || m->json_objects.count("trailer")) {
  1016 + if (all_objects || m->json_objects.contains("trailer")) {
1017 1017 JSON::writeDictionaryKey(p, first_object, "trailer", 2);
1018 1018 pdf.getTrailer().writeJSON(1, p, true, 2);
1019 1019 first_object = false;
... ... @@ -1021,7 +1021,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1021 1021 JSON::writeDictionaryClose(p, first_object, 1);
1022 1022 } else {
1023 1023 std::set<std::string> json_objects;
1024   - if (m->json_objects.count("trailer")) {
  1024 + if (m->json_objects.contains("trailer")) {
1025 1025 json_objects.insert("trailer");
1026 1026 }
1027 1027 for (auto og: getWantedJSONObjects()) {
... ... @@ -1048,7 +1048,7 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1048 1048 bool all_objects = m->json_objects.empty();
1049 1049 auto wanted_og = getWantedJSONObjects();
1050 1050 for (auto& obj: pdf.getAllObjects()) {
1051   - if (all_objects || wanted_og.count(obj.getObjGen())) {
  1051 + if (all_objects || wanted_og.contains(obj.getObjGen())) {
1052 1052 auto j_details = JSON::makeDictionary();
1053 1053 auto j_stream = j_details.addDictionaryMember("stream", JSON::makeDictionary());
1054 1054 bool is_stream = obj.isStream();
... ... @@ -1170,7 +1170,7 @@ QPDFJob::addOutlinesToJson(
1170 1170 JSON j_destpage = JSON::makeNull();
1171 1171 if (page.isIndirect()) {
1172 1172 QPDFObjGen og = page.getObjGen();
1173   - if (page_numbers.count(og)) {
  1173 + if (page_numbers.contains(og)) {
1174 1174 j_destpage = JSON::makeInt(page_numbers[og]);
1175 1175 }
1176 1176 }
... ... @@ -1913,7 +1913,7 @@ get_afdh_for_qpdf(
1913 1913 std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>& afdh_map, QPDF* q)
1914 1914 {
1915 1915 auto uid = q->getUniqueId();
1916   - if (!afdh_map.count(uid)) {
  1916 + if (!afdh_map.contains(uid)) {
1917 1917 afdh_map[uid] = std::make_shared<QPDFAcroFormDocumentHelper>(*q);
1918 1918 }
1919 1919 return afdh_map[uid].get();
... ... @@ -1931,7 +1931,7 @@ QPDFJob::doUnderOverlayForPage(
1931 1931 QPDFPageObjectHelper& dest_page)
1932 1932 {
1933 1933 int pageno = 1 + QIntC::to_int(page_idx);
1934   - if (!(pagenos.count(pageno) && pagenos[pageno].count(uo_idx))) {
  1934 + if (!(pagenos.contains(pageno) && pagenos[pageno].contains(uo_idx))) {
1935 1935 return "";
1936 1936 }
1937 1937  
... ... @@ -1950,7 +1950,7 @@ QPDFJob::doUnderOverlayForPage(
1950 1950 v << " " << uo.filename << " " << uo.which << " " << from_pageno << "\n";
1951 1951 });
1952 1952 auto from_page = pages.at(QIntC::to_size(from_pageno - 1));
1953   - if (fo[from_pageno].count(uo_idx) == 0) {
  1953 + if (!fo[from_pageno].contains(uo_idx)) {
1954 1954 fo[from_pageno][uo_idx] = pdf.copyForeignObject(from_page.getFormXObjectForPage());
1955 1955 }
1956 1956  
... ... @@ -2462,7 +2462,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2462 2462 std::vector<QPDFPageData> parsed_specs;
2463 2463 std::map<unsigned long long, std::set<QPDFObjGen>> copied_pages;
2464 2464 for (auto& page_spec: m->page_specs) {
2465   - if (page_spec_qpdfs.count(page_spec.filename) == 0) {
  2465 + if (!page_spec_qpdfs.contains(page_spec.filename)) {
2466 2466 // Open the PDF file and store the QPDF object. Throw a std::shared_ptr to the qpdf into
2467 2467 // a heap so that it survives through copying to the output but gets cleaned up
2468 2468 // automatically at the end. Do not canonicalize the file name. Using two different
... ... @@ -2512,13 +2512,13 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2512 2512 for (auto const& iter: page_spec_qpdfs) {
2513 2513 std::string const& filename = iter.first;
2514 2514 ClosedFileInputSource* cis = nullptr;
2515   - if (page_spec_cfis.count(filename)) {
  2515 + if (page_spec_cfis.contains(filename)) {
2516 2516 cis = page_spec_cfis[filename];
2517 2517 cis->stayOpen(true);
2518 2518 }
2519 2519 QPDF& other(*(iter.second));
2520 2520 auto other_uuid = other.getUniqueId();
2521   - if (remove_unreferenced.count(other_uuid) == 0) {
  2521 + if (!remove_unreferenced.contains(other_uuid)) {
2522 2522 remove_unreferenced[other_uuid] = shouldRemoveUnreferencedResources(other);
2523 2523 }
2524 2524 if (cis) {
... ... @@ -2585,7 +2585,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2585 2585 std::set<QPDFObjGen> referenced_fields;
2586 2586 for (auto& page_data: parsed_specs) {
2587 2587 ClosedFileInputSource* cis = nullptr;
2588   - if (page_spec_cfis.count(page_data.filename)) {
  2588 + if (page_spec_cfis.contains(page_data.filename)) {
2589 2589 cis = page_spec_cfis[page_data.filename];
2590 2590 cis->stayOpen(true);
2591 2591 }
... ... @@ -2604,7 +2604,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2604 2604 QPDFPageObjectHelper to_copy = page_data.orig_pages.at(QIntC::to_size(pageno));
2605 2605 QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen();
2606 2606 unsigned long long from_uuid = page_data.qpdf->getUniqueId();
2607   - if (copied_pages[from_uuid].count(to_copy_og)) {
  2607 + if (copied_pages[from_uuid].contains(to_copy_og)) {
2608 2608 QTC::TC(
2609 2609 "qpdf",
2610 2610 "QPDFJob copy same page more than once",
... ... @@ -2622,7 +2622,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2622 2622 if (this_file) {
2623 2623 // This is a page from the original file. Keep track of the fact that we are using
2624 2624 // it.
2625   - first_copy_from_orig = (selected_from_orig.count(pageno) == 0);
  2625 + first_copy_from_orig = (!selected_from_orig.contains(pageno));
2626 2626 selected_from_orig.insert(pageno);
2627 2627 }
2628 2628 auto new_page = added_page(pdf, to_copy);
... ... @@ -2667,7 +2667,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2667 2667 // sure we keep form fields from pages we preserved.
2668 2668 for (size_t pageno = 0; pageno < orig_pages.size(); ++pageno) {
2669 2669 auto page = orig_pages.at(pageno);
2670   - if (selected_from_orig.count(QIntC::to_int(pageno))) {
  2670 + if (selected_from_orig.contains(QIntC::to_int(pageno))) {
2671 2671 for (auto field: this_afdh->getFormFieldsForPage(page)) {
2672 2672 QTC::TC("qpdf", "QPDFJob pages keeping field from original");
2673 2673 referenced_fields.insert(field.getObjectHandle().getObjGen());
... ... @@ -2686,7 +2686,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2686 2686 new_fields = pdf.makeIndirectObject(new_fields);
2687 2687 }
2688 2688 for (auto const& field: fields.aitems()) {
2689   - if (referenced_fields.count(field.getObjGen())) {
  2689 + if (referenced_fields.contains(field.getObjGen())) {
2690 2690 new_fields.appendItem(field);
2691 2691 }
2692 2692 }
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -1184,7 +1184,7 @@ QPDFObjectHandle::mergeResources(
1184 1184 initialized_maps = true;
1185 1185 }
1186 1186 auto rval_og = rval.getObjGen();
1187   - if (rval.isIndirect() && og_to_name.count(rval_og)) {
  1187 + if (rval.isIndirect() && og_to_name.contains(rval_og)) {
1188 1188 QTC::TC("qpdf", "QPDFObjectHandle merge reuse");
1189 1189 auto new_key = og_to_name[rval_og];
1190 1190 if (new_key != key) {
... ... @@ -1208,7 +1208,7 @@ QPDFObjectHandle::mergeResources(
1208 1208 }
1209 1209 for (auto other_item: other_val.aitems()) {
1210 1210 if (other_item.isScalar()) {
1211   - if (scalars.count(other_item.unparse()) == 0) {
  1211 + if (!scalars.contains(other_item.unparse())) {
1212 1212 QTC::TC("qpdf", "QPDFObjectHandle merge array");
1213 1213 this_val.appendItem(other_item);
1214 1214 } else {
... ... @@ -1247,7 +1247,7 @@ QPDFObjectHandle::getUniqueResourceName(
1247 1247 int max_suffix = min_suffix + QIntC::to_int(names.size());
1248 1248 while (min_suffix <= max_suffix) {
1249 1249 std::string candidate = prefix + std::to_string(min_suffix);
1250   - if (names.count(candidate) == 0) {
  1250 + if (!names.contains(candidate)) {
1251 1251 return candidate;
1252 1252 }
1253 1253 // Increment after return; min_suffix should be the value
... ...
libqpdf/QPDFOutlineDocumentHelper.cc
... ... @@ -56,7 +56,7 @@ QPDFOutlineDocumentHelper::getOutlinesForPage(QPDFObjGen og)
56 56 initializeByPage();
57 57 }
58 58 std::vector<QPDFOutlineObjectHelper> result;
59   - if (m->by_page.count(og)) {
  59 + if (m->by_page.contains(og)) {
60 60 result = m->by_page[og];
61 61 }
62 62 return result;
... ...
libqpdf/QPDFPageObjectHelper.cc
... ... @@ -593,7 +593,7 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
593 593 for (auto const& i1: to_filter) {
594 594 for (auto const& n_iter: names_by_rtype[i1]) {
595 595 std::string const& name = n_iter.first;
596   - if (!known_names.count(name)) {
  596 + if (!known_names.contains(name)) {
597 597 unresolved.insert(name);
598 598 local_unresolved.insert(name);
599 599 }
... ... @@ -624,10 +624,10 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
624 624  
625 625 for (auto& dict: rdicts) {
626 626 for (auto const& key: dict.getKeys()) {
627   - if (is_page && unresolved.count(key)) {
  627 + if (is_page && unresolved.contains(key)) {
628 628 // This name is referenced by some nested form xobject, so don't remove it.
629 629 QTC::TC("qpdf", "QPDFPageObjectHelper resolving unresolved");
630   - } else if (!rf.getNames().count(key)) {
  630 + } else if (!rf.getNames().contains(key)) {
631 631 dict.removeKey(key);
632 632 }
633 633 }
... ...
libqpdf/QPDFParser.cc
... ... @@ -354,9 +354,9 @@ QPDFParser::parseRemainder(bool content_stream)
354 354 fixMissingKeys();
355 355 }
356 356  
357   - if (!frame->contents_string.empty() && dict.count("/Type") &&
358   - dict["/Type"].isNameAndEquals("/Sig") && dict.count("/ByteRange") &&
359   - dict.count("/Contents") && dict["/Contents"].isString()) {
  357 + if (!frame->contents_string.empty() && dict.contains("/Type") &&
  358 + dict["/Type"].isNameAndEquals("/Sig") && dict.contains("/ByteRange") &&
  359 + dict.contains("/Contents") && dict["/Contents"].isString()) {
360 360 dict["/Contents"] = QPDFObjectHandle::newString(frame->contents_string);
361 361 dict["/Contents"].setParsedOffset(frame->contents_offset);
362 362 }
... ... @@ -560,7 +560,7 @@ QPDFParser::fixMissingKeys()
560 560 for (auto const& item: frame->olist) {
561 561 while (true) {
562 562 const std::string key = "/QPDFFake" + std::to_string(next_fake_key++);
563   - const bool found_fake = frame->dict.count(key) == 0 && names.count(key) == 0;
  563 + const bool found_fake = !frame->dict.contains(key) && !names.contains(key);
564 564 QTC::TC("qpdf", "QPDFParser found fake", (found_fake ? 0 : 1));
565 565 if (found_fake) {
566 566 warn(
... ...
libqpdf/QPDFWriter.cc
... ... @@ -1065,7 +1065,7 @@ void
1065 1065 QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen og)
1066 1066 {
1067 1067 int objid = og.getObj();
1068   - if ((og.getGen() != 0) || (m->object_stream_to_objects.count(objid) == 0)) {
  1068 + if ((og.getGen() != 0) || (!m->object_stream_to_objects.contains(objid))) {
1069 1069 // This is not an object stream.
1070 1070 return;
1071 1071 }
... ... @@ -1115,7 +1115,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
1115 1115 m->object_queue.push_back(object);
1116 1116 obj.renumber = m->next_objid++;
1117 1117  
1118   - if ((og.getGen() == 0) && m->object_stream_to_objects.count(og.getObj())) {
  1118 + if ((og.getGen() == 0) && m->object_stream_to_objects.contains(og.getObj())) {
1119 1119 // For linearized files, uncompressed objects go at end, and we take care of
1120 1120 // assigning numbers to them elsewhere.
1121 1121 if (!m->linearized) {
... ... @@ -1285,7 +1285,7 @@ QPDFWriter::willFilterStream(
1285 1285 filter = true;
1286 1286 compress_stream = false;
1287 1287 uncompress = true;
1288   - } else if (filter_on_write && m->normalize_content && m->normalized_streams.count(old_og)) {
  1288 + } else if (filter_on_write && m->normalize_content && m->normalized_streams.contains(old_og)) {
1289 1289 normalize = true;
1290 1290 filter = true;
1291 1291 } else if (filter_on_write && filter && m->compress_streams) {
... ... @@ -1415,7 +1415,7 @@ QPDFWriter::unparseObject(
1415 1415  
1416 1416 if (extensions) {
1417 1417 std::set<std::string> keys = extensions.getKeys();
1418   - if (keys.count("/ADBE") > 0) {
  1418 + if (keys.contains("/ADBE")) {
1419 1419 have_extensions_adbe = true;
1420 1420 keys.erase("/ADBE");
1421 1421 }
... ... @@ -1807,12 +1807,12 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index)
1807 1807 indicateProgress(false, false);
1808 1808 auto new_id = m->obj[old_og].renumber;
1809 1809 if (m->qdf_mode) {
1810   - if (m->page_object_to_seq.count(old_og)) {
  1810 + if (m->page_object_to_seq.contains(old_og)) {
1811 1811 writeString("%% Page ");
1812 1812 writeString(std::to_string(m->page_object_to_seq[old_og]));
1813 1813 writeString("\n");
1814 1814 }
1815   - if (m->contents_to_page_seq.count(old_og)) {
  1815 + if (m->contents_to_page_seq.contains(old_og)) {
1816 1816 writeString("%% Contents for page ");
1817 1817 writeString(std::to_string(m->contents_to_page_seq[old_og]));
1818 1818 writeString("\n");
... ...
libqpdf/QPDF_Dictionary.cc
... ... @@ -20,7 +20,7 @@ bool
20 20 BaseDictionary::hasKey(std::string const& key) const
21 21 {
22 22 auto d = dict();
23   - return d->items.count(key) > 0 && !d->items[key].isNull();
  23 + return d->items.contains(key) && !d->items[key].null();
24 24 }
25 25  
26 26 QPDFObjectHandle
... ...
libqpdf/QPDF_json.cc
... ... @@ -889,7 +889,7 @@ QPDF::writeJSON(
889 889 for (auto& obj: getAllObjects()) {
890 890 auto const og = obj.getObjGen();
891 891 std::string key = "obj:" + og.unparse(' ') + " R";
892   - if (all_objects || wanted_objects.count(key)) {
  892 + if (all_objects || wanted_objects.contains(key)) {
893 893 if (first) {
894 894 jw << "\n \"" << key;
895 895 first = false;
... ... @@ -911,7 +911,7 @@ QPDF::writeJSON(
911 911 }
912 912 }
913 913 }
914   - if (all_objects || wanted_objects.count("trailer")) {
  914 + if (all_objects || wanted_objects.contains("trailer")) {
915 915 if (!first) {
916 916 jw << "\n },";
917 917 }
... ...
libqpdf/QPDF_linearization.cc
... ... @@ -10,7 +10,7 @@
10 10 #include <qpdf/Pl_Flate.hh>
11 11 #include <qpdf/Pl_String.hh>
12 12 #include <qpdf/QPDFExc.hh>
13   -#include <qpdf/QPDFLogger.hh>
  13 +#include <qpdf/QPDFObjectHandle_private.hh>
14 14 #include <qpdf/QPDFWriter_private.hh>
15 15 #include <qpdf/QTC.hh>
16 16 #include <qpdf/QUtil.hh>
... ... @@ -502,7 +502,7 @@ QPDF::checkLinearizationInternal()
502 502 qpdf_offset_t max_E = -1;
503 503 for (auto const& oh: m->part6) {
504 504 QPDFObjGen og(oh.getObjGen());
505   - if (m->obj_cache.count(og) == 0) {
  505 + if (!m->obj_cache.contains(og)) {
506 506 // All objects have to have been dereferenced to be classified.
507 507 throw std::logic_error("linearization part6 object not in cache");
508 508 }
... ... @@ -530,12 +530,12 @@ QPDF::checkLinearizationInternal()
530 530 qpdf_offset_t
531 531 QPDF::maxEnd(ObjUser const& ou)
532 532 {
533   - if (m->obj_user_to_objects.count(ou) == 0) {
  533 + if (!m->obj_user_to_objects.contains(ou)) {
534 534 stopOnError("no entry in object user table for requested object user");
535 535 }
536 536 qpdf_offset_t end = 0;
537 537 for (auto const& og: m->obj_user_to_objects[ou]) {
538   - if (!m->obj_cache.count(og)) {
  538 + if (!m->obj_cache.contains(og)) {
539 539 stopOnError("unknown object referenced in object user table");
540 540 }
541 541 end = std::max(end, m->obj_cache[og].end_after_space);
... ... @@ -568,7 +568,7 @@ QPDF::getLinearizationOffset(QPDFObjGen og)
568 568 QPDFObjectHandle
569 569 QPDF::getUncompressedObject(QPDFObjectHandle& obj, std::map<int, int> const& object_stream_data)
570 570 {
571   - if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) {
  571 + if (obj.null() || (!object_stream_data.contains(obj.getObjectID()))) {
572 572 return obj;
573 573 } else {
574 574 int repl = (*(object_stream_data.find(obj.getObjectID()))).second;
... ... @@ -593,11 +593,11 @@ QPDF::lengthNextN(int first_object, int n)
593 593 int length = 0;
594 594 for (int i = 0; i < n; ++i) {
595 595 QPDFObjGen og(first_object + i, 0);
596   - if (m->xref_table.count(og) == 0) {
  596 + if (!m->xref_table.contains(og)) {
597 597 linearizationWarning(
598 598 "no xref table entry for " + std::to_string(first_object + i) + " 0");
599 599 } else {
600   - if (m->obj_cache.count(og) == 0) {
  600 + if (!m->obj_cache.contains(og)) {
601 601 stopOnError("found unknown object while calculating length for linearization data");
602 602 }
603 603 length += toI(m->obj_cache[og].end_after_space - getLinearizationOffset(og));
... ... @@ -625,7 +625,7 @@ QPDF::checkHPageOffset(
625 625 int npages = toI(pages.size());
626 626 qpdf_offset_t table_offset = adjusted_offset(m->page_offset_hints.first_page_offset);
627 627 QPDFObjGen first_page_og(pages.at(0).getObjGen());
628   - if (m->xref_table.count(first_page_og) == 0) {
  628 + if (!m->xref_table.contains(first_page_og)) {
629 629 stopOnError("supposed first page object is not known");
630 630 }
631 631 qpdf_offset_t offset = getLinearizationOffset(first_page_og);
... ... @@ -636,7 +636,7 @@ QPDF::checkHPageOffset(
636 636 for (int pageno = 0; pageno < npages; ++pageno) {
637 637 QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen());
638 638 int first_object = page_og.getObj();
639   - if (m->xref_table.count(page_og) == 0) {
  639 + if (!m->xref_table.contains(page_og)) {
640 640 stopOnError("unknown object in page offset hint table");
641 641 }
642 642 offset = getLinearizationOffset(page_og);
... ... @@ -677,7 +677,7 @@ QPDF::checkHPageOffset(
677 677  
678 678 for (size_t i = 0; i < toS(he.nshared_objects); ++i) {
679 679 int idx = he.shared_identifiers.at(i);
680   - if (shared_idx_to_obj.count(idx) == 0) {
  680 + if (!shared_idx_to_obj.contains(idx)) {
681 681 stopOnError("unable to get object for item in shared objects hint table");
682 682 }
683 683 hint_shared.insert(shared_idx_to_obj[idx]);
... ... @@ -693,7 +693,7 @@ QPDF::checkHPageOffset(
693 693 }
694 694  
695 695 for (int iter: hint_shared) {
696   - if (!computed_shared.count(iter)) {
  696 + if (!computed_shared.contains(iter)) {
697 697 // pdlin puts thumbnails here even though it shouldn't
698 698 linearizationWarning(
699 699 "page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) +
... ... @@ -702,7 +702,7 @@ QPDF::checkHPageOffset(
702 702 }
703 703  
704 704 for (int iter: computed_shared) {
705   - if (!hint_shared.count(iter)) {
  705 + if (!hint_shared.contains(iter)) {
706 706 // Acrobat does not put some things including at least built-in fonts and procsets
707 707 // here, at least in some cases.
708 708 linearizationWarning(
... ... @@ -755,7 +755,7 @@ QPDF::checkHSharedObject(std::vector&lt;QPDFObjectHandle&gt; const&amp; pages, std::map&lt;in
755 755 cur_object = so.first_shared_obj;
756 756  
757 757 QPDFObjGen og(cur_object, 0);
758   - if (m->xref_table.count(og) == 0) {
  758 + if (!m->xref_table.contains(og)) {
759 759 stopOnError("unknown object in shared object hint table");
760 760 }
761 761 qpdf_offset_t offset = getLinearizationOffset(og);
... ... @@ -806,7 +806,7 @@ QPDF::checkHOutlines()
806 806 return;
807 807 }
808 808 QPDFObjGen og(outlines.getObjGen());
809   - if (m->xref_table.count(og) == 0) {
  809 + if (!m->xref_table.contains(og)) {
810 810 stopOnError("unknown object in outlines hint table");
811 811 }
812 812 qpdf_offset_t offset = getLinearizationOffset(og);
... ... @@ -1086,7 +1086,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1086 1086 break;
1087 1087  
1088 1088 case ObjUser::ou_root_key:
1089   - if (open_document_keys.count(ou.key) > 0) {
  1089 + if (open_document_keys.contains(ou.key)) {
1090 1090 in_open_document = true;
1091 1091 } else if (ou.key == "/Outlines") {
1092 1092 in_outlines = true;
... ... @@ -1187,7 +1187,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1187 1187 stopOnError("no pages found while calculating linearization data");
1188 1188 }
1189 1189 QPDFObjGen first_page_og(pages.at(0).getObjGen());
1190   - if (!lc_first_page_private.count(first_page_og)) {
  1190 + if (!lc_first_page_private.contains(first_page_og)) {
1191 1191 stopOnError(
1192 1192 "INTERNAL ERROR: QPDF::calculateLinearizationData: first page "
1193 1193 "object not in lc_first_page_private");
... ... @@ -1226,7 +1226,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1226 1226 // Place this page's page object
1227 1227  
1228 1228 QPDFObjGen page_og(pages.at(i).getObjGen());
1229   - if (!lc_other_page_private.count(page_og)) {
  1229 + if (!lc_other_page_private.contains(page_og)) {
1230 1230 stopOnError(
1231 1231 "INTERNAL ERROR: QPDF::calculateLinearizationData: page object for page " +
1232 1232 std::to_string(i) + " not in lc_other_page_private");
... ... @@ -1240,11 +1240,11 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1240 1240 m->c_page_offset_data.entries.at(i).nobjects = 1;
1241 1241  
1242 1242 ObjUser ou(ObjUser::ou_page, toI(i));
1243   - if (m->obj_user_to_objects.count(ou) == 0) {
  1243 + if (!m->obj_user_to_objects.contains(ou)) {
1244 1244 stopOnError("found unreferenced page while calculating linearization data");
1245 1245 }
1246 1246 for (auto const& og: m->obj_user_to_objects[ou]) {
1247   - if (lc_other_page_private.count(og)) {
  1247 + if (lc_other_page_private.contains(og)) {
1248 1248 lc_other_page_private.erase(og);
1249 1249 m->part7.push_back(getObject(og));
1250 1250 ++m->c_page_offset_data.entries.at(i).nobjects;
... ... @@ -1279,7 +1279,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1279 1279 stopOnError("found empty pages tree while calculating linearization data");
1280 1280 }
1281 1281 for (auto const& og: pages_ogs) {
1282   - if (lc_other.count(og)) {
  1282 + if (lc_other.contains(og)) {
1283 1283 lc_other.erase(og);
1284 1284 m->part9.push_back(getObject(og));
1285 1285 }
... ... @@ -1293,7 +1293,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1293 1293 if (!thumb.isNull()) {
1294 1294 // Output the thumbnail itself
1295 1295 QPDFObjGen thumb_og(thumb.getObjGen());
1296   - if (lc_thumbnail_private.count(thumb_og)) {
  1296 + if (lc_thumbnail_private.contains(thumb_og)) {
1297 1297 lc_thumbnail_private.erase(thumb_og);
1298 1298 m->part9.push_back(thumb);
1299 1299 } else {
... ... @@ -1304,7 +1304,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1304 1304 }
1305 1305 std::set<QPDFObjGen>& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))];
1306 1306 for (auto const& og: ogs) {
1307   - if (lc_thumbnail_private.count(og)) {
  1307 + if (lc_thumbnail_private.contains(og)) {
1308 1308 lc_thumbnail_private.erase(og);
1309 1309 m->part9.push_back(getObject(og));
1310 1310 }
... ... @@ -1384,11 +1384,11 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1384 1384 for (size_t i = 1; i < toS(npages); ++i) {
1385 1385 CHPageOffsetEntry& pe = m->c_page_offset_data.entries.at(i);
1386 1386 ObjUser ou(ObjUser::ou_page, toI(i));
1387   - if (m->obj_user_to_objects.count(ou) == 0) {
  1387 + if (!m->obj_user_to_objects.contains(ou)) {
1388 1388 stopOnError("found unreferenced page while calculating linearization data");
1389 1389 }
1390 1390 for (auto const& og: m->obj_user_to_objects[ou]) {
1391   - if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.count(og.getObj()) > 0)) {
  1391 + if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.contains(og.getObj()))) {
1392 1392 int idx = obj_to_index[og.getObj()];
1393 1393 ++pe.nshared_objects;
1394 1394 pe.shared_identifiers.push_back(idx);
... ...
libqpdf/QPDF_objects.cc
... ... @@ -442,7 +442,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset, bool in_stream_recovery)
442 442 } else {
443 443 xref_offset = read_xrefStream(xref_offset, in_stream_recovery);
444 444 }
445   - if (visited.count(xref_offset) != 0) {
  445 + if (visited.contains(xref_offset)) {
446 446 QTC::TC("qpdf", "QPDF xref loop");
447 447 throw damagedPDF("", -1, "loop detected following xref tables");
448 448 }
... ... @@ -1020,7 +1020,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2)
1020 1020 return;
1021 1021 }
1022 1022  
1023   - if (m->deleted_objects.count(obj)) {
  1023 + if (m->deleted_objects.contains(obj)) {
1024 1024 QTC::TC("qpdf", "QPDF xref deleted object");
1025 1025 return;
1026 1026 }
... ... @@ -1056,7 +1056,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2)
1056 1056 void
1057 1057 QPDF::insertFreeXrefEntry(QPDFObjGen og)
1058 1058 {
1059   - if (!m->xref_table.count(og)) {
  1059 + if (!m->xref_table.contains(og)) {
1060 1060 m->deleted_objects.insert(og.getObj());
1061 1061 }
1062 1062 }
... ... @@ -1476,7 +1476,7 @@ QPDF::readObjectAtOffset(
1476 1476 if (try_recovery) {
1477 1477 // Try again after reconstructing xref table
1478 1478 reconstruct_xref(e);
1479   - if (m->xref_table.count(exp_og) && (m->xref_table[exp_og].getType() == 1)) {
  1479 + if (m->xref_table.contains(exp_og) && m->xref_table[exp_og].getType() == 1) {
1480 1480 qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset();
1481 1481 QPDFObjectHandle result =
1482 1482 readObjectAtOffset(false, new_offset, description, exp_og, og, false);
... ... @@ -1522,7 +1522,7 @@ QPDF::readObjectAtOffset(
1522 1522 }
1523 1523 }
1524 1524 qpdf_offset_t end_after_space = m->file->tell();
1525   - if (skip_cache_if_in_xref && m->xref_table.count(og)) {
  1525 + if (skip_cache_if_in_xref && m->xref_table.contains(og)) {
1526 1526 // Ordinarily, an object gets read here when resolved through xref table or stream. In
1527 1527 // the special case of the xref stream and linearization hint tables, the offset comes
1528 1528 // from another source. For the specific case of xref streams, the xref stream is read
... ... @@ -1564,7 +1564,7 @@ QPDF::resolve(QPDFObjGen og)
1564 1564 return m->obj_cache[og].object;
1565 1565 }
1566 1566  
1567   - if (m->resolving.count(og)) {
  1567 + if (m->resolving.contains(og)) {
1568 1568 // This can happen if an object references itself directly or indirectly in some key that
1569 1569 // has to be resolved during object parsing, such as stream length.
1570 1570 QTC::TC("qpdf", "QPDF recursion loop in resolve");
... ... @@ -1574,7 +1574,7 @@ QPDF::resolve(QPDFObjGen og)
1574 1574 }
1575 1575 ResolveRecorder rr(this, og);
1576 1576  
1577   - if (m->xref_table.count(og) != 0) {
  1577 + if (m->xref_table.contains(og)) {
1578 1578 QPDFXRefEntry const& entry = m->xref_table[og];
1579 1579 try {
1580 1580 switch (entry.getType()) {
... ... @@ -1628,7 +1628,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1628 1628 true};
1629 1629 };
1630 1630  
1631   - if (m->resolved_object_streams.count(obj_stream_number)) {
  1631 + if (m->resolved_object_streams.contains(obj_stream_number)) {
1632 1632 return;
1633 1633 }
1634 1634 m->resolved_object_streams.insert(obj_stream_number);
... ... @@ -1791,7 +1791,7 @@ QPDF::updateCache(
1791 1791 bool
1792 1792 QPDF::isCached(QPDFObjGen og)
1793 1793 {
1794   - return m->obj_cache.count(og) != 0;
  1794 + return m->obj_cache.contains(og);
1795 1795 }
1796 1796  
1797 1797 bool
... ... @@ -1835,7 +1835,7 @@ QPDF::getObjectForParser(int id, int gen, bool parse_pdf)
1835 1835 if (auto iter = m->obj_cache.find(og); iter != m->obj_cache.end()) {
1836 1836 return iter->second.object;
1837 1837 }
1838   - if (m->xref_table.count(og) || !m->parsed) {
  1838 + if (m->xref_table.contains(og) || !m->parsed) {
1839 1839 return m->obj_cache.insert({og, QPDFObject::create<QPDF_Unresolved>(this, og)})
1840 1840 .first->second.object;
1841 1841 }
... ... @@ -1852,7 +1852,7 @@ QPDF::getObjectForJSON(int id, int gen)
1852 1852 auto [it, inserted] = m->obj_cache.try_emplace(og);
1853 1853 auto& obj = it->second.object;
1854 1854 if (inserted) {
1855   - obj = (m->parsed && !m->xref_table.count(og))
  1855 + obj = (m->parsed && !m->xref_table.contains(og))
1856 1856 ? QPDFObject::create<QPDF_Null>(this, og)
1857 1857 : QPDFObject::create<QPDF_Unresolved>(this, og);
1858 1858 }
... ... @@ -1864,7 +1864,7 @@ QPDF::getObject(QPDFObjGen og)
1864 1864 {
1865 1865 if (auto it = m->obj_cache.find(og); it != m->obj_cache.end()) {
1866 1866 return {it->second.object};
1867   - } else if (m->parsed && !m->xref_table.count(og)) {
  1867 + } else if (m->parsed && !m->xref_table.contains(og)) {
1868 1868 return QPDFObject::create<QPDF_Null>();
1869 1869 } else {
1870 1870 auto result =
... ...
libqpdf/QPDF_pages.cc
... ... @@ -303,7 +303,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
303 303 : 2); // insert in middle
304 304  
305 305 auto og = newpage.getObjGen();
306   - if (m->pageobj_to_pages_pos.count(og)) {
  306 + if (m->pageobj_to_pages_pos.contains(og)) {
307 307 QTC::TC("qpdf", "QPDF resolve duplicated page in insert");
308 308 newpage = makeIndirectObject(QPDFObjectHandle(newpage).shallowCopy());
309 309 }
... ...
libqpdf/QTC.cc
... ... @@ -39,7 +39,7 @@ QTC::TC_real(char const* const scope, char const* const ccase, int n)
39 39 }
40 40 #undef TC_ENV
41 41  
42   - if (cache.count(std::make_pair(ccase, n))) {
  42 + if (cache.contains(std::make_pair(ccase, n))) {
43 43 return;
44 44 }
45 45 cache.insert(std::make_pair(ccase, n));
... ...
libqpdf/QUtil.cc
... ... @@ -1395,7 +1395,7 @@ QUtil::parse_numrange(char const* range, int max)
1395 1395 work = last_group;
1396 1396 last_group.clear();
1397 1397 for (auto n: work) {
1398   - if (exclusions.count(n) == 0) {
  1398 + if (!exclusions.contains(n)) {
1399 1399 last_group.emplace_back(n);
1400 1400 }
1401 1401 }
... ... @@ -1886,7 +1886,7 @@ QUtil::possible_repaired_encodings(std::string supplied)
1886 1886 std::vector<std::string> t;
1887 1887 std::set<std::string> seen;
1888 1888 for (auto const& iter: result) {
1889   - if (!seen.count(iter)) {
  1889 + if (!seen.contains(iter)) {
1890 1890 seen.insert(iter);
1891 1891 t.push_back(iter);
1892 1892 }
... ... @@ -1988,7 +1988,7 @@ QUtil::get_max_memory_usage()
1988 1988 attrs[m2->str(1)] = m2->str(2);
1989 1989 }
1990 1990 if (tag == "total") {
1991   - if (attrs.count("size") > 0) {
  1991 + if (attrs.contains("size")) {
1992 1992 result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str()));
1993 1993 }
1994 1994 } else if (tag == "system" && attrs["type"] == "max") {
... ...
qpdf/test_driver.cc
... ... @@ -3621,7 +3621,7 @@ runtest(int n, char const* filename1, char const* arg2)
3621 3621 p[i] = static_cast<char>(p[i] ^ 0xcc);
3622 3622 }
3623 3623 pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), p, size);
3624   - } else if (ignore_filename.count(n)) {
  3624 + } else if (ignore_filename.contains(n)) {
3625 3625 // Ignore filename argument entirely
3626 3626 } else if (n == 89) {
3627 3627 pdf.createFromJSON(filename1);
... ...
qpdf/test_parsedoffset.cc
... ... @@ -77,7 +77,7 @@ process(std::string fn, std::vector&lt;std::vector&lt;std::pair&lt;qpdf_offset_t, std::st
77 77 std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
78 78  
79 79 for (auto const& oh: qpdf.getAllObjects()) {
80   - if (xrefs.count(oh.getObjGen()) == 0) {
  80 + if (!xrefs.contains(oh.getObjGen())) {
81 81 std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
82 82 << " is not found in xref table" << std::endl;
83 83 std::exit(2);
... ...
qpdf/test_renumber.cc
... ... @@ -26,7 +26,7 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
26 26 {
27 27 static std::set<QPDFObjGen> visited;
28 28 if (a.isIndirect()) {
29   - if (visited.count(a.getObjGen())) {
  29 + if (visited.contains(a.getObjGen())) {
30 30 return true;
31 31 }
32 32 visited.insert(a.getObjGen());
... ... @@ -128,7 +128,7 @@ compare_xref_table(std::map&lt;QPDFObjGen, QPDFXRefEntry&gt; a, std::map&lt;QPDFObjGen, Q
128 128 std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen()
129 129 << std::endl;
130 130  
131   - if (b.count(iter.first) == 0) {
  131 + if (!b.contains(iter.first)) {
132 132 std::cerr << "not found" << std::endl;
133 133 return false;
134 134 }
... ...