Commit 6c69a747b9f7a801be2ad58985f35886bd38239e

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 70ccd807

Code clean up: use range-style for loops wherever possible

Remove variables obsoleted by commit 4f24617.
examples/pdf-filter-tokens.cc
... ... @@ -191,9 +191,7 @@ main(int argc, char* argv[])
191 191 try {
192 192 QPDF pdf;
193 193 pdf.processFile(infilename);
194   - std::vector<QPDFPageObjectHelper> pages =
195   - QPDFPageDocumentHelper(pdf).getAllPages();
196   - for (auto& page: pages) {
  194 + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
197 195 // Attach two token filters to each page of this file.
198 196 // When the file is written, or when the pages' contents
199 197 // are retrieved in any other way, the filters will be
... ...
examples/pdf-invert-images.cc
... ... @@ -129,12 +129,9 @@ main(int argc, char* argv[])
129 129 auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv);
130 130  
131 131 // For each page...
132   - std::vector<QPDFPageObjectHelper> pages =
133   - QPDFPageDocumentHelper(qpdf).getAllPages();
134   - for (auto& page: pages) {
  132 + for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
135 133 // Get all images on the page.
136   - std::map<std::string, QPDFObjectHandle> images = page.getImages();
137   - for (auto& iter: images) {
  134 + for (auto& iter: page.getImages()) {
138 135 QPDFObjectHandle& image = iter.second;
139 136 QPDFObjectHandle image_dict = image.getDict();
140 137 QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
... ...
examples/pdf-overlay-page.cc
... ... @@ -40,9 +40,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
40 40 QPDFObjectHandle stamp_fo = inpdf.copyForeignObject(foreign_fo);
41 41  
42 42 // For each page...
43   - std::vector<QPDFPageObjectHelper> pages =
44   - QPDFPageDocumentHelper(inpdf).getAllPages();
45   - for (auto& ph: pages) {
  43 + for (auto& ph: QPDFPageDocumentHelper(inpdf).getAllPages()) {
46 44 // Find a unique resource name for the new form XObject
47 45 QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
48 46 int min_suffix = 1;
... ...
examples/pdf-set-form-values.cc
... ... @@ -50,15 +50,11 @@ main(int argc, char* argv[])
50 50 // illustrates how we can map from annotations to fields.
51 51  
52 52 QPDFAcroFormDocumentHelper afdh(qpdf);
53   - QPDFPageDocumentHelper pdh(qpdf);
54   - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
55   - for (auto const& page: pages) {
  53 + for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
56 54 // Get all widget annotations for each page. Widget
57 55 // annotations are the ones that contain the details of
58 56 // what's in a form field.
59   - std::vector<QPDFAnnotationObjectHelper> annotations =
60   - afdh.getWidgetAnnotationsForPage(page);
61   - for (auto& annot: annotations) {
  57 + for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) {
62 58 // For each annotation, find its associated field. If
63 59 // it's a text field, set its value.
64 60 QPDFFormFieldObjectHelper ffh =
... ...
fuzz/qpdf_fuzzer.cc
... ... @@ -131,10 +131,9 @@ FuzzHelper::testPages()
131 131 QPDFAcroFormDocumentHelper afdh(*q);
132 132 afdh.generateAppearancesIfNeeded();
133 133 pdh.flattenAnnotations();
134   - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
135 134 DiscardContents discard_contents;
136 135 int pageno = 0;
137   - for (auto& page: pages) {
  136 + for (auto& page: pdh.getAllPages()) {
138 137 ++pageno;
139 138 try {
140 139 page.coalesceContentStreams();
... ... @@ -145,9 +144,7 @@ FuzzHelper::testPages()
145 144 page_obj.getJSON(JSON::LATEST, true).unparse();
146 145 odh.getOutlinesForPage(page_obj.getObjGen());
147 146  
148   - std::vector<QPDFAnnotationObjectHelper> annotations =
149   - afdh.getWidgetAnnotationsForPage(page);
150   - for (auto& aoh: annotations) {
  147 + for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
151 148 afdh.getFieldForAnnotation(aoh);
152 149 }
153 150 } catch (QPDFExc& e) {
... ... @@ -164,8 +161,7 @@ FuzzHelper::testOutlines()
164 161 QPDFOutlineDocumentHelper odh(*q);
165 162 queue.push_back(odh.getTopLevelOutlines());
166 163 while (!queue.empty()) {
167   - std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin());
168   - for (auto& ol: outlines) {
  164 + for (auto& ol: *(queue.begin())) {
169 165 ol.getDestPage();
170 166 queue.push_back(ol.getKids());
171 167 }
... ...
libqpdf/QPDF.cc
... ... @@ -2369,8 +2369,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier&amp; obj_copier, bool top)
2369 2369 }
2370 2370 } else if (foreign.isDictionary()) {
2371 2371 QTC::TC("qpdf", "QPDF reserve dictionary");
2372   - std::set<std::string> keys = foreign.getKeys();
2373   - for (auto const& key: keys) {
  2372 + for (auto const& key: foreign.getKeys()) {
2374 2373 reserveObjects(foreign.getKey(key), obj_copier, false);
2375 2374 }
2376 2375 } else if (foreign.isStream()) {
... ...
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -294,12 +294,8 @@ QPDFAcroFormDocumentHelper::analyze()
294 294 // a file that contains this kind of error will probably not
295 295 // actually work with most viewers.
296 296  
297   - QPDFPageDocumentHelper dh(this->qpdf);
298   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
299   - for (auto const& ph: pages) {
300   - std::vector<QPDFAnnotationObjectHelper> annots =
301   - getWidgetAnnotationsForPage(ph);
302   - for (auto const& iter: annots) {
  297 + for (auto const& ph: QPDFPageDocumentHelper(this->qpdf).getAllPages()) {
  298 + for (auto const& iter: getWidgetAnnotationsForPage(ph)) {
303 299 QPDFObjectHandle annot(iter.getObjectHandle());
304 300 QPDFObjGen og(annot.getObjGen());
305 301 if (this->m->annotation_to_field.count(og) == 0) {
... ... @@ -451,12 +447,8 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
451 447 return;
452 448 }
453 449  
454   - QPDFPageDocumentHelper pdh(this->qpdf);
455   - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
456   - for (auto const& page: pages) {
457   - std::vector<QPDFAnnotationObjectHelper> annotations =
458   - getWidgetAnnotationsForPage(page);
459   - for (auto& aoh: annotations) {
  450 + for (auto const& page: QPDFPageDocumentHelper(this->qpdf).getAllPages()) {
  451 + for (auto& aoh: getWidgetAnnotationsForPage(page)) {
460 452 QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh);
461 453 if (ffh.getFieldType() == "/Btn") {
462 454 // Rather than generating appearances for button
... ...
libqpdf/QPDFJob.cc
... ... @@ -867,11 +867,9 @@ QPDFJob::doCheck(QPDF&amp; pdf)
867 867 w.write();
868 868  
869 869 // Parse all content streams
870   - QPDFPageDocumentHelper dh(pdf);
871   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
872 870 DiscardContents discard_contents;
873 871 int pageno = 0;
874   - for (auto& page: pages) {
  872 + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
875 873 ++pageno;
876 874 try {
877 875 page.parseContents(&discard_contents);
... ... @@ -939,11 +937,9 @@ QPDFJob::doShowObj(QPDF&amp; pdf)
939 937 void
940 938 QPDFJob::doShowPages(QPDF& pdf)
941 939 {
942   - QPDFPageDocumentHelper dh(pdf);
943   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
944 940 int pageno = 0;
945 941 auto& cout = *this->m->cout;
946   - for (auto& ph: pages) {
  942 + for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
947 943 QPDFObjectHandle page = ph.getObjectHandle();
948 944 ++pageno;
949 945  
... ... @@ -966,8 +962,7 @@ QPDFJob::doShowPages(QPDF&amp; pdf)
966 962 }
967 963  
968 964 cout << " content:" << std::endl;
969   - std::vector<QPDFObjectHandle> content = ph.getPageContents();
970   - for (auto& iter2: content) {
  965 + for (auto& iter2: ph.getPageContents()) {
971 966 cout << " " << iter2.unparse() << std::endl;
972 967 }
973 968 }
... ... @@ -1085,8 +1080,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1085 1080 JSON::writeDictionaryOpen(p, first_object, 1);
1086 1081 bool all_objects = m->json_objects.empty();
1087 1082 std::set<QPDFObjGen> wanted_og = getWantedJSONObjects();
1088   - std::vector<QPDFObjectHandle> objects = pdf.getAllObjects();
1089   - for (auto& obj: objects) {
  1083 + for (auto& obj: pdf.getAllObjects()) {
1090 1084 std::string key = obj.unparse();
1091 1085 if (this->m->json_version > 1) {
1092 1086 key = "obj:" + key;
... ... @@ -1140,20 +1134,17 @@ QPDFJob::doJSONPages(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1140 1134 JSON::writeDictionaryKey(p, first, "pages", 0);
1141 1135 bool first_page = true;
1142 1136 JSON::writeArrayOpen(p, first_page, 1);
1143   - QPDFPageDocumentHelper pdh(pdf);
1144 1137 QPDFPageLabelDocumentHelper pldh(pdf);
1145 1138 QPDFOutlineDocumentHelper odh(pdf);
1146   - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
1147 1139 int pageno = -1;
1148   - for (auto& ph: pages) {
  1140 + for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
1149 1141 ++pageno;
1150 1142 JSON j_page = JSON::makeDictionary();
1151 1143 QPDFObjectHandle page = ph.getObjectHandle();
1152 1144 j_page.addDictionaryMember(
1153 1145 "object", page.getJSON(this->m->json_version));
1154 1146 JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
1155   - std::map<std::string, QPDFObjectHandle> images = ph.getImages();
1156   - for (auto const& iter2: images) {
  1147 + for (auto const& iter2: ph.getImages()) {
1157 1148 JSON j_image = j_images.addArrayElement(JSON::makeDictionary());
1158 1149 j_image.addDictionaryMember("name", JSON::makeString(iter2.first));
1159 1150 QPDFObjectHandle image = iter2.second;
... ... @@ -1195,8 +1186,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1195 1186 j_page.addDictionaryMember("images", j_images);
1196 1187 JSON j_contents =
1197 1188 j_page.addDictionaryMember("contents", JSON::makeArray());
1198   - std::vector<QPDFObjectHandle> content = ph.getPageContents();
1199   - for (auto& iter2: content) {
  1189 + for (auto& iter2: ph.getPageContents()) {
1200 1190 j_contents.addArrayElement(iter2.getJSON(this->m->json_version));
1201 1191 }
1202 1192 j_page.addDictionaryMember(
... ... @@ -1285,10 +1275,8 @@ void
1285 1275 QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf)
1286 1276 {
1287 1277 std::map<QPDFObjGen, int> page_numbers;
1288   - QPDFPageDocumentHelper dh(pdf);
1289   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
1290 1278 int n = 0;
1291   - for (auto const& ph: pages) {
  1279 + for (auto const& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
1292 1280 QPDFObjectHandle oh = ph.getObjectHandle();
1293 1281 page_numbers[oh.getObjGen()] = ++n;
1294 1282 }
... ... @@ -1309,14 +1297,10 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1309 1297 j_acroform.addDictionaryMember(
1310 1298 "needappearances", JSON::makeBool(afdh.getNeedAppearances()));
1311 1299 JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray());
1312   - QPDFPageDocumentHelper pdh(pdf);
1313   - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
1314 1300 int pagepos1 = 0;
1315   - for (auto const& page: pages) {
  1301 + for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1316 1302 ++pagepos1;
1317   - std::vector<QPDFAnnotationObjectHelper> annotations =
1318   - afdh.getWidgetAnnotationsForPage(page);
1319   - for (auto& aoh: annotations) {
  1303 + for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
1320 1304 QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
1321 1305 JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
1322 1306 j_field.addDictionaryMember(
... ... @@ -1355,8 +1339,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1355 1339 j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText()));
1356 1340 JSON j_choices =
1357 1341 j_field.addDictionaryMember("choices", JSON::makeArray());
1358   - std::vector<std::string> choices = ffh.getChoices();
1359   - for (auto const& choice: choices) {
  1342 + for (auto const& choice: ffh.getChoices()) {
1360 1343 j_choices.addArrayElement(JSON::makeString(choice));
1361 1344 }
1362 1345 JSON j_annot = j_field.addDictionaryMember(
... ... @@ -2282,19 +2265,16 @@ QPDFJob::handleTransformations(QPDF&amp; pdf)
2282 2265 };
2283 2266 if (m->externalize_inline_images ||
2284 2267 (m->optimize_images && (!m->keep_inline_images))) {
2285   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
2286   - for (auto& ph: pages) {
  2268 + for (auto& ph: dh.getAllPages()) {
2287 2269 ph.externalizeInlineImages(m->ii_min_bytes);
2288 2270 }
2289 2271 }
2290 2272 if (m->optimize_images) {
2291 2273 int pageno = 0;
2292   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
2293   - for (auto& ph: pages) {
  2274 + for (auto& ph: dh.getAllPages()) {
2294 2275 ++pageno;
2295 2276 QPDFObjectHandle page = ph.getObjectHandle();
2296   - std::map<std::string, QPDFObjectHandle> images = ph.getImages();
2297   - for (auto& iter2: images) {
  2277 + for (auto& iter2: ph.getImages()) {
2298 2278 std::string name = iter2.first;
2299 2279 QPDFObjectHandle& image = iter2.second;
2300 2280 ImageOptimizer* io = new ImageOptimizer(
... ... @@ -2330,8 +2310,7 @@ QPDFJob::handleTransformations(QPDF&amp; pdf)
2330 2310 m->flatten_annotations_required, m->flatten_annotations_forbidden);
2331 2311 }
2332 2312 if (m->coalesce_contents) {
2333   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
2334   - for (auto& page: pages) {
  2313 + for (auto& page: dh.getAllPages()) {
2335 2314 page.coalesceContentStreams();
2336 2315 }
2337 2316 }
... ... @@ -2805,9 +2784,7 @@ QPDFJob::handleRotations(QPDF&amp; pdf)
2805 2784 std::string const& range = iter.first;
2806 2785 QPDFJob::RotationSpec const& rspec = iter.second;
2807 2786 // range has been previously validated
2808   - std::vector<int> to_rotate =
2809   - QUtil::parse_numrange(range.c_str(), npages);
2810   - for (int pageno_iter: to_rotate) {
  2787 + for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) {
2811 2788 int pageno = pageno_iter - 1;
2812 2789 if ((pageno >= 0) && (pageno < npages)) {
2813 2790 pages.at(QIntC::to_size(pageno))
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -1240,12 +1240,10 @@ QPDFObjectHandle::getResourceNames()
1240 1240 if (!isDictionary()) {
1241 1241 return result;
1242 1242 }
1243   - std::set<std::string> keys = getKeys();
1244   - for (auto const& key: keys) {
  1243 + for (auto const& key: getKeys()) {
1245 1244 QPDFObjectHandle val = getKey(key);
1246 1245 if (val.isDictionary()) {
1247   - std::set<std::string> val_keys = val.getKeys();
1248   - for (auto const& val_key: val_keys) {
  1246 + for (auto const& val_key: val.getKeys()) {
1249 1247 result.insert(val_key);
1250 1248 }
1251 1249 }
... ... @@ -1642,14 +1640,12 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
1642 1640 {
1643 1641 new_contents.assertStream();
1644 1642  
1645   - std::vector<QPDFObjectHandle> orig_contents = getPageContents();
1646   -
1647 1643 std::vector<QPDFObjectHandle> content_streams;
1648 1644 if (first) {
1649 1645 QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
1650 1646 content_streams.push_back(new_contents);
1651 1647 }
1652   - for (auto const& iter: orig_contents) {
  1648 + for (auto const& iter: getPageContents()) {
1653 1649 QTC::TC("qpdf", "QPDFObjectHandle append page contents");
1654 1650 content_streams.push_back(iter);
1655 1651 }
... ... @@ -1657,8 +1653,7 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
1657 1653 content_streams.push_back(new_contents);
1658 1654 }
1659 1655  
1660   - QPDFObjectHandle contents = QPDFObjectHandle::newArray(content_streams);
1661   - this->replaceKey("/Contents", contents);
  1656 + this->replaceKey("/Contents", newArray(content_streams));
1662 1657 }
1663 1658  
1664 1659 void
... ... @@ -2927,9 +2922,8 @@ QPDFObjectHandle::copyObject(
2927 2922 new_obj = std::shared_ptr<QPDFObject>(new QPDF_Array(items));
2928 2923 } else if (isDictionary()) {
2929 2924 QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
2930   - std::set<std::string> keys = getKeys();
2931 2925 std::map<std::string, QPDFObjectHandle> items;
2932   - for (auto const& key: keys) {
  2926 + for (auto const& key: getKeys()) {
2933 2927 items[key] = getKey(key);
2934 2928 if ((!first_level_only) &&
2935 2929 (cross_indirect || (!items[key].isIndirect()))) {
... ...
libqpdf/QPDFPageDocumentHelper.cc
... ... @@ -12,9 +12,8 @@ QPDFPageDocumentHelper::QPDFPageDocumentHelper(QPDF&amp; qpdf) :
12 12 std::vector<QPDFPageObjectHelper>
13 13 QPDFPageDocumentHelper::getAllPages()
14 14 {
15   - std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages();
16 15 std::vector<QPDFPageObjectHelper> pages;
17   - for (auto const& iter: pages_v) {
  16 + for (auto const& iter: this->qpdf.getAllPages()) {
18 17 pages.push_back(QPDFPageObjectHelper(iter));
19 18 }
20 19 return pages;
... ... @@ -29,8 +28,7 @@ QPDFPageDocumentHelper::pushInheritedAttributesToPage()
29 28 void
30 29 QPDFPageDocumentHelper::removeUnreferencedResources()
31 30 {
32   - std::vector<QPDFPageObjectHelper> pages = getAllPages();
33   - for (auto& ph: pages) {
  31 + for (auto& ph: getAllPages()) {
34 32 ph.removeUnreferencedResources();
35 33 }
36 34 }
... ... @@ -66,8 +64,7 @@ QPDFPageDocumentHelper::flattenAnnotations(
66 64 .warnIfPossible("document does not have updated appearance streams,"
67 65 " so form fields will not be flattened");
68 66 }
69   - std::vector<QPDFPageObjectHelper> pages = getAllPages();
70   - for (auto& ph: pages) {
  67 + for (auto& ph: getAllPages()) {
71 68 QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
72 69 if (!resources.isDictionary()) {
73 70 // This should never happen and is not exercised in the
... ...
libqpdf/QPDFTokenizer.cc
... ... @@ -567,8 +567,7 @@ QPDFTokenizer::findEI(std::shared_ptr&lt;InputSource&gt; input)
567 567 bool found_alpha = false;
568 568 bool found_non_printable = false;
569 569 bool found_other = false;
570   - std::string value = t.getValue();
571   - for (char ch: value) {
  570 + for (char ch: t.getValue()) {
572 571 if (((ch >= 'a') && (ch <= 'z')) ||
573 572 ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
574 573 // Treat '*' as alpha since there are valid
... ...
libqpdf/QPDFWriter.cc
... ... @@ -1237,8 +1237,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
1237 1237 }
1238 1238 }
1239 1239 } else if (object.isDictionary()) {
1240   - std::set<std::string> keys = object.getKeys();
1241   - for (auto const& key: keys) {
  1240 + for (auto const& key: object.getKeys()) {
1242 1241 if (!this->m->linearized) {
1243 1242 enqueueObject(object.getKey(key));
1244 1243 }
... ... @@ -1283,8 +1282,7 @@ QPDFWriter::writeTrailer(
1283 1282 writeString(" /Size ");
1284 1283 writeString(QUtil::int_to_string(size));
1285 1284 } else {
1286   - std::set<std::string> keys = trailer.getKeys();
1287   - for (auto const& key: keys) {
  1285 + for (auto const& key: trailer.getKeys()) {
1288 1286 writeStringQDF(" ");
1289 1287 writeStringNoQDF(" ");
1290 1288 writeString(QPDF_Name::normalizeName(key));
... ... @@ -1644,8 +1642,7 @@ QPDFWriter::unparseObject(
1644 1642 writeString("<<");
1645 1643 writeStringQDF("\n");
1646 1644  
1647   - std::set<std::string> keys = object.getKeys();
1648   - for (auto const& key: keys) {
  1645 + for (auto const& key: object.getKeys()) {
1649 1646 writeStringQDF(indent);
1650 1647 writeStringQDF(" ");
1651 1648 writeStringNoQDF(" ");
... ... @@ -2074,8 +2071,7 @@ QPDFWriter::generateID()
2074 2071 seed += " QPDF ";
2075 2072 if (trailer.hasKey("/Info")) {
2076 2073 QPDFObjectHandle info = trailer.getKey("/Info");
2077   - std::set<std::string> keys = info.getKeys();
2078   - for (auto const& key: keys) {
  2074 + for (auto const& key: info.getKeys()) {
2079 2075 QPDFObjectHandle obj = info.getKey(key);
2080 2076 if (obj.isString()) {
2081 2077 seed += " ";
... ... @@ -2365,8 +2361,7 @@ QPDFWriter::doWriteSetup()
2365 2361  
2366 2362 if (this->m->linearized) {
2367 2363 // Page dictionaries are not allowed to be compressed objects.
2368   - std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
2369   - for (auto& page: pages) {
  2364 + for (auto& page: this->m->pdf.getAllPages()) {
2370 2365 QPDFObjGen og = page.getObjGen();
2371 2366 if (this->m->object_to_object_stream.count(og)) {
2372 2367 QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
... ... @@ -3251,8 +3246,7 @@ QPDFWriter::enqueueObjectsStandard()
3251 3246 // dictionary into the queue, handling direct objects recursively.
3252 3247 // Root is already there, so enqueuing it a second time is a
3253 3248 // no-op.
3254   - std::set<std::string> keys = trailer.getKeys();
3255   - for (auto const& key: keys) {
  3249 + for (auto const& key: trailer.getKeys()) {
3256 3250 enqueueObject(trailer.getKey(key));
3257 3251 }
3258 3252 }
... ... @@ -3276,8 +3270,7 @@ QPDFWriter::enqueueObjectsPCLm()
3276 3270  
3277 3271 // enqueue all the strips for each page
3278 3272 QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject");
3279   - std::set<std::string> keys = strips.getKeys();
3280   - for (auto const& image: keys) {
  3273 + for (auto const& image: strips.getKeys()) {
3281 3274 enqueueObject(strips.getKey(image));
3282 3275 enqueueObject(QPDFObjectHandle::newStream(
3283 3276 &this->m->pdf, image_transform_content));
... ...
libqpdf/QPDF_linearization.cc
... ... @@ -663,9 +663,8 @@ QPDF::maxEnd(ObjUser const&amp; ou)
663 663 if (this->m->obj_user_to_objects.count(ou) == 0) {
664 664 stopOnError("no entry in object user table for requested object user");
665 665 }
666   - std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
667 666 qpdf_offset_t end = 0;
668   - for (auto const& og: ogs) {
  667 + for (auto const& og: this->m->obj_user_to_objects[ou]) {
669 668 if (this->m->obj_cache.count(og) == 0) {
670 669 stopOnError("unknown object referenced in object user table");
671 670 }
... ... @@ -1474,8 +1473,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1474 1473 stopOnError("found unreferenced page while"
1475 1474 " calculating linearization data");
1476 1475 }
1477   - std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];
1478   - for (auto const& og: ogs) {
  1476 + for (auto const& og: this->m->obj_user_to_objects[ou]) {
1479 1477 if (lc_other_page_private.count(og)) {
1480 1478 lc_other_page_private.erase(og);
1481 1479 this->m->part7.push_back(objGenToIndirect(og));
... ... @@ -1637,8 +1635,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1637 1635 stopOnError("found unreferenced page while"
1638 1636 " calculating linearization data");
1639 1637 }
1640   - std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
1641   - for (auto const& og: ogs) {
  1638 + for (auto const& og: this->m->obj_user_to_objects[ou]) {
1642 1639 if ((this->m->object_to_obj_users[og].size() > 1) &&
1643 1640 (obj_to_index.count(og.getObj()) > 0)) {
1644 1641 int idx = obj_to_index[og.getObj()];
... ...
libqpdf/QPDF_optimization.cc
... ... @@ -90,8 +90,7 @@ QPDF::optimize(
90 90 }
91 91  
92 92 // Traverse document-level items
93   - std::set<std::string> keys = this->m->trailer.getKeys();
94   - for (auto const& key: keys) {
  93 + for (auto const& key: this->m->trailer.getKeys()) {
95 94 if (key == "/Root") {
96 95 // handled separately
97 96 } else {
... ... @@ -102,8 +101,7 @@ QPDF::optimize(
102 101 }
103 102 }
104 103  
105   - keys = root.getKeys();
106   - for (auto const& key: keys) {
  104 + for (auto const& key: root.getKeys()) {
107 105 // Technically, /I keys from /Thread dictionaries are supposed
108 106 // to be handled separately, but we are going to disregard
109 107 // that specification for now. There is loads of evidence
... ... @@ -205,8 +203,7 @@ QPDF::pushInheritedAttributesToPageInternal(
205 203 // that have values for this attribute.
206 204  
207 205 std::set<std::string> inheritable_keys;
208   - std::set<std::string> keys = cur_pages.getKeys();
209   - for (auto const& key: keys) {
  206 + for (auto const& key: cur_pages.getKeys()) {
210 207 if ((key == "/MediaBox") || (key == "/CropBox") ||
211 208 (key == "/Resources") || (key == "/Rotate")) {
212 209 if (!allow_changes) {
... ... @@ -387,8 +384,7 @@ QPDF::updateObjectMapsInternal(
387 384 }
388 385 }
389 386  
390   - std::set<std::string> keys = dict.getKeys();
391   - for (auto const& key: keys) {
  387 + for (auto const& key: dict.getKeys()) {
392 388 if (is_page_node && (key == "/Thumb")) {
393 389 // Traverse page thumbnail dictionaries as a special
394 390 // case.
... ... @@ -437,8 +433,8 @@ QPDF::filterCompressedObjects(std::map&lt;int, int&gt; const&amp; object_stream_data)
437 433  
438 434 for (auto const& i1: this->m->obj_user_to_objects) {
439 435 ObjUser const& ou = i1.first;
440   - std::set<QPDFObjGen> const& objects = i1.second;
441   - for (auto const& og: objects) {
  436 + // Loop over objects.
  437 + for (auto const& og: i1.second) {
442 438 auto i2 = object_stream_data.find(og.getObj());
443 439 if (i2 == object_stream_data.end()) {
444 440 t_obj_user_to_objects[ou].insert(og);
... ... @@ -450,8 +446,8 @@ QPDF::filterCompressedObjects(std::map&lt;int, int&gt; const&amp; object_stream_data)
450 446  
451 447 for (auto const& i1: this->m->object_to_obj_users) {
452 448 QPDFObjGen const& og = i1.first;
453   - std::set<ObjUser> const& objusers = i1.second;
454   - for (auto const& ou: objusers) {
  449 + // Loop over obj_users.
  450 + for (auto const& ou: i1.second) {
455 451 auto i2 = object_stream_data.find(og.getObj());
456 452 if (i2 == object_stream_data.end()) {
457 453 t_object_to_obj_users[og].insert(ou);
... ...
qpdf/test_driver.cc
... ... @@ -377,15 +377,12 @@ test_4(QPDF&amp; pdf, char const* arg2)
377 377 static void
378 378 test_5(QPDF& pdf, char const* arg2)
379 379 {
380   - QPDFPageDocumentHelper dh(pdf);
381   - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
382 380 int pageno = 0;
383   - for (auto& page: pages) {
  381 + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
384 382 ++pageno;
385 383 std::cout << "page " << pageno << ":" << std::endl;
386 384 std::cout << " images:" << std::endl;
387   - std::map<std::string, QPDFObjectHandle> images = page.getImages();
388   - for (auto const& iter2: images) {
  385 + for (auto const& iter2: page.getImages()) {
389 386 std::string const& name = iter2.first;
390 387 QPDFObjectHandle image = iter2.second;
391 388 QPDFObjectHandle dict = image.getDict();
... ... @@ -1319,9 +1316,7 @@ static void
1319 1316 test_37(QPDF& pdf, char const* arg2)
1320 1317 {
1321 1318 // Parse content streams of all pages
1322   - std::vector<QPDFPageObjectHelper> pages =
1323   - QPDFPageDocumentHelper(pdf).getAllPages();
1324   - for (auto& page: pages) {
  1319 + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1325 1320 ParserCallbacks cb;
1326 1321 page.parseContents(&cb);
1327 1322 }
... ... @@ -1341,10 +1336,8 @@ static void
1341 1336 test_39(QPDF& pdf, char const* arg2)
1342 1337 {
1343 1338 // Display image filter and color set for each image on each page
1344   - std::vector<QPDFPageObjectHelper> pages =
1345   - QPDFPageDocumentHelper(pdf).getAllPages();
1346 1339 int pageno = 0;
1347   - for (auto& page: pages) {
  1340 + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1348 1341 std::cout << "page " << ++pageno << std::endl;
1349 1342 std::map<std::string, QPDFObjectHandle> images = page.getImages();
1350 1343 for (auto& i_iter: images) {
... ... @@ -1377,9 +1370,7 @@ test_41(QPDF&amp; pdf, char const* arg2)
1377 1370 {
1378 1371 // Apply a token filter. This test case is crafted to work
1379 1372 // with coalesce.pdf.
1380   - std::vector<QPDFPageObjectHelper> pages =
1381   - QPDFPageDocumentHelper(pdf).getAllPages();
1382   - for (auto& page: pages) {
  1373 + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1383 1374 page.addContentTokenFilter(
1384 1375 std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
1385 1376 }
... ... @@ -1509,8 +1500,7 @@ test_43(QPDF&amp; pdf, char const* arg2)
1509 1500 return;
1510 1501 }
1511 1502 std::cout << "iterating over form fields\n";
1512   - std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields();
1513   - for (auto& ffh: form_fields) {
  1503 + for (auto& ffh: afdh.getFormFields()) {
1514 1504 std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
1515 1505 QPDFFormFieldObjectHelper node = ffh;
1516 1506 while (!node.isNull()) {
... ... @@ -1548,9 +1538,7 @@ test_43(QPDF&amp; pdf, char const* arg2)
1548 1538 std::cout << "iterating over annotations per page\n";
1549 1539 for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1550 1540 std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
1551   - std::vector<QPDFAnnotationObjectHelper> annotations =
1552   - afdh.getWidgetAnnotationsForPage(page);
1553   - for (auto& ah: annotations) {
  1541 + for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) {
1554 1542 std::cout << " Annotation: " << ah.getObjectHandle().unparse()
1555 1543 << std::endl;
1556 1544 std::cout
... ... @@ -1578,9 +1566,7 @@ static void
1578 1566 test_44(QPDF& pdf, char const* arg2)
1579 1567 {
1580 1568 // Set form fields.
1581   - QPDFAcroFormDocumentHelper afdh(pdf);
1582   - std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields();
1583   - for (auto& field: fields) {
  1569 + for (auto& field: QPDFAcroFormDocumentHelper(pdf).getFormFields()) {
1584 1570 QPDFObjectHandle ft = field.getInheritableFieldValue("/FT");
1585 1571 if (ft.isName() && (ft.getName() == "/Tx")) {
1586 1572 // \xc3\xb7 is utf-8 for U+00F7 (divided by)
... ...
qpdf/test_parsedoffset.cc
... ... @@ -51,8 +51,7 @@ walk(
51 51 result[stream_number].push_back(p);
52 52  
53 53 if (obj.isArray()) {
54   - std::vector<QPDFObjectHandle> array = obj.getArrayAsVector();
55   - for (auto& oh: array) {
  54 + for (auto& oh: obj.getArrayAsVector()) {
56 55 if (!oh.isIndirect()) {
57 56 // QPDF::GetAllObjects() enumerates all indirect objects.
58 57 // So only the direct objects are recursed here.
... ... @@ -60,8 +59,7 @@ walk(
60 59 }
61 60 }
62 61 } else if (obj.isDictionary()) {
63   - std::set<std::string> keys = obj.getKeys();
64   - for (auto const& key: keys) {
  62 + for (auto const& key: obj.getKeys()) {
65 63 QPDFObjectHandle item = obj.getKey(key);
66 64 if (!item.isIndirect()) {
67 65 // QPDF::GetAllObjects() enumerates all indirect objects.
... ... @@ -81,10 +79,9 @@ process(
81 79 {
82 80 QPDF qpdf;
83 81 qpdf.processFile(fn.c_str());
84   - std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects();
85 82 std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
86 83  
87   - for (auto const& oh: objs) {
  84 + for (auto const& oh: qpdf.getAllObjects()) {
88 85 if (xrefs.count(oh.getObjGen()) == 0) {
89 86 std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
90 87 << " is not found in xref table" << std::endl;
... ...
qpdf/test_pdf_doc_encoding.cc
... ... @@ -26,8 +26,7 @@ main(int argc, char* argv[])
26 26 usage();
27 27 }
28 28 char const* infilename = argv[1];
29   - std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
30   - for (auto const& line: lines) {
  29 + for (auto const& line: QUtil::read_lines_from_file(infilename)) {
31 30 QPDFObjectHandle str = QPDFObjectHandle::newString(line);
32 31 std::cout << str.getUTF8Value() << std::endl;
33 32 }
... ...
qpdf/test_pdf_unicode.cc
... ... @@ -26,8 +26,7 @@ main(int argc, char* argv[])
26 26 usage();
27 27 }
28 28 char const* infilename = argv[1];
29   - std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
30   - for (auto const& line: lines) {
  29 + for (auto const& line: QUtil::read_lines_from_file(infilename)) {
31 30 QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
32 31 std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
33 32 << std::endl;
... ...
qpdf/test_tokenizer.cc
... ... @@ -198,10 +198,8 @@ process(char const* filename, bool include_ignorable, size_t max_len)
198 198 // Tokenize content streams, skipping inline images
199 199 QPDF qpdf;
200 200 qpdf.processFile(filename);
201   - std::vector<QPDFPageObjectHelper> pages =
202   - QPDFPageDocumentHelper(qpdf).getAllPages();
203 201 int pageno = 0;
204   - for (auto& page: pages) {
  202 + for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
205 203 ++pageno;
206 204 Pl_Buffer plb("buffer");
207 205 page.pipeContents(&plb);
... ...
qpdf/test_xref.cc
... ... @@ -19,9 +19,7 @@ main(int argc, char* argv[])
19 19 QPDF qpdf;
20 20 qpdf.processFile(argv[1]);
21 21  
22   - std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable();
23   -
24   - for (auto const& iter: xref) {
  22 + for (auto const& iter: qpdf.getXRefTable()) {
25 23 std::cout << iter.first.getObj() << "/" << iter.first.getGen()
26 24 << ", ";
27 25 switch (iter.second.getType()) {
... ...