Commit 4f24617e1ea4ba7a6627a9c44304c6e0a0114249
1 parent
7f023701
Code clean up: use range-style for loops wherever possible
Where not possible, use "auto" to get the iterator type. Editorial note: I have avoid this change for a long time because of not wanting to make gratuitous changes to version history, which can obscure when certain changes were made, but with having recently touched every single file to apply automatic code formatting and with making several broad changes to the API, I decided it was time to take the plunge and get rid of the older (pre-C++11) verbose iterator syntax. The new code is just easier to read and understand, and in many cases, it will be more effecient as fewer temporary copies are being made. m-holger, if you're reading, you can see that I've finally come around. :-)
Showing
32 changed files
with
367 additions
and
818 deletions
examples/pdf-filter-tokens.cc
| @@ -193,15 +193,12 @@ main(int argc, char* argv[]) | @@ -193,15 +193,12 @@ main(int argc, char* argv[]) | ||
| 193 | pdf.processFile(infilename); | 193 | pdf.processFile(infilename); |
| 194 | std::vector<QPDFPageObjectHelper> pages = | 194 | std::vector<QPDFPageObjectHelper> pages = |
| 195 | QPDFPageDocumentHelper(pdf).getAllPages(); | 195 | QPDFPageDocumentHelper(pdf).getAllPages(); |
| 196 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 197 | - iter != pages.end(); | ||
| 198 | - ++iter) { | 196 | + for (auto& page: pages) { |
| 199 | // Attach two token filters to each page of this file. | 197 | // Attach two token filters to each page of this file. |
| 200 | // When the file is written, or when the pages' contents | 198 | // When the file is written, or when the pages' contents |
| 201 | // are retrieved in any other way, the filters will be | 199 | // are retrieved in any other way, the filters will be |
| 202 | // applied. See comments on the filters for additional | 200 | // applied. See comments on the filters for additional |
| 203 | // details. | 201 | // details. |
| 204 | - QPDFPageObjectHelper& page(*iter); | ||
| 205 | page.addContentTokenFilter( | 202 | page.addContentTokenFilter( |
| 206 | std::shared_ptr<QPDFObjectHandle::TokenFilter>( | 203 | std::shared_ptr<QPDFObjectHandle::TokenFilter>( |
| 207 | new StringReverser)); | 204 | new StringReverser)); |
examples/pdf-invert-images.cc
| @@ -131,14 +131,11 @@ main(int argc, char* argv[]) | @@ -131,14 +131,11 @@ main(int argc, char* argv[]) | ||
| 131 | // For each page... | 131 | // For each page... |
| 132 | std::vector<QPDFPageObjectHelper> pages = | 132 | std::vector<QPDFPageObjectHelper> pages = |
| 133 | QPDFPageDocumentHelper(qpdf).getAllPages(); | 133 | QPDFPageDocumentHelper(qpdf).getAllPages(); |
| 134 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 135 | - iter != pages.end(); | ||
| 136 | - ++iter) { | ||
| 137 | - QPDFPageObjectHelper& page(*iter); | 134 | + for (auto& page: pages) { |
| 138 | // Get all images on the page. | 135 | // Get all images on the page. |
| 139 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); | 136 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 140 | - for (auto& iter2: images) { | ||
| 141 | - QPDFObjectHandle& image = iter2.second; | 137 | + for (auto& iter: images) { |
| 138 | + QPDFObjectHandle& image = iter.second; | ||
| 142 | QPDFObjectHandle image_dict = image.getDict(); | 139 | QPDFObjectHandle image_dict = image.getDict(); |
| 143 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); | 140 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); |
| 144 | QPDFObjectHandle bits_per_component = | 141 | QPDFObjectHandle bits_per_component = |
examples/pdf-mod-info.cc
| @@ -132,10 +132,7 @@ main(int argc, char* argv[]) | @@ -132,10 +132,7 @@ main(int argc, char* argv[]) | ||
| 132 | QPDFObjectHandle filetrailer = file.getTrailer(); | 132 | QPDFObjectHandle filetrailer = file.getTrailer(); |
| 133 | QPDFObjectHandle fileinfo; | 133 | QPDFObjectHandle fileinfo; |
| 134 | 134 | ||
| 135 | - for (std::map<std::string, std::string>::const_iterator it = | ||
| 136 | - Keys.begin(); | ||
| 137 | - Keys.end() != it; | ||
| 138 | - ++it) { | 135 | + for (auto const& it: Keys) { |
| 139 | if (!fileinfo.isInitialized()) { | 136 | if (!fileinfo.isInitialized()) { |
| 140 | if (filetrailer.hasKey("/Info")) { | 137 | if (filetrailer.hasKey("/Info")) { |
| 141 | QTC::TC("examples", "pdf-mod-info has info"); | 138 | QTC::TC("examples", "pdf-mod-info has info"); |
| @@ -146,12 +143,12 @@ main(int argc, char* argv[]) | @@ -146,12 +143,12 @@ main(int argc, char* argv[]) | ||
| 146 | filetrailer.replaceKey("/Info", fileinfo); | 143 | filetrailer.replaceKey("/Info", fileinfo); |
| 147 | } | 144 | } |
| 148 | } | 145 | } |
| 149 | - if (it->second == "") { | ||
| 150 | - fileinfo.removeKey(it->first); | 146 | + if (it.second == "") { |
| 147 | + fileinfo.removeKey(it.first); | ||
| 151 | } else { | 148 | } else { |
| 152 | - QPDFObjectHandle elt = fileinfo.newString(it->second); | 149 | + QPDFObjectHandle elt = fileinfo.newString(it.second); |
| 153 | elt.makeDirect(); | 150 | elt.makeDirect(); |
| 154 | - fileinfo.replaceKey(it->first, elt); | 151 | + fileinfo.replaceKey(it.first, elt); |
| 155 | } | 152 | } |
| 156 | } | 153 | } |
| 157 | QPDFWriter w(file, fl_tmp.c_str()); | 154 | QPDFWriter w(file, fl_tmp.c_str()); |
examples/pdf-overlay-page.cc
| @@ -42,11 +42,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | @@ -42,11 +42,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | ||
| 42 | // For each page... | 42 | // For each page... |
| 43 | std::vector<QPDFPageObjectHelper> pages = | 43 | std::vector<QPDFPageObjectHelper> pages = |
| 44 | QPDFPageDocumentHelper(inpdf).getAllPages(); | 44 | QPDFPageDocumentHelper(inpdf).getAllPages(); |
| 45 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 46 | - iter != pages.end(); | ||
| 47 | - ++iter) { | ||
| 48 | - QPDFPageObjectHelper& ph = *iter; | ||
| 49 | - | 45 | + for (auto& ph: pages) { |
| 50 | // Find a unique resource name for the new form XObject | 46 | // Find a unique resource name for the new form XObject |
| 51 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); | 47 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); |
| 52 | int min_suffix = 1; | 48 | int min_suffix = 1; |
examples/pdf-set-form-values.cc
| @@ -52,23 +52,17 @@ main(int argc, char* argv[]) | @@ -52,23 +52,17 @@ main(int argc, char* argv[]) | ||
| 52 | QPDFAcroFormDocumentHelper afdh(qpdf); | 52 | QPDFAcroFormDocumentHelper afdh(qpdf); |
| 53 | QPDFPageDocumentHelper pdh(qpdf); | 53 | QPDFPageDocumentHelper pdh(qpdf); |
| 54 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | 54 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); |
| 55 | - for (std::vector<QPDFPageObjectHelper>::iterator page_iter = | ||
| 56 | - pages.begin(); | ||
| 57 | - page_iter != pages.end(); | ||
| 58 | - ++page_iter) { | 55 | + for (auto const& page: pages) { |
| 59 | // Get all widget annotations for each page. Widget | 56 | // Get all widget annotations for each page. Widget |
| 60 | // annotations are the ones that contain the details of | 57 | // annotations are the ones that contain the details of |
| 61 | // what's in a form field. | 58 | // what's in a form field. |
| 62 | std::vector<QPDFAnnotationObjectHelper> annotations = | 59 | std::vector<QPDFAnnotationObjectHelper> annotations = |
| 63 | - afdh.getWidgetAnnotationsForPage(*page_iter); | ||
| 64 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter = | ||
| 65 | - annotations.begin(); | ||
| 66 | - annot_iter != annotations.end(); | ||
| 67 | - ++annot_iter) { | 60 | + afdh.getWidgetAnnotationsForPage(page); |
| 61 | + for (auto& annot: annotations) { | ||
| 68 | // For each annotation, find its associated field. If | 62 | // For each annotation, find its associated field. If |
| 69 | // it's a text field, set its value. | 63 | // it's a text field, set its value. |
| 70 | QPDFFormFieldObjectHelper ffh = | 64 | QPDFFormFieldObjectHelper ffh = |
| 71 | - afdh.getFieldForAnnotation(*annot_iter); | 65 | + afdh.getFieldForAnnotation(annot); |
| 72 | if (ffh.getFieldType() == "/Tx") { | 66 | if (ffh.getFieldType() == "/Tx") { |
| 73 | // Set the value. Passing false as the second | 67 | // Set the value. Passing false as the second |
| 74 | // value prevents qpdf from setting | 68 | // value prevents qpdf from setting |
| @@ -81,7 +75,7 @@ main(int argc, char* argv[]) | @@ -81,7 +75,7 @@ main(int argc, char* argv[]) | ||
| 81 | // additional details, please see comments in | 75 | // additional details, please see comments in |
| 82 | // QPDFFormFieldObjectHelper.hh for this method. | 76 | // QPDFFormFieldObjectHelper.hh for this method. |
| 83 | ffh.setV(value, false); | 77 | ffh.setV(value, false); |
| 84 | - ffh.generateAppearance(*annot_iter); | 78 | + ffh.generateAppearance(annot); |
| 85 | } | 79 | } |
| 86 | } | 80 | } |
| 87 | } | 81 | } |
examples/pdf-split-pages.cc
| @@ -27,10 +27,7 @@ process(char const* whoami, char const* infile, std::string outprefix) | @@ -27,10 +27,7 @@ process(char const* whoami, char const* infile, std::string outprefix) | ||
| 27 | int pageno_len = | 27 | int pageno_len = |
| 28 | QIntC::to_int(QUtil::uint_to_string(pages.size()).length()); | 28 | QIntC::to_int(QUtil::uint_to_string(pages.size()).length()); |
| 29 | int pageno = 0; | 29 | int pageno = 0; |
| 30 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 31 | - iter != pages.end(); | ||
| 32 | - ++iter) { | ||
| 33 | - QPDFPageObjectHelper& page(*iter); | 30 | + for (auto& page: pages) { |
| 34 | std::string outfile = | 31 | std::string outfile = |
| 35 | outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf"; | 32 | outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf"; |
| 36 | QPDF outpdf; | 33 | QPDF outpdf; |
fuzz/qpdf_fuzzer.cc
| @@ -134,10 +134,7 @@ FuzzHelper::testPages() | @@ -134,10 +134,7 @@ FuzzHelper::testPages() | ||
| 134 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | 134 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); |
| 135 | DiscardContents discard_contents; | 135 | DiscardContents discard_contents; |
| 136 | int pageno = 0; | 136 | int pageno = 0; |
| 137 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 138 | - iter != pages.end(); | ||
| 139 | - ++iter) { | ||
| 140 | - QPDFPageObjectHelper& page(*iter); | 137 | + for (auto& page: pages) { |
| 141 | ++pageno; | 138 | ++pageno; |
| 142 | try { | 139 | try { |
| 143 | page.coalesceContentStreams(); | 140 | page.coalesceContentStreams(); |
| @@ -150,11 +147,7 @@ FuzzHelper::testPages() | @@ -150,11 +147,7 @@ FuzzHelper::testPages() | ||
| 150 | 147 | ||
| 151 | std::vector<QPDFAnnotationObjectHelper> annotations = | 148 | std::vector<QPDFAnnotationObjectHelper> annotations = |
| 152 | afdh.getWidgetAnnotationsForPage(page); | 149 | afdh.getWidgetAnnotationsForPage(page); |
| 153 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter = | ||
| 154 | - annotations.begin(); | ||
| 155 | - annot_iter != annotations.end(); | ||
| 156 | - ++annot_iter) { | ||
| 157 | - QPDFAnnotationObjectHelper& aoh = *annot_iter; | 150 | + for (auto& aoh: annotations) { |
| 158 | afdh.getFieldForAnnotation(aoh); | 151 | afdh.getFieldForAnnotation(aoh); |
| 159 | } | 152 | } |
| 160 | } catch (QPDFExc& e) { | 153 | } catch (QPDFExc& e) { |
| @@ -172,11 +165,7 @@ FuzzHelper::testOutlines() | @@ -172,11 +165,7 @@ FuzzHelper::testOutlines() | ||
| 172 | queue.push_back(odh.getTopLevelOutlines()); | 165 | queue.push_back(odh.getTopLevelOutlines()); |
| 173 | while (!queue.empty()) { | 166 | while (!queue.empty()) { |
| 174 | std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin()); | 167 | std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin()); |
| 175 | - for (std::vector<QPDFOutlineObjectHelper>::iterator iter = | ||
| 176 | - outlines.begin(); | ||
| 177 | - iter != outlines.end(); | ||
| 178 | - ++iter) { | ||
| 179 | - QPDFOutlineObjectHelper& ol = *iter; | 168 | + for (auto& ol: outlines) { |
| 180 | ol.getDestPage(); | 169 | ol.getDestPage(); |
| 181 | queue.push_back(ol.getKids()); | 170 | queue.push_back(ol.getKids()); |
| 182 | } | 171 | } |
libqpdf/QPDF.cc
| @@ -262,11 +262,8 @@ QPDF::~QPDF() | @@ -262,11 +262,8 @@ QPDF::~QPDF() | ||
| 262 | // have the effect of undoing any modifications that may have been | 262 | // have the effect of undoing any modifications that may have been |
| 263 | // made to any of the objects. | 263 | // made to any of the objects. |
| 264 | this->m->xref_table.clear(); | 264 | this->m->xref_table.clear(); |
| 265 | - for (std::map<QPDFObjGen, ObjCache>::iterator iter = | ||
| 266 | - this->m->obj_cache.begin(); | ||
| 267 | - iter != this->m->obj_cache.end(); | ||
| 268 | - ++iter) { | ||
| 269 | - QPDFObject::ObjAccessor::releaseResolved((*iter).second.object.get()); | 265 | + for (auto const& iter: this->m->obj_cache) { |
| 266 | + QPDFObject::ObjAccessor::releaseResolved(iter.second.object.get()); | ||
| 270 | } | 267 | } |
| 271 | } | 268 | } |
| 272 | 269 | ||
| @@ -577,18 +574,13 @@ QPDF::reconstruct_xref(QPDFExc& e) | @@ -577,18 +574,13 @@ QPDF::reconstruct_xref(QPDFExc& e) | ||
| 577 | 574 | ||
| 578 | // Delete all references to type 1 (uncompressed) objects | 575 | // Delete all references to type 1 (uncompressed) objects |
| 579 | std::set<QPDFObjGen> to_delete; | 576 | std::set<QPDFObjGen> to_delete; |
| 580 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = | ||
| 581 | - this->m->xref_table.begin(); | ||
| 582 | - iter != this->m->xref_table.end(); | ||
| 583 | - ++iter) { | ||
| 584 | - if (((*iter).second).getType() == 1) { | ||
| 585 | - to_delete.insert((*iter).first); | 577 | + for (auto const& iter: this->m->xref_table) { |
| 578 | + if (iter.second.getType() == 1) { | ||
| 579 | + to_delete.insert(iter.first); | ||
| 586 | } | 580 | } |
| 587 | } | 581 | } |
| 588 | - for (std::set<QPDFObjGen>::iterator iter = to_delete.begin(); | ||
| 589 | - iter != to_delete.end(); | ||
| 590 | - ++iter) { | ||
| 591 | - this->m->xref_table.erase(*iter); | 582 | + for (auto const& iter: to_delete) { |
| 583 | + this->m->xref_table.erase(iter); | ||
| 592 | } | 584 | } |
| 593 | 585 | ||
| 594 | this->m->file->seek(0, SEEK_END); | 586 | this->m->file->seek(0, SEEK_END); |
| @@ -1015,10 +1007,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -1015,10 +1007,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 1015 | } | 1007 | } |
| 1016 | 1008 | ||
| 1017 | // Handle any deleted items now that we've read the /XRefStm. | 1009 | // Handle any deleted items now that we've read the /XRefStm. |
| 1018 | - for (std::vector<QPDFObjGen>::iterator iter = deleted_items.begin(); | ||
| 1019 | - iter != deleted_items.end(); | ||
| 1020 | - ++iter) { | ||
| 1021 | - QPDFObjGen& og = *iter; | 1010 | + for (auto const& og: deleted_items) { |
| 1022 | insertXrefEntry(og.getObj(), 0, 0, og.getGen()); | 1011 | insertXrefEntry(og.getObj(), 0, 0, og.getGen()); |
| 1023 | } | 1012 | } |
| 1024 | 1013 | ||
| @@ -1351,12 +1340,9 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | @@ -1351,12 +1340,9 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | ||
| 1351 | void | 1340 | void |
| 1352 | QPDF::showXRefTable() | 1341 | QPDF::showXRefTable() |
| 1353 | { | 1342 | { |
| 1354 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = | ||
| 1355 | - this->m->xref_table.begin(); | ||
| 1356 | - iter != this->m->xref_table.end(); | ||
| 1357 | - ++iter) { | ||
| 1358 | - QPDFObjGen const& og = (*iter).first; | ||
| 1359 | - QPDFXRefEntry const& entry = (*iter).second; | 1343 | + for (auto const& iter: this->m->xref_table) { |
| 1344 | + QPDFObjGen const& og = iter.first; | ||
| 1345 | + QPDFXRefEntry const& entry = iter.second; | ||
| 1360 | *this->m->out_stream << og.getObj() << "/" << og.getGen() << ": "; | 1346 | *this->m->out_stream << og.getObj() << "/" << og.getGen() << ": "; |
| 1361 | switch (entry.getType()) { | 1347 | switch (entry.getType()) { |
| 1362 | case 1: | 1348 | case 1: |
| @@ -1390,27 +1376,19 @@ QPDF::fixDanglingReferences(bool force) | @@ -1390,27 +1376,19 @@ QPDF::fixDanglingReferences(bool force) | ||
| 1390 | // Create a set of all known indirect objects including those | 1376 | // Create a set of all known indirect objects including those |
| 1391 | // we've previously resolved and those that we have created. | 1377 | // we've previously resolved and those that we have created. |
| 1392 | std::set<QPDFObjGen> to_process; | 1378 | std::set<QPDFObjGen> to_process; |
| 1393 | - for (std::map<QPDFObjGen, ObjCache>::iterator iter = | ||
| 1394 | - this->m->obj_cache.begin(); | ||
| 1395 | - iter != this->m->obj_cache.end(); | ||
| 1396 | - ++iter) { | ||
| 1397 | - to_process.insert((*iter).first); | 1379 | + for (auto const& iter: this->m->obj_cache) { |
| 1380 | + to_process.insert(iter.first); | ||
| 1398 | } | 1381 | } |
| 1399 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = | ||
| 1400 | - this->m->xref_table.begin(); | ||
| 1401 | - iter != this->m->xref_table.end(); | ||
| 1402 | - ++iter) { | ||
| 1403 | - to_process.insert((*iter).first); | 1382 | + for (auto const& iter: this->m->xref_table) { |
| 1383 | + to_process.insert(iter.first); | ||
| 1404 | } | 1384 | } |
| 1405 | 1385 | ||
| 1406 | // For each non-scalar item to process, put it in the queue. | 1386 | // For each non-scalar item to process, put it in the queue. |
| 1407 | std::list<QPDFObjectHandle> queue; | 1387 | std::list<QPDFObjectHandle> queue; |
| 1408 | queue.push_back(this->m->trailer); | 1388 | queue.push_back(this->m->trailer); |
| 1409 | - for (std::set<QPDFObjGen>::iterator iter = to_process.begin(); | ||
| 1410 | - iter != to_process.end(); | ||
| 1411 | - ++iter) { | 1389 | + for (auto const& iter: to_process) { |
| 1412 | QPDFObjectHandle obj = QPDFObjectHandle::Factory::newIndirect( | 1390 | QPDFObjectHandle obj = QPDFObjectHandle::Factory::newIndirect( |
| 1413 | - this, (*iter).getObj(), (*iter).getGen()); | 1391 | + this, iter.getObj(), iter.getGen()); |
| 1414 | if (obj.isDictionary() || obj.isArray()) { | 1392 | if (obj.isDictionary() || obj.isArray()) { |
| 1415 | queue.push_back(obj); | 1393 | queue.push_back(obj); |
| 1416 | } else if (obj.isStream()) { | 1394 | } else if (obj.isStream()) { |
| @@ -1428,21 +1406,15 @@ QPDF::fixDanglingReferences(bool force) | @@ -1428,21 +1406,15 @@ QPDF::fixDanglingReferences(bool force) | ||
| 1428 | if (obj.isDictionary()) { | 1406 | if (obj.isDictionary()) { |
| 1429 | std::map<std::string, QPDFObjectHandle> members = | 1407 | std::map<std::string, QPDFObjectHandle> members = |
| 1430 | obj.getDictAsMap(); | 1408 | obj.getDictAsMap(); |
| 1431 | - for (std::map<std::string, QPDFObjectHandle>::iterator iter = | ||
| 1432 | - members.begin(); | ||
| 1433 | - iter != members.end(); | ||
| 1434 | - ++iter) { | ||
| 1435 | - to_check.push_back((*iter).second); | 1409 | + for (auto const& iter: members) { |
| 1410 | + to_check.push_back(iter.second); | ||
| 1436 | } | 1411 | } |
| 1437 | } else if (obj.isArray()) { | 1412 | } else if (obj.isArray()) { |
| 1438 | QPDF_Array* arr = dynamic_cast<QPDF_Array*>( | 1413 | QPDF_Array* arr = dynamic_cast<QPDF_Array*>( |
| 1439 | QPDFObjectHandle::ObjAccessor::getObject(obj).get()); | 1414 | QPDFObjectHandle::ObjAccessor::getObject(obj).get()); |
| 1440 | arr->addExplicitElementsToList(to_check); | 1415 | arr->addExplicitElementsToList(to_check); |
| 1441 | } | 1416 | } |
| 1442 | - for (std::list<QPDFObjectHandle>::iterator iter = to_check.begin(); | ||
| 1443 | - iter != to_check.end(); | ||
| 1444 | - ++iter) { | ||
| 1445 | - QPDFObjectHandle sub = *iter; | 1417 | + for (auto sub: to_check) { |
| 1446 | if (sub.isIndirect()) { | 1418 | if (sub.isIndirect()) { |
| 1447 | if (sub.getOwningQPDF() == this) { | 1419 | if (sub.getOwningQPDF() == this) { |
| 1448 | QPDFObjGen og(sub.getObjGen()); | 1420 | QPDFObjGen og(sub.getObjGen()); |
| @@ -1480,11 +1452,8 @@ QPDF::getAllObjects() | @@ -1480,11 +1452,8 @@ QPDF::getAllObjects() | ||
| 1480 | // object cache. | 1452 | // object cache. |
| 1481 | fixDanglingReferences(true); | 1453 | fixDanglingReferences(true); |
| 1482 | std::vector<QPDFObjectHandle> result; | 1454 | std::vector<QPDFObjectHandle> result; |
| 1483 | - for (std::map<QPDFObjGen, ObjCache>::iterator iter = | ||
| 1484 | - this->m->obj_cache.begin(); | ||
| 1485 | - iter != this->m->obj_cache.end(); | ||
| 1486 | - ++iter) { | ||
| 1487 | - QPDFObjGen const& og = (*iter).first; | 1455 | + for (auto const& iter: this->m->obj_cache) { |
| 1456 | + QPDFObjGen const& og = iter.first; | ||
| 1488 | result.push_back( | 1457 | result.push_back( |
| 1489 | // line-break | 1458 | // line-break |
| 1490 | QPDFObjectHandle::Factory::newIndirect( | 1459 | QPDFObjectHandle::Factory::newIndirect( |
| @@ -1733,12 +1702,9 @@ QPDF::recoverStreamLength( | @@ -1733,12 +1702,9 @@ QPDF::recoverStreamLength( | ||
| 1733 | QPDFObjGen this_obj(0, 0); | 1702 | QPDFObjGen this_obj(0, 0); |
| 1734 | 1703 | ||
| 1735 | // Make sure this is inside this object | 1704 | // Make sure this is inside this object |
| 1736 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = | ||
| 1737 | - this->m->xref_table.begin(); | ||
| 1738 | - iter != this->m->xref_table.end(); | ||
| 1739 | - ++iter) { | ||
| 1740 | - QPDFObjGen const& og = (*iter).first; | ||
| 1741 | - QPDFXRefEntry const& entry = (*iter).second; | 1705 | + for (auto const& iter: this->m->xref_table) { |
| 1706 | + QPDFObjGen const& og = iter.first; | ||
| 1707 | + QPDFXRefEntry const& entry = iter.second; | ||
| 1742 | if (entry.getType() == 1) { | 1708 | if (entry.getType() == 1) { |
| 1743 | qpdf_offset_t obj_offset = entry.getOffset(); | 1709 | qpdf_offset_t obj_offset = entry.getOffset(); |
| 1744 | if ((obj_offset > stream_offset) && | 1710 | if ((obj_offset > stream_offset) && |
| @@ -2157,15 +2123,13 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -2157,15 +2123,13 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 2157 | // that some objects stored here might have been overridden by new | 2123 | // that some objects stored here might have been overridden by new |
| 2158 | // objects appended to the file, so it is necessary to recheck the | 2124 | // objects appended to the file, so it is necessary to recheck the |
| 2159 | // xref table and only cache what would actually be resolved here. | 2125 | // xref table and only cache what would actually be resolved here. |
| 2160 | - for (std::map<int, int>::iterator iter = offsets.begin(); | ||
| 2161 | - iter != offsets.end(); | ||
| 2162 | - ++iter) { | ||
| 2163 | - int obj = (*iter).first; | 2126 | + for (auto const& iter: offsets) { |
| 2127 | + int obj = iter.first; | ||
| 2164 | QPDFObjGen og(obj, 0); | 2128 | QPDFObjGen og(obj, 0); |
| 2165 | QPDFXRefEntry const& entry = this->m->xref_table[og]; | 2129 | QPDFXRefEntry const& entry = this->m->xref_table[og]; |
| 2166 | if ((entry.getType() == 2) && | 2130 | if ((entry.getType() == 2) && |
| 2167 | (entry.getObjStreamNumber() == obj_stream_number)) { | 2131 | (entry.getObjStreamNumber() == obj_stream_number)) { |
| 2168 | - int offset = (*iter).second; | 2132 | + int offset = iter.second; |
| 2169 | input->seek(offset, SEEK_SET); | 2133 | input->seek(offset, SEEK_SET); |
| 2170 | QPDFObjectHandle oh = readObject(input, "", obj, 0, true); | 2134 | QPDFObjectHandle oh = readObject(input, "", obj, 0, true); |
| 2171 | this->m->obj_cache[og] = ObjCache( | 2135 | this->m->obj_cache[og] = ObjCache( |
| @@ -2317,11 +2281,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | @@ -2317,11 +2281,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | ||
| 2317 | } | 2281 | } |
| 2318 | 2282 | ||
| 2319 | // Copy any new objects and replace the reservations. | 2283 | // Copy any new objects and replace the reservations. |
| 2320 | - for (std::vector<QPDFObjectHandle>::iterator iter = | ||
| 2321 | - obj_copier.to_copy.begin(); | ||
| 2322 | - iter != obj_copier.to_copy.end(); | ||
| 2323 | - ++iter) { | ||
| 2324 | - QPDFObjectHandle& to_copy = *iter; | 2284 | + for (auto& to_copy: obj_copier.to_copy) { |
| 2325 | QPDFObjectHandle copy = | 2285 | QPDFObjectHandle copy = |
| 2326 | replaceForeignIndirectObjects(to_copy, obj_copier, true); | 2286 | replaceForeignIndirectObjects(to_copy, obj_copier, true); |
| 2327 | if (!to_copy.isStream()) { | 2287 | if (!to_copy.isStream()) { |
| @@ -2365,8 +2325,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2365,8 +2325,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2365 | } | 2325 | } |
| 2366 | QTC::TC("qpdf", "QPDF copy indirect"); | 2326 | QTC::TC("qpdf", "QPDF copy indirect"); |
| 2367 | obj_copier.visiting.insert(foreign_og); | 2327 | obj_copier.visiting.insert(foreign_og); |
| 2368 | - std::map<QPDFObjGen, QPDFObjectHandle>::iterator mapping = | ||
| 2369 | - obj_copier.object_map.find(foreign_og); | 2328 | + auto mapping = obj_copier.object_map.find(foreign_og); |
| 2370 | if (mapping == obj_copier.object_map.end()) { | 2329 | if (mapping == obj_copier.object_map.end()) { |
| 2371 | obj_copier.to_copy.push_back(foreign); | 2330 | obj_copier.to_copy.push_back(foreign); |
| 2372 | QPDFObjectHandle reservation; | 2331 | QPDFObjectHandle reservation; |
| @@ -2388,10 +2347,8 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2388,10 +2347,8 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2388 | } else if (foreign.isDictionary()) { | 2347 | } else if (foreign.isDictionary()) { |
| 2389 | QTC::TC("qpdf", "QPDF reserve dictionary"); | 2348 | QTC::TC("qpdf", "QPDF reserve dictionary"); |
| 2390 | std::set<std::string> keys = foreign.getKeys(); | 2349 | std::set<std::string> keys = foreign.getKeys(); |
| 2391 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 2392 | - iter != keys.end(); | ||
| 2393 | - ++iter) { | ||
| 2394 | - reserveObjects(foreign.getKey(*iter), obj_copier, false); | 2350 | + for (auto const& key: keys) { |
| 2351 | + reserveObjects(foreign.getKey(key), obj_copier, false); | ||
| 2395 | } | 2352 | } |
| 2396 | } else if (foreign.isStream()) { | 2353 | } else if (foreign.isStream()) { |
| 2397 | QTC::TC("qpdf", "QPDF reserve stream"); | 2354 | QTC::TC("qpdf", "QPDF reserve stream"); |
| @@ -2412,8 +2369,7 @@ QPDF::replaceForeignIndirectObjects( | @@ -2412,8 +2369,7 @@ QPDF::replaceForeignIndirectObjects( | ||
| 2412 | if ((!top) && foreign.isIndirect()) { | 2369 | if ((!top) && foreign.isIndirect()) { |
| 2413 | QTC::TC("qpdf", "QPDF replace indirect"); | 2370 | QTC::TC("qpdf", "QPDF replace indirect"); |
| 2414 | QPDFObjGen foreign_og(foreign.getObjGen()); | 2371 | QPDFObjGen foreign_og(foreign.getObjGen()); |
| 2415 | - std::map<QPDFObjGen, QPDFObjectHandle>::iterator mapping = | ||
| 2416 | - obj_copier.object_map.find(foreign_og); | 2372 | + auto mapping = obj_copier.object_map.find(foreign_og); |
| 2417 | if (mapping == obj_copier.object_map.end()) { | 2373 | if (mapping == obj_copier.object_map.end()) { |
| 2418 | // This case would occur if this is a reference to a Page | 2374 | // This case would occur if this is a reference to a Page |
| 2419 | // or Pages object that we didn't traverse into. | 2375 | // or Pages object that we didn't traverse into. |
| @@ -2657,12 +2613,9 @@ QPDF::getXRefTable() | @@ -2657,12 +2613,9 @@ QPDF::getXRefTable() | ||
| 2657 | void | 2613 | void |
| 2658 | QPDF::getObjectStreamData(std::map<int, int>& omap) | 2614 | QPDF::getObjectStreamData(std::map<int, int>& omap) |
| 2659 | { | 2615 | { |
| 2660 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = | ||
| 2661 | - this->m->xref_table.begin(); | ||
| 2662 | - iter != this->m->xref_table.end(); | ||
| 2663 | - ++iter) { | ||
| 2664 | - QPDFObjGen const& og = (*iter).first; | ||
| 2665 | - QPDFXRefEntry const& entry = (*iter).second; | 2616 | + for (auto const& iter: this->m->xref_table) { |
| 2617 | + QPDFObjGen const& og = iter.first; | ||
| 2618 | + QPDFXRefEntry const& entry = iter.second; | ||
| 2666 | if (entry.getType() == 2) { | 2619 | if (entry.getType() == 2) { |
| 2667 | omap[og.getObj()] = entry.getObjStreamNumber(); | 2620 | omap[og.getObj()] = entry.getObjStreamNumber(); |
| 2668 | } | 2621 | } |
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -182,11 +182,8 @@ QPDFAcroFormDocumentHelper::getFormFields() | @@ -182,11 +182,8 @@ QPDFAcroFormDocumentHelper::getFormFields() | ||
| 182 | { | 182 | { |
| 183 | analyze(); | 183 | analyze(); |
| 184 | std::vector<QPDFFormFieldObjectHelper> result; | 184 | std::vector<QPDFFormFieldObjectHelper> result; |
| 185 | - for (std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>>::iterator | ||
| 186 | - iter = this->m->field_to_annotations.begin(); | ||
| 187 | - iter != this->m->field_to_annotations.end(); | ||
| 188 | - ++iter) { | ||
| 189 | - result.push_back(this->qpdf.getObjectByObjGen((*iter).first)); | 185 | + for (auto const& iter: this->m->field_to_annotations) { |
| 186 | + result.push_back(this->qpdf.getObjectByObjGen(iter.first)); | ||
| 190 | } | 187 | } |
| 191 | return result; | 188 | return result; |
| 192 | } | 189 | } |
| @@ -299,17 +296,11 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -299,17 +296,11 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 299 | 296 | ||
| 300 | QPDFPageDocumentHelper dh(this->qpdf); | 297 | QPDFPageDocumentHelper dh(this->qpdf); |
| 301 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 298 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 302 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 303 | - iter != pages.end(); | ||
| 304 | - ++iter) { | ||
| 305 | - QPDFPageObjectHelper ph(*iter); | 299 | + for (auto const& ph: pages) { |
| 306 | std::vector<QPDFAnnotationObjectHelper> annots = | 300 | std::vector<QPDFAnnotationObjectHelper> annots = |
| 307 | getWidgetAnnotationsForPage(ph); | 301 | getWidgetAnnotationsForPage(ph); |
| 308 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator i2 = | ||
| 309 | - annots.begin(); | ||
| 310 | - i2 != annots.end(); | ||
| 311 | - ++i2) { | ||
| 312 | - QPDFObjectHandle annot((*i2).getObjectHandle()); | 302 | + for (auto const& iter: annots) { |
| 303 | + QPDFObjectHandle annot(iter.getObjectHandle()); | ||
| 313 | QPDFObjGen og(annot.getObjGen()); | 304 | QPDFObjGen og(annot.getObjGen()); |
| 314 | if (this->m->annotation_to_field.count(og) == 0) { | 305 | if (this->m->annotation_to_field.count(og) == 0) { |
| 315 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget"); | 306 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget"); |
| @@ -462,16 +453,10 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() | @@ -462,16 +453,10 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() | ||
| 462 | 453 | ||
| 463 | QPDFPageDocumentHelper pdh(this->qpdf); | 454 | QPDFPageDocumentHelper pdh(this->qpdf); |
| 464 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | 455 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); |
| 465 | - for (std::vector<QPDFPageObjectHelper>::iterator page_iter = pages.begin(); | ||
| 466 | - page_iter != pages.end(); | ||
| 467 | - ++page_iter) { | 456 | + for (auto const& page: pages) { |
| 468 | std::vector<QPDFAnnotationObjectHelper> annotations = | 457 | std::vector<QPDFAnnotationObjectHelper> annotations = |
| 469 | - getWidgetAnnotationsForPage(*page_iter); | ||
| 470 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter = | ||
| 471 | - annotations.begin(); | ||
| 472 | - annot_iter != annotations.end(); | ||
| 473 | - ++annot_iter) { | ||
| 474 | - QPDFAnnotationObjectHelper& aoh = *annot_iter; | 458 | + getWidgetAnnotationsForPage(page); |
| 459 | + for (auto& aoh: annotations) { | ||
| 475 | QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh); | 460 | QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh); |
| 476 | if (ffh.getFieldType() == "/Btn") { | 461 | if (ffh.getFieldType() == "/Btn") { |
| 477 | // Rather than generating appearances for button | 462 | // Rather than generating appearances for button |
libqpdf/QPDFArgParser.cc
| @@ -294,10 +294,7 @@ QPDFArgParser::handleBashArguments() | @@ -294,10 +294,7 @@ QPDFArgParser::handleBashArguments() | ||
| 294 | bool last_was_backslash = false; | 294 | bool last_was_backslash = false; |
| 295 | enum { st_top, st_squote, st_dquote } state = st_top; | 295 | enum { st_top, st_squote, st_dquote } state = st_top; |
| 296 | std::string arg; | 296 | std::string arg; |
| 297 | - for (std::string::iterator iter = this->m->bash_line.begin(); | ||
| 298 | - iter != this->m->bash_line.end(); | ||
| 299 | - ++iter) { | ||
| 300 | - char ch = (*iter); | 297 | + for (char ch: this->m->bash_line) { |
| 301 | if (last_was_backslash) { | 298 | if (last_was_backslash) { |
| 302 | arg.append(1, ch); | 299 | arg.append(1, ch); |
| 303 | last_was_backslash = false; | 300 | last_was_backslash = false; |
| @@ -560,13 +557,14 @@ QPDFArgParser::parseArgs() | @@ -560,13 +557,14 @@ QPDFArgParser::parseArgs() | ||
| 560 | } else if (!oe.choices.empty()) { | 557 | } else if (!oe.choices.empty()) { |
| 561 | QTC::TC("libtests", "QPDFArgParser required choices"); | 558 | QTC::TC("libtests", "QPDFArgParser required choices"); |
| 562 | message += "{"; | 559 | message += "{"; |
| 563 | - for (std::set<std::string>::iterator iter = oe.choices.begin(); | ||
| 564 | - iter != oe.choices.end(); | ||
| 565 | - ++iter) { | ||
| 566 | - if (iter != oe.choices.begin()) { | 560 | + bool first = true; |
| 561 | + for (auto const& choice: oe.choices) { | ||
| 562 | + if (first) { | ||
| 563 | + first = false; | ||
| 564 | + } else { | ||
| 567 | message += ","; | 565 | message += ","; |
| 568 | } | 566 | } |
| 569 | - message += *iter; | 567 | + message += choice; |
| 570 | } | 568 | } |
| 571 | message += "}"; | 569 | message += "}"; |
| 572 | } else if (!oe.parameter_name.empty()) { | 570 | } else if (!oe.parameter_name.empty()) { |
| @@ -624,11 +622,9 @@ QPDFArgParser::addChoicesToCompletions( | @@ -624,11 +622,9 @@ QPDFArgParser::addChoicesToCompletions( | ||
| 624 | { | 622 | { |
| 625 | if (option_table.count(option) != 0) { | 623 | if (option_table.count(option) != 0) { |
| 626 | OptionEntry& oe = option_table[option]; | 624 | OptionEntry& oe = option_table[option]; |
| 627 | - for (std::set<std::string>::iterator iter = oe.choices.begin(); | ||
| 628 | - iter != oe.choices.end(); | ||
| 629 | - ++iter) { | 625 | + for (auto const& choice: oe.choices) { |
| 630 | QTC::TC("libtests", "QPDFArgParser complete choices"); | 626 | QTC::TC("libtests", "QPDFArgParser complete choices"); |
| 631 | - this->m->completions.insert(extra_prefix + *iter); | 627 | + this->m->completions.insert(extra_prefix + choice); |
| 632 | } | 628 | } |
| 633 | } | 629 | } |
| 634 | } | 630 | } |
| @@ -714,11 +710,9 @@ QPDFArgParser::handleCompletion() | @@ -714,11 +710,9 @@ QPDFArgParser::handleCompletion() | ||
| 714 | } | 710 | } |
| 715 | } | 711 | } |
| 716 | std::string prefix = extra_prefix + this->m->bash_cur; | 712 | std::string prefix = extra_prefix + this->m->bash_cur; |
| 717 | - for (std::set<std::string>::iterator iter = this->m->completions.begin(); | ||
| 718 | - iter != this->m->completions.end(); | ||
| 719 | - ++iter) { | ||
| 720 | - if (prefix.empty() || ((*iter).substr(0, prefix.length()) == prefix)) { | ||
| 721 | - std::cout << *iter << std::endl; | 713 | + for (auto const& iter: this->m->completions) { |
| 714 | + if (prefix.empty() || (iter.substr(0, prefix.length()) == prefix)) { | ||
| 715 | + std::cout << iter << std::endl; | ||
| 722 | } | 716 | } |
| 723 | } | 717 | } |
| 724 | exit(0); | 718 | exit(0); |
libqpdf/QPDFJob.cc
| @@ -852,10 +852,7 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -852,10 +852,7 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 852 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 852 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 853 | DiscardContents discard_contents; | 853 | DiscardContents discard_contents; |
| 854 | int pageno = 0; | 854 | int pageno = 0; |
| 855 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 856 | - iter != pages.end(); | ||
| 857 | - ++iter) { | ||
| 858 | - QPDFPageObjectHelper& page(*iter); | 855 | + for (auto& page: pages) { |
| 859 | ++pageno; | 856 | ++pageno; |
| 860 | try { | 857 | try { |
| 861 | page.parseContents(&discard_contents); | 858 | page.parseContents(&discard_contents); |
| @@ -927,10 +924,7 @@ QPDFJob::doShowPages(QPDF& pdf) | @@ -927,10 +924,7 @@ QPDFJob::doShowPages(QPDF& pdf) | ||
| 927 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 924 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 928 | int pageno = 0; | 925 | int pageno = 0; |
| 929 | auto& cout = *this->m->cout; | 926 | auto& cout = *this->m->cout; |
| 930 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 931 | - iter != pages.end(); | ||
| 932 | - ++iter) { | ||
| 933 | - QPDFPageObjectHelper& ph(*iter); | 927 | + for (auto& ph: pages) { |
| 934 | QPDFObjectHandle page = ph.getObjectHandle(); | 928 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 935 | ++pageno; | 929 | ++pageno; |
| 936 | 930 | ||
| @@ -1058,12 +1052,9 @@ QPDFJob::doJSONObjects(QPDF& pdf, JSON& j) | @@ -1058,12 +1052,9 @@ QPDFJob::doJSONObjects(QPDF& pdf, JSON& j) | ||
| 1058 | "trailer", pdf.getTrailer().getJSON(true)); | 1052 | "trailer", pdf.getTrailer().getJSON(true)); |
| 1059 | } | 1053 | } |
| 1060 | std::vector<QPDFObjectHandle> objects = pdf.getAllObjects(); | 1054 | std::vector<QPDFObjectHandle> objects = pdf.getAllObjects(); |
| 1061 | - for (std::vector<QPDFObjectHandle>::iterator iter = objects.begin(); | ||
| 1062 | - iter != objects.end(); | ||
| 1063 | - ++iter) { | ||
| 1064 | - if (all_objects || wanted_og.count((*iter).getObjGen())) { | ||
| 1065 | - j_objects.addDictionaryMember( | ||
| 1066 | - (*iter).unparse(), (*iter).getJSON(true)); | 1055 | + for (auto& obj: objects) { |
| 1056 | + if (all_objects || wanted_og.count(obj.getObjGen())) { | ||
| 1057 | + j_objects.addDictionaryMember(obj.unparse(), obj.getJSON(true)); | ||
| 1067 | } | 1058 | } |
| 1068 | } | 1059 | } |
| 1069 | } | 1060 | } |
| @@ -1106,12 +1097,10 @@ QPDFJob::doJSONPages(QPDF& pdf, JSON& j) | @@ -1106,12 +1097,10 @@ QPDFJob::doJSONPages(QPDF& pdf, JSON& j) | ||
| 1106 | QPDFOutlineDocumentHelper odh(pdf); | 1097 | QPDFOutlineDocumentHelper odh(pdf); |
| 1107 | pdh.pushInheritedAttributesToPage(); | 1098 | pdh.pushInheritedAttributesToPage(); |
| 1108 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | 1099 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); |
| 1109 | - int pageno = 0; | ||
| 1110 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 1111 | - iter != pages.end(); | ||
| 1112 | - ++iter, ++pageno) { | 1100 | + int pageno = -1; |
| 1101 | + for (auto& ph: pages) { | ||
| 1102 | + ++pageno; | ||
| 1113 | JSON j_page = j_pages.addArrayElement(JSON::makeDictionary()); | 1103 | JSON j_page = j_pages.addArrayElement(JSON::makeDictionary()); |
| 1114 | - QPDFPageObjectHelper& ph(*iter); | ||
| 1115 | QPDFObjectHandle page = ph.getObjectHandle(); | 1104 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 1116 | j_page.addDictionaryMember("object", page.getJSON()); | 1105 | j_page.addDictionaryMember("object", page.getJSON()); |
| 1117 | JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray()); | 1106 | JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray()); |
| @@ -1161,17 +1150,14 @@ QPDFJob::doJSONPages(QPDF& pdf, JSON& j) | @@ -1161,17 +1150,14 @@ QPDFJob::doJSONPages(QPDF& pdf, JSON& j) | ||
| 1161 | j_page.addDictionaryMember("outlines", JSON::makeArray()); | 1150 | j_page.addDictionaryMember("outlines", JSON::makeArray()); |
| 1162 | std::vector<QPDFOutlineObjectHelper> outlines = | 1151 | std::vector<QPDFOutlineObjectHelper> outlines = |
| 1163 | odh.getOutlinesForPage(page.getObjGen()); | 1152 | odh.getOutlinesForPage(page.getObjGen()); |
| 1164 | - for (std::vector<QPDFOutlineObjectHelper>::iterator oiter = | ||
| 1165 | - outlines.begin(); | ||
| 1166 | - oiter != outlines.end(); | ||
| 1167 | - ++oiter) { | 1153 | + for (auto& oiter: outlines) { |
| 1168 | JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary()); | 1154 | JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary()); |
| 1169 | j_outline.addDictionaryMember( | 1155 | j_outline.addDictionaryMember( |
| 1170 | - "object", (*oiter).getObjectHandle().getJSON()); | 1156 | + "object", oiter.getObjectHandle().getJSON()); |
| 1171 | j_outline.addDictionaryMember( | 1157 | j_outline.addDictionaryMember( |
| 1172 | - "title", JSON::makeString((*oiter).getTitle())); | 1158 | + "title", JSON::makeString(oiter.getTitle())); |
| 1173 | j_outline.addDictionaryMember( | 1159 | j_outline.addDictionaryMember( |
| 1174 | - "dest", (*oiter).getDest().getJSON(true)); | 1160 | + "dest", oiter.getDest().getJSON(true)); |
| 1175 | } | 1161 | } |
| 1176 | j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno)); | 1162 | j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno)); |
| 1177 | } | 1163 | } |
| @@ -1188,10 +1174,8 @@ QPDFJob::doJSONPageLabels(QPDF& pdf, JSON& j) | @@ -1188,10 +1174,8 @@ QPDFJob::doJSONPageLabels(QPDF& pdf, JSON& j) | ||
| 1188 | std::vector<QPDFObjectHandle> labels; | 1174 | std::vector<QPDFObjectHandle> labels; |
| 1189 | pldh.getLabelsForPageRange( | 1175 | pldh.getLabelsForPageRange( |
| 1190 | 0, QIntC::to_int(pages.size()) - 1, 0, labels); | 1176 | 0, QIntC::to_int(pages.size()) - 1, 0, labels); |
| 1191 | - for (std::vector<QPDFObjectHandle>::iterator iter = labels.begin(); | ||
| 1192 | - iter != labels.end(); | ||
| 1193 | - ++iter) { | ||
| 1194 | - std::vector<QPDFObjectHandle>::iterator next = iter; | 1177 | + for (auto iter = labels.begin(); iter != labels.end(); ++iter) { |
| 1178 | + auto next = iter; | ||
| 1195 | ++next; | 1179 | ++next; |
| 1196 | if (next == labels.end()) { | 1180 | if (next == labels.end()) { |
| 1197 | // This can't happen, so ignore it. This could only | 1181 | // This can't happen, so ignore it. This could only |
| @@ -1213,10 +1197,7 @@ add_outlines_to_json( | @@ -1213,10 +1197,7 @@ add_outlines_to_json( | ||
| 1213 | JSON& j, | 1197 | JSON& j, |
| 1214 | std::map<QPDFObjGen, int>& page_numbers) | 1198 | std::map<QPDFObjGen, int>& page_numbers) |
| 1215 | { | 1199 | { |
| 1216 | - for (std::vector<QPDFOutlineObjectHelper>::iterator iter = outlines.begin(); | ||
| 1217 | - iter != outlines.end(); | ||
| 1218 | - ++iter) { | ||
| 1219 | - QPDFOutlineObjectHelper& ol = *iter; | 1200 | + for (auto& ol: outlines) { |
| 1220 | JSON jo = j.addArrayElement(JSON::makeDictionary()); | 1201 | JSON jo = j.addArrayElement(JSON::makeDictionary()); |
| 1221 | jo.addDictionaryMember("object", ol.getObjectHandle().getJSON()); | 1202 | jo.addDictionaryMember("object", ol.getObjectHandle().getJSON()); |
| 1222 | jo.addDictionaryMember("title", JSON::makeString(ol.getTitle())); | 1203 | jo.addDictionaryMember("title", JSON::makeString(ol.getTitle())); |
| @@ -1243,10 +1224,8 @@ QPDFJob::doJSONOutlines(QPDF& pdf, JSON& j) | @@ -1243,10 +1224,8 @@ QPDFJob::doJSONOutlines(QPDF& pdf, JSON& j) | ||
| 1243 | QPDFPageDocumentHelper dh(pdf); | 1224 | QPDFPageDocumentHelper dh(pdf); |
| 1244 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 1225 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 1245 | int n = 0; | 1226 | int n = 0; |
| 1246 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 1247 | - iter != pages.end(); | ||
| 1248 | - ++iter) { | ||
| 1249 | - QPDFObjectHandle oh = (*iter).getObjectHandle(); | 1227 | + for (auto const& ph: pages) { |
| 1228 | + QPDFObjectHandle oh = ph.getObjectHandle(); | ||
| 1250 | page_numbers[oh.getObjGen()] = ++n; | 1229 | page_numbers[oh.getObjGen()] = ++n; |
| 1251 | } | 1230 | } |
| 1252 | 1231 | ||
| @@ -1268,17 +1247,11 @@ QPDFJob::doJSONAcroform(QPDF& pdf, JSON& j) | @@ -1268,17 +1247,11 @@ QPDFJob::doJSONAcroform(QPDF& pdf, JSON& j) | ||
| 1268 | QPDFPageDocumentHelper pdh(pdf); | 1247 | QPDFPageDocumentHelper pdh(pdf); |
| 1269 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | 1248 | std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); |
| 1270 | int pagepos1 = 0; | 1249 | int pagepos1 = 0; |
| 1271 | - for (std::vector<QPDFPageObjectHelper>::iterator page_iter = pages.begin(); | ||
| 1272 | - page_iter != pages.end(); | ||
| 1273 | - ++page_iter) { | 1250 | + for (auto const& page: pages) { |
| 1274 | ++pagepos1; | 1251 | ++pagepos1; |
| 1275 | std::vector<QPDFAnnotationObjectHelper> annotations = | 1252 | std::vector<QPDFAnnotationObjectHelper> annotations = |
| 1276 | - afdh.getWidgetAnnotationsForPage(*page_iter); | ||
| 1277 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter = | ||
| 1278 | - annotations.begin(); | ||
| 1279 | - annot_iter != annotations.end(); | ||
| 1280 | - ++annot_iter) { | ||
| 1281 | - QPDFAnnotationObjectHelper& aoh = *annot_iter; | 1253 | + afdh.getWidgetAnnotationsForPage(page); |
| 1254 | + for (auto& aoh: annotations) { | ||
| 1282 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); | 1255 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); |
| 1283 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); | 1256 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); |
| 1284 | j_field.addDictionaryMember( | 1257 | j_field.addDictionaryMember( |
| @@ -1314,10 +1287,8 @@ QPDFJob::doJSONAcroform(QPDF& pdf, JSON& j) | @@ -1314,10 +1287,8 @@ QPDFJob::doJSONAcroform(QPDF& pdf, JSON& j) | ||
| 1314 | JSON j_choices = | 1287 | JSON j_choices = |
| 1315 | j_field.addDictionaryMember("choices", JSON::makeArray()); | 1288 | j_field.addDictionaryMember("choices", JSON::makeArray()); |
| 1316 | std::vector<std::string> choices = ffh.getChoices(); | 1289 | std::vector<std::string> choices = ffh.getChoices(); |
| 1317 | - for (std::vector<std::string>::iterator iter = choices.begin(); | ||
| 1318 | - iter != choices.end(); | ||
| 1319 | - ++iter) { | ||
| 1320 | - j_choices.addArrayElement(JSON::makeString(*iter)); | 1290 | + for (auto const& choice: choices) { |
| 1291 | + j_choices.addArrayElement(JSON::makeString(choice)); | ||
| 1321 | } | 1292 | } |
| 1322 | JSON j_annot = j_field.addDictionaryMember( | 1293 | JSON j_annot = j_field.addDictionaryMember( |
| 1323 | "annotation", JSON::makeDictionary()); | 1294 | "annotation", JSON::makeDictionary()); |
| @@ -1688,10 +1659,8 @@ Please report this as a bug at\n\ | @@ -1688,10 +1659,8 @@ Please report this as a bug at\n\ | ||
| 1688 | https://github.com/qpdf/qpdf/issues/new\n\ | 1659 | https://github.com/qpdf/qpdf/issues/new\n\ |
| 1689 | ideally with the file that caused the error and the output below. Thanks!\n\ | 1660 | ideally with the file that caused the error and the output below. Thanks!\n\ |
| 1690 | \n"; | 1661 | \n"; |
| 1691 | - for (std::list<std::string>::iterator iter = errors.begin(); | ||
| 1692 | - iter != errors.end(); | ||
| 1693 | - ++iter) { | ||
| 1694 | - *(this->m->cerr) << (*iter) << std::endl; | 1662 | + for (auto const& error: errors) { |
| 1663 | + *(this->m->cerr) << error << std::endl; | ||
| 1695 | } | 1664 | } |
| 1696 | } | 1665 | } |
| 1697 | 1666 | ||
| @@ -1816,10 +1785,8 @@ QPDFJob::doProcess( | @@ -1816,10 +1785,8 @@ QPDFJob::doProcess( | ||
| 1816 | QUtil::possible_repaired_encodings(password); | 1785 | QUtil::possible_repaired_encodings(password); |
| 1817 | // Represent to char const*, as required by the QPDF class. | 1786 | // Represent to char const*, as required by the QPDF class. |
| 1818 | std::vector<char const*> passwords; | 1787 | std::vector<char const*> passwords; |
| 1819 | - for (std::vector<std::string>::iterator iter = passwords_str.begin(); | ||
| 1820 | - iter != passwords_str.end(); | ||
| 1821 | - ++iter) { | ||
| 1822 | - passwords.push_back((*iter).c_str()); | 1788 | + for (auto const& iter: passwords_str) { |
| 1789 | + passwords.push_back(iter.c_str()); | ||
| 1823 | } | 1790 | } |
| 1824 | // We always try the supplied password first because it is the | 1791 | // We always try the supplied password first because it is the |
| 1825 | // first string returned by possible_repaired_encodings. If there | 1792 | // first string returned by possible_repaired_encodings. If there |
| @@ -1835,13 +1802,11 @@ QPDFJob::doProcess( | @@ -1835,13 +1802,11 @@ QPDFJob::doProcess( | ||
| 1835 | // attempt, which, like the first attempt, will be with the | 1802 | // attempt, which, like the first attempt, will be with the |
| 1836 | // supplied password. | 1803 | // supplied password. |
| 1837 | bool warned = false; | 1804 | bool warned = false; |
| 1838 | - for (std::vector<char const*>::iterator iter = passwords.begin(); | ||
| 1839 | - iter != passwords.end(); | ||
| 1840 | - ++iter) { | 1805 | + for (auto iter = passwords.begin(); iter != passwords.end(); ++iter) { |
| 1841 | try { | 1806 | try { |
| 1842 | return doProcessOnce(fn, *iter, empty, used_for_input); | 1807 | return doProcessOnce(fn, *iter, empty, used_for_input); |
| 1843 | } catch (QPDFExc& e) { | 1808 | } catch (QPDFExc& e) { |
| 1844 | - std::vector<char const*>::iterator next = iter; | 1809 | + auto next = iter; |
| 1845 | ++next; | 1810 | ++next; |
| 1846 | if (next == passwords.end()) { | 1811 | if (next == passwords.end()) { |
| 1847 | throw e; | 1812 | throw e; |
| @@ -1961,10 +1926,7 @@ QPDFJob::doUnderOverlayForPage( | @@ -1961,10 +1926,7 @@ QPDFJob::doUnderOverlayForPage( | ||
| 1961 | resources = dest_page.getObjectHandle().replaceKeyAndGet( | 1926 | resources = dest_page.getObjectHandle().replaceKeyAndGet( |
| 1962 | "/Resources", QPDFObjectHandle::newDictionary()); | 1927 | "/Resources", QPDFObjectHandle::newDictionary()); |
| 1963 | } | 1928 | } |
| 1964 | - for (std::vector<int>::iterator iter = pagenos[pageno].begin(); | ||
| 1965 | - iter != pagenos[pageno].end(); | ||
| 1966 | - ++iter) { | ||
| 1967 | - int from_pageno = *iter; | 1929 | + for (int from_pageno: pagenos[pageno]) { |
| 1968 | doIfVerbose([&](std::ostream& cout, std::string const& prefix) { | 1930 | doIfVerbose([&](std::ostream& cout, std::string const& prefix) { |
| 1969 | cout << " " << uo.which << " " << from_pageno << std::endl; | 1931 | cout << " " << uo.which << " " << from_pageno << std::endl; |
| 1970 | }); | 1932 | }); |
| @@ -2017,15 +1979,14 @@ QPDFJob::getUOPagenos( | @@ -2017,15 +1979,14 @@ QPDFJob::getUOPagenos( | ||
| 2017 | size_t idx = 0; | 1979 | size_t idx = 0; |
| 2018 | size_t from_size = uo.from_pagenos.size(); | 1980 | size_t from_size = uo.from_pagenos.size(); |
| 2019 | size_t repeat_size = uo.repeat_pagenos.size(); | 1981 | size_t repeat_size = uo.repeat_pagenos.size(); |
| 2020 | - for (std::vector<int>::iterator iter = uo.to_pagenos.begin(); | ||
| 2021 | - iter != uo.to_pagenos.end(); | ||
| 2022 | - ++iter, ++idx) { | 1982 | + for (int to_pageno: uo.to_pagenos) { |
| 2023 | if (idx < from_size) { | 1983 | if (idx < from_size) { |
| 2024 | - pagenos[*iter].push_back(uo.from_pagenos.at(idx)); | 1984 | + pagenos[to_pageno].push_back(uo.from_pagenos.at(idx)); |
| 2025 | } else if (repeat_size) { | 1985 | } else if (repeat_size) { |
| 2026 | - pagenos[*iter].push_back( | 1986 | + pagenos[to_pageno].push_back( |
| 2027 | uo.repeat_pagenos.at((idx - from_size) % repeat_size)); | 1987 | uo.repeat_pagenos.at((idx - from_size) % repeat_size)); |
| 2028 | } | 1988 | } |
| 1989 | + ++idx; | ||
| 2029 | } | 1990 | } |
| 2030 | } | 1991 | } |
| 2031 | 1992 | ||
| @@ -2206,21 +2167,15 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2206,21 +2167,15 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2206 | if (m->externalize_inline_images || | 2167 | if (m->externalize_inline_images || |
| 2207 | (m->optimize_images && (!m->keep_inline_images))) { | 2168 | (m->optimize_images && (!m->keep_inline_images))) { |
| 2208 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 2169 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 2209 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 2210 | - iter != pages.end(); | ||
| 2211 | - ++iter) { | ||
| 2212 | - QPDFPageObjectHelper& ph(*iter); | 2170 | + for (auto& ph: pages) { |
| 2213 | ph.externalizeInlineImages(m->ii_min_bytes); | 2171 | ph.externalizeInlineImages(m->ii_min_bytes); |
| 2214 | } | 2172 | } |
| 2215 | } | 2173 | } |
| 2216 | if (m->optimize_images) { | 2174 | if (m->optimize_images) { |
| 2217 | int pageno = 0; | 2175 | int pageno = 0; |
| 2218 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 2176 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 2219 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 2220 | - iter != pages.end(); | ||
| 2221 | - ++iter) { | 2177 | + for (auto& ph: pages) { |
| 2222 | ++pageno; | 2178 | ++pageno; |
| 2223 | - QPDFPageObjectHelper& ph(*iter); | ||
| 2224 | QPDFObjectHandle page = ph.getObjectHandle(); | 2179 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 2225 | std::map<std::string, QPDFObjectHandle> images = ph.getImages(); | 2180 | std::map<std::string, QPDFObjectHandle> images = ph.getImages(); |
| 2226 | for (auto& iter2: images) { | 2181 | for (auto& iter2: images) { |
| @@ -2260,10 +2215,8 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2260,10 +2215,8 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2260 | } | 2215 | } |
| 2261 | if (m->coalesce_contents) { | 2216 | if (m->coalesce_contents) { |
| 2262 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 2217 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 2263 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 2264 | - iter != pages.end(); | ||
| 2265 | - ++iter) { | ||
| 2266 | - (*iter).coalesceContentStreams(); | 2218 | + for (auto& page: pages) { |
| 2219 | + page.coalesceContentStreams(); | ||
| 2267 | } | 2220 | } |
| 2268 | } | 2221 | } |
| 2269 | if (m->flatten_rotation) { | 2222 | if (m->flatten_rotation) { |
| @@ -2428,10 +2381,7 @@ QPDFJob::handlePageSpecs( | @@ -2428,10 +2381,7 @@ QPDFJob::handlePageSpecs( | ||
| 2428 | // actual pages. | 2381 | // actual pages. |
| 2429 | 2382 | ||
| 2430 | // Handle "." as a shortcut for the input file | 2383 | // Handle "." as a shortcut for the input file |
| 2431 | - for (std::vector<QPDFJob::PageSpec>::iterator iter = m->page_specs.begin(); | ||
| 2432 | - iter != m->page_specs.end(); | ||
| 2433 | - ++iter) { | ||
| 2434 | - QPDFJob::PageSpec& page_spec = *iter; | 2384 | + for (auto& page_spec: m->page_specs) { |
| 2435 | if (page_spec.filename == ".") { | 2385 | if (page_spec.filename == ".") { |
| 2436 | page_spec.filename = m->infilename.get(); | 2386 | page_spec.filename = m->infilename.get(); |
| 2437 | } | 2387 | } |
| @@ -2463,10 +2413,7 @@ QPDFJob::handlePageSpecs( | @@ -2463,10 +2413,7 @@ QPDFJob::handlePageSpecs( | ||
| 2463 | page_spec_qpdfs[m->infilename.get()] = &pdf; | 2413 | page_spec_qpdfs[m->infilename.get()] = &pdf; |
| 2464 | std::vector<QPDFPageData> parsed_specs; | 2414 | std::vector<QPDFPageData> parsed_specs; |
| 2465 | std::map<unsigned long long, std::set<QPDFObjGen>> copied_pages; | 2415 | std::map<unsigned long long, std::set<QPDFObjGen>> copied_pages; |
| 2466 | - for (std::vector<QPDFJob::PageSpec>::iterator iter = m->page_specs.begin(); | ||
| 2467 | - iter != m->page_specs.end(); | ||
| 2468 | - ++iter) { | ||
| 2469 | - QPDFJob::PageSpec& page_spec = *iter; | 2416 | + for (auto& page_spec: m->page_specs) { |
| 2470 | if (page_spec_qpdfs.count(page_spec.filename) == 0) { | 2417 | if (page_spec_qpdfs.count(page_spec.filename) == 0) { |
| 2471 | // Open the PDF file and store the QPDF object. Throw a | 2418 | // Open the PDF file and store the QPDF object. Throw a |
| 2472 | // std::shared_ptr to the qpdf into a heap so that it | 2419 | // std::shared_ptr to the qpdf into a heap so that it |
| @@ -2523,17 +2470,14 @@ QPDFJob::handlePageSpecs( | @@ -2523,17 +2470,14 @@ QPDFJob::handlePageSpecs( | ||
| 2523 | 2470 | ||
| 2524 | std::map<unsigned long long, bool> remove_unreferenced; | 2471 | std::map<unsigned long long, bool> remove_unreferenced; |
| 2525 | if (m->remove_unreferenced_page_resources != QPDFJob::re_no) { | 2472 | if (m->remove_unreferenced_page_resources != QPDFJob::re_no) { |
| 2526 | - for (std::map<std::string, QPDF*>::iterator iter = | ||
| 2527 | - page_spec_qpdfs.begin(); | ||
| 2528 | - iter != page_spec_qpdfs.end(); | ||
| 2529 | - ++iter) { | ||
| 2530 | - std::string const& filename = (*iter).first; | 2473 | + for (auto const& iter: page_spec_qpdfs) { |
| 2474 | + std::string const& filename = iter.first; | ||
| 2531 | ClosedFileInputSource* cis = 0; | 2475 | ClosedFileInputSource* cis = 0; |
| 2532 | if (page_spec_cfis.count(filename)) { | 2476 | if (page_spec_cfis.count(filename)) { |
| 2533 | cis = page_spec_cfis[filename]; | 2477 | cis = page_spec_cfis[filename]; |
| 2534 | cis->stayOpen(true); | 2478 | cis->stayOpen(true); |
| 2535 | } | 2479 | } |
| 2536 | - QPDF& other(*((*iter).second)); | 2480 | + QPDF& other(*(iter.second)); |
| 2537 | auto other_uuid = other.getUniqueId(); | 2481 | auto other_uuid = other.getUniqueId(); |
| 2538 | if (remove_unreferenced.count(other_uuid) == 0) { | 2482 | if (remove_unreferenced.count(other_uuid) == 0) { |
| 2539 | remove_unreferenced[other_uuid] = | 2483 | remove_unreferenced[other_uuid] = |
| @@ -2556,10 +2500,8 @@ QPDFJob::handlePageSpecs( | @@ -2556,10 +2500,8 @@ QPDFJob::handlePageSpecs( | ||
| 2556 | }); | 2500 | }); |
| 2557 | QPDFPageDocumentHelper dh(pdf); | 2501 | QPDFPageDocumentHelper dh(pdf); |
| 2558 | std::vector<QPDFPageObjectHelper> orig_pages = dh.getAllPages(); | 2502 | std::vector<QPDFPageObjectHelper> orig_pages = dh.getAllPages(); |
| 2559 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = orig_pages.begin(); | ||
| 2560 | - iter != orig_pages.end(); | ||
| 2561 | - ++iter) { | ||
| 2562 | - dh.removePage(*iter); | 2503 | + for (auto const& page: orig_pages) { |
| 2504 | + dh.removePage(page); | ||
| 2563 | } | 2505 | } |
| 2564 | 2506 | ||
| 2565 | if (m->collate && (parsed_specs.size() > 1)) { | 2507 | if (m->collate && (parsed_specs.size() > 1)) { |
| @@ -2601,10 +2543,7 @@ QPDFJob::handlePageSpecs( | @@ -2601,10 +2543,7 @@ QPDFJob::handlePageSpecs( | ||
| 2601 | afdh_map; | 2543 | afdh_map; |
| 2602 | auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); | 2544 | auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); |
| 2603 | std::set<QPDFObjGen> referenced_fields; | 2545 | std::set<QPDFObjGen> referenced_fields; |
| 2604 | - for (std::vector<QPDFPageData>::iterator iter = parsed_specs.begin(); | ||
| 2605 | - iter != parsed_specs.end(); | ||
| 2606 | - ++iter) { | ||
| 2607 | - QPDFPageData& page_data = *iter; | 2546 | + for (auto& page_data: parsed_specs) { |
| 2608 | ClosedFileInputSource* cis = 0; | 2547 | ClosedFileInputSource* cis = 0; |
| 2609 | if (page_spec_cfis.count(page_data.filename)) { | 2548 | if (page_spec_cfis.count(page_data.filename)) { |
| 2610 | cis = page_spec_cfis[page_data.filename]; | 2549 | cis = page_spec_cfis[page_data.filename]; |
| @@ -2619,14 +2558,12 @@ QPDFJob::handlePageSpecs( | @@ -2619,14 +2558,12 @@ QPDFJob::handlePageSpecs( | ||
| 2619 | cout << prefix << ": adding pages from " << page_data.filename | 2558 | cout << prefix << ": adding pages from " << page_data.filename |
| 2620 | << std::endl; | 2559 | << std::endl; |
| 2621 | }); | 2560 | }); |
| 2622 | - for (std::vector<int>::iterator pageno_iter = | ||
| 2623 | - page_data.selected_pages.begin(); | ||
| 2624 | - pageno_iter != page_data.selected_pages.end(); | ||
| 2625 | - ++pageno_iter, ++out_pageno) { | 2561 | + for (auto pageno_iter: page_data.selected_pages) { |
| 2626 | // Pages are specified from 1 but numbered from 0 in the | 2562 | // Pages are specified from 1 but numbered from 0 in the |
| 2627 | // vector | 2563 | // vector |
| 2628 | - int pageno = *pageno_iter - 1; | ||
| 2629 | - pldh.getLabelsForPageRange(pageno, pageno, out_pageno, new_labels); | 2564 | + int pageno = pageno_iter - 1; |
| 2565 | + pldh.getLabelsForPageRange( | ||
| 2566 | + pageno, pageno, out_pageno++, new_labels); | ||
| 2630 | QPDFPageObjectHelper to_copy = | 2567 | QPDFPageObjectHelper to_copy = |
| 2631 | page_data.orig_pages.at(QIntC::to_size(pageno)); | 2568 | page_data.orig_pages.at(QIntC::to_size(pageno)); |
| 2632 | QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen(); | 2569 | QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen(); |
| @@ -2748,19 +2685,14 @@ QPDFJob::handleRotations(QPDF& pdf) | @@ -2748,19 +2685,14 @@ QPDFJob::handleRotations(QPDF& pdf) | ||
| 2748 | QPDFPageDocumentHelper dh(pdf); | 2685 | QPDFPageDocumentHelper dh(pdf); |
| 2749 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 2686 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 2750 | int npages = QIntC::to_int(pages.size()); | 2687 | int npages = QIntC::to_int(pages.size()); |
| 2751 | - for (std::map<std::string, QPDFJob::RotationSpec>::iterator iter = | ||
| 2752 | - m->rotations.begin(); | ||
| 2753 | - iter != m->rotations.end(); | ||
| 2754 | - ++iter) { | ||
| 2755 | - std::string const& range = (*iter).first; | ||
| 2756 | - QPDFJob::RotationSpec const& rspec = (*iter).second; | 2688 | + for (auto const& iter: m->rotations) { |
| 2689 | + std::string const& range = iter.first; | ||
| 2690 | + QPDFJob::RotationSpec const& rspec = iter.second; | ||
| 2757 | // range has been previously validated | 2691 | // range has been previously validated |
| 2758 | std::vector<int> to_rotate = | 2692 | std::vector<int> to_rotate = |
| 2759 | QUtil::parse_numrange(range.c_str(), npages); | 2693 | QUtil::parse_numrange(range.c_str(), npages); |
| 2760 | - for (std::vector<int>::iterator i2 = to_rotate.begin(); | ||
| 2761 | - i2 != to_rotate.end(); | ||
| 2762 | - ++i2) { | ||
| 2763 | - int pageno = *i2 - 1; | 2694 | + for (int pageno_iter: to_rotate) { |
| 2695 | + int pageno = pageno_iter - 1; | ||
| 2764 | if ((pageno >= 0) && (pageno < npages)) { | 2696 | if ((pageno >= 0) && (pageno < npages)) { |
| 2765 | pages.at(QIntC::to_size(pageno)) | 2697 | pages.at(QIntC::to_size(pageno)) |
| 2766 | .rotatePage(rspec.angle, rspec.relative); | 2698 | .rotatePage(rspec.angle, rspec.relative); |
libqpdf/QPDFObjectHandle.cc
| @@ -1244,17 +1244,12 @@ QPDFObjectHandle::getResourceNames() | @@ -1244,17 +1244,12 @@ QPDFObjectHandle::getResourceNames() | ||
| 1244 | return result; | 1244 | return result; |
| 1245 | } | 1245 | } |
| 1246 | std::set<std::string> keys = getKeys(); | 1246 | std::set<std::string> keys = getKeys(); |
| 1247 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 1248 | - iter != keys.end(); | ||
| 1249 | - ++iter) { | ||
| 1250 | - std::string const& key = *iter; | 1247 | + for (auto const& key: keys) { |
| 1251 | QPDFObjectHandle val = getKey(key); | 1248 | QPDFObjectHandle val = getKey(key); |
| 1252 | if (val.isDictionary()) { | 1249 | if (val.isDictionary()) { |
| 1253 | std::set<std::string> val_keys = val.getKeys(); | 1250 | std::set<std::string> val_keys = val.getKeys(); |
| 1254 | - for (std::set<std::string>::iterator i2 = val_keys.begin(); | ||
| 1255 | - i2 != val_keys.end(); | ||
| 1256 | - ++i2) { | ||
| 1257 | - result.insert(*i2); | 1251 | + for (auto const& val_key: val_keys) { |
| 1252 | + result.insert(val_key); | ||
| 1258 | } | 1253 | } |
| 1259 | } | 1254 | } |
| 1260 | } | 1255 | } |
| @@ -1620,10 +1615,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( | @@ -1620,10 +1615,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( | ||
| 1620 | } | 1615 | } |
| 1621 | 1616 | ||
| 1622 | bool first = true; | 1617 | bool first = true; |
| 1623 | - for (std::vector<QPDFObjectHandle>::iterator iter = result.begin(); | ||
| 1624 | - iter != result.end(); | ||
| 1625 | - ++iter) { | ||
| 1626 | - QPDFObjectHandle item = *iter; | 1618 | + for (auto const& item: result) { |
| 1627 | std::string og = QUtil::int_to_string(item.getObjectID()) + " " + | 1619 | std::string og = QUtil::int_to_string(item.getObjectID()) + " " + |
| 1628 | QUtil::int_to_string(item.getGeneration()); | 1620 | QUtil::int_to_string(item.getGeneration()); |
| 1629 | if (first) { | 1621 | if (first) { |
| @@ -1660,11 +1652,9 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) | @@ -1660,11 +1652,9 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) | ||
| 1660 | QTC::TC("qpdf", "QPDFObjectHandle prepend page contents"); | 1652 | QTC::TC("qpdf", "QPDFObjectHandle prepend page contents"); |
| 1661 | content_streams.push_back(new_contents); | 1653 | content_streams.push_back(new_contents); |
| 1662 | } | 1654 | } |
| 1663 | - for (std::vector<QPDFObjectHandle>::iterator iter = orig_contents.begin(); | ||
| 1664 | - iter != orig_contents.end(); | ||
| 1665 | - ++iter) { | 1655 | + for (auto const& iter: orig_contents) { |
| 1666 | QTC::TC("qpdf", "QPDFObjectHandle append page contents"); | 1656 | QTC::TC("qpdf", "QPDFObjectHandle append page contents"); |
| 1667 | - content_streams.push_back(*iter); | 1657 | + content_streams.push_back(iter); |
| 1668 | } | 1658 | } |
| 1669 | if (!first) { | 1659 | if (!first) { |
| 1670 | content_streams.push_back(new_contents); | 1660 | content_streams.push_back(new_contents); |
| @@ -1865,14 +1855,11 @@ QPDFObjectHandle::pipeContentStreams( | @@ -1865,14 +1855,11 @@ QPDFObjectHandle::pipeContentStreams( | ||
| 1865 | arrayOrStreamToStreamArray(description, all_description); | 1855 | arrayOrStreamToStreamArray(description, all_description); |
| 1866 | bool need_newline = false; | 1856 | bool need_newline = false; |
| 1867 | Pl_Buffer buf("concatenated content stream buffer"); | 1857 | Pl_Buffer buf("concatenated content stream buffer"); |
| 1868 | - for (std::vector<QPDFObjectHandle>::iterator iter = streams.begin(); | ||
| 1869 | - iter != streams.end(); | ||
| 1870 | - ++iter) { | 1858 | + for (auto stream: streams) { |
| 1871 | if (need_newline) { | 1859 | if (need_newline) { |
| 1872 | buf.write(QUtil::unsigned_char_pointer("\n"), 1); | 1860 | buf.write(QUtil::unsigned_char_pointer("\n"), 1); |
| 1873 | } | 1861 | } |
| 1874 | LastChar lc(&buf); | 1862 | LastChar lc(&buf); |
| 1875 | - QPDFObjectHandle stream = *iter; | ||
| 1876 | std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + | 1863 | std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + |
| 1877 | QUtil::int_to_string(stream.getGeneration()); | 1864 | QUtil::int_to_string(stream.getGeneration()); |
| 1878 | std::string w_description = "content stream object " + og; | 1865 | std::string w_description = "content stream object " + og; |
| @@ -2920,13 +2907,11 @@ QPDFObjectHandle::copyObject( | @@ -2920,13 +2907,11 @@ QPDFObjectHandle::copyObject( | ||
| 2920 | QTC::TC("qpdf", "QPDFObjectHandle clone dictionary"); | 2907 | QTC::TC("qpdf", "QPDFObjectHandle clone dictionary"); |
| 2921 | std::set<std::string> keys = getKeys(); | 2908 | std::set<std::string> keys = getKeys(); |
| 2922 | std::map<std::string, QPDFObjectHandle> items; | 2909 | std::map<std::string, QPDFObjectHandle> items; |
| 2923 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 2924 | - iter != keys.end(); | ||
| 2925 | - ++iter) { | ||
| 2926 | - items[*iter] = getKey(*iter); | 2910 | + for (auto const& key: keys) { |
| 2911 | + items[key] = getKey(key); | ||
| 2927 | if ((!first_level_only) && | 2912 | if ((!first_level_only) && |
| 2928 | - (cross_indirect || (!items[*iter].isIndirect()))) { | ||
| 2929 | - items[*iter].copyObject( | 2913 | + (cross_indirect || (!items[key].isIndirect()))) { |
| 2914 | + items[key].copyObject( | ||
| 2930 | visited, cross_indirect, first_level_only, stop_at_streams); | 2915 | visited, cross_indirect, first_level_only, stop_at_streams); |
| 2931 | } | 2916 | } |
| 2932 | } | 2917 | } |
libqpdf/QPDFPageDocumentHelper.cc
| @@ -14,10 +14,8 @@ QPDFPageDocumentHelper::getAllPages() | @@ -14,10 +14,8 @@ QPDFPageDocumentHelper::getAllPages() | ||
| 14 | { | 14 | { |
| 15 | std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages(); | 15 | std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages(); |
| 16 | std::vector<QPDFPageObjectHelper> pages; | 16 | std::vector<QPDFPageObjectHelper> pages; |
| 17 | - for (std::vector<QPDFObjectHandle>::const_iterator iter = pages_v.begin(); | ||
| 18 | - iter != pages_v.end(); | ||
| 19 | - ++iter) { | ||
| 20 | - pages.push_back(QPDFPageObjectHelper(*iter)); | 17 | + for (auto const& iter: pages_v) { |
| 18 | + pages.push_back(QPDFPageObjectHelper(iter)); | ||
| 21 | } | 19 | } |
| 22 | return pages; | 20 | return pages; |
| 23 | } | 21 | } |
| @@ -32,10 +30,8 @@ void | @@ -32,10 +30,8 @@ void | ||
| 32 | QPDFPageDocumentHelper::removeUnreferencedResources() | 30 | QPDFPageDocumentHelper::removeUnreferencedResources() |
| 33 | { | 31 | { |
| 34 | std::vector<QPDFPageObjectHelper> pages = getAllPages(); | 32 | std::vector<QPDFPageObjectHelper> pages = getAllPages(); |
| 35 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 36 | - iter != pages.end(); | ||
| 37 | - ++iter) { | ||
| 38 | - (*iter).removeUnreferencedResources(); | 33 | + for (auto& ph: pages) { |
| 34 | + ph.removeUnreferencedResources(); | ||
| 39 | } | 35 | } |
| 40 | } | 36 | } |
| 41 | 37 | ||
| @@ -71,10 +67,7 @@ QPDFPageDocumentHelper::flattenAnnotations( | @@ -71,10 +67,7 @@ QPDFPageDocumentHelper::flattenAnnotations( | ||
| 71 | " so form fields will not be flattened"); | 67 | " so form fields will not be flattened"); |
| 72 | } | 68 | } |
| 73 | std::vector<QPDFPageObjectHelper> pages = getAllPages(); | 69 | std::vector<QPDFPageObjectHelper> pages = getAllPages(); |
| 74 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 75 | - iter != pages.end(); | ||
| 76 | - ++iter) { | ||
| 77 | - QPDFPageObjectHelper ph(*iter); | 70 | + for (auto& ph: pages) { |
| 78 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); | 71 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); |
| 79 | if (!resources.isDictionary()) { | 72 | if (!resources.isDictionary()) { |
| 80 | // This should never happen and is not exercised in the | 73 | // This should never happen and is not exercised in the |
| @@ -107,11 +100,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | @@ -107,11 +100,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | ||
| 107 | rotate = rotate_obj.getIntValueAsInt(); | 100 | rotate = rotate_obj.getIntValueAsInt(); |
| 108 | } | 101 | } |
| 109 | int next_fx = 1; | 102 | int next_fx = 1; |
| 110 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator iter = | ||
| 111 | - annots.begin(); | ||
| 112 | - iter != annots.end(); | ||
| 113 | - ++iter) { | ||
| 114 | - QPDFAnnotationObjectHelper& aoh(*iter); | 103 | + for (auto& aoh: annots) { |
| 115 | QPDFObjectHandle as = aoh.getAppearanceStream("/N"); | 104 | QPDFObjectHandle as = aoh.getAppearanceStream("/N"); |
| 116 | bool is_widget = (aoh.getSubtype() == "/Widget"); | 105 | bool is_widget = (aoh.getSubtype() == "/Widget"); |
| 117 | bool process = true; | 106 | bool process = true; |
libqpdf/QPDFTokenizer.cc
| @@ -568,10 +568,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) | @@ -568,10 +568,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) | ||
| 568 | bool found_non_printable = false; | 568 | bool found_non_printable = false; |
| 569 | bool found_other = false; | 569 | bool found_other = false; |
| 570 | std::string value = t.getValue(); | 570 | std::string value = t.getValue(); |
| 571 | - for (std::string::iterator iter = value.begin(); | ||
| 572 | - iter != value.end(); | ||
| 573 | - ++iter) { | ||
| 574 | - char ch = *iter; | 571 | + for (char ch: value) { |
| 575 | if (((ch >= 'a') && (ch <= 'z')) || | 572 | if (((ch >= 'a') && (ch <= 'z')) || |
| 576 | ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) { | 573 | ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) { |
| 577 | // Treat '*' as alpha since there are valid | 574 | // Treat '*' as alpha since there are valid |
libqpdf/QPDFWriter.cc
| @@ -755,10 +755,8 @@ QPDFWriter::setEncryptionParameters( | @@ -755,10 +755,8 @@ QPDFWriter::setEncryptionParameters( | ||
| 755 | 755 | ||
| 756 | int P = 0; | 756 | int P = 0; |
| 757 | // Create the complement of P, then invert. | 757 | // Create the complement of P, then invert. |
| 758 | - for (std::set<int>::iterator iter = bits_to_clear.begin(); | ||
| 759 | - iter != bits_to_clear.end(); | ||
| 760 | - ++iter) { | ||
| 761 | - P |= (1 << ((*iter) - 1)); | 758 | + for (int b: bits_to_clear) { |
| 759 | + P |= (1 << (b - 1)); | ||
| 762 | } | 760 | } |
| 763 | P = ~P; | 761 | P = ~P; |
| 764 | 762 | ||
| @@ -1277,11 +1275,8 @@ QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const& og) | @@ -1277,11 +1275,8 @@ QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const& og) | ||
| 1277 | 1275 | ||
| 1278 | // Reserve numbers for the objects that belong to this object | 1276 | // Reserve numbers for the objects that belong to this object |
| 1279 | // stream. | 1277 | // stream. |
| 1280 | - for (std::set<QPDFObjGen>::iterator iter = | ||
| 1281 | - this->m->object_stream_to_objects[objid].begin(); | ||
| 1282 | - iter != this->m->object_stream_to_objects[objid].end(); | ||
| 1283 | - ++iter) { | ||
| 1284 | - this->m->obj_renumber[*iter] = this->m->next_objid++; | 1278 | + for (auto const& iter: this->m->object_stream_to_objects[objid]) { |
| 1279 | + this->m->obj_renumber[iter] = this->m->next_objid++; | ||
| 1285 | } | 1280 | } |
| 1286 | } | 1281 | } |
| 1287 | 1282 | ||
| @@ -1353,11 +1348,9 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1353,11 +1348,9 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1353 | } | 1348 | } |
| 1354 | } else if (object.isDictionary()) { | 1349 | } else if (object.isDictionary()) { |
| 1355 | std::set<std::string> keys = object.getKeys(); | 1350 | std::set<std::string> keys = object.getKeys(); |
| 1356 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 1357 | - iter != keys.end(); | ||
| 1358 | - ++iter) { | 1351 | + for (auto const& key: keys) { |
| 1359 | if (!this->m->linearized) { | 1352 | if (!this->m->linearized) { |
| 1360 | - enqueueObject(object.getKey(*iter)); | 1353 | + enqueueObject(object.getKey(key)); |
| 1361 | } | 1354 | } |
| 1362 | } | 1355 | } |
| 1363 | } else { | 1356 | } else { |
| @@ -1401,10 +1394,7 @@ QPDFWriter::writeTrailer( | @@ -1401,10 +1394,7 @@ QPDFWriter::writeTrailer( | ||
| 1401 | writeString(QUtil::int_to_string(size)); | 1394 | writeString(QUtil::int_to_string(size)); |
| 1402 | } else { | 1395 | } else { |
| 1403 | std::set<std::string> keys = trailer.getKeys(); | 1396 | std::set<std::string> keys = trailer.getKeys(); |
| 1404 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 1405 | - iter != keys.end(); | ||
| 1406 | - ++iter) { | ||
| 1407 | - std::string const& key = *iter; | 1397 | + for (auto const& key: keys) { |
| 1408 | writeStringQDF(" "); | 1398 | writeStringQDF(" "); |
| 1409 | writeStringNoQDF(" "); | 1399 | writeStringNoQDF(" "); |
| 1410 | writeString(QPDF_Name::normalizeName(key)); | 1400 | writeString(QPDF_Name::normalizeName(key)); |
| @@ -1758,11 +1748,7 @@ QPDFWriter::unparseObject( | @@ -1758,11 +1748,7 @@ QPDFWriter::unparseObject( | ||
| 1758 | writeStringQDF("\n"); | 1748 | writeStringQDF("\n"); |
| 1759 | 1749 | ||
| 1760 | std::set<std::string> keys = object.getKeys(); | 1750 | std::set<std::string> keys = object.getKeys(); |
| 1761 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 1762 | - iter != keys.end(); | ||
| 1763 | - ++iter) { | ||
| 1764 | - std::string const& key = *iter; | ||
| 1765 | - | 1751 | + for (auto const& key: keys) { |
| 1766 | writeStringQDF(indent); | 1752 | writeStringQDF(indent); |
| 1767 | writeStringQDF(" "); | 1753 | writeStringQDF(" "); |
| 1768 | writeStringNoQDF(" "); | 1754 | writeStringNoQDF(" "); |
| @@ -1930,12 +1916,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1930,12 +1916,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1930 | pushDiscardFilter(pp_ostream); | 1916 | pushDiscardFilter(pp_ostream); |
| 1931 | } else { | 1917 | } else { |
| 1932 | // Adjust offsets to skip over comment before first object | 1918 | // Adjust offsets to skip over comment before first object |
| 1933 | - | ||
| 1934 | first = offsets.at(0); | 1919 | first = offsets.at(0); |
| 1935 | - for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin(); | ||
| 1936 | - iter != offsets.end(); | ||
| 1937 | - ++iter) { | ||
| 1938 | - *iter -= first; | 1920 | + for (auto& iter: offsets) { |
| 1921 | + iter -= first; | ||
| 1939 | } | 1922 | } |
| 1940 | 1923 | ||
| 1941 | // Take one pass at writing pairs of numbers so we can get | 1924 | // Take one pass at writing pairs of numbers so we can get |
| @@ -1960,12 +1943,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1960,12 +1943,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1960 | writeObjectStreamOffsets(offsets, first_obj); | 1943 | writeObjectStreamOffsets(offsets, first_obj); |
| 1961 | } | 1944 | } |
| 1962 | 1945 | ||
| 1963 | - int count = 0; | ||
| 1964 | - for (std::set<QPDFObjGen>::iterator iter = | ||
| 1965 | - this->m->object_stream_to_objects[old_id].begin(); | ||
| 1966 | - iter != this->m->object_stream_to_objects[old_id].end(); | ||
| 1967 | - ++iter, ++count) { | ||
| 1968 | - QPDFObjGen obj = *iter; | 1946 | + int count = -1; |
| 1947 | + for (auto const& obj: this->m->object_stream_to_objects[old_id]) { | ||
| 1948 | + ++count; | ||
| 1969 | int new_obj = this->m->obj_renumber[obj]; | 1949 | int new_obj = this->m->obj_renumber[obj]; |
| 1970 | if (first_obj == -1) { | 1950 | if (first_obj == -1) { |
| 1971 | first_obj = new_obj; | 1951 | first_obj = new_obj; |
| @@ -2197,10 +2177,8 @@ QPDFWriter::generateID() | @@ -2197,10 +2177,8 @@ QPDFWriter::generateID() | ||
| 2197 | if (trailer.hasKey("/Info")) { | 2177 | if (trailer.hasKey("/Info")) { |
| 2198 | QPDFObjectHandle info = trailer.getKey("/Info"); | 2178 | QPDFObjectHandle info = trailer.getKey("/Info"); |
| 2199 | std::set<std::string> keys = info.getKeys(); | 2179 | std::set<std::string> keys = info.getKeys(); |
| 2200 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 2201 | - iter != keys.end(); | ||
| 2202 | - ++iter) { | ||
| 2203 | - QPDFObjectHandle obj = info.getKey(*iter); | 2180 | + for (auto const& key: keys) { |
| 2181 | + QPDFObjectHandle obj = info.getKey(key); | ||
| 2204 | if (obj.isString()) { | 2182 | if (obj.isString()) { |
| 2205 | seed += " "; | 2183 | seed += " "; |
| 2206 | seed += obj.getStringValue(); | 2184 | seed += obj.getStringValue(); |
| @@ -2235,10 +2213,7 @@ QPDFWriter::initializeSpecialStreams() | @@ -2235,10 +2213,7 @@ QPDFWriter::initializeSpecialStreams() | ||
| 2235 | // normalizing. | 2213 | // normalizing. |
| 2236 | std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); | 2214 | std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); |
| 2237 | int num = 0; | 2215 | int num = 0; |
| 2238 | - for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin(); | ||
| 2239 | - iter != pages.end(); | ||
| 2240 | - ++iter) { | ||
| 2241 | - QPDFObjectHandle& page = *iter; | 2216 | + for (auto& page: pages) { |
| 2242 | this->m->page_object_to_seq[page.getObjGen()] = ++num; | 2217 | this->m->page_object_to_seq[page.getObjGen()] = ++num; |
| 2243 | QPDFObjectHandle contents = page.getKey("/Contents"); | 2218 | QPDFObjectHandle contents = page.getKey("/Contents"); |
| 2244 | std::vector<QPDFObjGen> contents_objects; | 2219 | std::vector<QPDFObjGen> contents_objects; |
| @@ -2322,9 +2297,7 @@ QPDFWriter::generateObjectStreams() | @@ -2322,9 +2297,7 @@ QPDFWriter::generateObjectStreams() | ||
| 2322 | } | 2297 | } |
| 2323 | unsigned int n = 0; | 2298 | unsigned int n = 0; |
| 2324 | int cur_ostream = 0; | 2299 | int cur_ostream = 0; |
| 2325 | - for (std::vector<QPDFObjGen>::const_iterator iter = eligible.begin(); | ||
| 2326 | - iter != eligible.end(); | ||
| 2327 | - ++iter) { | 2300 | + for (auto const& iter: eligible) { |
| 2328 | if ((n % n_per) == 0) { | 2301 | if ((n % n_per) == 0) { |
| 2329 | if (n > 0) { | 2302 | if (n > 0) { |
| 2330 | QTC::TC("qpdf", "QPDFWriter generate >1 ostream"); | 2303 | QTC::TC("qpdf", "QPDFWriter generate >1 ostream"); |
| @@ -2339,7 +2312,7 @@ QPDFWriter::generateObjectStreams() | @@ -2339,7 +2312,7 @@ QPDFWriter::generateObjectStreams() | ||
| 2339 | this->m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()) | 2312 | this->m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()) |
| 2340 | .getObjectID(); | 2313 | .getObjectID(); |
| 2341 | } | 2314 | } |
| 2342 | - this->m->object_to_object_stream[*iter] = cur_ostream; | 2315 | + this->m->object_to_object_stream[iter] = cur_ostream; |
| 2343 | ++n; | 2316 | ++n; |
| 2344 | } | 2317 | } |
| 2345 | } | 2318 | } |
| @@ -2495,10 +2468,7 @@ QPDFWriter::doWriteSetup() | @@ -2495,10 +2468,7 @@ QPDFWriter::doWriteSetup() | ||
| 2495 | if (this->m->linearized) { | 2468 | if (this->m->linearized) { |
| 2496 | // Page dictionaries are not allowed to be compressed objects. | 2469 | // Page dictionaries are not allowed to be compressed objects. |
| 2497 | std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); | 2470 | std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); |
| 2498 | - for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin(); | ||
| 2499 | - iter != pages.end(); | ||
| 2500 | - ++iter) { | ||
| 2501 | - QPDFObjectHandle& page = *iter; | 2471 | + for (auto& page: pages) { |
| 2502 | QPDFObjGen og = page.getObjGen(); | 2472 | QPDFObjGen og = page.getObjGen(); |
| 2503 | if (this->m->object_to_object_stream.count(og)) { | 2473 | if (this->m->object_to_object_stream.count(og)) { |
| 2504 | QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary"); | 2474 | QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary"); |
| @@ -2521,12 +2491,9 @@ QPDFWriter::doWriteSetup() | @@ -2521,12 +2491,9 @@ QPDFWriter::doWriteSetup() | ||
| 2521 | } | 2491 | } |
| 2522 | 2492 | ||
| 2523 | // Generate reverse mapping from object stream to objects | 2493 | // Generate reverse mapping from object stream to objects |
| 2524 | - for (std::map<QPDFObjGen, int>::iterator iter = | ||
| 2525 | - this->m->object_to_object_stream.begin(); | ||
| 2526 | - iter != this->m->object_to_object_stream.end(); | ||
| 2527 | - ++iter) { | ||
| 2528 | - QPDFObjGen obj = (*iter).first; | ||
| 2529 | - int stream = (*iter).second; | 2494 | + for (auto const& iter: this->m->object_to_object_stream) { |
| 2495 | + QPDFObjGen const& obj = iter.first; | ||
| 2496 | + int stream = iter.second; | ||
| 2530 | this->m->object_stream_to_objects[stream].insert(obj); | 2497 | this->m->object_stream_to_objects[stream].insert(obj); |
| 2531 | this->m->max_ostream_index = std::max( | 2498 | this->m->max_ostream_index = std::max( |
| 2532 | this->m->max_ostream_index, | 2499 | this->m->max_ostream_index, |
| @@ -2591,11 +2558,9 @@ QPDFWriter::getWrittenXRefTable() | @@ -2591,11 +2558,9 @@ QPDFWriter::getWrittenXRefTable() | ||
| 2591 | { | 2558 | { |
| 2592 | std::map<QPDFObjGen, QPDFXRefEntry> result; | 2559 | std::map<QPDFObjGen, QPDFXRefEntry> result; |
| 2593 | 2560 | ||
| 2594 | - for (std::map<int, QPDFXRefEntry>::iterator iter = this->m->xref.begin(); | ||
| 2595 | - iter != this->m->xref.end(); | ||
| 2596 | - ++iter) { | ||
| 2597 | - if (iter->first != 0 && iter->second.getType() != 0) { | ||
| 2598 | - result[QPDFObjGen(iter->first, 0)] = iter->second; | 2561 | + for (auto const& iter: this->m->xref) { |
| 2562 | + if (iter.first != 0 && iter.second.getType() != 0) { | ||
| 2563 | + result[QPDFObjGen(iter.first, 0)] = iter.second; | ||
| 2599 | } | 2564 | } |
| 2600 | } | 2565 | } |
| 2601 | 2566 | ||
| @@ -2605,10 +2570,8 @@ QPDFWriter::getWrittenXRefTable() | @@ -2605,10 +2570,8 @@ QPDFWriter::getWrittenXRefTable() | ||
| 2605 | void | 2570 | void |
| 2606 | QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part) | 2571 | QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part) |
| 2607 | { | 2572 | { |
| 2608 | - for (std::vector<QPDFObjectHandle>::iterator iter = part.begin(); | ||
| 2609 | - iter != part.end(); | ||
| 2610 | - ++iter) { | ||
| 2611 | - enqueueObject(*iter); | 2573 | + for (auto const& oh: part) { |
| 2574 | + enqueueObject(oh); | ||
| 2612 | } | 2575 | } |
| 2613 | } | 2576 | } |
| 2614 | 2577 | ||
| @@ -2617,14 +2580,11 @@ QPDFWriter::writeEncryptionDictionary() | @@ -2617,14 +2580,11 @@ QPDFWriter::writeEncryptionDictionary() | ||
| 2617 | { | 2580 | { |
| 2618 | this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid); | 2581 | this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid); |
| 2619 | writeString("<<"); | 2582 | writeString("<<"); |
| 2620 | - for (std::map<std::string, std::string>::iterator iter = | ||
| 2621 | - this->m->encryption_dictionary.begin(); | ||
| 2622 | - iter != this->m->encryption_dictionary.end(); | ||
| 2623 | - ++iter) { | 2583 | + for (auto const& iter: this->m->encryption_dictionary) { |
| 2624 | writeString(" "); | 2584 | writeString(" "); |
| 2625 | - writeString((*iter).first); | 2585 | + writeString(iter.first); |
| 2626 | writeString(" "); | 2586 | writeString(" "); |
| 2627 | - writeString((*iter).second); | 2587 | + writeString(iter.second); |
| 2628 | } | 2588 | } |
| 2629 | writeString(" >>"); | 2589 | writeString(" >>"); |
| 2630 | closeObject(this->m->encryption_dict_objid); | 2590 | closeObject(this->m->encryption_dict_objid); |
| @@ -2937,10 +2897,8 @@ QPDFWriter::discardGeneration( | @@ -2937,10 +2897,8 @@ QPDFWriter::discardGeneration( | ||
| 2937 | // maps for QPDF that throw away generation numbers. | 2897 | // maps for QPDF that throw away generation numbers. |
| 2938 | 2898 | ||
| 2939 | out.clear(); | 2899 | out.clear(); |
| 2940 | - for (std::map<QPDFObjGen, int>::const_iterator iter = in.begin(); | ||
| 2941 | - iter != in.end(); | ||
| 2942 | - ++iter) { | ||
| 2943 | - if (out.count((*iter).first.getObj())) { | 2900 | + for (auto const& iter: in) { |
| 2901 | + if (out.count(iter.first.getObj())) { | ||
| 2944 | throw std::runtime_error( | 2902 | throw std::runtime_error( |
| 2945 | "QPDF cannot currently linearize files that contain" | 2903 | "QPDF cannot currently linearize files that contain" |
| 2946 | " multiple objects with the same object ID and different" | 2904 | " multiple objects with the same object ID and different" |
| @@ -2950,7 +2908,7 @@ QPDFWriter::discardGeneration( | @@ -2950,7 +2908,7 @@ QPDFWriter::discardGeneration( | ||
| 2950 | " linearizing, and then linearize the result of that" | 2908 | " linearizing, and then linearize the result of that" |
| 2951 | " conversion."); | 2909 | " conversion."); |
| 2952 | } | 2910 | } |
| 2953 | - out[(*iter).first.getObj()] = (*iter).second; | 2911 | + out[iter.first.getObj()] = iter.second; |
| 2954 | } | 2912 | } |
| 2955 | } | 2913 | } |
| 2956 | 2914 | ||
| @@ -3020,10 +2978,8 @@ QPDFWriter::writeLinearized() | @@ -3020,10 +2978,8 @@ QPDFWriter::writeLinearized() | ||
| 3020 | // Assign numbers to all compressed objects in the second half. | 2978 | // Assign numbers to all compressed objects in the second half. |
| 3021 | std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9}; | 2979 | std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9}; |
| 3022 | for (int i = 0; i < 3; ++i) { | 2980 | for (int i = 0; i < 3; ++i) { |
| 3023 | - for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs2[i]).begin(); | ||
| 3024 | - iter != (*vecs2[i]).end(); | ||
| 3025 | - ++iter) { | ||
| 3026 | - assignCompressedObjectNumbers((*iter).getObjGen()); | 2981 | + for (auto const& oh: *vecs2[i]) { |
| 2982 | + assignCompressedObjectNumbers(oh.getObjGen()); | ||
| 3027 | } | 2983 | } |
| 3028 | } | 2984 | } |
| 3029 | int second_half_end = this->m->next_objid - 1; | 2985 | int second_half_end = this->m->next_objid - 1; |
| @@ -3049,10 +3005,8 @@ QPDFWriter::writeLinearized() | @@ -3049,10 +3005,8 @@ QPDFWriter::writeLinearized() | ||
| 3049 | // Assign numbers to all compressed objects in the first half | 3005 | // Assign numbers to all compressed objects in the first half |
| 3050 | std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6}; | 3006 | std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6}; |
| 3051 | for (int i = 0; i < 2; ++i) { | 3007 | for (int i = 0; i < 2; ++i) { |
| 3052 | - for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs1[i]).begin(); | ||
| 3053 | - iter != (*vecs1[i]).end(); | ||
| 3054 | - ++iter) { | ||
| 3055 | - assignCompressedObjectNumbers((*iter).getObjGen()); | 3008 | + for (auto const& oh: *vecs1[i]) { |
| 3009 | + assignCompressedObjectNumbers(oh.getObjGen()); | ||
| 3056 | } | 3010 | } |
| 3057 | } | 3011 | } |
| 3058 | int first_half_end = this->m->next_objid - 1; | 3012 | int first_half_end = this->m->next_objid - 1; |
| @@ -3240,11 +3194,7 @@ QPDFWriter::writeLinearized() | @@ -3240,11 +3194,7 @@ QPDFWriter::writeLinearized() | ||
| 3240 | 3194 | ||
| 3241 | // Parts 4 through 9 | 3195 | // Parts 4 through 9 |
| 3242 | 3196 | ||
| 3243 | - for (std::list<QPDFObjectHandle>::iterator iter = | ||
| 3244 | - this->m->object_queue.begin(); | ||
| 3245 | - iter != this->m->object_queue.end(); | ||
| 3246 | - ++iter) { | ||
| 3247 | - QPDFObjectHandle cur_object = (*iter); | 3197 | + for (auto const& cur_object: this->m->object_queue) { |
| 3248 | if (cur_object.getObjectID() == part6_end_marker) { | 3198 | if (cur_object.getObjectID() == part6_end_marker) { |
| 3249 | first_half_max_obj_offset = this->m->pipeline->getCount(); | 3199 | first_half_max_obj_offset = this->m->pipeline->getCount(); |
| 3250 | } | 3200 | } |
| @@ -3390,11 +3340,8 @@ QPDFWriter::enqueueObjectsStandard() | @@ -3390,11 +3340,8 @@ QPDFWriter::enqueueObjectsStandard() | ||
| 3390 | { | 3340 | { |
| 3391 | if (this->m->preserve_unreferenced_objects) { | 3341 | if (this->m->preserve_unreferenced_objects) { |
| 3392 | QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard"); | 3342 | QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard"); |
| 3393 | - std::vector<QPDFObjectHandle> all = this->m->pdf.getAllObjects(); | ||
| 3394 | - for (std::vector<QPDFObjectHandle>::iterator iter = all.begin(); | ||
| 3395 | - iter != all.end(); | ||
| 3396 | - ++iter) { | ||
| 3397 | - enqueueObject(*iter); | 3343 | + for (auto const& oh: this->m->pdf.getAllObjects()) { |
| 3344 | + enqueueObject(oh); | ||
| 3398 | } | 3345 | } |
| 3399 | } | 3346 | } |
| 3400 | 3347 | ||
| @@ -3407,10 +3354,8 @@ QPDFWriter::enqueueObjectsStandard() | @@ -3407,10 +3354,8 @@ QPDFWriter::enqueueObjectsStandard() | ||
| 3407 | // Root is already there, so enqueuing it a second time is a | 3354 | // Root is already there, so enqueuing it a second time is a |
| 3408 | // no-op. | 3355 | // no-op. |
| 3409 | std::set<std::string> keys = trailer.getKeys(); | 3356 | std::set<std::string> keys = trailer.getKeys(); |
| 3410 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 3411 | - iter != keys.end(); | ||
| 3412 | - ++iter) { | ||
| 3413 | - enqueueObject(trailer.getKey(*iter)); | 3357 | + for (auto const& key: keys) { |
| 3358 | + enqueueObject(trailer.getKey(key)); | ||
| 3414 | } | 3359 | } |
| 3415 | } | 3360 | } |
| 3416 | 3361 | ||
| @@ -3424,23 +3369,18 @@ QPDFWriter::enqueueObjectsPCLm() | @@ -3424,23 +3369,18 @@ QPDFWriter::enqueueObjectsPCLm() | ||
| 3424 | 3369 | ||
| 3425 | // enqueue all pages first | 3370 | // enqueue all pages first |
| 3426 | std::vector<QPDFObjectHandle> all = this->m->pdf.getAllPages(); | 3371 | std::vector<QPDFObjectHandle> all = this->m->pdf.getAllPages(); |
| 3427 | - for (std::vector<QPDFObjectHandle>::iterator iter = all.begin(); | ||
| 3428 | - iter != all.end(); | ||
| 3429 | - ++iter) { | 3372 | + for (auto& page: all) { |
| 3430 | // enqueue page | 3373 | // enqueue page |
| 3431 | - enqueueObject(*iter); | 3374 | + enqueueObject(page); |
| 3432 | 3375 | ||
| 3433 | // enqueue page contents stream | 3376 | // enqueue page contents stream |
| 3434 | - enqueueObject((*iter).getKey("/Contents")); | 3377 | + enqueueObject(page.getKey("/Contents")); |
| 3435 | 3378 | ||
| 3436 | // enqueue all the strips for each page | 3379 | // enqueue all the strips for each page |
| 3437 | - QPDFObjectHandle strips = | ||
| 3438 | - (*iter).getKey("/Resources").getKey("/XObject"); | 3380 | + QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); |
| 3439 | std::set<std::string> keys = strips.getKeys(); | 3381 | std::set<std::string> keys = strips.getKeys(); |
| 3440 | - for (std::set<std::string>::iterator image = keys.begin(); | ||
| 3441 | - image != keys.end(); | ||
| 3442 | - ++image) { | ||
| 3443 | - enqueueObject(strips.getKey(*image)); | 3382 | + for (auto const& image: keys) { |
| 3383 | + enqueueObject(strips.getKey(image)); | ||
| 3444 | enqueueObject(QPDFObjectHandle::newStream( | 3384 | enqueueObject(QPDFObjectHandle::newStream( |
| 3445 | &this->m->pdf, image_transform_content)); | 3385 | &this->m->pdf, image_transform_content)); |
| 3446 | } | 3386 | } |
libqpdf/QPDF_Array.cc
| @@ -99,10 +99,8 @@ void | @@ -99,10 +99,8 @@ void | ||
| 99 | QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v) | 99 | QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v) |
| 100 | { | 100 | { |
| 101 | this->elements = SparseOHArray(); | 101 | this->elements = SparseOHArray(); |
| 102 | - for (std::vector<QPDFObjectHandle>::const_iterator iter = v.begin(); | ||
| 103 | - iter != v.end(); | ||
| 104 | - ++iter) { | ||
| 105 | - this->elements.append(*iter); | 102 | + for (auto const& iter: v) { |
| 103 | + this->elements.append(iter); | ||
| 106 | } | 104 | } |
| 107 | } | 105 | } |
| 108 | 106 |
libqpdf/QPDF_Dictionary.cc
| @@ -12,11 +12,8 @@ QPDF_Dictionary::QPDF_Dictionary( | @@ -12,11 +12,8 @@ QPDF_Dictionary::QPDF_Dictionary( | ||
| 12 | void | 12 | void |
| 13 | QPDF_Dictionary::releaseResolved() | 13 | QPDF_Dictionary::releaseResolved() |
| 14 | { | 14 | { |
| 15 | - for (std::map<std::string, QPDFObjectHandle>::iterator iter = | ||
| 16 | - this->items.begin(); | ||
| 17 | - iter != this->items.end(); | ||
| 18 | - ++iter) { | ||
| 19 | - QPDFObjectHandle::ReleaseResolver::releaseResolved((*iter).second); | 15 | + for (auto& iter: this->items) { |
| 16 | + QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second); | ||
| 20 | } | 17 | } |
| 21 | } | 18 | } |
| 22 | 19 |
libqpdf/QPDF_encryption.cc
| @@ -945,11 +945,7 @@ QPDF::initializeEncryption() | @@ -945,11 +945,7 @@ QPDF::initializeEncryption() | ||
| 945 | 945 | ||
| 946 | if ((V == 4) || (V == 5)) { | 946 | if ((V == 4) || (V == 5)) { |
| 947 | QPDFObjectHandle CF = encryption_dict.getKey("/CF"); | 947 | QPDFObjectHandle CF = encryption_dict.getKey("/CF"); |
| 948 | - std::set<std::string> keys = CF.getKeys(); | ||
| 949 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 950 | - iter != keys.end(); | ||
| 951 | - ++iter) { | ||
| 952 | - std::string const& filter = *iter; | 948 | + for (auto const& filter: CF.getKeys()) { |
| 953 | QPDFObjectHandle cdict = CF.getKey(filter); | 949 | QPDFObjectHandle cdict = CF.getKey(filter); |
| 954 | if (cdict.isDictionary()) { | 950 | if (cdict.isDictionary()) { |
| 955 | encryption_method_e method = e_none; | 951 | encryption_method_e method = e_none; |
libqpdf/QPDF_linearization.cc
| @@ -583,12 +583,9 @@ QPDF::checkLinearizationInternal() | @@ -583,12 +583,9 @@ QPDF::checkLinearizationInternal() | ||
| 583 | // uncompressed. | 583 | // uncompressed. |
| 584 | { // local scope | 584 | { // local scope |
| 585 | std::map<int, int> object_stream_data; | 585 | std::map<int, int> object_stream_data; |
| 586 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::const_iterator iter = | ||
| 587 | - this->m->xref_table.begin(); | ||
| 588 | - iter != this->m->xref_table.end(); | ||
| 589 | - ++iter) { | ||
| 590 | - QPDFObjGen const& og = (*iter).first; | ||
| 591 | - QPDFXRefEntry const& entry = (*iter).second; | 586 | + for (auto const& iter: this->m->xref_table) { |
| 587 | + QPDFObjGen const& og = iter.first; | ||
| 588 | + QPDFXRefEntry const& entry = iter.second; | ||
| 592 | if (entry.getType() == 2) { | 589 | if (entry.getType() == 2) { |
| 593 | object_stream_data[og.getObj()] = entry.getObjStreamNumber(); | 590 | object_stream_data[og.getObj()] = entry.getObjStreamNumber(); |
| 594 | } | 591 | } |
| @@ -613,10 +610,8 @@ QPDF::checkLinearizationInternal() | @@ -613,10 +610,8 @@ QPDF::checkLinearizationInternal() | ||
| 613 | } | 610 | } |
| 614 | qpdf_offset_t min_E = -1; | 611 | qpdf_offset_t min_E = -1; |
| 615 | qpdf_offset_t max_E = -1; | 612 | qpdf_offset_t max_E = -1; |
| 616 | - for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin(); | ||
| 617 | - iter != this->m->part6.end(); | ||
| 618 | - ++iter) { | ||
| 619 | - QPDFObjGen og((*iter).getObjGen()); | 613 | + for (auto const& oh: this->m->part6) { |
| 614 | + QPDFObjGen og(oh.getObjGen()); | ||
| 620 | if (this->m->obj_cache.count(og) == 0) { | 615 | if (this->m->obj_cache.count(og) == 0) { |
| 621 | // All objects have to have been dereferenced to be classified. | 616 | // All objects have to have been dereferenced to be classified. |
| 622 | throw std::logic_error("linearization part6 object not in cache"); | 617 | throw std::logic_error("linearization part6 object not in cache"); |
| @@ -651,19 +646,15 @@ QPDF::checkLinearizationInternal() | @@ -651,19 +646,15 @@ QPDF::checkLinearizationInternal() | ||
| 651 | // code. | 646 | // code. |
| 652 | if (!errors.empty()) { | 647 | if (!errors.empty()) { |
| 653 | result = false; | 648 | result = false; |
| 654 | - for (std::list<std::string>::iterator iter = errors.begin(); | ||
| 655 | - iter != errors.end(); | ||
| 656 | - ++iter) { | ||
| 657 | - *this->m->err_stream << "WARNING: " << (*iter) << std::endl; | 649 | + for (auto const& error: errors) { |
| 650 | + *this->m->err_stream << "WARNING: " << error << std::endl; | ||
| 658 | } | 651 | } |
| 659 | } | 652 | } |
| 660 | 653 | ||
| 661 | if (!warnings.empty()) { | 654 | if (!warnings.empty()) { |
| 662 | result = false; | 655 | result = false; |
| 663 | - for (std::list<std::string>::iterator iter = warnings.begin(); | ||
| 664 | - iter != warnings.end(); | ||
| 665 | - ++iter) { | ||
| 666 | - *this->m->err_stream << "WARNING: " << (*iter) << std::endl; | 656 | + for (auto const& warning: warnings) { |
| 657 | + *this->m->err_stream << "WARNING: " << warning << std::endl; | ||
| 667 | } | 658 | } |
| 668 | } | 659 | } |
| 669 | 660 | ||
| @@ -678,10 +669,7 @@ QPDF::maxEnd(ObjUser const& ou) | @@ -678,10 +669,7 @@ QPDF::maxEnd(ObjUser const& ou) | ||
| 678 | } | 669 | } |
| 679 | std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; | 670 | std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; |
| 680 | qpdf_offset_t end = 0; | 671 | qpdf_offset_t end = 0; |
| 681 | - for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin(); | ||
| 682 | - iter != ogs.end(); | ||
| 683 | - ++iter) { | ||
| 684 | - QPDFObjGen const& og = *iter; | 672 | + for (auto const& og: ogs) { |
| 685 | if (this->m->obj_cache.count(og) == 0) { | 673 | if (this->m->obj_cache.count(og) == 0) { |
| 686 | stopOnError("unknown object referenced in object user table"); | 674 | stopOnError("unknown object referenced in object user table"); |
| 687 | } | 675 | } |
| @@ -855,28 +843,24 @@ QPDF::checkHPageOffset( | @@ -855,28 +843,24 @@ QPDF::checkHPageOffset( | ||
| 855 | computed_shared.insert(obj); | 843 | computed_shared.insert(obj); |
| 856 | } | 844 | } |
| 857 | 845 | ||
| 858 | - for (std::set<int>::iterator iter = hint_shared.begin(); | ||
| 859 | - iter != hint_shared.end(); | ||
| 860 | - ++iter) { | ||
| 861 | - if (!computed_shared.count(*iter)) { | 846 | + for (int iter: hint_shared) { |
| 847 | + if (!computed_shared.count(iter)) { | ||
| 862 | // pdlin puts thumbnails here even though it shouldn't | 848 | // pdlin puts thumbnails here even though it shouldn't |
| 863 | warnings.push_back( | 849 | warnings.push_back( |
| 864 | "page " + QUtil::int_to_string(pageno) + | 850 | "page " + QUtil::int_to_string(pageno) + |
| 865 | - ": shared object " + QUtil::int_to_string(*iter) + | 851 | + ": shared object " + QUtil::int_to_string(iter) + |
| 866 | ": in hint table but not computed list"); | 852 | ": in hint table but not computed list"); |
| 867 | } | 853 | } |
| 868 | } | 854 | } |
| 869 | 855 | ||
| 870 | - for (std::set<int>::iterator iter = computed_shared.begin(); | ||
| 871 | - iter != computed_shared.end(); | ||
| 872 | - ++iter) { | ||
| 873 | - if (!hint_shared.count(*iter)) { | 856 | + for (int iter: computed_shared) { |
| 857 | + if (!hint_shared.count(iter)) { | ||
| 874 | // Acrobat does not put some things including at least | 858 | // Acrobat does not put some things including at least |
| 875 | // built-in fonts and procsets here, at least in some | 859 | // built-in fonts and procsets here, at least in some |
| 876 | // cases. | 860 | // cases. |
| 877 | warnings.push_back( | 861 | warnings.push_back( |
| 878 | "page " + QUtil::int_to_string(pageno) + | 862 | "page " + QUtil::int_to_string(pageno) + |
| 879 | - ": shared object " + QUtil::int_to_string(*iter) + | 863 | + ": shared object " + QUtil::int_to_string(iter) + |
| 880 | ": in computed list but not hint table"); | 864 | ": in computed list but not hint table"); |
| 881 | } | 865 | } |
| 882 | } | 866 | } |
| @@ -1290,13 +1274,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1290,13 +1274,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1290 | std::set<QPDFObjGen> lc_outlines; | 1274 | std::set<QPDFObjGen> lc_outlines; |
| 1291 | std::set<QPDFObjGen> lc_root; | 1275 | std::set<QPDFObjGen> lc_root; |
| 1292 | 1276 | ||
| 1293 | - for (std::map<QPDFObjGen, std::set<ObjUser>>::iterator oiter = | ||
| 1294 | - this->m->object_to_obj_users.begin(); | ||
| 1295 | - oiter != this->m->object_to_obj_users.end(); | ||
| 1296 | - ++oiter) { | ||
| 1297 | - QPDFObjGen const& og = (*oiter).first; | ||
| 1298 | - | ||
| 1299 | - std::set<ObjUser>& ous = (*oiter).second; | 1277 | + for (auto& oiter: this->m->object_to_obj_users) { |
| 1278 | + QPDFObjGen const& og = oiter.first; | ||
| 1279 | + std::set<ObjUser>& ous = oiter.second; | ||
| 1300 | 1280 | ||
| 1301 | bool in_open_document = false; | 1281 | bool in_open_document = false; |
| 1302 | bool in_first_page = false; | 1282 | bool in_first_page = false; |
| @@ -1306,10 +1286,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1306,10 +1286,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1306 | bool in_outlines = false; | 1286 | bool in_outlines = false; |
| 1307 | bool is_root = false; | 1287 | bool is_root = false; |
| 1308 | 1288 | ||
| 1309 | - for (std::set<ObjUser>::iterator uiter = ous.begin(); | ||
| 1310 | - uiter != ous.end(); | ||
| 1311 | - ++uiter) { | ||
| 1312 | - ObjUser const& ou = *uiter; | 1289 | + for (auto const& ou: ous) { |
| 1313 | switch (ou.ou_type) { | 1290 | switch (ou.ou_type) { |
| 1314 | case ObjUser::ou_trailer_key: | 1291 | case ObjUser::ou_trailer_key: |
| 1315 | if (ou.key == "/Encrypt") { | 1292 | if (ou.key == "/Encrypt") { |
| @@ -1396,11 +1373,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1396,11 +1373,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1396 | { // local scope | 1373 | { // local scope |
| 1397 | // Map all page objects to the containing object stream. This | 1374 | // Map all page objects to the containing object stream. This |
| 1398 | // should be a no-op in a properly linearized file. | 1375 | // should be a no-op in a properly linearized file. |
| 1399 | - std::vector<QPDFObjectHandle> t = getAllPages(); | ||
| 1400 | - for (std::vector<QPDFObjectHandle>::iterator iter = t.begin(); | ||
| 1401 | - iter != t.end(); | ||
| 1402 | - ++iter) { | ||
| 1403 | - pages.push_back(getUncompressedObject(*iter, object_stream_data)); | 1376 | + for (auto oh: getAllPages()) { |
| 1377 | + pages.push_back(getUncompressedObject(oh, object_stream_data)); | ||
| 1404 | } | 1378 | } |
| 1405 | } | 1379 | } |
| 1406 | int npages = toI(pages.size()); | 1380 | int npages = toI(pages.size()); |
| @@ -1427,10 +1401,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1427,10 +1401,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1427 | " calculating linearization data"); | 1401 | " calculating linearization data"); |
| 1428 | } | 1402 | } |
| 1429 | this->m->part4.push_back(objGenToIndirect(*(lc_root.begin()))); | 1403 | this->m->part4.push_back(objGenToIndirect(*(lc_root.begin()))); |
| 1430 | - for (std::set<QPDFObjGen>::iterator iter = lc_open_document.begin(); | ||
| 1431 | - iter != lc_open_document.end(); | ||
| 1432 | - ++iter) { | ||
| 1433 | - this->m->part4.push_back(objGenToIndirect(*iter)); | 1404 | + for (auto const& og: lc_open_document) { |
| 1405 | + this->m->part4.push_back(objGenToIndirect(og)); | ||
| 1434 | } | 1406 | } |
| 1435 | 1407 | ||
| 1436 | // Part 6: first page objects. Note: implementation note 124 | 1408 | // Part 6: first page objects. Note: implementation note 124 |
| @@ -1458,16 +1430,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1458,16 +1430,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1458 | // groups private and shared objects contiguously for the sake of | 1430 | // groups private and shared objects contiguously for the sake of |
| 1459 | // hint tables. | 1431 | // hint tables. |
| 1460 | 1432 | ||
| 1461 | - for (std::set<QPDFObjGen>::iterator iter = lc_first_page_private.begin(); | ||
| 1462 | - iter != lc_first_page_private.end(); | ||
| 1463 | - ++iter) { | ||
| 1464 | - this->m->part6.push_back(objGenToIndirect(*iter)); | 1433 | + for (auto const& og: lc_first_page_private) { |
| 1434 | + this->m->part6.push_back(objGenToIndirect(og)); | ||
| 1465 | } | 1435 | } |
| 1466 | 1436 | ||
| 1467 | - for (std::set<QPDFObjGen>::iterator iter = lc_first_page_shared.begin(); | ||
| 1468 | - iter != lc_first_page_shared.end(); | ||
| 1469 | - ++iter) { | ||
| 1470 | - this->m->part6.push_back(objGenToIndirect(*iter)); | 1437 | + for (auto const& og: lc_first_page_shared) { |
| 1438 | + this->m->part6.push_back(objGenToIndirect(og)); | ||
| 1471 | } | 1439 | } |
| 1472 | 1440 | ||
| 1473 | // Place the outline dictionary if it goes in the first page section. | 1441 | // Place the outline dictionary if it goes in the first page section. |
| @@ -1511,10 +1479,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1511,10 +1479,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1511 | " calculating linearization data"); | 1479 | " calculating linearization data"); |
| 1512 | } | 1480 | } |
| 1513 | std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou]; | 1481 | std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou]; |
| 1514 | - for (std::set<QPDFObjGen>::iterator iter = ogs.begin(); | ||
| 1515 | - iter != ogs.end(); | ||
| 1516 | - ++iter) { | ||
| 1517 | - QPDFObjGen const& og = (*iter); | 1482 | + for (auto const& og: ogs) { |
| 1518 | if (lc_other_page_private.count(og)) { | 1483 | if (lc_other_page_private.count(og)) { |
| 1519 | lc_other_page_private.erase(og); | 1484 | lc_other_page_private.erase(og); |
| 1520 | this->m->part7.push_back(objGenToIndirect(og)); | 1485 | this->m->part7.push_back(objGenToIndirect(og)); |
| @@ -1533,10 +1498,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1533,10 +1498,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1533 | // Part 8: other pages' shared objects | 1498 | // Part 8: other pages' shared objects |
| 1534 | 1499 | ||
| 1535 | // Order is unimportant. | 1500 | // Order is unimportant. |
| 1536 | - for (std::set<QPDFObjGen>::iterator iter = lc_other_page_shared.begin(); | ||
| 1537 | - iter != lc_other_page_shared.end(); | ||
| 1538 | - ++iter) { | ||
| 1539 | - this->m->part8.push_back(objGenToIndirect(*iter)); | 1501 | + for (auto const& og: lc_other_page_shared) { |
| 1502 | + this->m->part8.push_back(objGenToIndirect(og)); | ||
| 1540 | } | 1503 | } |
| 1541 | 1504 | ||
| 1542 | // Part 9: other objects | 1505 | // Part 9: other objects |
| @@ -1555,10 +1518,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1555,10 +1518,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1555 | stopOnError("found empty pages tree while" | 1518 | stopOnError("found empty pages tree while" |
| 1556 | " calculating linearization data"); | 1519 | " calculating linearization data"); |
| 1557 | } | 1520 | } |
| 1558 | - for (std::set<QPDFObjGen>::iterator iter = pages_ogs.begin(); | ||
| 1559 | - iter != pages_ogs.end(); | ||
| 1560 | - ++iter) { | ||
| 1561 | - QPDFObjGen const& og = *iter; | 1521 | + for (auto const& og: pages_ogs) { |
| 1562 | if (lc_other.count(og)) { | 1522 | if (lc_other.count(og)) { |
| 1563 | lc_other.erase(og); | 1523 | lc_other.erase(og); |
| 1564 | this->m->part9.push_back(objGenToIndirect(og)); | 1524 | this->m->part9.push_back(objGenToIndirect(og)); |
| @@ -1588,10 +1548,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1588,10 +1548,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1588 | std::set<QPDFObjGen>& ogs = | 1548 | std::set<QPDFObjGen>& ogs = |
| 1589 | this->m | 1549 | this->m |
| 1590 | ->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; | 1550 | ->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; |
| 1591 | - for (std::set<QPDFObjGen>::iterator iter = ogs.begin(); | ||
| 1592 | - iter != ogs.end(); | ||
| 1593 | - ++iter) { | ||
| 1594 | - QPDFObjGen const& og = *iter; | 1551 | + for (auto const& og: ogs) { |
| 1595 | if (lc_thumbnail_private.count(og)) { | 1552 | if (lc_thumbnail_private.count(og)) { |
| 1596 | lc_thumbnail_private.erase(og); | 1553 | lc_thumbnail_private.erase(og); |
| 1597 | this->m->part9.push_back(objGenToIndirect(og)); | 1554 | this->m->part9.push_back(objGenToIndirect(og)); |
| @@ -1606,10 +1563,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1606,10 +1563,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1606 | } | 1563 | } |
| 1607 | 1564 | ||
| 1608 | // Place shared thumbnail objects | 1565 | // Place shared thumbnail objects |
| 1609 | - for (std::set<QPDFObjGen>::iterator iter = lc_thumbnail_shared.begin(); | ||
| 1610 | - iter != lc_thumbnail_shared.end(); | ||
| 1611 | - ++iter) { | ||
| 1612 | - this->m->part9.push_back(objGenToIndirect(*iter)); | 1566 | + for (auto const& og: lc_thumbnail_shared) { |
| 1567 | + this->m->part9.push_back(objGenToIndirect(og)); | ||
| 1613 | } | 1568 | } |
| 1614 | 1569 | ||
| 1615 | // Place outlines unless in first page | 1570 | // Place outlines unless in first page |
| @@ -1618,10 +1573,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1618,10 +1573,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1618 | } | 1573 | } |
| 1619 | 1574 | ||
| 1620 | // Place all remaining objects | 1575 | // Place all remaining objects |
| 1621 | - for (std::set<QPDFObjGen>::iterator iter = lc_other.begin(); | ||
| 1622 | - iter != lc_other.end(); | ||
| 1623 | - ++iter) { | ||
| 1624 | - this->m->part9.push_back(objGenToIndirect(*iter)); | 1576 | + for (auto const& og: lc_other) { |
| 1577 | + this->m->part9.push_back(objGenToIndirect(og)); | ||
| 1625 | } | 1578 | } |
| 1626 | 1579 | ||
| 1627 | // Make sure we got everything exactly once. | 1580 | // Make sure we got everything exactly once. |
| @@ -1658,10 +1611,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1658,10 +1611,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1658 | 1611 | ||
| 1659 | std::vector<CHSharedObjectEntry>& shared = | 1612 | std::vector<CHSharedObjectEntry>& shared = |
| 1660 | this->m->c_shared_object_data.entries; | 1613 | this->m->c_shared_object_data.entries; |
| 1661 | - for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin(); | ||
| 1662 | - iter != this->m->part6.end(); | ||
| 1663 | - ++iter) { | ||
| 1664 | - QPDFObjectHandle& oh = *iter; | 1614 | + for (auto& oh: this->m->part6) { |
| 1665 | int obj = oh.getObjectID(); | 1615 | int obj = oh.getObjectID(); |
| 1666 | obj_to_index[obj] = toI(shared.size()); | 1616 | obj_to_index[obj] = toI(shared.size()); |
| 1667 | shared.push_back(CHSharedObjectEntry(obj)); | 1617 | shared.push_back(CHSharedObjectEntry(obj)); |
| @@ -1670,11 +1620,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1670,11 +1620,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1670 | if (!this->m->part8.empty()) { | 1620 | if (!this->m->part8.empty()) { |
| 1671 | this->m->c_shared_object_data.first_shared_obj = | 1621 | this->m->c_shared_object_data.first_shared_obj = |
| 1672 | this->m->part8.at(0).getObjectID(); | 1622 | this->m->part8.at(0).getObjectID(); |
| 1673 | - for (std::vector<QPDFObjectHandle>::iterator iter = | ||
| 1674 | - this->m->part8.begin(); | ||
| 1675 | - iter != this->m->part8.end(); | ||
| 1676 | - ++iter) { | ||
| 1677 | - QPDFObjectHandle& oh = *iter; | 1623 | + for (auto& oh: this->m->part8) { |
| 1678 | int obj = oh.getObjectID(); | 1624 | int obj = oh.getObjectID(); |
| 1679 | obj_to_index[obj] = toI(shared.size()); | 1625 | obj_to_index[obj] = toI(shared.size()); |
| 1680 | shared.push_back(CHSharedObjectEntry(obj)); | 1626 | shared.push_back(CHSharedObjectEntry(obj)); |
| @@ -1696,10 +1642,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1696,10 +1642,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1696 | " calculating linearization data"); | 1642 | " calculating linearization data"); |
| 1697 | } | 1643 | } |
| 1698 | std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; | 1644 | std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; |
| 1699 | - for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin(); | ||
| 1700 | - iter != ogs.end(); | ||
| 1701 | - ++iter) { | ||
| 1702 | - QPDFObjGen const& og = *iter; | 1645 | + for (auto const& og: ogs) { |
| 1703 | if ((this->m->object_to_obj_users[og].size() > 1) && | 1646 | if ((this->m->object_to_obj_users[og].size() > 1) && |
| 1704 | (obj_to_index.count(og.getObj()) > 0)) { | 1647 | (obj_to_index.count(og.getObj()) > 0)) { |
| 1705 | int idx = obj_to_index[og.getObj()]; | 1648 | int idx = obj_to_index[og.getObj()]; |
| @@ -1733,10 +1676,8 @@ QPDF::pushOutlinesToPart( | @@ -1733,10 +1676,8 @@ QPDF::pushOutlinesToPart( | ||
| 1733 | this->m->c_outline_data.nobjects = 1; | 1676 | this->m->c_outline_data.nobjects = 1; |
| 1734 | lc_outlines.erase(outlines_og); | 1677 | lc_outlines.erase(outlines_og); |
| 1735 | part.push_back(outlines); | 1678 | part.push_back(outlines); |
| 1736 | - for (std::set<QPDFObjGen>::iterator iter = lc_outlines.begin(); | ||
| 1737 | - iter != lc_outlines.end(); | ||
| 1738 | - ++iter) { | ||
| 1739 | - part.push_back(objGenToIndirect(*iter)); | 1679 | + for (auto const& og: lc_outlines) { |
| 1680 | + part.push_back(objGenToIndirect(og)); | ||
| 1740 | ++this->m->c_outline_data.nobjects; | 1681 | ++this->m->c_outline_data.nobjects; |
| 1741 | } | 1682 | } |
| 1742 | } | 1683 | } |
libqpdf/QPDF_optimization.cc
| @@ -90,10 +90,7 @@ QPDF::optimize( | @@ -90,10 +90,7 @@ QPDF::optimize( | ||
| 90 | 90 | ||
| 91 | // Traverse document-level items | 91 | // Traverse document-level items |
| 92 | std::set<std::string> keys = this->m->trailer.getKeys(); | 92 | std::set<std::string> keys = this->m->trailer.getKeys(); |
| 93 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 94 | - iter != keys.end(); | ||
| 95 | - ++iter) { | ||
| 96 | - std::string const& key = *iter; | 93 | + for (auto const& key: keys) { |
| 97 | if (key == "/Root") { | 94 | if (key == "/Root") { |
| 98 | // handled separately | 95 | // handled separately |
| 99 | } else { | 96 | } else { |
| @@ -105,17 +102,13 @@ QPDF::optimize( | @@ -105,17 +102,13 @@ QPDF::optimize( | ||
| 105 | } | 102 | } |
| 106 | 103 | ||
| 107 | keys = root.getKeys(); | 104 | keys = root.getKeys(); |
| 108 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 109 | - iter != keys.end(); | ||
| 110 | - ++iter) { | 105 | + for (auto const& key: keys) { |
| 111 | // Technically, /I keys from /Thread dictionaries are supposed | 106 | // Technically, /I keys from /Thread dictionaries are supposed |
| 112 | // to be handled separately, but we are going to disregard | 107 | // to be handled separately, but we are going to disregard |
| 113 | // that specification for now. There is loads of evidence | 108 | // that specification for now. There is loads of evidence |
| 114 | // that pdlin and Acrobat both disregard things like this from | 109 | // that pdlin and Acrobat both disregard things like this from |
| 115 | // time to time, so this is almost certain not to cause any | 110 | // time to time, so this is almost certain not to cause any |
| 116 | // problems. | 111 | // problems. |
| 117 | - | ||
| 118 | - std::string const& key = *iter; | ||
| 119 | updateObjectMaps( | 112 | updateObjectMaps( |
| 120 | ObjUser(ObjUser::ou_root_key, key), | 113 | ObjUser(ObjUser::ou_root_key, key), |
| 121 | root.getKey(key), | 114 | root.getKey(key), |
| @@ -212,10 +205,7 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -212,10 +205,7 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 212 | 205 | ||
| 213 | std::set<std::string> inheritable_keys; | 206 | std::set<std::string> inheritable_keys; |
| 214 | std::set<std::string> keys = cur_pages.getKeys(); | 207 | std::set<std::string> keys = cur_pages.getKeys(); |
| 215 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 216 | - iter != keys.end(); | ||
| 217 | - ++iter) { | ||
| 218 | - std::string const& key = *iter; | 208 | + for (auto const& key: keys) { |
| 219 | if ((key == "/MediaBox") || (key == "/CropBox") || | 209 | if ((key == "/MediaBox") || (key == "/CropBox") || |
| 220 | (key == "/Resources") || (key == "/Rotate")) { | 210 | (key == "/Resources") || (key == "/Rotate")) { |
| 221 | if (!allow_changes) { | 211 | if (!allow_changes) { |
| @@ -298,11 +288,7 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -298,11 +288,7 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 298 | 288 | ||
| 299 | if (!inheritable_keys.empty()) { | 289 | if (!inheritable_keys.empty()) { |
| 300 | QTC::TC("qpdf", "QPDF opt inheritable keys"); | 290 | QTC::TC("qpdf", "QPDF opt inheritable keys"); |
| 301 | - for (std::set<std::string>::iterator iter = | ||
| 302 | - inheritable_keys.begin(); | ||
| 303 | - iter != inheritable_keys.end(); | ||
| 304 | - ++iter) { | ||
| 305 | - std::string const& key = (*iter); | 291 | + for (auto const& key: inheritable_keys) { |
| 306 | key_ancestors[key].pop_back(); | 292 | key_ancestors[key].pop_back(); |
| 307 | if (key_ancestors[key].empty()) { | 293 | if (key_ancestors[key].empty()) { |
| 308 | QTC::TC("qpdf", "QPDF opt erase empty key ancestor"); | 294 | QTC::TC("qpdf", "QPDF opt erase empty key ancestor"); |
| @@ -315,14 +301,11 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -315,14 +301,11 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 315 | } else if (type == "/Page") { | 301 | } else if (type == "/Page") { |
| 316 | // Add all available inheritable attributes not present in | 302 | // Add all available inheritable attributes not present in |
| 317 | // this object to this object. | 303 | // this object to this object. |
| 318 | - for (std::map<std::string, std::vector<QPDFObjectHandle>>::iterator | ||
| 319 | - iter = key_ancestors.begin(); | ||
| 320 | - iter != key_ancestors.end(); | ||
| 321 | - ++iter) { | ||
| 322 | - std::string const& key = (*iter).first; | 304 | + for (auto const& iter: key_ancestors) { |
| 305 | + std::string const& key = iter.first; | ||
| 323 | if (!cur_pages.hasKey(key)) { | 306 | if (!cur_pages.hasKey(key)) { |
| 324 | QTC::TC("qpdf", "QPDF opt resource inherited"); | 307 | QTC::TC("qpdf", "QPDF opt resource inherited"); |
| 325 | - cur_pages.replaceKey(key, (*iter).second.back()); | 308 | + cur_pages.replaceKey(key, iter.second.back()); |
| 326 | } else { | 309 | } else { |
| 327 | QTC::TC("qpdf", "QPDF opt page resource hides ancestor"); | 310 | QTC::TC("qpdf", "QPDF opt page resource hides ancestor"); |
| 328 | } | 311 | } |
| @@ -404,10 +387,7 @@ QPDF::updateObjectMapsInternal( | @@ -404,10 +387,7 @@ QPDF::updateObjectMapsInternal( | ||
| 404 | } | 387 | } |
| 405 | 388 | ||
| 406 | std::set<std::string> keys = dict.getKeys(); | 389 | std::set<std::string> keys = dict.getKeys(); |
| 407 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 408 | - iter != keys.end(); | ||
| 409 | - ++iter) { | ||
| 410 | - std::string const& key = *iter; | 390 | + for (auto const& key: keys) { |
| 411 | if (is_page_node && (key == "/Thumb")) { | 391 | if (is_page_node && (key == "/Thumb")) { |
| 412 | // Traverse page thumbnail dictionaries as a special | 392 | // Traverse page thumbnail dictionaries as a special |
| 413 | // case. | 393 | // case. |
| @@ -454,42 +434,28 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | @@ -454,42 +434,28 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | ||
| 454 | std::map<ObjUser, std::set<QPDFObjGen>> t_obj_user_to_objects; | 434 | std::map<ObjUser, std::set<QPDFObjGen>> t_obj_user_to_objects; |
| 455 | std::map<QPDFObjGen, std::set<ObjUser>> t_object_to_obj_users; | 435 | std::map<QPDFObjGen, std::set<ObjUser>> t_object_to_obj_users; |
| 456 | 436 | ||
| 457 | - for (std::map<ObjUser, std::set<QPDFObjGen>>::iterator i1 = | ||
| 458 | - this->m->obj_user_to_objects.begin(); | ||
| 459 | - i1 != this->m->obj_user_to_objects.end(); | ||
| 460 | - ++i1) { | ||
| 461 | - ObjUser const& ou = (*i1).first; | ||
| 462 | - std::set<QPDFObjGen> const& objects = (*i1).second; | ||
| 463 | - for (std::set<QPDFObjGen>::const_iterator i2 = objects.begin(); | ||
| 464 | - i2 != objects.end(); | ||
| 465 | - ++i2) { | ||
| 466 | - QPDFObjGen const& og = (*i2); | ||
| 467 | - std::map<int, int>::const_iterator i3 = | ||
| 468 | - object_stream_data.find(og.getObj()); | ||
| 469 | - if (i3 == object_stream_data.end()) { | 437 | + for (auto const& i1: this->m->obj_user_to_objects) { |
| 438 | + ObjUser const& ou = i1.first; | ||
| 439 | + std::set<QPDFObjGen> const& objects = i1.second; | ||
| 440 | + for (auto const& og: objects) { | ||
| 441 | + auto i2 = object_stream_data.find(og.getObj()); | ||
| 442 | + if (i2 == object_stream_data.end()) { | ||
| 470 | t_obj_user_to_objects[ou].insert(og); | 443 | t_obj_user_to_objects[ou].insert(og); |
| 471 | } else { | 444 | } else { |
| 472 | - t_obj_user_to_objects[ou].insert(QPDFObjGen((*i3).second, 0)); | 445 | + t_obj_user_to_objects[ou].insert(QPDFObjGen(i2->second, 0)); |
| 473 | } | 446 | } |
| 474 | } | 447 | } |
| 475 | } | 448 | } |
| 476 | 449 | ||
| 477 | - for (std::map<QPDFObjGen, std::set<ObjUser>>::iterator i1 = | ||
| 478 | - this->m->object_to_obj_users.begin(); | ||
| 479 | - i1 != this->m->object_to_obj_users.end(); | ||
| 480 | - ++i1) { | ||
| 481 | - QPDFObjGen const& og = (*i1).first; | ||
| 482 | - std::set<ObjUser> const& objusers = (*i1).second; | ||
| 483 | - for (std::set<ObjUser>::const_iterator i2 = objusers.begin(); | ||
| 484 | - i2 != objusers.end(); | ||
| 485 | - ++i2) { | ||
| 486 | - ObjUser const& ou = (*i2); | ||
| 487 | - std::map<int, int>::const_iterator i3 = | ||
| 488 | - object_stream_data.find(og.getObj()); | ||
| 489 | - if (i3 == object_stream_data.end()) { | 450 | + for (auto const& i1: this->m->object_to_obj_users) { |
| 451 | + QPDFObjGen const& og = i1.first; | ||
| 452 | + std::set<ObjUser> const& objusers = i1.second; | ||
| 453 | + for (auto const& ou: objusers) { | ||
| 454 | + auto i2 = object_stream_data.find(og.getObj()); | ||
| 455 | + if (i2 == object_stream_data.end()) { | ||
| 490 | t_object_to_obj_users[og].insert(ou); | 456 | t_object_to_obj_users[og].insert(ou); |
| 491 | } else { | 457 | } else { |
| 492 | - t_object_to_obj_users[QPDFObjGen((*i3).second, 0)].insert(ou); | 458 | + t_object_to_obj_users[QPDFObjGen(i2->second, 0)].insert(ou); |
| 493 | } | 459 | } |
| 494 | } | 460 | } |
| 495 | } | 461 | } |
libqpdf/QPDF_pages.cc
| @@ -319,8 +319,7 @@ int | @@ -319,8 +319,7 @@ int | ||
| 319 | QPDF::findPage(QPDFObjGen const& og) | 319 | QPDF::findPage(QPDFObjGen const& og) |
| 320 | { | 320 | { |
| 321 | flattenPagesTree(); | 321 | flattenPagesTree(); |
| 322 | - std::map<QPDFObjGen, int>::iterator it = | ||
| 323 | - this->m->pageobj_to_pages_pos.find(og); | 322 | + auto it = this->m->pageobj_to_pages_pos.find(og); |
| 324 | if (it == this->m->pageobj_to_pages_pos.end()) { | 323 | if (it == this->m->pageobj_to_pages_pos.end()) { |
| 325 | QTC::TC("qpdf", "QPDF_pages findPage not found"); | 324 | QTC::TC("qpdf", "QPDF_pages findPage not found"); |
| 326 | setLastObjectDescription("page object", og.getObj(), og.getGen()); | 325 | setLastObjectDescription("page object", og.getObj(), og.getGen()); |
libqpdf/QUtil.cc
| @@ -786,14 +786,13 @@ QUtil::hex_decode(std::string const& input) | @@ -786,14 +786,13 @@ QUtil::hex_decode(std::string const& input) | ||
| 786 | { | 786 | { |
| 787 | std::string result; | 787 | std::string result; |
| 788 | size_t pos = 0; | 788 | size_t pos = 0; |
| 789 | - for (std::string::const_iterator p = input.begin(); p != input.end(); ++p) { | ||
| 790 | - char ch = *p; | 789 | + for (auto ch: input) { |
| 791 | bool skip = false; | 790 | bool skip = false; |
| 792 | - if ((*p >= 'A') && (*p <= 'F')) { | 791 | + if ((ch >= 'A') && (ch <= 'F')) { |
| 793 | ch = QIntC::to_char(ch - 'A' + 10); | 792 | ch = QIntC::to_char(ch - 'A' + 10); |
| 794 | - } else if ((*p >= 'a') && (*p <= 'f')) { | 793 | + } else if ((ch >= 'a') && (ch <= 'f')) { |
| 795 | ch = QIntC::to_char(ch - 'a' + 10); | 794 | ch = QIntC::to_char(ch - 'a' + 10); |
| 796 | - } else if ((*p >= '0') && (*p <= '9')) { | 795 | + } else if ((ch >= '0') && (ch <= '9')) { |
| 797 | ch = QIntC::to_char(ch - '0'); | 796 | ch = QIntC::to_char(ch - '0'); |
| 798 | } else { | 797 | } else { |
| 799 | skip = true; | 798 | skip = true; |
| @@ -1921,12 +1920,10 @@ QUtil::possible_repaired_encodings(std::string supplied) | @@ -1921,12 +1920,10 @@ QUtil::possible_repaired_encodings(std::string supplied) | ||
| 1921 | // De-duplicate | 1920 | // De-duplicate |
| 1922 | std::vector<std::string> t; | 1921 | std::vector<std::string> t; |
| 1923 | std::set<std::string> seen; | 1922 | std::set<std::string> seen; |
| 1924 | - for (std::vector<std::string>::iterator iter = result.begin(); | ||
| 1925 | - iter != result.end(); | ||
| 1926 | - ++iter) { | ||
| 1927 | - if (!seen.count(*iter)) { | ||
| 1928 | - seen.insert(*iter); | ||
| 1929 | - t.push_back(*iter); | 1923 | + for (auto const& iter: result) { |
| 1924 | + if (!seen.count(iter)) { | ||
| 1925 | + seen.insert(iter); | ||
| 1926 | + t.push_back(iter); | ||
| 1930 | } | 1927 | } |
| 1931 | } | 1928 | } |
| 1932 | return t; | 1929 | return t; |
libtests/json.cc
| @@ -130,10 +130,8 @@ check_schema( | @@ -130,10 +130,8 @@ check_schema( | ||
| 130 | std::list<std::string> errors; | 130 | std::list<std::string> errors; |
| 131 | std::cout << "--- " << description << std::endl; | 131 | std::cout << "--- " << description << std::endl; |
| 132 | assert(exp == obj.checkSchema(schema, flags, errors)); | 132 | assert(exp == obj.checkSchema(schema, flags, errors)); |
| 133 | - for (std::list<std::string>::iterator iter = errors.begin(); | ||
| 134 | - iter != errors.end(); | ||
| 135 | - ++iter) { | ||
| 136 | - std::cout << *iter << std::endl; | 133 | + for (auto const& error: errors) { |
| 134 | + std::cout << error << std::endl; | ||
| 137 | } | 135 | } |
| 138 | std::cout << "---" << std::endl; | 136 | std::cout << "---" << std::endl; |
| 139 | } | 137 | } |
libtests/numrange.cc
| @@ -9,10 +9,8 @@ test_numrange(char const* range) | @@ -9,10 +9,8 @@ test_numrange(char const* range) | ||
| 9 | } else { | 9 | } else { |
| 10 | std::vector<int> result = QUtil::parse_numrange(range, 15); | 10 | std::vector<int> result = QUtil::parse_numrange(range, 15); |
| 11 | std::cout << "numeric range " << range << " ->"; | 11 | std::cout << "numeric range " << range << " ->"; |
| 12 | - for (std::vector<int>::iterator iter = result.begin(); | ||
| 13 | - iter != result.end(); | ||
| 14 | - ++iter) { | ||
| 15 | - std::cout << " " << *iter; | 12 | + for (int i: result) { |
| 13 | + std::cout << " " << i; | ||
| 16 | } | 14 | } |
| 17 | std::cout << std::endl; | 15 | std::cout << std::endl; |
| 18 | } | 16 | } |
libtests/qutil.cc
| @@ -229,12 +229,10 @@ print_utf8(unsigned long val) | @@ -229,12 +229,10 @@ print_utf8(unsigned long val) | ||
| 229 | // Emacs has trouble with utf-8 encoding files with characters | 229 | // Emacs has trouble with utf-8 encoding files with characters |
| 230 | // outside the 16-bit portion, so just show the character | 230 | // outside the 16-bit portion, so just show the character |
| 231 | // values. | 231 | // values. |
| 232 | - for (std::string::iterator iter = result.begin(); iter != result.end(); | ||
| 233 | - ++iter) { | 232 | + for (auto const& ch: result) { |
| 234 | std::cout << " " | 233 | std::cout << " " |
| 235 | << QUtil::int_to_string_base( | 234 | << QUtil::int_to_string_base( |
| 236 | - static_cast<int>( | ||
| 237 | - static_cast<unsigned char>(*iter)), | 235 | + static_cast<int>(static_cast<unsigned char>(ch)), |
| 238 | 16, | 236 | 16, |
| 239 | 2); | 237 | 2); |
| 240 | } | 238 | } |
| @@ -289,11 +287,10 @@ print_utf16(unsigned long val) | @@ -289,11 +287,10 @@ print_utf16(unsigned long val) | ||
| 289 | { | 287 | { |
| 290 | std::string result = QUtil::toUTF16(val); | 288 | std::string result = QUtil::toUTF16(val); |
| 291 | std::cout << "0x" << QUtil::uint_to_string_base(val, 16) << " ->"; | 289 | std::cout << "0x" << QUtil::uint_to_string_base(val, 16) << " ->"; |
| 292 | - for (std::string::iterator iter = result.begin(); iter != result.end(); | ||
| 293 | - ++iter) { | 290 | + for (auto const& ch: result) { |
| 294 | std::cout << " " | 291 | std::cout << " " |
| 295 | << QUtil::int_to_string_base( | 292 | << QUtil::int_to_string_base( |
| 296 | - static_cast<int>(static_cast<unsigned char>(*iter)), | 293 | + static_cast<int>(static_cast<unsigned char>(ch)), |
| 297 | 16, | 294 | 16, |
| 298 | 2); | 295 | 2); |
| 299 | } | 296 | } |
| @@ -516,10 +513,8 @@ void | @@ -516,10 +513,8 @@ void | ||
| 516 | read_from_file_test() | 513 | read_from_file_test() |
| 517 | { | 514 | { |
| 518 | std::list<std::string> lines = QUtil::read_lines_from_file("other-file"); | 515 | std::list<std::string> lines = QUtil::read_lines_from_file("other-file"); |
| 519 | - for (std::list<std::string>::iterator iter = lines.begin(); | ||
| 520 | - iter != lines.end(); | ||
| 521 | - ++iter) { | ||
| 522 | - std::cout << *iter << std::endl; | 516 | + for (auto const& line: lines) { |
| 517 | + std::cout << line << std::endl; | ||
| 523 | } | 518 | } |
| 524 | // Test the other versions and make sure we get the same results | 519 | // Test the other versions and make sure we get the same results |
| 525 | { | 520 | { |
qpdf/test_driver.cc
| @@ -383,14 +383,9 @@ test_5(QPDF& pdf, char const* arg2) | @@ -383,14 +383,9 @@ test_5(QPDF& pdf, char const* arg2) | ||
| 383 | QPDFPageDocumentHelper dh(pdf); | 383 | QPDFPageDocumentHelper dh(pdf); |
| 384 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | 384 | std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); |
| 385 | int pageno = 0; | 385 | int pageno = 0; |
| 386 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 387 | - iter != pages.end(); | ||
| 388 | - ++iter) { | ||
| 389 | - QPDFPageObjectHelper& page(*iter); | 386 | + for (auto& page: pages) { |
| 390 | ++pageno; | 387 | ++pageno; |
| 391 | - | ||
| 392 | std::cout << "page " << pageno << ":" << std::endl; | 388 | std::cout << "page " << pageno << ":" << std::endl; |
| 393 | - | ||
| 394 | std::cout << " images:" << std::endl; | 389 | std::cout << " images:" << std::endl; |
| 395 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); | 390 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 396 | for (auto const& iter2: images) { | 391 | for (auto const& iter2: images) { |
| @@ -714,19 +709,19 @@ test_15(QPDF& pdf, char const* arg2) | @@ -714,19 +709,19 @@ test_15(QPDF& pdf, char const* arg2) | ||
| 714 | // a shallow copy. | 709 | // a shallow copy. |
| 715 | QPDFObjectHandle page_template = pages.at(0); | 710 | QPDFObjectHandle page_template = pages.at(0); |
| 716 | std::vector<QPDFObjectHandle> new_pages; | 711 | std::vector<QPDFObjectHandle> new_pages; |
| 717 | - for (std::vector<QPDFObjectHandle>::iterator iter = contents.begin(); | ||
| 718 | - iter != contents.end(); | ||
| 719 | - ++iter) { | 712 | + bool first = true; |
| 713 | + for (auto const& iter: contents) { | ||
| 720 | // We will retain indirect object references to other | 714 | // We will retain indirect object references to other |
| 721 | // indirect objects other than page content. | 715 | // indirect objects other than page content. |
| 722 | QPDFObjectHandle page = page_template.shallowCopy(); | 716 | QPDFObjectHandle page = page_template.shallowCopy(); |
| 723 | - page.replaceKey("/Contents", *iter); | ||
| 724 | - if (iter == contents.begin()) { | 717 | + page.replaceKey("/Contents", iter); |
| 718 | + if (first) { | ||
| 725 | // leave direct | 719 | // leave direct |
| 726 | - new_pages.push_back(page); | 720 | + first = false; |
| 727 | } else { | 721 | } else { |
| 728 | - new_pages.push_back(pdf.makeIndirectObject(page)); | 722 | + page = pdf.makeIndirectObject(page); |
| 729 | } | 723 | } |
| 724 | + new_pages.push_back(page); | ||
| 730 | } | 725 | } |
| 731 | 726 | ||
| 732 | // Now insert the pages | 727 | // Now insert the pages |
| @@ -1269,14 +1264,11 @@ test_35(QPDF& pdf, char const* arg2) | @@ -1269,14 +1264,11 @@ test_35(QPDF& pdf, char const* arg2) | ||
| 1269 | attachments[filename] = stream.getStreamData(); | 1264 | attachments[filename] = stream.getStreamData(); |
| 1270 | } | 1265 | } |
| 1271 | } | 1266 | } |
| 1272 | - for (std::map<std::string, std::shared_ptr<Buffer>>::iterator iter = | ||
| 1273 | - attachments.begin(); | ||
| 1274 | - iter != attachments.end(); | ||
| 1275 | - ++iter) { | ||
| 1276 | - std::string const& filename = (*iter).first; | 1267 | + for (auto const& iter: attachments) { |
| 1268 | + std::string const& filename = iter.first; | ||
| 1277 | std::string data = std::string( | 1269 | std::string data = std::string( |
| 1278 | - reinterpret_cast<char const*>((*iter).second->getBuffer()), | ||
| 1279 | - (*iter).second->getSize()); | 1270 | + reinterpret_cast<char const*>(iter.second->getBuffer()), |
| 1271 | + iter.second->getSize()); | ||
| 1280 | bool is_binary = false; | 1272 | bool is_binary = false; |
| 1281 | for (size_t i = 0; i < data.size(); ++i) { | 1273 | for (size_t i = 0; i < data.size(); ++i) { |
| 1282 | if ((data.at(i) < 0) || (data.at(i) > 126)) { | 1274 | if ((data.at(i) < 0) || (data.at(i) > 126)) { |
| @@ -1338,10 +1330,7 @@ test_37(QPDF& pdf, char const* arg2) | @@ -1338,10 +1330,7 @@ test_37(QPDF& pdf, char const* arg2) | ||
| 1338 | // Parse content streams of all pages | 1330 | // Parse content streams of all pages |
| 1339 | std::vector<QPDFPageObjectHelper> pages = | 1331 | std::vector<QPDFPageObjectHelper> pages = |
| 1340 | QPDFPageDocumentHelper(pdf).getAllPages(); | 1332 | QPDFPageDocumentHelper(pdf).getAllPages(); |
| 1341 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 1342 | - iter != pages.end(); | ||
| 1343 | - ++iter) { | ||
| 1344 | - QPDFPageObjectHelper& page(*iter); | 1333 | + for (auto& page: pages) { |
| 1345 | ParserCallbacks cb; | 1334 | ParserCallbacks cb; |
| 1346 | page.parseContents(&cb); | 1335 | page.parseContents(&cb); |
| 1347 | } | 1336 | } |
| @@ -1364,16 +1353,11 @@ test_39(QPDF& pdf, char const* arg2) | @@ -1364,16 +1353,11 @@ test_39(QPDF& pdf, char const* arg2) | ||
| 1364 | std::vector<QPDFPageObjectHelper> pages = | 1353 | std::vector<QPDFPageObjectHelper> pages = |
| 1365 | QPDFPageDocumentHelper(pdf).getAllPages(); | 1354 | QPDFPageDocumentHelper(pdf).getAllPages(); |
| 1366 | int pageno = 0; | 1355 | int pageno = 0; |
| 1367 | - for (std::vector<QPDFPageObjectHelper>::iterator p_iter = pages.begin(); | ||
| 1368 | - p_iter != pages.end(); | ||
| 1369 | - ++p_iter) { | 1356 | + for (auto& page: pages) { |
| 1370 | std::cout << "page " << ++pageno << std::endl; | 1357 | std::cout << "page " << ++pageno << std::endl; |
| 1371 | - std::map<std::string, QPDFObjectHandle> images = (*p_iter).getImages(); | ||
| 1372 | - for (std::map<std::string, QPDFObjectHandle>::iterator i_iter = | ||
| 1373 | - images.begin(); | ||
| 1374 | - i_iter != images.end(); | ||
| 1375 | - ++i_iter) { | ||
| 1376 | - QPDFObjectHandle image_dict = (*i_iter).second.getDict(); | 1358 | + std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 1359 | + for (auto& i_iter: images) { | ||
| 1360 | + QPDFObjectHandle image_dict = i_iter.second.getDict(); | ||
| 1377 | std::cout << "filter: " | 1361 | std::cout << "filter: " |
| 1378 | << image_dict.getKey("/Filter").unparseResolved() | 1362 | << image_dict.getKey("/Filter").unparseResolved() |
| 1379 | << ", color space: " | 1363 | << ", color space: " |
| @@ -1404,10 +1388,8 @@ test_41(QPDF& pdf, char const* arg2) | @@ -1404,10 +1388,8 @@ test_41(QPDF& pdf, char const* arg2) | ||
| 1404 | // with coalesce.pdf. | 1388 | // with coalesce.pdf. |
| 1405 | std::vector<QPDFPageObjectHelper> pages = | 1389 | std::vector<QPDFPageObjectHelper> pages = |
| 1406 | QPDFPageDocumentHelper(pdf).getAllPages(); | 1390 | QPDFPageDocumentHelper(pdf).getAllPages(); |
| 1407 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 1408 | - iter != pages.end(); | ||
| 1409 | - ++iter) { | ||
| 1410 | - (*iter).addContentTokenFilter( | 1391 | + for (auto& page: pages) { |
| 1392 | + page.addContentTokenFilter( | ||
| 1411 | std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter())); | 1393 | std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter())); |
| 1412 | } | 1394 | } |
| 1413 | QPDFWriter w(pdf, "a.pdf"); | 1395 | QPDFWriter w(pdf, "a.pdf"); |
| @@ -1537,11 +1519,7 @@ test_43(QPDF& pdf, char const* arg2) | @@ -1537,11 +1519,7 @@ test_43(QPDF& pdf, char const* arg2) | ||
| 1537 | } | 1519 | } |
| 1538 | std::cout << "iterating over form fields\n"; | 1520 | std::cout << "iterating over form fields\n"; |
| 1539 | std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields(); | 1521 | std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields(); |
| 1540 | - for (std::vector<QPDFFormFieldObjectHelper>::iterator iter = | ||
| 1541 | - form_fields.begin(); | ||
| 1542 | - iter != form_fields.end(); | ||
| 1543 | - ++iter) { | ||
| 1544 | - QPDFFormFieldObjectHelper ffh(*iter); | 1522 | + for (auto& ffh: form_fields) { |
| 1545 | std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl; | 1523 | std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl; |
| 1546 | QPDFFormFieldObjectHelper node = ffh; | 1524 | QPDFFormFieldObjectHelper node = ffh; |
| 1547 | while (!node.isNull()) { | 1525 | while (!node.isNull()) { |
| @@ -1571,29 +1549,17 @@ test_43(QPDF& pdf, char const* arg2) | @@ -1571,29 +1549,17 @@ test_43(QPDF& pdf, char const* arg2) | ||
| 1571 | std::cout << " Quadding: " << ffh.getQuadding() << std::endl; | 1549 | std::cout << " Quadding: " << ffh.getQuadding() << std::endl; |
| 1572 | std::vector<QPDFAnnotationObjectHelper> annotations = | 1550 | std::vector<QPDFAnnotationObjectHelper> annotations = |
| 1573 | afdh.getAnnotationsForField(ffh); | 1551 | afdh.getAnnotationsForField(ffh); |
| 1574 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator i2 = | ||
| 1575 | - annotations.begin(); | ||
| 1576 | - i2 != annotations.end(); | ||
| 1577 | - ++i2) { | ||
| 1578 | - std::cout << " Annotation: " << (*i2).getObjectHandle().unparse() | 1552 | + for (auto& aoh: annotations) { |
| 1553 | + std::cout << " Annotation: " << aoh.getObjectHandle().unparse() | ||
| 1579 | << std::endl; | 1554 | << std::endl; |
| 1580 | } | 1555 | } |
| 1581 | } | 1556 | } |
| 1582 | std::cout << "iterating over annotations per page\n"; | 1557 | std::cout << "iterating over annotations per page\n"; |
| 1583 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 1584 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 1585 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 1586 | - iter != pages.end(); | ||
| 1587 | - ++iter) { | ||
| 1588 | - std::cout << "Page: " << (*iter).getObjectHandle().unparse() | ||
| 1589 | - << std::endl; | 1558 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1559 | + std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl; | ||
| 1590 | std::vector<QPDFAnnotationObjectHelper> annotations = | 1560 | std::vector<QPDFAnnotationObjectHelper> annotations = |
| 1591 | - afdh.getWidgetAnnotationsForPage(*iter); | ||
| 1592 | - for (std::vector<QPDFAnnotationObjectHelper>::iterator i2 = | ||
| 1593 | - annotations.begin(); | ||
| 1594 | - i2 != annotations.end(); | ||
| 1595 | - ++i2) { | ||
| 1596 | - QPDFAnnotationObjectHelper ah(*i2); | 1561 | + afdh.getWidgetAnnotationsForPage(page); |
| 1562 | + for (auto& ah: annotations) { | ||
| 1597 | std::cout << " Annotation: " << ah.getObjectHandle().unparse() | 1563 | std::cout << " Annotation: " << ah.getObjectHandle().unparse() |
| 1598 | << std::endl; | 1564 | << std::endl; |
| 1599 | std::cout | 1565 | std::cout |
| @@ -1623,10 +1589,7 @@ test_44(QPDF& pdf, char const* arg2) | @@ -1623,10 +1589,7 @@ test_44(QPDF& pdf, char const* arg2) | ||
| 1623 | // Set form fields. | 1589 | // Set form fields. |
| 1624 | QPDFAcroFormDocumentHelper afdh(pdf); | 1590 | QPDFAcroFormDocumentHelper afdh(pdf); |
| 1625 | std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields(); | 1591 | std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields(); |
| 1626 | - for (std::vector<QPDFFormFieldObjectHelper>::iterator iter = fields.begin(); | ||
| 1627 | - iter != fields.end(); | ||
| 1628 | - ++iter) { | ||
| 1629 | - QPDFFormFieldObjectHelper& field(*iter); | 1592 | + for (auto& field: fields) { |
| 1630 | QPDFObjectHandle ft = field.getInheritableFieldValue("/FT"); | 1593 | QPDFObjectHandle ft = field.getInheritableFieldValue("/FT"); |
| 1631 | if (ft.isName() && (ft.getName() == "/Tx")) { | 1594 | if (ft.isName() && (ft.getName() == "/Tx")) { |
| 1632 | // \xc3\xb7 is utf-8 for U+00F7 (divided by) | 1595 | // \xc3\xb7 is utf-8 for U+00F7 (divided by) |
| @@ -1950,23 +1913,16 @@ static void | @@ -1950,23 +1913,16 @@ static void | ||
| 1950 | test_49(QPDF& pdf, char const* arg2) | 1913 | test_49(QPDF& pdf, char const* arg2) |
| 1951 | { | 1914 | { |
| 1952 | // Outlines | 1915 | // Outlines |
| 1953 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 1954 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 1955 | QPDFOutlineDocumentHelper odh(pdf); | 1916 | QPDFOutlineDocumentHelper odh(pdf); |
| 1956 | int pageno = 0; | 1917 | int pageno = 0; |
| 1957 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 1958 | - iter != pages.end(); | ||
| 1959 | - ++iter, ++pageno) { | ||
| 1960 | - std::vector<QPDFOutlineObjectHelper> outlines = | ||
| 1961 | - odh.getOutlinesForPage((*iter).getObjectHandle().getObjGen()); | ||
| 1962 | - for (std::vector<QPDFOutlineObjectHelper>::iterator oiter = | ||
| 1963 | - outlines.begin(); | ||
| 1964 | - oiter != outlines.end(); | ||
| 1965 | - ++oiter) { | ||
| 1966 | - std::cout << "page " << pageno << ": " << (*oiter).getTitle() | ||
| 1967 | - << " -> " << (*oiter).getDest().unparseResolved() | ||
| 1968 | - << std::endl; | 1918 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1919 | + auto outlines = | ||
| 1920 | + odh.getOutlinesForPage(page.getObjectHandle().getObjGen()); | ||
| 1921 | + for (auto& ol: outlines) { | ||
| 1922 | + std::cout << "page " << pageno << ": " << ol.getTitle() << " -> " | ||
| 1923 | + << ol.getDest().unparseResolved() << std::endl; | ||
| 1969 | } | 1924 | } |
| 1925 | + ++pageno; | ||
| 1970 | } | 1926 | } |
| 1971 | } | 1927 | } |
| 1972 | 1928 | ||
| @@ -1981,11 +1937,8 @@ test_50(QPDF& pdf, char const* arg2) | @@ -1981,11 +1937,8 @@ test_50(QPDF& pdf, char const* arg2) | ||
| 1981 | std::cout << d1.getJSON().unparse() << std::endl; | 1937 | std::cout << d1.getJSON().unparse() << std::endl; |
| 1982 | // Top-level type mismatch | 1938 | // Top-level type mismatch |
| 1983 | d1.mergeResources(d2.getKey("/k1")); | 1939 | d1.mergeResources(d2.getKey("/k1")); |
| 1984 | - std::set<std::string> names = d1.getResourceNames(); | ||
| 1985 | - for (std::set<std::string>::iterator iter = names.begin(); | ||
| 1986 | - iter != names.end(); | ||
| 1987 | - ++iter) { | ||
| 1988 | - std::cout << *iter << std::endl; | 1940 | + for (auto const& name: d1.getResourceNames()) { |
| 1941 | + std::cout << name << std::endl; | ||
| 1989 | } | 1942 | } |
| 1990 | } | 1943 | } |
| 1991 | 1944 | ||
| @@ -2064,11 +2017,8 @@ test_53(QPDF& pdf, char const* arg2) | @@ -2064,11 +2017,8 @@ test_53(QPDF& pdf, char const* arg2) | ||
| 2064 | root.replaceKey( | 2017 | root.replaceKey( |
| 2065 | "/Q1", pdf.makeIndirectObject(QPDFObjectHandle::newString("potato"))); | 2018 | "/Q1", pdf.makeIndirectObject(QPDFObjectHandle::newString("potato"))); |
| 2066 | std::cout << "all objects" << std::endl; | 2019 | std::cout << "all objects" << std::endl; |
| 2067 | - std::vector<QPDFObjectHandle> all = pdf.getAllObjects(); | ||
| 2068 | - for (std::vector<QPDFObjectHandle>::iterator iter = all.begin(); | ||
| 2069 | - iter != all.end(); | ||
| 2070 | - ++iter) { | ||
| 2071 | - std::cout << (*iter).unparse() << std::endl; | 2020 | + for (auto& obj: pdf.getAllObjects()) { |
| 2021 | + std::cout << obj.unparse() << std::endl; | ||
| 2072 | } | 2022 | } |
| 2073 | 2023 | ||
| 2074 | QPDFWriter w(pdf, "a.pdf"); | 2024 | QPDFWriter w(pdf, "a.pdf"); |
qpdf/test_parsedoffset.cc
| @@ -52,21 +52,17 @@ walk( | @@ -52,21 +52,17 @@ walk( | ||
| 52 | 52 | ||
| 53 | if (obj.isArray()) { | 53 | if (obj.isArray()) { |
| 54 | std::vector<QPDFObjectHandle> array = obj.getArrayAsVector(); | 54 | std::vector<QPDFObjectHandle> array = obj.getArrayAsVector(); |
| 55 | - for (std::vector<QPDFObjectHandle>::iterator iter = array.begin(); | ||
| 56 | - iter != array.end(); | ||
| 57 | - ++iter) { | ||
| 58 | - if (!iter->isIndirect()) { | 55 | + for (auto& oh: array) { |
| 56 | + if (!oh.isIndirect()) { | ||
| 59 | // QPDF::GetAllObjects() enumerates all indirect objects. | 57 | // QPDF::GetAllObjects() enumerates all indirect objects. |
| 60 | // So only the direct objects are recursed here. | 58 | // So only the direct objects are recursed here. |
| 61 | - walk(stream_number, *iter, result); | 59 | + walk(stream_number, oh, result); |
| 62 | } | 60 | } |
| 63 | } | 61 | } |
| 64 | } else if (obj.isDictionary()) { | 62 | } else if (obj.isDictionary()) { |
| 65 | std::set<std::string> keys = obj.getKeys(); | 63 | std::set<std::string> keys = obj.getKeys(); |
| 66 | - for (std::set<std::string>::iterator iter = keys.begin(); | ||
| 67 | - iter != keys.end(); | ||
| 68 | - ++iter) { | ||
| 69 | - QPDFObjectHandle item = obj.getKey(*iter); | 64 | + for (auto const& key: keys) { |
| 65 | + QPDFObjectHandle item = obj.getKey(key); | ||
| 70 | if (!item.isIndirect()) { | 66 | if (!item.isIndirect()) { |
| 71 | // QPDF::GetAllObjects() enumerates all indirect objects. | 67 | // QPDF::GetAllObjects() enumerates all indirect objects. |
| 72 | // So only the direct objects are recursed here. | 68 | // So only the direct objects are recursed here. |
| @@ -88,21 +84,19 @@ process( | @@ -88,21 +84,19 @@ process( | ||
| 88 | std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects(); | 84 | std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects(); |
| 89 | std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable(); | 85 | std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable(); |
| 90 | 86 | ||
| 91 | - for (std::vector<QPDFObjectHandle>::iterator iter = objs.begin(); | ||
| 92 | - iter != objs.end(); | ||
| 93 | - ++iter) { | ||
| 94 | - if (xrefs.count(iter->getObjGen()) == 0) { | ||
| 95 | - std::cerr << iter->getObjectID() << "/" << iter->getGeneration() | 87 | + for (auto const& oh: objs) { |
| 88 | + if (xrefs.count(oh.getObjGen()) == 0) { | ||
| 89 | + std::cerr << oh.getObjectID() << "/" << oh.getGeneration() | ||
| 96 | << " is not found in xref table" << std::endl; | 90 | << " is not found in xref table" << std::endl; |
| 97 | std::exit(2); | 91 | std::exit(2); |
| 98 | } | 92 | } |
| 99 | 93 | ||
| 100 | - QPDFXRefEntry xref = xrefs[iter->getObjGen()]; | 94 | + QPDFXRefEntry xref = xrefs[oh.getObjGen()]; |
| 101 | size_t stream_number; | 95 | size_t stream_number; |
| 102 | 96 | ||
| 103 | switch (xref.getType()) { | 97 | switch (xref.getType()) { |
| 104 | case 0: | 98 | case 0: |
| 105 | - std::cerr << iter->getObjectID() << "/" << iter->getGeneration() | 99 | + std::cerr << oh.getObjectID() << "/" << oh.getGeneration() |
| 106 | << " xref entry is free" << std::endl; | 100 | << " xref entry is free" << std::endl; |
| 107 | std::exit(2); | 101 | std::exit(2); |
| 108 | case 1: | 102 | case 1: |
| @@ -116,7 +110,7 @@ process( | @@ -116,7 +110,7 @@ process( | ||
| 116 | std::exit(2); | 110 | std::exit(2); |
| 117 | } | 111 | } |
| 118 | 112 | ||
| 119 | - walk(stream_number, *iter, result); | 113 | + walk(stream_number, oh, result); |
| 120 | } | 114 | } |
| 121 | } | 115 | } |
| 122 | 116 | ||
| @@ -146,11 +140,8 @@ main(int argc, char* argv[]) | @@ -146,11 +140,8 @@ main(int argc, char* argv[]) | ||
| 146 | << std::endl; | 140 | << std::endl; |
| 147 | } | 141 | } |
| 148 | 142 | ||
| 149 | - for (std::vector<std::pair<qpdf_offset_t, std::string>>::iterator | ||
| 150 | - iter = table[i].begin(); | ||
| 151 | - iter != table[i].end(); | ||
| 152 | - ++iter) { | ||
| 153 | - std::cout << iter->second << std::endl; | 143 | + for (auto const& iter: table[i]) { |
| 144 | + std::cout << iter.second << std::endl; | ||
| 154 | } | 145 | } |
| 155 | } | 146 | } |
| 156 | 147 |
qpdf/test_pdf_doc_encoding.cc
| @@ -27,10 +27,8 @@ main(int argc, char* argv[]) | @@ -27,10 +27,8 @@ main(int argc, char* argv[]) | ||
| 27 | } | 27 | } |
| 28 | char const* infilename = argv[1]; | 28 | char const* infilename = argv[1]; |
| 29 | std::list<std::string> lines = QUtil::read_lines_from_file(infilename); | 29 | std::list<std::string> lines = QUtil::read_lines_from_file(infilename); |
| 30 | - for (std::list<std::string>::iterator iter = lines.begin(); | ||
| 31 | - iter != lines.end(); | ||
| 32 | - ++iter) { | ||
| 33 | - QPDFObjectHandle str = QPDFObjectHandle::newString(*iter); | 30 | + for (auto const& line: lines) { |
| 31 | + QPDFObjectHandle str = QPDFObjectHandle::newString(line); | ||
| 34 | std::cout << str.getUTF8Value() << std::endl; | 32 | std::cout << str.getUTF8Value() << std::endl; |
| 35 | } | 33 | } |
| 36 | return 0; | 34 | return 0; |
qpdf/test_pdf_unicode.cc
| @@ -27,10 +27,8 @@ main(int argc, char* argv[]) | @@ -27,10 +27,8 @@ main(int argc, char* argv[]) | ||
| 27 | } | 27 | } |
| 28 | char const* infilename = argv[1]; | 28 | char const* infilename = argv[1]; |
| 29 | std::list<std::string> lines = QUtil::read_lines_from_file(infilename); | 29 | std::list<std::string> lines = QUtil::read_lines_from_file(infilename); |
| 30 | - for (std::list<std::string>::iterator iter = lines.begin(); | ||
| 31 | - iter != lines.end(); | ||
| 32 | - ++iter) { | ||
| 33 | - QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(*iter); | 30 | + for (auto const& line: lines) { |
| 31 | + QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line); | ||
| 34 | std::cout << str.getUTF8Value() << " // " << str.unparseBinary() | 32 | std::cout << str.getUTF8Value() << " // " << str.unparseBinary() |
| 35 | << std::endl; | 33 | << std::endl; |
| 36 | } | 34 | } |
qpdf/test_renumber.cc
| @@ -97,10 +97,8 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) | @@ -97,10 +97,8 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) | ||
| 97 | return false; | 97 | return false; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | - for (std::set<std::string>::iterator iter = keys_a.begin(); | ||
| 101 | - iter != keys_a.end(); | ||
| 102 | - ++iter) { | ||
| 103 | - if (!compare(a.getKey(*iter), b.getKey(*iter))) { | 100 | + for (auto const& key: keys_a) { |
| 101 | + if (!compare(a.getKey(key), b.getKey(key))) { | ||
| 104 | std::cerr << "different dictionary item" << std::endl; | 102 | std::cerr << "different dictionary item" << std::endl; |
| 105 | return false; | 103 | return false; |
| 106 | } | 104 | } |
| @@ -130,19 +128,17 @@ compare_xref_table( | @@ -130,19 +128,17 @@ compare_xref_table( | ||
| 130 | return false; | 128 | return false; |
| 131 | } | 129 | } |
| 132 | 130 | ||
| 133 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = a.begin(); | ||
| 134 | - iter != a.end(); | ||
| 135 | - ++iter) { | ||
| 136 | - std::cout << "xref entry for " << iter->first.getObj() << "/" | ||
| 137 | - << iter->first.getGen() << std::endl; | 131 | + for (auto const& iter: a) { |
| 132 | + std::cout << "xref entry for " << iter.first.getObj() << "/" | ||
| 133 | + << iter.first.getGen() << std::endl; | ||
| 138 | 134 | ||
| 139 | - if (b.count(iter->first) == 0) { | 135 | + if (b.count(iter.first) == 0) { |
| 140 | std::cerr << "not found" << std::endl; | 136 | std::cerr << "not found" << std::endl; |
| 141 | return false; | 137 | return false; |
| 142 | } | 138 | } |
| 143 | 139 | ||
| 144 | - QPDFXRefEntry xref_a = iter->second; | ||
| 145 | - QPDFXRefEntry xref_b = b[iter->first]; | 140 | + QPDFXRefEntry xref_a = iter.second; |
| 141 | + QPDFXRefEntry xref_b = b[iter.first]; | ||
| 146 | if (xref_a.getType() != xref_b.getType()) { | 142 | if (xref_a.getType() != xref_b.getType()) { |
| 147 | std::cerr << "different xref entry type" << std::endl; | 143 | std::cerr << "different xref entry type" << std::endl; |
| 148 | return false; | 144 | return false; |
| @@ -235,10 +231,8 @@ main(int argc, char* argv[]) | @@ -235,10 +231,8 @@ main(int argc, char* argv[]) | ||
| 235 | 231 | ||
| 236 | std::cout << "--- compare between input and renumbered objects ---" | 232 | std::cout << "--- compare between input and renumbered objects ---" |
| 237 | << std::endl; | 233 | << std::endl; |
| 238 | - for (std::vector<QPDFObjectHandle>::iterator iter = objs_in.begin(); | ||
| 239 | - iter != objs_in.end(); | ||
| 240 | - ++iter) { | ||
| 241 | - QPDFObjGen og_in = iter->getObjGen(); | 234 | + for (auto const& iter: objs_in) { |
| 235 | + QPDFObjGen og_in = iter.getObjGen(); | ||
| 242 | QPDFObjGen og_ren = w.getRenumberedObjGen(og_in); | 236 | QPDFObjGen og_ren = w.getRenumberedObjGen(og_in); |
| 243 | 237 | ||
| 244 | std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() | 238 | std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() |
| @@ -250,7 +244,7 @@ main(int argc, char* argv[]) | @@ -250,7 +244,7 @@ main(int argc, char* argv[]) | ||
| 250 | continue; | 244 | continue; |
| 251 | } | 245 | } |
| 252 | 246 | ||
| 253 | - if (!compare(*iter, qpdf_ren.getObjectByObjGen(og_ren))) { | 247 | + if (!compare(iter, qpdf_ren.getObjectByObjGen(og_ren))) { |
| 254 | std::cerr << "different" << std::endl; | 248 | std::cerr << "different" << std::endl; |
| 255 | std::exit(2); | 249 | std::exit(2); |
| 256 | } | 250 | } |
qpdf/test_tokenizer.cc
| @@ -99,14 +99,13 @@ static std::string | @@ -99,14 +99,13 @@ static std::string | ||
| 99 | sanitize(std::string const& value) | 99 | sanitize(std::string const& value) |
| 100 | { | 100 | { |
| 101 | std::string result; | 101 | std::string result; |
| 102 | - for (std::string::const_iterator iter = value.begin(); iter != value.end(); | ||
| 103 | - ++iter) { | ||
| 104 | - if ((*iter >= 32) && (*iter <= 126)) { | ||
| 105 | - result.append(1, *iter); | 102 | + for (auto const& iter: value) { |
| 103 | + if ((iter >= 32) && (iter <= 126)) { | ||
| 104 | + result.append(1, iter); | ||
| 106 | } else { | 105 | } else { |
| 107 | result += "\\x" + | 106 | result += "\\x" + |
| 108 | QUtil::int_to_string_base( | 107 | QUtil::int_to_string_base( |
| 109 | - static_cast<unsigned char>(*iter), 16, 2); | 108 | + static_cast<unsigned char>(iter), 16, 2); |
| 110 | } | 109 | } |
| 111 | } | 110 | } |
| 112 | return result; | 111 | return result; |
| @@ -203,12 +202,10 @@ process(char const* filename, bool include_ignorable, size_t max_len) | @@ -203,12 +202,10 @@ process(char const* filename, bool include_ignorable, size_t max_len) | ||
| 203 | std::vector<QPDFPageObjectHelper> pages = | 202 | std::vector<QPDFPageObjectHelper> pages = |
| 204 | QPDFPageDocumentHelper(qpdf).getAllPages(); | 203 | QPDFPageDocumentHelper(qpdf).getAllPages(); |
| 205 | int pageno = 0; | 204 | int pageno = 0; |
| 206 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | ||
| 207 | - iter != pages.end(); | ||
| 208 | - ++iter) { | 205 | + for (auto& page: pages) { |
| 209 | ++pageno; | 206 | ++pageno; |
| 210 | Pl_Buffer plb("buffer"); | 207 | Pl_Buffer plb("buffer"); |
| 211 | - (*iter).pipeContents(&plb); | 208 | + page.pipeContents(&plb); |
| 212 | auto content_data = plb.getBufferSharedPointer(); | 209 | auto content_data = plb.getBufferSharedPointer(); |
| 213 | BufferInputSource* bis = | 210 | BufferInputSource* bis = |
| 214 | new BufferInputSource("content data", content_data.get()); | 211 | new BufferInputSource("content data", content_data.get()); |
| @@ -223,20 +220,16 @@ process(char const* filename, bool include_ignorable, size_t max_len) | @@ -223,20 +220,16 @@ process(char const* filename, bool include_ignorable, size_t max_len) | ||
| 223 | } | 220 | } |
| 224 | 221 | ||
| 225 | // Tokenize object streams | 222 | // Tokenize object streams |
| 226 | - std::vector<QPDFObjectHandle> all = qpdf.getAllObjects(); | ||
| 227 | - for (std::vector<QPDFObjectHandle>::iterator iter = all.begin(); | ||
| 228 | - iter != all.end(); | ||
| 229 | - ++iter) { | ||
| 230 | - if ((*iter).isStream() && (*iter).getDict().getKey("/Type").isName() && | ||
| 231 | - (*iter).getDict().getKey("/Type").getName() == "/ObjStm") { | ||
| 232 | - std::shared_ptr<Buffer> b = | ||
| 233 | - (*iter).getStreamData(qpdf_dl_specialized); | 223 | + for (auto& obj: qpdf.getAllObjects()) { |
| 224 | + if (obj.isStream() && obj.getDict().getKey("/Type").isName() && | ||
| 225 | + obj.getDict().getKey("/Type").getName() == "/ObjStm") { | ||
| 226 | + std::shared_ptr<Buffer> b = obj.getStreamData(qpdf_dl_specialized); | ||
| 234 | BufferInputSource* bis = | 227 | BufferInputSource* bis = |
| 235 | new BufferInputSource("object stream data", b.get()); | 228 | new BufferInputSource("object stream data", b.get()); |
| 236 | is = std::shared_ptr<InputSource>(bis); | 229 | is = std::shared_ptr<InputSource>(bis); |
| 237 | dump_tokens( | 230 | dump_tokens( |
| 238 | is, | 231 | is, |
| 239 | - "OBJECT STREAM " + QUtil::int_to_string((*iter).getObjectID()), | 232 | + "OBJECT STREAM " + QUtil::int_to_string(obj.getObjectID()), |
| 240 | max_len, | 233 | max_len, |
| 241 | include_ignorable, | 234 | include_ignorable, |
| 242 | false, | 235 | false, |
qpdf/test_xref.cc
| @@ -21,26 +21,24 @@ main(int argc, char* argv[]) | @@ -21,26 +21,24 @@ main(int argc, char* argv[]) | ||
| 21 | 21 | ||
| 22 | std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable(); | 22 | std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable(); |
| 23 | 23 | ||
| 24 | - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = xref.begin(); | ||
| 25 | - iter != xref.end(); | ||
| 26 | - ++iter) { | ||
| 27 | - std::cout << iter->first.getObj() << "/" << iter->first.getGen() | 24 | + for (auto const& iter: xref) { |
| 25 | + std::cout << iter.first.getObj() << "/" << iter.first.getGen() | ||
| 28 | << ", "; | 26 | << ", "; |
| 29 | - switch (iter->second.getType()) { | 27 | + switch (iter.second.getType()) { |
| 30 | case 0: | 28 | case 0: |
| 31 | std::cout << "free entry" << std::endl; | 29 | std::cout << "free entry" << std::endl; |
| 32 | break; | 30 | break; |
| 33 | case 1: | 31 | case 1: |
| 34 | std::cout << "uncompressed, offset = " | 32 | std::cout << "uncompressed, offset = " |
| 35 | - << iter->second.getOffset() << " (0x" << std::hex | ||
| 36 | - << iter->second.getOffset() << std::dec << ")" | 33 | + << iter.second.getOffset() << " (0x" << std::hex |
| 34 | + << iter.second.getOffset() << std::dec << ")" | ||
| 37 | << std::endl; | 35 | << std::endl; |
| 38 | break; | 36 | break; |
| 39 | case 2: | 37 | case 2: |
| 40 | std::cout << "compressed, stream number = " | 38 | std::cout << "compressed, stream number = " |
| 41 | - << iter->second.getObjStreamNumber() | 39 | + << iter.second.getObjStreamNumber() |
| 42 | << ", stream index = " | 40 | << ", stream index = " |
| 43 | - << iter->second.getObjStreamIndex() << std::endl; | 41 | + << iter.second.getObjStreamIndex() << std::endl; |
| 44 | break; | 42 | break; |
| 45 | default: | 43 | default: |
| 46 | std::cerr << "unknown" << std::endl; | 44 | std::cerr << "unknown" << std::endl; |