diff --git a/examples/pdf-bookmarks.cc b/examples/pdf-bookmarks.cc index 87a3b9d..00558a3 100644 --- a/examples/pdf-bookmarks.cc +++ b/examples/pdf-bookmarks.cc @@ -104,7 +104,7 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector numbers) QPDFObjectHandle dest_page = outline.getDestPage(); if (!dest_page.isNull()) { QTC::TC("examples", "pdf-bookmarks dest"); - if (page_map.count(dest_page)) { + if (page_map.contains(dest_page)) { target = std::to_string(page_map[dest_page]); } } diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc index 1a8f14e..ac949a1 100644 --- a/examples/pdf-custom-filter.cc +++ b/examples/pdf-custom-filter.cc @@ -276,7 +276,7 @@ StreamReplacer::registerStream( // We don't need to process a stream more than once. In this example, we are just iterating // through objects, but if we were doing something like iterating through images on pages, we // might realistically encounter the same stream more than once. - if (this->copied_streams.count(og) > 0) { + if (this->copied_streams.contains(og)) { return; } // Store something in copied_streams so that we don't double-process even in the negative case. diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc index 09e115d..de2da9b 100644 --- a/examples/pdf-invert-images.cc +++ b/examples/pdf-invert-images.cc @@ -52,7 +52,7 @@ ImageInverter::registerImage( // Store information about the images based on the object and generation number. Recall that a // single image object may be used more than once, so no need to update the same stream multiple // times. - if (this->copied_images.count(og) > 0) { + if (copied_images.contains(og)) { return; } this->copied_images[og] = image.copyStream(); diff --git a/include/qpdf/QPDFObjGen.hh b/include/qpdf/QPDFObjGen.hh index 8bdeea7..f984668 100644 --- a/include/qpdf/QPDFObjGen.hh +++ b/include/qpdf/QPDFObjGen.hh @@ -110,7 +110,7 @@ class QPDFObjGen add(QPDFObjGen og) { if (og.isIndirect()) { - if (count(og) > 0) { + if (count(og)) { return false; } emplace(og); diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index aef1bb4..852e53c 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -516,11 +516,11 @@ JSON::checkSchemaInternal( } } } - for (auto const& [key, val]: this_dict->members) { - if (!sch_dict->members.contains(key)) { + for (auto const& item: this_dict->members) { + if (!sch_dict->members.contains(item.first)) { QTC::TC("libtests", "JSON key extra in object"); errors.emplace_back( - err_prefix + ": key \"" + key + + err_prefix + ": key \"" + item.first + "\" is not present in schema but appears in object"); } } diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index c048f75..a0c2054 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -564,7 +564,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) obj_copier.to_copy.clear(); auto og = foreign.getObjGen(); - if (!obj_copier.object_map.count(og)) { + if (!obj_copier.object_map.contains(og)) { warn(damagedPDF( other.getFilename() + " object " + og.unparse(' '), foreign.getParsedOffset(), @@ -594,7 +594,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) QTC::TC("qpdf", "QPDF loop reserving objects"); return; } - if (obj_copier.object_map.count(foreign_og) > 0) { + if (obj_copier.object_map.contains(foreign_og)) { QTC::TC("qpdf", "QPDF already reserved object"); if (!(top && foreign.isPageObject() && obj_copier.object_map[foreign_og].isNull())) { obj_copier.visiting.erase(foreign); diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 8f47616..46e87c9 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -85,7 +85,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(std::vector // this field's /T is always at the end of the fully qualified name, appending to /T // has the effect of appending the same thing to the fully qualified name. std::string old_name = QPDFFormFieldObjectHelper(obj).getFullyQualifiedName(); - if (renames.count(old_name) == 0) { + if (!renames.contains(old_name)) { std::string new_name = old_name; int suffix = 0; std::string append; @@ -145,7 +145,7 @@ QPDFAcroFormDocumentHelper::removeFormFields(std::set const& to_remo int i = 0; while (i < fields.getArrayNItems()) { auto field = fields.getArrayItem(i); - if (to_remove.count(field.getObjGen())) { + if (to_remove.contains(field.getObjGen())) { fields.eraseItem(i); } else { ++i; @@ -191,7 +191,7 @@ QPDFAcroFormDocumentHelper::getAnnotationsForField(QPDFFormFieldObjectHelper h) analyze(); std::vector result; QPDFObjGen og(h.getObjectHandle().getObjGen()); - if (m->field_to_annotations.count(og)) { + if (m->field_to_annotations.contains(og)) { result = m->field_to_annotations[og]; } return result; @@ -228,7 +228,7 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) } analyze(); QPDFObjGen og(oh.getObjGen()); - if (m->annotation_to_field.count(og)) { + if (m->annotation_to_field.contains(og)) { result = m->annotation_to_field[og]; } return result; @@ -271,7 +271,7 @@ QPDFAcroFormDocumentHelper::analyze() for (auto const& iter: getWidgetAnnotationsForPage(ph)) { QPDFObjectHandle annot(iter.getObjectHandle()); QPDFObjGen og(annot.getObjGen()); - if (m->annotation_to_field.count(og) == 0) { + if (!m->annotation_to_field.contains(og)) { QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget"); // This is not supposed to happen, but it's easy enough for us to handle this case. // Treat the annotation as its own field. This could allow qpdf to sensibly handle a @@ -542,7 +542,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token) bool wrote = false; if (token.getType() == QPDFTokenizer::tt_name) { std::string name = QPDFObjectHandle::newName(token.getValue()).getName(); - if (to_replace.count(name) && to_replace[name].count(offset)) { + if (to_replace.contains(name) && to_replace[name].contains(offset)) { QTC::TC("qpdf", "QPDFAcroFormDocumentHelper replaced DA token"); write(to_replace[name][offset]); wrote = true; @@ -807,7 +807,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( std::map orig_to_copy; auto maybe_copy_object = [&](QPDFObjectHandle& to_copy) { auto og = to_copy.getObjGen(); - if (orig_to_copy.count(og)) { + if (orig_to_copy.contains(og)) { to_copy = orig_to_copy[og]; return false; } else { @@ -893,7 +893,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( auto parent = obj.getKey("/Parent"); if (parent.isIndirect()) { auto parent_og = parent.getObjGen(); - if (orig_to_copy.count(parent_og)) { + if (orig_to_copy.contains(parent_og)) { obj.replaceKey("/Parent", orig_to_copy[parent_og]); } else { parent.warnIfPossible( diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc index c16c18b..08e727c 100644 --- a/libqpdf/QPDFArgParser.cc +++ b/libqpdf/QPDFArgParser.cc @@ -71,7 +71,7 @@ QPDFArgParser::selectOptionTable(std::string const& name) void QPDFArgParser::registerOptionTable(std::string const& name, bare_arg_handler_t end_handler) { - if (0 != m->option_tables.count(name)) { + if (m->option_tables.contains(name)) { QTC::TC("libtests", "QPDFArgParser register registered table"); throw std::logic_error( "QPDFArgParser: registering already registered option table " + name); @@ -84,7 +84,7 @@ QPDFArgParser::registerOptionTable(std::string const& name, bare_arg_handler_t e QPDFArgParser::OptionEntry& QPDFArgParser::registerArg(std::string const& arg) { - if (0 != m->option_table->count(arg)) { + if (m->option_table->contains(arg)) { QTC::TC("libtests", "QPDFArgParser duplicate handler"); throw std::logic_error( "QPDFArgParser: adding a duplicate handler for option " + arg + " in " + @@ -481,7 +481,7 @@ QPDFArgParser::parseArgs() } if ((!m->bash_completion) && (m->argc == 2) && (m->cur_arg == 1) && - m->help_option_table.count(arg_s)) { + m->help_option_table.contains(arg_s)) { // Handle help option, which is only valid as the sole option. QTC::TC("libtests", "QPDFArgParser help option"); oep = m->help_option_table.find(arg_s); @@ -508,8 +508,8 @@ QPDFArgParser::parseArgs() } OptionEntry& oe = oep->second; - if ((oe.parameter_needed && (!have_parameter)) || - ((!oe.choices.empty() && have_parameter && (0 == oe.choices.count(parameter))))) { + if ((oe.parameter_needed && !have_parameter) || + (!oe.choices.empty() && have_parameter && !oe.choices.contains(parameter))) { std::string message = "--" + arg_s + " must be given as --" + arg_s + "="; if (oe.invalid_choice_handler) { oe.invalid_choice_handler(parameter); @@ -584,7 +584,7 @@ void QPDFArgParser::addChoicesToCompletions( option_table_t& option_table, std::string const& option, std::string const& extra_prefix) { - if (option_table.count(option) != 0) { + if (option_table.contains(option)) { OptionEntry& oe = option_table[option]; for (auto const& choice: oe.choices) { QTC::TC("libtests", "QPDFArgParser complete choices"); @@ -690,7 +690,7 @@ QPDFArgParser::addHelpTopic( QTC::TC("libtests", "QPDFArgParser bad topic for help"); throw std::logic_error("QPDFArgParser: help topics must not start with -"); } - if (m->help_topics.count(topic)) { + if (m->help_topics.contains(topic)) { QTC::TC("libtests", "QPDFArgParser add existing topic"); throw std::logic_error("QPDFArgParser: topic " + topic + " has already been added"); } @@ -710,7 +710,7 @@ QPDFArgParser::addOptionHelp( QTC::TC("libtests", "QPDFArgParser bad option for help"); throw std::logic_error("QPDFArgParser: options for help must start with --"); } - if (m->option_help.count(option_name)) { + if (m->option_help.contains(option_name)) { QTC::TC("libtests", "QPDFArgParser duplicate option help"); throw std::logic_error("QPDFArgParser: option " + option_name + " already has help"); } @@ -782,9 +782,9 @@ QPDFArgParser::getHelp(std::string const& arg) } else { if (arg == "all") { getAllHelp(msg); - } else if (m->option_help.count(arg)) { + } else if (m->option_help.contains(arg)) { getTopicHelp(arg, m->option_help[arg], msg); - } else if (m->help_topics.count(arg)) { + } else if (m->help_topics.contains(arg)) { getTopicHelp(arg, m->help_topics[arg], msg); } else { // should not be possible diff --git a/libqpdf/QPDFCryptoProvider.cc b/libqpdf/QPDFCryptoProvider.cc index 89b5284..df5eff0 100644 --- a/libqpdf/QPDFCryptoProvider.cc +++ b/libqpdf/QPDFCryptoProvider.cc @@ -88,7 +88,7 @@ QPDFCryptoProvider::registerImpl_internal(std::string const& name, provider_fn f void QPDFCryptoProvider::setDefaultProvider_internal(std::string const& name) { - if (!m->providers.count(name)) { + if (!m->providers.contains(name)) { throw std::logic_error( "QPDFCryptoProvider: request to set default provider to unknown implementation \"" + name + "\""); diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 99ccd15..1a74ea4 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -673,7 +673,7 @@ QPDFJob::checkConfiguration() usage("json key \"qpdf\" is only valid for json version > 1"); } } else { - if (m->json_keys.contains("objectinfo") || m->json_keys.count("objects")) { + if (m->json_keys.contains("objectinfo") || m->json_keys.contains("objects")) { usage("json keys \"objects\" and \"objectinfo\" are only valid for json version 1"); } } @@ -1007,13 +1007,13 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) for (auto& obj: pdf.getAllObjects()) { std::string key = obj.unparse(); - if (all_objects || wanted_og.count(obj.getObjGen())) { + if (all_objects || wanted_og.contains(obj.getObjGen())) { JSON::writeDictionaryKey(p, first_object, obj.unparse(), 2); obj.writeJSON(1, p, true, 2); first_object = false; } } - if (all_objects || m->json_objects.count("trailer")) { + if (all_objects || m->json_objects.contains("trailer")) { JSON::writeDictionaryKey(p, first_object, "trailer", 2); pdf.getTrailer().writeJSON(1, p, true, 2); first_object = false; @@ -1021,7 +1021,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) JSON::writeDictionaryClose(p, first_object, 1); } else { std::set json_objects; - if (m->json_objects.count("trailer")) { + if (m->json_objects.contains("trailer")) { json_objects.insert("trailer"); } for (auto og: getWantedJSONObjects()) { @@ -1048,7 +1048,7 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) bool all_objects = m->json_objects.empty(); auto wanted_og = getWantedJSONObjects(); for (auto& obj: pdf.getAllObjects()) { - if (all_objects || wanted_og.count(obj.getObjGen())) { + if (all_objects || wanted_og.contains(obj.getObjGen())) { auto j_details = JSON::makeDictionary(); auto j_stream = j_details.addDictionaryMember("stream", JSON::makeDictionary()); bool is_stream = obj.isStream(); @@ -1170,7 +1170,7 @@ QPDFJob::addOutlinesToJson( JSON j_destpage = JSON::makeNull(); if (page.isIndirect()) { QPDFObjGen og = page.getObjGen(); - if (page_numbers.count(og)) { + if (page_numbers.contains(og)) { j_destpage = JSON::makeInt(page_numbers[og]); } } @@ -1913,7 +1913,7 @@ get_afdh_for_qpdf( std::map>& afdh_map, QPDF* q) { auto uid = q->getUniqueId(); - if (!afdh_map.count(uid)) { + if (!afdh_map.contains(uid)) { afdh_map[uid] = std::make_shared(*q); } return afdh_map[uid].get(); @@ -1931,7 +1931,7 @@ QPDFJob::doUnderOverlayForPage( QPDFPageObjectHelper& dest_page) { int pageno = 1 + QIntC::to_int(page_idx); - if (!(pagenos.count(pageno) && pagenos[pageno].count(uo_idx))) { + if (!(pagenos.contains(pageno) && pagenos[pageno].contains(uo_idx))) { return ""; } @@ -1950,7 +1950,7 @@ QPDFJob::doUnderOverlayForPage( v << " " << uo.filename << " " << uo.which << " " << from_pageno << "\n"; }); auto from_page = pages.at(QIntC::to_size(from_pageno - 1)); - if (fo[from_pageno].count(uo_idx) == 0) { + if (!fo[from_pageno].contains(uo_idx)) { fo[from_pageno][uo_idx] = pdf.copyForeignObject(from_page.getFormXObjectForPage()); } @@ -2462,7 +2462,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea std::vector parsed_specs; std::map> copied_pages; for (auto& page_spec: m->page_specs) { - if (page_spec_qpdfs.count(page_spec.filename) == 0) { + if (!page_spec_qpdfs.contains(page_spec.filename)) { // Open the PDF file and store the QPDF object. Throw a std::shared_ptr to the qpdf into // a heap so that it survives through copying to the output but gets cleaned up // automatically at the end. Do not canonicalize the file name. Using two different @@ -2512,13 +2512,13 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea for (auto const& iter: page_spec_qpdfs) { std::string const& filename = iter.first; ClosedFileInputSource* cis = nullptr; - if (page_spec_cfis.count(filename)) { + if (page_spec_cfis.contains(filename)) { cis = page_spec_cfis[filename]; cis->stayOpen(true); } QPDF& other(*(iter.second)); auto other_uuid = other.getUniqueId(); - if (remove_unreferenced.count(other_uuid) == 0) { + if (!remove_unreferenced.contains(other_uuid)) { remove_unreferenced[other_uuid] = shouldRemoveUnreferencedResources(other); } if (cis) { @@ -2585,7 +2585,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea std::set referenced_fields; for (auto& page_data: parsed_specs) { ClosedFileInputSource* cis = nullptr; - if (page_spec_cfis.count(page_data.filename)) { + if (page_spec_cfis.contains(page_data.filename)) { cis = page_spec_cfis[page_data.filename]; cis->stayOpen(true); } @@ -2604,7 +2604,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea QPDFPageObjectHelper to_copy = page_data.orig_pages.at(QIntC::to_size(pageno)); QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen(); unsigned long long from_uuid = page_data.qpdf->getUniqueId(); - if (copied_pages[from_uuid].count(to_copy_og)) { + if (copied_pages[from_uuid].contains(to_copy_og)) { QTC::TC( "qpdf", "QPDFJob copy same page more than once", @@ -2622,7 +2622,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea if (this_file) { // This is a page from the original file. Keep track of the fact that we are using // it. - first_copy_from_orig = (selected_from_orig.count(pageno) == 0); + first_copy_from_orig = (!selected_from_orig.contains(pageno)); selected_from_orig.insert(pageno); } auto new_page = added_page(pdf, to_copy); @@ -2667,7 +2667,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea // sure we keep form fields from pages we preserved. for (size_t pageno = 0; pageno < orig_pages.size(); ++pageno) { auto page = orig_pages.at(pageno); - if (selected_from_orig.count(QIntC::to_int(pageno))) { + if (selected_from_orig.contains(QIntC::to_int(pageno))) { for (auto field: this_afdh->getFormFieldsForPage(page)) { QTC::TC("qpdf", "QPDFJob pages keeping field from original"); referenced_fields.insert(field.getObjectHandle().getObjGen()); @@ -2686,7 +2686,7 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector>& page_hea new_fields = pdf.makeIndirectObject(new_fields); } for (auto const& field: fields.aitems()) { - if (referenced_fields.count(field.getObjGen())) { + if (referenced_fields.contains(field.getObjGen())) { new_fields.appendItem(field); } } diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 9ce200e..fba9cbc 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1184,7 +1184,7 @@ QPDFObjectHandle::mergeResources( initialized_maps = true; } auto rval_og = rval.getObjGen(); - if (rval.isIndirect() && og_to_name.count(rval_og)) { + if (rval.isIndirect() && og_to_name.contains(rval_og)) { QTC::TC("qpdf", "QPDFObjectHandle merge reuse"); auto new_key = og_to_name[rval_og]; if (new_key != key) { @@ -1208,7 +1208,7 @@ QPDFObjectHandle::mergeResources( } for (auto other_item: other_val.aitems()) { if (other_item.isScalar()) { - if (scalars.count(other_item.unparse()) == 0) { + if (!scalars.contains(other_item.unparse())) { QTC::TC("qpdf", "QPDFObjectHandle merge array"); this_val.appendItem(other_item); } else { @@ -1247,7 +1247,7 @@ QPDFObjectHandle::getUniqueResourceName( int max_suffix = min_suffix + QIntC::to_int(names.size()); while (min_suffix <= max_suffix) { std::string candidate = prefix + std::to_string(min_suffix); - if (names.count(candidate) == 0) { + if (!names.contains(candidate)) { return candidate; } // Increment after return; min_suffix should be the value diff --git a/libqpdf/QPDFOutlineDocumentHelper.cc b/libqpdf/QPDFOutlineDocumentHelper.cc index 9028cd3..13107c3 100644 --- a/libqpdf/QPDFOutlineDocumentHelper.cc +++ b/libqpdf/QPDFOutlineDocumentHelper.cc @@ -56,7 +56,7 @@ QPDFOutlineDocumentHelper::getOutlinesForPage(QPDFObjGen og) initializeByPage(); } std::vector result; - if (m->by_page.count(og)) { + if (m->by_page.contains(og)) { result = m->by_page[og]; } return result; diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index ea866f1..67badaa 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -593,7 +593,7 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( for (auto const& i1: to_filter) { for (auto const& n_iter: names_by_rtype[i1]) { std::string const& name = n_iter.first; - if (!known_names.count(name)) { + if (!known_names.contains(name)) { unresolved.insert(name); local_unresolved.insert(name); } @@ -624,10 +624,10 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( for (auto& dict: rdicts) { for (auto const& key: dict.getKeys()) { - if (is_page && unresolved.count(key)) { + if (is_page && unresolved.contains(key)) { // This name is referenced by some nested form xobject, so don't remove it. QTC::TC("qpdf", "QPDFPageObjectHelper resolving unresolved"); - } else if (!rf.getNames().count(key)) { + } else if (!rf.getNames().contains(key)) { dict.removeKey(key); } } diff --git a/libqpdf/QPDFParser.cc b/libqpdf/QPDFParser.cc index 1690f39..faeba7e 100644 --- a/libqpdf/QPDFParser.cc +++ b/libqpdf/QPDFParser.cc @@ -354,9 +354,9 @@ QPDFParser::parseRemainder(bool content_stream) fixMissingKeys(); } - if (!frame->contents_string.empty() && dict.count("/Type") && - dict["/Type"].isNameAndEquals("/Sig") && dict.count("/ByteRange") && - dict.count("/Contents") && dict["/Contents"].isString()) { + if (!frame->contents_string.empty() && dict.contains("/Type") && + dict["/Type"].isNameAndEquals("/Sig") && dict.contains("/ByteRange") && + dict.contains("/Contents") && dict["/Contents"].isString()) { dict["/Contents"] = QPDFObjectHandle::newString(frame->contents_string); dict["/Contents"].setParsedOffset(frame->contents_offset); } @@ -560,7 +560,7 @@ QPDFParser::fixMissingKeys() for (auto const& item: frame->olist) { while (true) { const std::string key = "/QPDFFake" + std::to_string(next_fake_key++); - const bool found_fake = frame->dict.count(key) == 0 && names.count(key) == 0; + const bool found_fake = !frame->dict.contains(key) && !names.contains(key); QTC::TC("qpdf", "QPDFParser found fake", (found_fake ? 0 : 1)); if (found_fake) { warn( diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index d18bb32..de7227d 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1065,7 +1065,7 @@ void QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen og) { int objid = og.getObj(); - if ((og.getGen() != 0) || (m->object_stream_to_objects.count(objid) == 0)) { + if ((og.getGen() != 0) || (!m->object_stream_to_objects.contains(objid))) { // This is not an object stream. return; } @@ -1115,7 +1115,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) m->object_queue.push_back(object); obj.renumber = m->next_objid++; - if ((og.getGen() == 0) && m->object_stream_to_objects.count(og.getObj())) { + if ((og.getGen() == 0) && m->object_stream_to_objects.contains(og.getObj())) { // For linearized files, uncompressed objects go at end, and we take care of // assigning numbers to them elsewhere. if (!m->linearized) { @@ -1285,7 +1285,7 @@ QPDFWriter::willFilterStream( filter = true; compress_stream = false; uncompress = true; - } else if (filter_on_write && m->normalize_content && m->normalized_streams.count(old_og)) { + } else if (filter_on_write && m->normalize_content && m->normalized_streams.contains(old_og)) { normalize = true; filter = true; } else if (filter_on_write && filter && m->compress_streams) { @@ -1415,7 +1415,7 @@ QPDFWriter::unparseObject( if (extensions) { std::set keys = extensions.getKeys(); - if (keys.count("/ADBE") > 0) { + if (keys.contains("/ADBE")) { have_extensions_adbe = true; keys.erase("/ADBE"); } @@ -1807,12 +1807,12 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) indicateProgress(false, false); auto new_id = m->obj[old_og].renumber; if (m->qdf_mode) { - if (m->page_object_to_seq.count(old_og)) { + if (m->page_object_to_seq.contains(old_og)) { writeString("%% Page "); writeString(std::to_string(m->page_object_to_seq[old_og])); writeString("\n"); } - if (m->contents_to_page_seq.count(old_og)) { + if (m->contents_to_page_seq.contains(old_og)) { writeString("%% Contents for page "); writeString(std::to_string(m->contents_to_page_seq[old_og])); writeString("\n"); diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index e28d30a..d34d309 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -20,7 +20,7 @@ bool BaseDictionary::hasKey(std::string const& key) const { auto d = dict(); - return d->items.count(key) > 0 && !d->items[key].isNull(); + return d->items.contains(key) && !d->items[key].null(); } QPDFObjectHandle diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 81c5506..14f6693 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -889,7 +889,7 @@ QPDF::writeJSON( for (auto& obj: getAllObjects()) { auto const og = obj.getObjGen(); std::string key = "obj:" + og.unparse(' ') + " R"; - if (all_objects || wanted_objects.count(key)) { + if (all_objects || wanted_objects.contains(key)) { if (first) { jw << "\n \"" << key; first = false; @@ -911,7 +911,7 @@ QPDF::writeJSON( } } } - if (all_objects || wanted_objects.count("trailer")) { + if (all_objects || wanted_objects.contains("trailer")) { if (!first) { jw << "\n },"; } diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 6519f6d..c9f0233 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -502,7 +502,7 @@ QPDF::checkLinearizationInternal() qpdf_offset_t max_E = -1; for (auto const& oh: m->part6) { QPDFObjGen og(oh.getObjGen()); - if (m->obj_cache.count(og) == 0) { + if (!m->obj_cache.contains(og)) { // All objects have to have been dereferenced to be classified. throw std::logic_error("linearization part6 object not in cache"); } @@ -530,12 +530,12 @@ QPDF::checkLinearizationInternal() qpdf_offset_t QPDF::maxEnd(ObjUser const& ou) { - if (m->obj_user_to_objects.count(ou) == 0) { + if (!m->obj_user_to_objects.contains(ou)) { stopOnError("no entry in object user table for requested object user"); } qpdf_offset_t end = 0; for (auto const& og: m->obj_user_to_objects[ou]) { - if (!m->obj_cache.count(og)) { + if (!m->obj_cache.contains(og)) { stopOnError("unknown object referenced in object user table"); } end = std::max(end, m->obj_cache[og].end_after_space); @@ -568,7 +568,7 @@ QPDF::getLinearizationOffset(QPDFObjGen og) QPDFObjectHandle QPDF::getUncompressedObject(QPDFObjectHandle& obj, std::map const& object_stream_data) { - if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) { + if (obj.null() || (!object_stream_data.contains(obj.getObjectID()))) { return obj; } else { int repl = (*(object_stream_data.find(obj.getObjectID()))).second; @@ -593,11 +593,11 @@ QPDF::lengthNextN(int first_object, int n) int length = 0; for (int i = 0; i < n; ++i) { QPDFObjGen og(first_object + i, 0); - if (m->xref_table.count(og) == 0) { + if (!m->xref_table.contains(og)) { linearizationWarning( "no xref table entry for " + std::to_string(first_object + i) + " 0"); } else { - if (m->obj_cache.count(og) == 0) { + if (!m->obj_cache.contains(og)) { stopOnError("found unknown object while calculating length for linearization data"); } length += toI(m->obj_cache[og].end_after_space - getLinearizationOffset(og)); @@ -625,7 +625,7 @@ QPDF::checkHPageOffset( int npages = toI(pages.size()); qpdf_offset_t table_offset = adjusted_offset(m->page_offset_hints.first_page_offset); QPDFObjGen first_page_og(pages.at(0).getObjGen()); - if (m->xref_table.count(first_page_og) == 0) { + if (!m->xref_table.contains(first_page_og)) { stopOnError("supposed first page object is not known"); } qpdf_offset_t offset = getLinearizationOffset(first_page_og); @@ -636,7 +636,7 @@ QPDF::checkHPageOffset( for (int pageno = 0; pageno < npages; ++pageno) { QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen()); int first_object = page_og.getObj(); - if (m->xref_table.count(page_og) == 0) { + if (!m->xref_table.contains(page_og)) { stopOnError("unknown object in page offset hint table"); } offset = getLinearizationOffset(page_og); @@ -677,7 +677,7 @@ QPDF::checkHPageOffset( for (size_t i = 0; i < toS(he.nshared_objects); ++i) { int idx = he.shared_identifiers.at(i); - if (shared_idx_to_obj.count(idx) == 0) { + if (!shared_idx_to_obj.contains(idx)) { stopOnError("unable to get object for item in shared objects hint table"); } hint_shared.insert(shared_idx_to_obj[idx]); @@ -693,7 +693,7 @@ QPDF::checkHPageOffset( } for (int iter: hint_shared) { - if (!computed_shared.count(iter)) { + if (!computed_shared.contains(iter)) { // pdlin puts thumbnails here even though it shouldn't linearizationWarning( "page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) + @@ -702,7 +702,7 @@ QPDF::checkHPageOffset( } for (int iter: computed_shared) { - if (!hint_shared.count(iter)) { + if (!hint_shared.contains(iter)) { // Acrobat does not put some things including at least built-in fonts and procsets // here, at least in some cases. linearizationWarning( @@ -755,7 +755,7 @@ QPDF::checkHSharedObject(std::vector const& pages, std::mapxref_table.count(og) == 0) { + if (!m->xref_table.contains(og)) { stopOnError("unknown object in shared object hint table"); } qpdf_offset_t offset = getLinearizationOffset(og); @@ -806,7 +806,7 @@ QPDF::checkHOutlines() return; } QPDFObjGen og(outlines.getObjGen()); - if (m->xref_table.count(og) == 0) { + if (!m->xref_table.contains(og)) { stopOnError("unknown object in outlines hint table"); } qpdf_offset_t offset = getLinearizationOffset(og); @@ -1086,7 +1086,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) break; case ObjUser::ou_root_key: - if (open_document_keys.count(ou.key) > 0) { + if (open_document_keys.contains(ou.key)) { in_open_document = true; } else if (ou.key == "/Outlines") { in_outlines = true; @@ -1187,7 +1187,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) stopOnError("no pages found while calculating linearization data"); } QPDFObjGen first_page_og(pages.at(0).getObjGen()); - if (!lc_first_page_private.count(first_page_og)) { + if (!lc_first_page_private.contains(first_page_og)) { stopOnError( "INTERNAL ERROR: QPDF::calculateLinearizationData: first page " "object not in lc_first_page_private"); @@ -1226,7 +1226,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) // Place this page's page object QPDFObjGen page_og(pages.at(i).getObjGen()); - if (!lc_other_page_private.count(page_og)) { + if (!lc_other_page_private.contains(page_og)) { stopOnError( "INTERNAL ERROR: QPDF::calculateLinearizationData: page object for page " + std::to_string(i) + " not in lc_other_page_private"); @@ -1240,11 +1240,11 @@ QPDF::calculateLinearizationData(T const& object_stream_data) m->c_page_offset_data.entries.at(i).nobjects = 1; ObjUser ou(ObjUser::ou_page, toI(i)); - if (m->obj_user_to_objects.count(ou) == 0) { + if (!m->obj_user_to_objects.contains(ou)) { stopOnError("found unreferenced page while calculating linearization data"); } for (auto const& og: m->obj_user_to_objects[ou]) { - if (lc_other_page_private.count(og)) { + if (lc_other_page_private.contains(og)) { lc_other_page_private.erase(og); m->part7.push_back(getObject(og)); ++m->c_page_offset_data.entries.at(i).nobjects; @@ -1279,7 +1279,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) stopOnError("found empty pages tree while calculating linearization data"); } for (auto const& og: pages_ogs) { - if (lc_other.count(og)) { + if (lc_other.contains(og)) { lc_other.erase(og); m->part9.push_back(getObject(og)); } @@ -1293,7 +1293,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) if (!thumb.isNull()) { // Output the thumbnail itself QPDFObjGen thumb_og(thumb.getObjGen()); - if (lc_thumbnail_private.count(thumb_og)) { + if (lc_thumbnail_private.contains(thumb_og)) { lc_thumbnail_private.erase(thumb_og); m->part9.push_back(thumb); } else { @@ -1304,7 +1304,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) } std::set& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; for (auto const& og: ogs) { - if (lc_thumbnail_private.count(og)) { + if (lc_thumbnail_private.contains(og)) { lc_thumbnail_private.erase(og); m->part9.push_back(getObject(og)); } @@ -1384,11 +1384,11 @@ QPDF::calculateLinearizationData(T const& object_stream_data) for (size_t i = 1; i < toS(npages); ++i) { CHPageOffsetEntry& pe = m->c_page_offset_data.entries.at(i); ObjUser ou(ObjUser::ou_page, toI(i)); - if (m->obj_user_to_objects.count(ou) == 0) { + if (!m->obj_user_to_objects.contains(ou)) { stopOnError("found unreferenced page while calculating linearization data"); } for (auto const& og: m->obj_user_to_objects[ou]) { - if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.count(og.getObj()) > 0)) { + if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.contains(og.getObj()))) { int idx = obj_to_index[og.getObj()]; ++pe.nshared_objects; pe.shared_identifiers.push_back(idx); diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index 7ef8427..12ad916 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -442,7 +442,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset, bool in_stream_recovery) } else { xref_offset = read_xrefStream(xref_offset, in_stream_recovery); } - if (visited.count(xref_offset) != 0) { + if (visited.contains(xref_offset)) { QTC::TC("qpdf", "QPDF xref loop"); throw damagedPDF("", -1, "loop detected following xref tables"); } @@ -1020,7 +1020,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2) return; } - if (m->deleted_objects.count(obj)) { + if (m->deleted_objects.contains(obj)) { QTC::TC("qpdf", "QPDF xref deleted object"); return; } @@ -1056,7 +1056,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2) void QPDF::insertFreeXrefEntry(QPDFObjGen og) { - if (!m->xref_table.count(og)) { + if (!m->xref_table.contains(og)) { m->deleted_objects.insert(og.getObj()); } } @@ -1476,7 +1476,7 @@ QPDF::readObjectAtOffset( if (try_recovery) { // Try again after reconstructing xref table reconstruct_xref(e); - if (m->xref_table.count(exp_og) && (m->xref_table[exp_og].getType() == 1)) { + if (m->xref_table.contains(exp_og) && m->xref_table[exp_og].getType() == 1) { qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset(); QPDFObjectHandle result = readObjectAtOffset(false, new_offset, description, exp_og, og, false); @@ -1522,7 +1522,7 @@ QPDF::readObjectAtOffset( } } qpdf_offset_t end_after_space = m->file->tell(); - if (skip_cache_if_in_xref && m->xref_table.count(og)) { + if (skip_cache_if_in_xref && m->xref_table.contains(og)) { // Ordinarily, an object gets read here when resolved through xref table or stream. In // the special case of the xref stream and linearization hint tables, the offset comes // from another source. For the specific case of xref streams, the xref stream is read @@ -1564,7 +1564,7 @@ QPDF::resolve(QPDFObjGen og) return m->obj_cache[og].object; } - if (m->resolving.count(og)) { + if (m->resolving.contains(og)) { // This can happen if an object references itself directly or indirectly in some key that // has to be resolved during object parsing, such as stream length. QTC::TC("qpdf", "QPDF recursion loop in resolve"); @@ -1574,7 +1574,7 @@ QPDF::resolve(QPDFObjGen og) } ResolveRecorder rr(this, og); - if (m->xref_table.count(og) != 0) { + if (m->xref_table.contains(og)) { QPDFXRefEntry const& entry = m->xref_table[og]; try { switch (entry.getType()) { @@ -1628,7 +1628,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) true}; }; - if (m->resolved_object_streams.count(obj_stream_number)) { + if (m->resolved_object_streams.contains(obj_stream_number)) { return; } m->resolved_object_streams.insert(obj_stream_number); @@ -1791,7 +1791,7 @@ QPDF::updateCache( bool QPDF::isCached(QPDFObjGen og) { - return m->obj_cache.count(og) != 0; + return m->obj_cache.contains(og); } bool @@ -1835,7 +1835,7 @@ QPDF::getObjectForParser(int id, int gen, bool parse_pdf) if (auto iter = m->obj_cache.find(og); iter != m->obj_cache.end()) { return iter->second.object; } - if (m->xref_table.count(og) || !m->parsed) { + if (m->xref_table.contains(og) || !m->parsed) { return m->obj_cache.insert({og, QPDFObject::create(this, og)}) .first->second.object; } @@ -1852,7 +1852,7 @@ QPDF::getObjectForJSON(int id, int gen) auto [it, inserted] = m->obj_cache.try_emplace(og); auto& obj = it->second.object; if (inserted) { - obj = (m->parsed && !m->xref_table.count(og)) + obj = (m->parsed && !m->xref_table.contains(og)) ? QPDFObject::create(this, og) : QPDFObject::create(this, og); } @@ -1864,7 +1864,7 @@ QPDF::getObject(QPDFObjGen og) { if (auto it = m->obj_cache.find(og); it != m->obj_cache.end()) { return {it->second.object}; - } else if (m->parsed && !m->xref_table.count(og)) { + } else if (m->parsed && !m->xref_table.contains(og)) { return QPDFObject::create(); } else { auto result = diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc index f19539a..1b18981 100644 --- a/libqpdf/QPDF_pages.cc +++ b/libqpdf/QPDF_pages.cc @@ -303,7 +303,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) : 2); // insert in middle auto og = newpage.getObjGen(); - if (m->pageobj_to_pages_pos.count(og)) { + if (m->pageobj_to_pages_pos.contains(og)) { QTC::TC("qpdf", "QPDF resolve duplicated page in insert"); newpage = makeIndirectObject(QPDFObjectHandle(newpage).shallowCopy()); } diff --git a/libqpdf/QTC.cc b/libqpdf/QTC.cc index ae9649a..e69f2b7 100644 --- a/libqpdf/QTC.cc +++ b/libqpdf/QTC.cc @@ -39,7 +39,7 @@ QTC::TC_real(char const* const scope, char const* const ccase, int n) } #undef TC_ENV - if (cache.count(std::make_pair(ccase, n))) { + if (cache.contains(std::make_pair(ccase, n))) { return; } cache.insert(std::make_pair(ccase, n)); diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 05b53ba..19e85b4 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -1395,7 +1395,7 @@ QUtil::parse_numrange(char const* range, int max) work = last_group; last_group.clear(); for (auto n: work) { - if (exclusions.count(n) == 0) { + if (!exclusions.contains(n)) { last_group.emplace_back(n); } } @@ -1886,7 +1886,7 @@ QUtil::possible_repaired_encodings(std::string supplied) std::vector t; std::set seen; for (auto const& iter: result) { - if (!seen.count(iter)) { + if (!seen.contains(iter)) { seen.insert(iter); t.push_back(iter); } @@ -1988,7 +1988,7 @@ QUtil::get_max_memory_usage() attrs[m2->str(1)] = m2->str(2); } if (tag == "total") { - if (attrs.count("size") > 0) { + if (attrs.contains("size")) { result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str())); } } else if (tag == "system" && attrs["type"] == "max") { diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 4cb8882..14cf65f 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -3621,7 +3621,7 @@ runtest(int n, char const* filename1, char const* arg2) p[i] = static_cast(p[i] ^ 0xcc); } pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), p, size); - } else if (ignore_filename.count(n)) { + } else if (ignore_filename.contains(n)) { // Ignore filename argument entirely } else if (n == 89) { pdf.createFromJSON(filename1); diff --git a/qpdf/test_parsedoffset.cc b/qpdf/test_parsedoffset.cc index 0978bfc..f2b13b6 100644 --- a/qpdf/test_parsedoffset.cc +++ b/qpdf/test_parsedoffset.cc @@ -77,7 +77,7 @@ process(std::string fn, std::vector xrefs = qpdf.getXRefTable(); for (auto const& oh: qpdf.getAllObjects()) { - if (xrefs.count(oh.getObjGen()) == 0) { + if (!xrefs.contains(oh.getObjGen())) { std::cerr << oh.getObjectID() << "/" << oh.getGeneration() << " is not found in xref table" << std::endl; std::exit(2); diff --git a/qpdf/test_renumber.cc b/qpdf/test_renumber.cc index 3eaa889..33127f1 100644 --- a/qpdf/test_renumber.cc +++ b/qpdf/test_renumber.cc @@ -26,7 +26,7 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) { static std::set visited; if (a.isIndirect()) { - if (visited.count(a.getObjGen())) { + if (visited.contains(a.getObjGen())) { return true; } visited.insert(a.getObjGen()); @@ -128,7 +128,7 @@ compare_xref_table(std::map a, std::map