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

Remove variables obsoleted by commit 4f24617.
This commit is contained in:
m-holger 2022-05-21 15:18:15 +01:00 committed by Jay Berkenbilt
parent 70ccd807c4
commit 6c69a747b9
20 changed files with 72 additions and 166 deletions

View File

@ -191,9 +191,7 @@ main(int argc, char* argv[])
try {
QPDF pdf;
pdf.processFile(infilename);
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(pdf).getAllPages();
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
// Attach two token filters to each page of this file.
// When the file is written, or when the pages' contents
// are retrieved in any other way, the filters will be

View File

@ -129,12 +129,9 @@ main(int argc, char* argv[])
auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv);
// For each page...
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(qpdf).getAllPages();
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
// Get all images on the page.
std::map<std::string, QPDFObjectHandle> images = page.getImages();
for (auto& iter: images) {
for (auto& iter: page.getImages()) {
QPDFObjectHandle& image = iter.second;
QPDFObjectHandle image_dict = image.getDict();
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");

View File

@ -40,9 +40,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
QPDFObjectHandle stamp_fo = inpdf.copyForeignObject(foreign_fo);
// For each page...
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(inpdf).getAllPages();
for (auto& ph: pages) {
for (auto& ph: QPDFPageDocumentHelper(inpdf).getAllPages()) {
// Find a unique resource name for the new form XObject
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
int min_suffix = 1;

View File

@ -50,15 +50,11 @@ main(int argc, char* argv[])
// illustrates how we can map from annotations to fields.
QPDFAcroFormDocumentHelper afdh(qpdf);
QPDFPageDocumentHelper pdh(qpdf);
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
for (auto const& page: pages) {
for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
// Get all widget annotations for each page. Widget
// annotations are the ones that contain the details of
// what's in a form field.
std::vector<QPDFAnnotationObjectHelper> annotations =
afdh.getWidgetAnnotationsForPage(page);
for (auto& annot: annotations) {
for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) {
// For each annotation, find its associated field. If
// it's a text field, set its value.
QPDFFormFieldObjectHelper ffh =

View File

@ -131,10 +131,9 @@ FuzzHelper::testPages()
QPDFAcroFormDocumentHelper afdh(*q);
afdh.generateAppearancesIfNeeded();
pdh.flattenAnnotations();
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
DiscardContents discard_contents;
int pageno = 0;
for (auto& page: pages) {
for (auto& page: pdh.getAllPages()) {
++pageno;
try {
page.coalesceContentStreams();
@ -145,9 +144,7 @@ FuzzHelper::testPages()
page_obj.getJSON(JSON::LATEST, true).unparse();
odh.getOutlinesForPage(page_obj.getObjGen());
std::vector<QPDFAnnotationObjectHelper> annotations =
afdh.getWidgetAnnotationsForPage(page);
for (auto& aoh: annotations) {
for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
afdh.getFieldForAnnotation(aoh);
}
} catch (QPDFExc& e) {
@ -164,8 +161,7 @@ FuzzHelper::testOutlines()
QPDFOutlineDocumentHelper odh(*q);
queue.push_back(odh.getTopLevelOutlines());
while (!queue.empty()) {
std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin());
for (auto& ol: outlines) {
for (auto& ol: *(queue.begin())) {
ol.getDestPage();
queue.push_back(ol.getKids());
}

View File

@ -2369,8 +2369,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
}
} else if (foreign.isDictionary()) {
QTC::TC("qpdf", "QPDF reserve dictionary");
std::set<std::string> keys = foreign.getKeys();
for (auto const& key: keys) {
for (auto const& key: foreign.getKeys()) {
reserveObjects(foreign.getKey(key), obj_copier, false);
}
} else if (foreign.isStream()) {

View File

@ -294,12 +294,8 @@ QPDFAcroFormDocumentHelper::analyze()
// a file that contains this kind of error will probably not
// actually work with most viewers.
QPDFPageDocumentHelper dh(this->qpdf);
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
for (auto const& ph: pages) {
std::vector<QPDFAnnotationObjectHelper> annots =
getWidgetAnnotationsForPage(ph);
for (auto const& iter: annots) {
for (auto const& ph: QPDFPageDocumentHelper(this->qpdf).getAllPages()) {
for (auto const& iter: getWidgetAnnotationsForPage(ph)) {
QPDFObjectHandle annot(iter.getObjectHandle());
QPDFObjGen og(annot.getObjGen());
if (this->m->annotation_to_field.count(og) == 0) {
@ -451,12 +447,8 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
return;
}
QPDFPageDocumentHelper pdh(this->qpdf);
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
for (auto const& page: pages) {
std::vector<QPDFAnnotationObjectHelper> annotations =
getWidgetAnnotationsForPage(page);
for (auto& aoh: annotations) {
for (auto const& page: QPDFPageDocumentHelper(this->qpdf).getAllPages()) {
for (auto& aoh: getWidgetAnnotationsForPage(page)) {
QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh);
if (ffh.getFieldType() == "/Btn") {
// Rather than generating appearances for button

View File

@ -867,11 +867,9 @@ QPDFJob::doCheck(QPDF& pdf)
w.write();
// Parse all content streams
QPDFPageDocumentHelper dh(pdf);
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
DiscardContents discard_contents;
int pageno = 0;
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
++pageno;
try {
page.parseContents(&discard_contents);
@ -939,11 +937,9 @@ QPDFJob::doShowObj(QPDF& pdf)
void
QPDFJob::doShowPages(QPDF& pdf)
{
QPDFPageDocumentHelper dh(pdf);
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
int pageno = 0;
auto& cout = *this->m->cout;
for (auto& ph: pages) {
for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
QPDFObjectHandle page = ph.getObjectHandle();
++pageno;
@ -966,8 +962,7 @@ QPDFJob::doShowPages(QPDF& pdf)
}
cout << " content:" << std::endl;
std::vector<QPDFObjectHandle> content = ph.getPageContents();
for (auto& iter2: content) {
for (auto& iter2: ph.getPageContents()) {
cout << " " << iter2.unparse() << std::endl;
}
}
@ -1085,8 +1080,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
JSON::writeDictionaryOpen(p, first_object, 1);
bool all_objects = m->json_objects.empty();
std::set<QPDFObjGen> wanted_og = getWantedJSONObjects();
std::vector<QPDFObjectHandle> objects = pdf.getAllObjects();
for (auto& obj: objects) {
for (auto& obj: pdf.getAllObjects()) {
std::string key = obj.unparse();
if (this->m->json_version > 1) {
key = "obj:" + key;
@ -1140,20 +1134,17 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
JSON::writeDictionaryKey(p, first, "pages", 0);
bool first_page = true;
JSON::writeArrayOpen(p, first_page, 1);
QPDFPageDocumentHelper pdh(pdf);
QPDFPageLabelDocumentHelper pldh(pdf);
QPDFOutlineDocumentHelper odh(pdf);
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
int pageno = -1;
for (auto& ph: pages) {
for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
++pageno;
JSON j_page = JSON::makeDictionary();
QPDFObjectHandle page = ph.getObjectHandle();
j_page.addDictionaryMember(
"object", page.getJSON(this->m->json_version));
JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
for (auto const& iter2: images) {
for (auto const& iter2: ph.getImages()) {
JSON j_image = j_images.addArrayElement(JSON::makeDictionary());
j_image.addDictionaryMember("name", JSON::makeString(iter2.first));
QPDFObjectHandle image = iter2.second;
@ -1195,8 +1186,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
j_page.addDictionaryMember("images", j_images);
JSON j_contents =
j_page.addDictionaryMember("contents", JSON::makeArray());
std::vector<QPDFObjectHandle> content = ph.getPageContents();
for (auto& iter2: content) {
for (auto& iter2: ph.getPageContents()) {
j_contents.addArrayElement(iter2.getJSON(this->m->json_version));
}
j_page.addDictionaryMember(
@ -1285,10 +1275,8 @@ void
QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf)
{
std::map<QPDFObjGen, int> page_numbers;
QPDFPageDocumentHelper dh(pdf);
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
int n = 0;
for (auto const& ph: pages) {
for (auto const& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
QPDFObjectHandle oh = ph.getObjectHandle();
page_numbers[oh.getObjGen()] = ++n;
}
@ -1309,14 +1297,10 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
j_acroform.addDictionaryMember(
"needappearances", JSON::makeBool(afdh.getNeedAppearances()));
JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray());
QPDFPageDocumentHelper pdh(pdf);
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
int pagepos1 = 0;
for (auto const& page: pages) {
for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
++pagepos1;
std::vector<QPDFAnnotationObjectHelper> annotations =
afdh.getWidgetAnnotationsForPage(page);
for (auto& aoh: annotations) {
for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
j_field.addDictionaryMember(
@ -1355,8 +1339,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText()));
JSON j_choices =
j_field.addDictionaryMember("choices", JSON::makeArray());
std::vector<std::string> choices = ffh.getChoices();
for (auto const& choice: choices) {
for (auto const& choice: ffh.getChoices()) {
j_choices.addArrayElement(JSON::makeString(choice));
}
JSON j_annot = j_field.addDictionaryMember(
@ -2282,19 +2265,16 @@ QPDFJob::handleTransformations(QPDF& pdf)
};
if (m->externalize_inline_images ||
(m->optimize_images && (!m->keep_inline_images))) {
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
for (auto& ph: pages) {
for (auto& ph: dh.getAllPages()) {
ph.externalizeInlineImages(m->ii_min_bytes);
}
}
if (m->optimize_images) {
int pageno = 0;
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
for (auto& ph: pages) {
for (auto& ph: dh.getAllPages()) {
++pageno;
QPDFObjectHandle page = ph.getObjectHandle();
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
for (auto& iter2: images) {
for (auto& iter2: ph.getImages()) {
std::string name = iter2.first;
QPDFObjectHandle& image = iter2.second;
ImageOptimizer* io = new ImageOptimizer(
@ -2330,8 +2310,7 @@ QPDFJob::handleTransformations(QPDF& pdf)
m->flatten_annotations_required, m->flatten_annotations_forbidden);
}
if (m->coalesce_contents) {
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
for (auto& page: pages) {
for (auto& page: dh.getAllPages()) {
page.coalesceContentStreams();
}
}
@ -2805,9 +2784,7 @@ QPDFJob::handleRotations(QPDF& pdf)
std::string const& range = iter.first;
QPDFJob::RotationSpec const& rspec = iter.second;
// range has been previously validated
std::vector<int> to_rotate =
QUtil::parse_numrange(range.c_str(), npages);
for (int pageno_iter: to_rotate) {
for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) {
int pageno = pageno_iter - 1;
if ((pageno >= 0) && (pageno < npages)) {
pages.at(QIntC::to_size(pageno))

View File

@ -1240,12 +1240,10 @@ QPDFObjectHandle::getResourceNames()
if (!isDictionary()) {
return result;
}
std::set<std::string> keys = getKeys();
for (auto const& key: keys) {
for (auto const& key: getKeys()) {
QPDFObjectHandle val = getKey(key);
if (val.isDictionary()) {
std::set<std::string> val_keys = val.getKeys();
for (auto const& val_key: val_keys) {
for (auto const& val_key: val.getKeys()) {
result.insert(val_key);
}
}
@ -1642,14 +1640,12 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
{
new_contents.assertStream();
std::vector<QPDFObjectHandle> orig_contents = getPageContents();
std::vector<QPDFObjectHandle> content_streams;
if (first) {
QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
content_streams.push_back(new_contents);
}
for (auto const& iter: orig_contents) {
for (auto const& iter: getPageContents()) {
QTC::TC("qpdf", "QPDFObjectHandle append page contents");
content_streams.push_back(iter);
}
@ -1657,8 +1653,7 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
content_streams.push_back(new_contents);
}
QPDFObjectHandle contents = QPDFObjectHandle::newArray(content_streams);
this->replaceKey("/Contents", contents);
this->replaceKey("/Contents", newArray(content_streams));
}
void
@ -2927,9 +2922,8 @@ QPDFObjectHandle::copyObject(
new_obj = std::shared_ptr<QPDFObject>(new QPDF_Array(items));
} else if (isDictionary()) {
QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
std::set<std::string> keys = getKeys();
std::map<std::string, QPDFObjectHandle> items;
for (auto const& key: keys) {
for (auto const& key: getKeys()) {
items[key] = getKey(key);
if ((!first_level_only) &&
(cross_indirect || (!items[key].isIndirect()))) {

View File

@ -12,9 +12,8 @@ QPDFPageDocumentHelper::QPDFPageDocumentHelper(QPDF& qpdf) :
std::vector<QPDFPageObjectHelper>
QPDFPageDocumentHelper::getAllPages()
{
std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages();
std::vector<QPDFPageObjectHelper> pages;
for (auto const& iter: pages_v) {
for (auto const& iter: this->qpdf.getAllPages()) {
pages.push_back(QPDFPageObjectHelper(iter));
}
return pages;
@ -29,8 +28,7 @@ QPDFPageDocumentHelper::pushInheritedAttributesToPage()
void
QPDFPageDocumentHelper::removeUnreferencedResources()
{
std::vector<QPDFPageObjectHelper> pages = getAllPages();
for (auto& ph: pages) {
for (auto& ph: getAllPages()) {
ph.removeUnreferencedResources();
}
}
@ -66,8 +64,7 @@ QPDFPageDocumentHelper::flattenAnnotations(
.warnIfPossible("document does not have updated appearance streams,"
" so form fields will not be flattened");
}
std::vector<QPDFPageObjectHelper> pages = getAllPages();
for (auto& ph: pages) {
for (auto& ph: getAllPages()) {
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
if (!resources.isDictionary()) {
// This should never happen and is not exercised in the

View File

@ -567,8 +567,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input)
bool found_alpha = false;
bool found_non_printable = false;
bool found_other = false;
std::string value = t.getValue();
for (char ch: value) {
for (char ch: t.getValue()) {
if (((ch >= 'a') && (ch <= 'z')) ||
((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
// Treat '*' as alpha since there are valid

View File

@ -1237,8 +1237,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
}
}
} else if (object.isDictionary()) {
std::set<std::string> keys = object.getKeys();
for (auto const& key: keys) {
for (auto const& key: object.getKeys()) {
if (!this->m->linearized) {
enqueueObject(object.getKey(key));
}
@ -1283,8 +1282,7 @@ QPDFWriter::writeTrailer(
writeString(" /Size ");
writeString(QUtil::int_to_string(size));
} else {
std::set<std::string> keys = trailer.getKeys();
for (auto const& key: keys) {
for (auto const& key: trailer.getKeys()) {
writeStringQDF(" ");
writeStringNoQDF(" ");
writeString(QPDF_Name::normalizeName(key));
@ -1644,8 +1642,7 @@ QPDFWriter::unparseObject(
writeString("<<");
writeStringQDF("\n");
std::set<std::string> keys = object.getKeys();
for (auto const& key: keys) {
for (auto const& key: object.getKeys()) {
writeStringQDF(indent);
writeStringQDF(" ");
writeStringNoQDF(" ");
@ -2074,8 +2071,7 @@ QPDFWriter::generateID()
seed += " QPDF ";
if (trailer.hasKey("/Info")) {
QPDFObjectHandle info = trailer.getKey("/Info");
std::set<std::string> keys = info.getKeys();
for (auto const& key: keys) {
for (auto const& key: info.getKeys()) {
QPDFObjectHandle obj = info.getKey(key);
if (obj.isString()) {
seed += " ";
@ -2365,8 +2361,7 @@ QPDFWriter::doWriteSetup()
if (this->m->linearized) {
// Page dictionaries are not allowed to be compressed objects.
std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
for (auto& page: pages) {
for (auto& page: this->m->pdf.getAllPages()) {
QPDFObjGen og = page.getObjGen();
if (this->m->object_to_object_stream.count(og)) {
QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
@ -3251,8 +3246,7 @@ QPDFWriter::enqueueObjectsStandard()
// dictionary into the queue, handling direct objects recursively.
// Root is already there, so enqueuing it a second time is a
// no-op.
std::set<std::string> keys = trailer.getKeys();
for (auto const& key: keys) {
for (auto const& key: trailer.getKeys()) {
enqueueObject(trailer.getKey(key));
}
}
@ -3276,8 +3270,7 @@ QPDFWriter::enqueueObjectsPCLm()
// enqueue all the strips for each page
QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject");
std::set<std::string> keys = strips.getKeys();
for (auto const& image: keys) {
for (auto const& image: strips.getKeys()) {
enqueueObject(strips.getKey(image));
enqueueObject(QPDFObjectHandle::newStream(
&this->m->pdf, image_transform_content));

View File

@ -663,9 +663,8 @@ QPDF::maxEnd(ObjUser const& ou)
if (this->m->obj_user_to_objects.count(ou) == 0) {
stopOnError("no entry in object user table for requested object user");
}
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
qpdf_offset_t end = 0;
for (auto const& og: ogs) {
for (auto const& og: this->m->obj_user_to_objects[ou]) {
if (this->m->obj_cache.count(og) == 0) {
stopOnError("unknown object referenced in object user table");
}
@ -1474,8 +1473,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
stopOnError("found unreferenced page while"
" calculating linearization data");
}
std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];
for (auto const& og: ogs) {
for (auto const& og: this->m->obj_user_to_objects[ou]) {
if (lc_other_page_private.count(og)) {
lc_other_page_private.erase(og);
this->m->part7.push_back(objGenToIndirect(og));
@ -1637,8 +1635,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
stopOnError("found unreferenced page while"
" calculating linearization data");
}
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
for (auto const& og: ogs) {
for (auto const& og: this->m->obj_user_to_objects[ou]) {
if ((this->m->object_to_obj_users[og].size() > 1) &&
(obj_to_index.count(og.getObj()) > 0)) {
int idx = obj_to_index[og.getObj()];

View File

@ -90,8 +90,7 @@ QPDF::optimize(
}
// Traverse document-level items
std::set<std::string> keys = this->m->trailer.getKeys();
for (auto const& key: keys) {
for (auto const& key: this->m->trailer.getKeys()) {
if (key == "/Root") {
// handled separately
} else {
@ -102,8 +101,7 @@ QPDF::optimize(
}
}
keys = root.getKeys();
for (auto const& key: keys) {
for (auto const& key: root.getKeys()) {
// Technically, /I keys from /Thread dictionaries are supposed
// to be handled separately, but we are going to disregard
// that specification for now. There is loads of evidence
@ -205,8 +203,7 @@ QPDF::pushInheritedAttributesToPageInternal(
// that have values for this attribute.
std::set<std::string> inheritable_keys;
std::set<std::string> keys = cur_pages.getKeys();
for (auto const& key: keys) {
for (auto const& key: cur_pages.getKeys()) {
if ((key == "/MediaBox") || (key == "/CropBox") ||
(key == "/Resources") || (key == "/Rotate")) {
if (!allow_changes) {
@ -387,8 +384,7 @@ QPDF::updateObjectMapsInternal(
}
}
std::set<std::string> keys = dict.getKeys();
for (auto const& key: keys) {
for (auto const& key: dict.getKeys()) {
if (is_page_node && (key == "/Thumb")) {
// Traverse page thumbnail dictionaries as a special
// case.
@ -437,8 +433,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data)
for (auto const& i1: this->m->obj_user_to_objects) {
ObjUser const& ou = i1.first;
std::set<QPDFObjGen> const& objects = i1.second;
for (auto const& og: objects) {
// Loop over objects.
for (auto const& og: i1.second) {
auto i2 = object_stream_data.find(og.getObj());
if (i2 == object_stream_data.end()) {
t_obj_user_to_objects[ou].insert(og);
@ -450,8 +446,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data)
for (auto const& i1: this->m->object_to_obj_users) {
QPDFObjGen const& og = i1.first;
std::set<ObjUser> const& objusers = i1.second;
for (auto const& ou: objusers) {
// Loop over obj_users.
for (auto const& ou: i1.second) {
auto i2 = object_stream_data.find(og.getObj());
if (i2 == object_stream_data.end()) {
t_object_to_obj_users[og].insert(ou);

View File

@ -377,15 +377,12 @@ test_4(QPDF& pdf, char const* arg2)
static void
test_5(QPDF& pdf, char const* arg2)
{
QPDFPageDocumentHelper dh(pdf);
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
int pageno = 0;
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
++pageno;
std::cout << "page " << pageno << ":" << std::endl;
std::cout << " images:" << std::endl;
std::map<std::string, QPDFObjectHandle> images = page.getImages();
for (auto const& iter2: images) {
for (auto const& iter2: page.getImages()) {
std::string const& name = iter2.first;
QPDFObjectHandle image = iter2.second;
QPDFObjectHandle dict = image.getDict();
@ -1319,9 +1316,7 @@ static void
test_37(QPDF& pdf, char const* arg2)
{
// Parse content streams of all pages
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(pdf).getAllPages();
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
ParserCallbacks cb;
page.parseContents(&cb);
}
@ -1341,10 +1336,8 @@ static void
test_39(QPDF& pdf, char const* arg2)
{
// Display image filter and color set for each image on each page
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(pdf).getAllPages();
int pageno = 0;
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
std::cout << "page " << ++pageno << std::endl;
std::map<std::string, QPDFObjectHandle> images = page.getImages();
for (auto& i_iter: images) {
@ -1377,9 +1370,7 @@ test_41(QPDF& pdf, char const* arg2)
{
// Apply a token filter. This test case is crafted to work
// with coalesce.pdf.
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(pdf).getAllPages();
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
page.addContentTokenFilter(
std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
}
@ -1509,8 +1500,7 @@ test_43(QPDF& pdf, char const* arg2)
return;
}
std::cout << "iterating over form fields\n";
std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields();
for (auto& ffh: form_fields) {
for (auto& ffh: afdh.getFormFields()) {
std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
QPDFFormFieldObjectHelper node = ffh;
while (!node.isNull()) {
@ -1548,9 +1538,7 @@ test_43(QPDF& pdf, char const* arg2)
std::cout << "iterating over annotations per page\n";
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
std::vector<QPDFAnnotationObjectHelper> annotations =
afdh.getWidgetAnnotationsForPage(page);
for (auto& ah: annotations) {
for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) {
std::cout << " Annotation: " << ah.getObjectHandle().unparse()
<< std::endl;
std::cout
@ -1578,9 +1566,7 @@ static void
test_44(QPDF& pdf, char const* arg2)
{
// Set form fields.
QPDFAcroFormDocumentHelper afdh(pdf);
std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields();
for (auto& field: fields) {
for (auto& field: QPDFAcroFormDocumentHelper(pdf).getFormFields()) {
QPDFObjectHandle ft = field.getInheritableFieldValue("/FT");
if (ft.isName() && (ft.getName() == "/Tx")) {
// \xc3\xb7 is utf-8 for U+00F7 (divided by)

View File

@ -51,8 +51,7 @@ walk(
result[stream_number].push_back(p);
if (obj.isArray()) {
std::vector<QPDFObjectHandle> array = obj.getArrayAsVector();
for (auto& oh: array) {
for (auto& oh: obj.getArrayAsVector()) {
if (!oh.isIndirect()) {
// QPDF::GetAllObjects() enumerates all indirect objects.
// So only the direct objects are recursed here.
@ -60,8 +59,7 @@ walk(
}
}
} else if (obj.isDictionary()) {
std::set<std::string> keys = obj.getKeys();
for (auto const& key: keys) {
for (auto const& key: obj.getKeys()) {
QPDFObjectHandle item = obj.getKey(key);
if (!item.isIndirect()) {
// QPDF::GetAllObjects() enumerates all indirect objects.
@ -81,10 +79,9 @@ process(
{
QPDF qpdf;
qpdf.processFile(fn.c_str());
std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects();
std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
for (auto const& oh: objs) {
for (auto const& oh: qpdf.getAllObjects()) {
if (xrefs.count(oh.getObjGen()) == 0) {
std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
<< " is not found in xref table" << std::endl;

View File

@ -26,8 +26,7 @@ main(int argc, char* argv[])
usage();
}
char const* infilename = argv[1];
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
for (auto const& line: lines) {
for (auto const& line: QUtil::read_lines_from_file(infilename)) {
QPDFObjectHandle str = QPDFObjectHandle::newString(line);
std::cout << str.getUTF8Value() << std::endl;
}

View File

@ -26,8 +26,7 @@ main(int argc, char* argv[])
usage();
}
char const* infilename = argv[1];
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
for (auto const& line: lines) {
for (auto const& line: QUtil::read_lines_from_file(infilename)) {
QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
<< std::endl;

View File

@ -198,10 +198,8 @@ process(char const* filename, bool include_ignorable, size_t max_len)
// Tokenize content streams, skipping inline images
QPDF qpdf;
qpdf.processFile(filename);
std::vector<QPDFPageObjectHelper> pages =
QPDFPageDocumentHelper(qpdf).getAllPages();
int pageno = 0;
for (auto& page: pages) {
for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
++pageno;
Pl_Buffer plb("buffer");
page.pipeContents(&plb);

View File

@ -19,9 +19,7 @@ main(int argc, char* argv[])
QPDF qpdf;
qpdf.processFile(argv[1]);
std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable();
for (auto const& iter: xref) {
for (auto const& iter: qpdf.getXRefTable()) {
std::cout << iter.first.getObj() << "/" << iter.first.getGen()
<< ", ";
switch (iter.second.getType()) {