Commit 33e8195c3af99f73e09ec88eae004330fc0480dc

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 6dd84659

Tidy pdf-count-strings example

Convert loop to use range-based for statement.
Remove unnecessary variables.
Showing 1 changed file with 3 additions and 7 deletions
examples/pdf-count-strings.cc
@@ -91,13 +91,9 @@ int main(int argc, char* argv[]) @@ -91,13 +91,9 @@ int main(int argc, char* argv[])
91 { 91 {
92 QPDF pdf; 92 QPDF pdf;
93 pdf.processFile(infilename); 93 pdf.processFile(infilename);
94 - std::vector<QPDFPageObjectHelper> pages =  
95 - QPDFPageDocumentHelper(pdf).getAllPages();  
96 int pageno = 0; 94 int pageno = 0;
97 - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();  
98 - iter != pages.end(); ++iter) 95 + for (auto& page : QPDFPageDocumentHelper(pdf).getAllPages())
99 { 96 {
100 - QPDFPageObjectHelper& ph(*iter);  
101 ++pageno; 97 ++pageno;
102 // Pass the contents of a page through our string counter. 98 // Pass the contents of a page through our string counter.
103 // If it's an even page, capture the output. This 99 // If it's an even page, capture the output. This
@@ -107,14 +103,14 @@ int main(int argc, char* argv[]) @@ -107,14 +103,14 @@ int main(int argc, char* argv[])
107 if (pageno % 2) 103 if (pageno % 2)
108 { 104 {
109 // Ignore output for odd pages. 105 // Ignore output for odd pages.
110 - ph.filterContents(&counter); 106 + page.filterContents(&counter);
111 } 107 }
112 else 108 else
113 { 109 {
114 // Write output to stdout for even pages. 110 // Write output to stdout for even pages.
115 Pl_StdioFile out("stdout", stdout); 111 Pl_StdioFile out("stdout", stdout);
116 std::cout << "% Contents of page " << pageno << std::endl; 112 std::cout << "% Contents of page " << pageno << std::endl;
117 - ph.filterContents(&counter, &out); 113 + page.filterContents(&counter, &out);
118 std::cout << "\n% end " << pageno << std::endl; 114 std::cout << "\n% end " << pageno << std::endl;
119 } 115 }
120 std::cout << "Page " << pageno 116 std::cout << "Page " << pageno