Commit 361b19be4a5ebcd639bf97a02a50f4a63323308e

Authored by m-holger
Committed by GitHub
2 parents eda40d87 54afdecb

Merge pull request #1463 from m-holger/modernize

Modernize code
Showing 128 changed files with 1403 additions and 1439 deletions

Too many changes.

To preserve performance only 100 of 128 files are displayed.

... ... @@ -45,7 +45,6 @@ with modern equivalent. Key updates are:
45 45 Next steps are:
46 46  
47 47 * review function signatures in the public API
48   -* replace code that uses QUtil::make_shared_cstr etc
49 48  
50 49 Except for the above, prefer to make modernization changes as part of other updates.
51 50  
... ...
compare-for-test/qpdf-test-compare.cc
... ... @@ -13,18 +13,14 @@ static char const* whoami = nullptr;
13 13 void
14 14 usage()
15 15 {
16   - std::cerr << "Usage: " << whoami << " actual expected" << std::endl
17   - << R"(Where "actual" is the actual output and "expected" is the expected)"
18   - << std::endl
19   - << "output of a test, compare the two PDF files. The files are considered"
20   - << std::endl
21   - << "to match if all their objects are identical except that, if a stream is"
22   - << std::endl
23   - << "compressed with FlateDecode, the uncompressed data must match." << std::endl
24   - << std::endl
25   - << "If the files match, the output is the expected file. Otherwise, it is"
26   - << std::endl
27   - << "the actual file. Read comments in the code for rationale." << std::endl;
  16 + std::cerr << "Usage: " << whoami << " actual expected" << '\n'
  17 + << R"(Where "actual" is the actual output and "expected" is the expected)" << '\n'
  18 + << "output of a test, compare the two PDF files. The files are considered" << '\n'
  19 + << "to match if all their objects are identical except that, if a stream is" << '\n'
  20 + << "compressed with FlateDecode, the uncompressed data must match." << '\n'
  21 + << '\n'
  22 + << "If the files match, the output is the expected file. Otherwise, it is" << '\n'
  23 + << "the actual file. Read comments in the code for rationale." << '\n';
28 24 exit(2);
29 25 }
30 26  
... ... @@ -187,7 +183,7 @@ main(int argc, char* argv[])
187 183 }
188 184  
189 185 if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
190   - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl;
  186 + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << '\n';
191 187 exit(0);
192 188 }
193 189  
... ... @@ -211,7 +207,7 @@ main(int argc, char* argv[])
211 207 to_output = expected;
212 208 } else {
213 209 if (show_why) {
214   - std::cerr << difference << std::endl;
  210 + std::cerr << difference << '\n';
215 211 exit(2);
216 212 }
217 213 // The files differ; write the actual file. If it is determined that the actual file
... ... @@ -237,7 +233,7 @@ main(int argc, char* argv[])
237 233 exit(2);
238 234 }
239 235 } catch (std::exception& e) {
240   - std::cerr << whoami << ": " << e.what() << std::endl;
  236 + std::cerr << whoami << ": " << e.what() << '\n';
241 237 exit(2);
242 238 }
243 239 return 0;
... ...
examples/pdf-attach-file.cc
... ... @@ -19,15 +19,15 @@ static char const* whoami = nullptr;
19 19 static void
20 20 usage(std::string const& msg)
21 21 {
22   - std::cerr << msg << std::endl
23   - << std::endl
24   - << "Usage: " << whoami << " options" << std::endl
25   - << "Options:" << std::endl
26   - << " --infile infile.pdf" << std::endl
27   - << " --outfile outfile.pdf" << std::endl
28   - << " --attachment attachment" << std::endl
29   - << " [--password infile-password]" << std::endl
30   - << " [--mimetype attachment mime type]" << std::endl;
  22 + std::cerr << msg << '\n'
  23 + << '\n'
  24 + << "Usage: " << whoami << " options\n"
  25 + << "Options:\n"
  26 + << " --infile infile.pdf\n"
  27 + << " --outfile outfile.pdf\n"
  28 + << " --attachment attachment\n"
  29 + << " [--password infile-password]\n"
  30 + << " [--mimetype attachment mime type]\n";
31 31 exit(2);
32 32 }
33 33  
... ... @@ -69,7 +69,7 @@ process(
69 69  
70 70 // Create a file spec.
71 71 std::string key = QUtil::path_basename(attachment);
72   - std::cout << whoami << ": attaching " << attachment << " as " << key << std::endl;
  72 + std::cout << whoami << ": attaching " << attachment << " as " << key << '\n';
73 73 auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment);
74 74  
75 75 if (mimetype) {
... ... @@ -208,7 +208,7 @@ main(int argc, char* argv[])
208 208 try {
209 209 process(infilename, password, attachment, mimetype, outfilename);
210 210 } catch (std::exception& e) {
211   - std::cerr << whoami << " exception: " << e.what() << std::endl;
  211 + std::cerr << whoami << " exception: " << e.what() << '\n';
212 212 exit(2);
213 213 }
214 214  
... ...
examples/pdf-bookmarks.cc
... ... @@ -23,12 +23,12 @@ static std::map&lt;QPDFObjGen, int&gt; page_map;
23 23 void
24 24 usage()
25 25 {
26   - std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl
27   - << "Options:" << std::endl
28   - << " --numbers give bookmarks outline-style numbers" << std::endl
29   - << " --lines draw lines to show bookmark hierarchy" << std::endl
30   - << " --show-open indicate whether a bookmark is initially open" << std::endl
31   - << " --show-targets show target if possible" << std::endl;
  26 + std::cerr << "Usage: " << whoami << " [options] file.pdf [password]\n"
  27 + << "Options:\n"
  28 + << " --numbers give bookmarks outline-style numbers\n"
  29 + << " --lines draw lines to show bookmark hierarchy\n"
  30 + << " --show-open indicate whether a bookmark is initially open\n"
  31 + << " --show-targets show target if possible\n";
32 32 exit(2);
33 33 }
34 34  
... ... @@ -74,7 +74,7 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector&lt;int&gt; numbers)
74 74 case st_lines:
75 75 QTC::TC("examples", "pdf-bookmarks lines");
76 76 print_lines(numbers);
77   - std::cout << "|" << std::endl;
  77 + std::cout << "|\n";
78 78 print_lines(numbers);
79 79 std::cout << "+-+ ";
80 80 break;
... ... @@ -104,7 +104,7 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector&lt;int&gt; numbers)
104 104 QPDFObjectHandle dest_page = outline.getDestPage();
105 105 if (!dest_page.isNull()) {
106 106 QTC::TC("examples", "pdf-bookmarks dest");
107   - if (page_map.count(dest_page)) {
  107 + if (page_map.contains(dest_page)) {
108 108 target = std::to_string(page_map[dest_page]);
109 109 }
110 110 }
... ... @@ -136,7 +136,7 @@ main(int argc, char* argv[])
136 136 whoami = QUtil::getWhoami(argv[0]);
137 137  
138 138 if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
139   - std::cout << whoami << " version 1.5" << std::endl;
  139 + std::cout << whoami << " version 1.5\n";
140 140 exit(0);
141 141 }
142 142  
... ... @@ -185,10 +185,10 @@ main(int argc, char* argv[])
185 185 }
186 186 extract_bookmarks(odh.getTopLevelOutlines(), numbers);
187 187 } else {
188   - std::cout << filename << " has no bookmarks" << std::endl;
  188 + std::cout << filename << " has no bookmarks\n";
189 189 }
190 190 } catch (std::exception& e) {
191   - std::cerr << whoami << " processing file " << filename << ": " << e.what() << std::endl;
  191 + std::cerr << whoami << " processing file " << filename << ": " << e.what() << '\n';
192 192 exit(2);
193 193 }
194 194  
... ...
examples/pdf-count-strings.cc
... ... @@ -18,8 +18,8 @@ static char const* whoami = nullptr;
18 18 void
19 19 usage()
20 20 {
21   - std::cerr << "Usage: " << whoami << " infile" << std::endl
22   - << "Applies token filters to infile" << std::endl;
  21 + std::cerr << "Usage: " << whoami << " infile\n"
  22 + << "Applies token filters to infile\n";
23 23 exit(2);
24 24 }
25 25  
... ... @@ -88,14 +88,14 @@ main(int argc, char* argv[])
88 88 } else {
89 89 // Write output to stdout for even pages.
90 90 Pl_StdioFile out("stdout", stdout);
91   - std::cout << "% Contents of page " << pageno << std::endl;
  91 + std::cout << "% Contents of page " << pageno << '\n';
92 92 page.filterContents(&counter, &out);
93   - std::cout << "\n% end " << pageno << std::endl;
  93 + std::cout << "\n% end " << pageno << '\n';
94 94 }
95   - std::cout << "Page " << pageno << ": strings = " << counter.getCount() << std::endl;
  95 + std::cout << "Page " << pageno << ": strings = " << counter.getCount() << '\n';
96 96 }
97 97 } catch (std::exception& e) {
98   - std::cerr << whoami << ": " << e.what() << std::endl;
  98 + std::cerr << whoami << ": " << e.what() << '\n';
99 99 exit(2);
100 100 }
101 101  
... ...
examples/pdf-create.cc
... ... @@ -117,8 +117,8 @@ ImageProvider::provideStreamData(QPDFObjGen const&amp;, Pipeline* pipeline)
117 117 void
118 118 usage()
119 119 {
120   - std::cerr << "Usage: " << whoami << " filename" << std::endl
121   - << "Creates a simple PDF and writes it to filename" << std::endl;
  120 + std::cerr << "Usage: " << whoami << " filename\n"
  121 + << "Creates a simple PDF and writes it to filename\n";
122 122 exit(2);
123 123 }
124 124  
... ... @@ -257,12 +257,12 @@ check(
257 257 if (!filter.isNameAndEquals(desired_filter)) {
258 258 this_errors = errors = true;
259 259 std::cout << "page " << pageno << ": expected filter " << desired_filter
260   - << "; actual filter = " << filter.unparse() << std::endl;
  260 + << "; actual filter = " << filter.unparse() << '\n';
261 261 }
262 262 if (!color_space.isNameAndEquals(desired_color_space)) {
263 263 this_errors = errors = true;
264 264 std::cout << "page " << pageno << ": expected color space " << desired_color_space
265   - << "; actual color space = " << color_space.unparse() << std::endl;
  265 + << "; actual color space = " << color_space.unparse() << '\n';
266 266 }
267 267  
268 268 if (!this_errors) {
... ... @@ -275,7 +275,7 @@ check(
275 275 std::shared_ptr<Buffer> desired_data(b_p.getBuffer());
276 276  
277 277 if (desired_data->getSize() != actual_data->getSize()) {
278   - std::cout << "page " << pageno << ": image data length mismatch" << std::endl;
  278 + std::cout << "page " << pageno << ": image data length mismatch\n";
279 279 this_errors = errors = true;
280 280 } else {
281 281 // Compare bytes. For JPEG, allow a certain number of the bytes to be off desired by
... ... @@ -297,7 +297,7 @@ check(
297 297 if (mismatches > threshold) {
298 298 std::cout << "page " << pageno << ": " << desired_color_space << ", "
299 299 << desired_filter << ": mismatches: " << mismatches << " of " << len
300   - << std::endl;
  300 + << '\n';
301 301 this_errors = errors = true;
302 302 }
303 303 }
... ... @@ -308,7 +308,7 @@ check(
308 308 if (errors) {
309 309 throw std::logic_error("errors found");
310 310 } else {
311   - std::cout << "all checks passed" << std::endl;
  311 + std::cout << "all checks passed\n";
312 312 }
313 313 }
314 314  
... ... @@ -366,7 +366,7 @@ main(int argc, char* argv[])
366 366 try {
367 367 create_pdf(filename);
368 368 } catch (std::exception& e) {
369   - std::cerr << e.what() << std::endl;
  369 + std::cerr << e.what() << '\n';
370 370 exit(2);
371 371 }
372 372  
... ...
examples/pdf-custom-filter.cc
... ... @@ -116,7 +116,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms)
116 116 this->key = buf->getBuffer()[0];
117 117 return true;
118 118 } catch (std::exception& e) {
119   - std::cerr << "Error extracting key for /XORDecode: " << e.what() << std::endl;
  119 + std::cerr << "Error extracting key for /XORDecode: " << e.what() << '\n';
120 120 }
121 121 return false;
122 122 }
... ... @@ -276,7 +276,7 @@ StreamReplacer::registerStream(
276 276 // We don't need to process a stream more than once. In this example, we are just iterating
277 277 // through objects, but if we were doing something like iterating through images on pages, we
278 278 // might realistically encounter the same stream more than once.
279   - if (this->copied_streams.count(og) > 0) {
  279 + if (this->copied_streams.contains(og)) {
280 280 return;
281 281 }
282 282 // Store something in copied_streams so that we don't double-process even in the negative case.
... ... @@ -361,15 +361,13 @@ process(char const* infilename, char const* outfilename, bool decode_specialized
361 361 // For the test suite, use static IDs.
362 362 w.setStaticID(true); // for testing only
363 363 w.write();
364   - std::cout << whoami << ": new file written to " << outfilename << std::endl;
  364 + std::cout << whoami << ": new file written to " << outfilename << '\n';
365 365 }
366 366  
367 367 static void
368 368 usage()
369 369 {
370   - std::cerr << "\n"
371   - << "Usage: " << whoami << " [--decode-specialized] infile outfile\n"
372   - << std::endl;
  370 + std::cerr << '\n' << "Usage: " << whoami << " [--decode-specialized] infile outfile\n" << '\n';
373 371 exit(2);
374 372 }
375 373  
... ... @@ -404,7 +402,7 @@ main(int argc, char* argv[])
404 402 // Do the actual processing.
405 403 process(infilename, outfilename, decode_specialized);
406 404 } catch (std::exception& e) {
407   - std::cerr << whoami << ": exception: " << e.what() << std::endl;
  405 + std::cerr << whoami << ": exception: " << e.what() << '\n';
408 406 exit(2);
409 407 }
410 408  
... ...
examples/pdf-double-page-size.cc
... ... @@ -13,8 +13,8 @@ static char const* whoami = nullptr;
13 13 void
14 14 usage()
15 15 {
16   - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl
17   - << "Double size of all pages in infile.pdf; write output to outfile.pdf" << std::endl;
  16 + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]\n"
  17 + << "Double size of all pages in infile.pdf; write output to outfile.pdf\n";
18 18 exit(2);
19 19 }
20 20  
... ... @@ -87,9 +87,9 @@ main(int argc, char* argv[])
87 87 w.setStreamDataMode(qpdf_s_uncompress);
88 88 }
89 89 w.write();
90   - std::cout << whoami << ": new file written to " << outfilename << std::endl;
  90 + std::cout << whoami << ": new file written to " << outfilename << '\n';
91 91 } catch (std::exception& e) {
92   - std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
  92 + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << '\n';
93 93 exit(2);
94 94 }
95 95  
... ...
examples/pdf-filter-tokens.cc
... ... @@ -20,8 +20,8 @@ static char const* whoami = nullptr;
20 20 void
21 21 usage()
22 22 {
23   - std::cerr << "Usage: " << whoami << " infile outfile" << std::endl
24   - << "Applies token filters to infile and writes outfile" << std::endl;
  23 + std::cerr << "Usage: " << whoami << " infile outfile\n"
  24 + << "Applies token filters to infile and writes outfile\n";
25 25 exit(2);
26 26 }
27 27  
... ... @@ -184,7 +184,7 @@ main(int argc, char* argv[])
184 184 w.setQDFMode(true);
185 185 w.write();
186 186 } catch (std::exception& e) {
187   - std::cerr << whoami << ": " << e.what() << std::endl;
  187 + std::cerr << whoami << ": " << e.what() << '\n';
188 188 exit(2);
189 189 }
190 190  
... ...
examples/pdf-invert-images.cc
... ... @@ -14,8 +14,8 @@ static char const* whoami = nullptr;
14 14 void
15 15 usage()
16 16 {
17   - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl
18   - << "Invert some images in infile.pdf; write output to outfile.pdf" << std::endl;
  17 + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]\n"
  18 + << "Invert some images in infile.pdf; write output to outfile.pdf\n";
19 19 exit(2);
20 20 }
21 21  
... ... @@ -52,7 +52,7 @@ ImageInverter::registerImage(
52 52 // Store information about the images based on the object and generation number. Recall that a
53 53 // single image object may be used more than once, so no need to update the same stream multiple
54 54 // times.
55   - if (this->copied_images.count(og) > 0) {
  55 + if (copied_images.contains(og)) {
56 56 return;
57 57 }
58 58 this->copied_images[og] = image.copyStream();
... ... @@ -137,9 +137,9 @@ main(int argc, char* argv[])
137 137 w.setStaticID(true); // for testing only
138 138 }
139 139 w.write();
140   - std::cout << whoami << ": new file written to " << outfilename << std::endl;
  140 + std::cout << whoami << ": new file written to " << outfilename << '\n';
141 141 } catch (std::exception& e) {
142   - std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
  142 + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << '\n';
143 143 exit(2);
144 144 }
145 145  
... ...
examples/pdf-mod-info.cc
... ... @@ -39,7 +39,7 @@ dumpInfoDict(QPDF&amp; pdf, std::ostream&amp; os = std::cout, std::string const&amp; sep = &quot;
39 39 {
40 40 val = it.second.unparseResolved();
41 41 }
42   - os << it.first.substr(1) << sep << val << std::endl; // skip '/'
  42 + os << it.first.substr(1) << sep << val << '\n'; // skip '/'
43 43 }
44 44 }
45 45 }
... ... @@ -52,7 +52,7 @@ pdfDumpInfoDict(char const* fname)
52 52 pdf.processFile(fname);
53 53 dumpInfoDict(pdf);
54 54 } catch (std::exception& e) {
55   - std::cerr << e.what() << std::endl;
  55 + std::cerr << e.what() << '\n';
56 56 exit(2);
57 57 }
58 58 }
... ... @@ -66,7 +66,7 @@ main(int argc, char* argv[])
66 66 whoami = QUtil::getWhoami(argv[0]);
67 67  
68 68 if ((argc == 2) && (!strcmp(argv[1], "--version"))) {
69   - std::cout << whoami << " version " << version << std::endl;
  69 + std::cout << whoami << " version " << version << '\n';
70 70 exit(0);
71 71 }
72 72 if ((argc == 3) && (!strcmp(argv[1], "--dump"))) {
... ... @@ -90,11 +90,11 @@ main(int argc, char* argv[])
90 90 } else if ((!strcmp(argv[i], "--key")) && (++i < argc)) {
91 91 QTC::TC("examples", "pdf-mod-info -key");
92 92 cur_key = argv[i];
93   - if (!((cur_key.length() > 0) && (cur_key.at(0) == '/'))) {
  93 + if (cur_key.empty() || cur_key.at(0) != '/') {
94 94 cur_key = "/" + cur_key;
95 95 }
96 96 Keys[cur_key] = "";
97   - } else if ((!strcmp(argv[i], "--val")) && (++i < argc)) {
  97 + } else if (!strcmp(argv[i], "--val") && ++i < argc) {
98 98 if (cur_key.empty()) {
99 99 QTC::TC("examples", "pdf-mod-info usage wrong val");
100 100 usage();
... ... @@ -115,7 +115,7 @@ main(int argc, char* argv[])
115 115 QTC::TC("examples", "pdf-mod-info in-place");
116 116 fl_out = fl_in;
117 117 }
118   - if (Keys.size() == 0) {
  118 + if (Keys.empty()) {
119 119 QTC::TC("examples", "pdf-mod-info no keys");
120 120 usage();
121 121 }
... ... @@ -141,7 +141,7 @@ main(int argc, char* argv[])
141 141 filetrailer.replaceKey("/Info", fileinfo);
142 142 }
143 143 }
144   - if (it.second == "") {
  144 + if (it.second.empty()) {
145 145 fileinfo.removeKey(it.first);
146 146 } else {
147 147 QPDFObjectHandle elt = fileinfo.newString(it.second);
... ... @@ -155,7 +155,7 @@ main(int argc, char* argv[])
155 155 w.setStaticID(static_id); // for testing only
156 156 w.write();
157 157 } catch (std::exception& e) {
158   - std::cerr << e.what() << std::endl;
  158 + std::cerr << e.what() << '\n';
159 159 exit(2);
160 160 }
161 161  
... ... @@ -164,7 +164,7 @@ main(int argc, char* argv[])
164 164 QUtil::os_wrapper(
165 165 "rename " + fl_tmp + " " + std::string(fl_out), rename(fl_tmp.c_str(), fl_out));
166 166 } catch (std::exception& e) {
167   - std::cerr << e.what() << std::endl;
  167 + std::cerr << e.what() << '\n';
168 168 exit(2);
169 169 }
170 170  
... ...
examples/pdf-name-number-tree.cc
... ... @@ -10,8 +10,8 @@ static char const* whoami = nullptr;
10 10 void
11 11 usage()
12 12 {
13   - std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl
14   - << "Create some name/number trees and write to a file" << std::endl;
  13 + std::cerr << "Usage: " << whoami << " outfile.pdf" << '\n'
  14 + << "Create some name/number trees and write to a file\n";
15 15 exit(2);
16 16 }
17 17  
... ... @@ -57,64 +57,63 @@ main(int argc, char* argv[])
57 57 name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight"));
58 58 auto iter = name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn"));
59 59 // Look at the iterator
60   - std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << std::endl;
  60 + std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << '\n';
61 61 --iter;
62   - std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << std::endl;
  62 + std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << '\n';
63 63 ++iter;
64 64 ++iter;
65   - std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << std::endl;
  65 + std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << '\n';
66 66  
67 67 // Use range-for iteration
68   - std::cout << "Name tree items:" << std::endl;
  68 + std::cout << "Name tree items:\n";
69 69 for (auto i: name_tree) {
70   - std::cout << " " << i.first << " -> " << i.second.unparse() << std::endl;
  70 + std::cout << " " << i.first << " -> " << i.second.unparse() << '\n';
71 71 }
72 72  
73 73 // This is a small tree, so everything will be at the root. We can look at it using dictionary
74 74 // and array iterators.
75   - std::cout << "Keys in name tree object:" << std::endl;
  75 + std::cout << "Keys in name tree object:\n";
76 76 QPDFObjectHandle names;
77 77 for (auto const& i: name_tree_oh.ditems()) {
78   - std::cout << i.first << std::endl;
  78 + std::cout << i.first << '\n';
79 79 if (i.first == "/Names") {
80 80 names = i.second;
81 81 }
82 82 }
83 83 // Values in names array:
84   - std::cout << "Values in names:" << std::endl;
  84 + std::cout << "Values in names:\n";
85 85 for (auto& i: names.aitems()) {
86   - std::cout << " " << i.unparse() << std::endl;
  86 + std::cout << " " << i.unparse() << '\n';
87 87 }
88 88  
89 89 // pre 10.2 API
90   - std::cout << "Has Q?: " << name_tree.hasName("Q") << std::endl;
91   - std::cout << "Has W?: " << name_tree.hasName("W") << std::endl;
  90 + std::cout << "Has Q?: " << name_tree.hasName("Q") << '\n';
  91 + std::cout << "Has W?: " << name_tree.hasName("W") << '\n';
92 92 QPDFObjectHandle obj;
93   - std::cout << "Found W?: " << name_tree.findObject("W", obj) << std::endl;
94   - std::cout << "Found Q?: " << name_tree.findObject("Q", obj) << std::endl;
95   - std::cout << "Q: " << obj.unparse() << std::endl;
  93 + std::cout << "Found W?: " << name_tree.findObject("W", obj) << '\n';
  94 + std::cout << "Found Q?: " << name_tree.findObject("Q", obj) << '\n';
  95 + std::cout << "Q: " << obj.unparse() << '\n';
96 96  
97 97 // 10.2 API
98 98 iter = name_tree.find("Q");
99   - std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << std::endl;
  99 + std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << '\n';
100 100 iter = name_tree.find("W");
101   - std::cout << "W found: " << (iter != name_tree.end()) << std::endl;
  101 + std::cout << "W found: " << (iter != name_tree.end()) << '\n';
102 102 // Allow find to return predecessor
103 103 iter = name_tree.find("W", true);
104   - std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse()
105   - << std::endl;
  104 + std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse() << '\n';
106 105  
107 106 // We can also remove items
108   - std::cout << "Remove P: " << name_tree.remove("P", &obj) << std::endl;
109   - std::cout << "Value removed: " << obj.unparse() << std::endl;
110   - std::cout << "Has P?: " << name_tree.hasName("P") << std::endl;
  107 + std::cout << "Remove P: " << name_tree.remove("P", &obj) << '\n';
  108 + std::cout << "Value removed: " << obj.unparse() << '\n';
  109 + std::cout << "Has P?: " << name_tree.hasName("P") << '\n';
111 110 // Or we can remove using an iterator
112 111 iter = name_tree.find("K");
113   - std::cout << "Find K: " << iter->second.unparse() << std::endl;
  112 + std::cout << "Find K: " << iter->second.unparse() << '\n';
114 113 iter.remove();
115 114 std::cout << "Iter after removing K: " << iter->first << " -> " << iter->second.unparse()
116   - << std::endl;
117   - std::cout << "Has K?: " << name_tree.hasName("K") << std::endl;
  115 + << '\n';
  116 + std::cout << "Has K?: " << name_tree.hasName("K") << '\n';
118 117  
119 118 // Illustrate some more advanced usage using number trees. These calls work for name trees too.
120 119  
... ... @@ -129,14 +128,14 @@ main(int argc, char* argv[])
129 128 for (int i = 7; i <= 350; i += 7) {
130 129 iter2.insertAfter(i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
131 130 }
132   - std::cout << "Numbers:" << std::endl;
  131 + std::cout << "Numbers:\n";
133 132 int n = 1;
134 133 for (auto& i: number_tree) {
135 134 std::cout << i.first << " -> " << i.second.getUTF8Value();
136 135 if (n % 5) {
137 136 std::cout << ", ";
138 137 } else {
139   - std::cout << std::endl;
  138 + std::cout << '\n';
140 139 }
141 140 ++n;
142 141 }
... ... @@ -151,14 +150,14 @@ main(int argc, char* argv[])
151 150 ++iter2;
152 151 }
153 152 }
154   - std::cout << "Numbers after filtering:" << std::endl;
  153 + std::cout << "Numbers after filtering:\n";
155 154 n = 1;
156 155 for (auto& i: number_tree) {
157 156 std::cout << i.first << " -> " << i.second.getUTF8Value();
158 157 if (n % 5) {
159 158 std::cout << ", ";
160 159 } else {
161   - std::cout << std::endl;
  160 + std::cout << '\n';
162 161 }
163 162 ++n;
164 163 }
... ...
examples/pdf-npages.cc
... ... @@ -10,8 +10,8 @@ static char const* whoami = nullptr;
10 10 void
11 11 usage()
12 12 {
13   - std::cerr << "Usage: " << whoami << " filename" << std::endl
14   - << "Prints the number of pages in filename" << std::endl;
  13 + std::cerr << "Usage: " << whoami << " filename\n"
  14 + << "Prints the number of pages in filename\n";
15 15 exit(2);
16 16 }
17 17  
... ... @@ -21,7 +21,7 @@ main(int argc, char* argv[])
21 21 whoami = QUtil::getWhoami(argv[0]);
22 22  
23 23 if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
24   - std::cout << whoami << " version 1.3" << std::endl;
  24 + std::cout << whoami << " version 1.3\n";
25 25 exit(0);
26 26 }
27 27  
... ... @@ -36,9 +36,9 @@ main(int argc, char* argv[])
36 36 QPDFObjectHandle root = pdf.getRoot();
37 37 QPDFObjectHandle pages = root.getKey("/Pages");
38 38 QPDFObjectHandle count = pages.getKey("/Count");
39   - std::cout << count.getIntValue() << std::endl;
  39 + std::cout << count.getIntValue() << '\n';
40 40 } catch (std::exception& e) {
41   - std::cerr << whoami << ": " << e.what() << std::endl;
  41 + std::cerr << whoami << ": " << e.what() << '\n';
42 42 exit(2);
43 43 }
44 44  
... ...
examples/pdf-overlay-page.cc
... ... @@ -15,9 +15,8 @@ static char const* whoami = nullptr;
15 15 void
16 16 usage()
17 17 {
18   - std::cerr << "Usage: " << whoami << " infile pagefile outfile" << std::endl
19   - << "Stamp page 1 of pagefile on every page of infile, writing to outfile"
20   - << std::endl;
  18 + std::cerr << "Usage: " << whoami << " infile pagefile outfile\n"
  19 + << "Stamp page 1 of pagefile on every page of infile, writing to outfile\n";
21 20 exit(2);
22 21 }
23 22  
... ... @@ -81,7 +80,7 @@ main(int argc, char* argv[])
81 80 try {
82 81 stamp_page(infile, stampfile, outfile);
83 82 } catch (std::exception& e) {
84   - std::cerr << whoami << ": " << e.what() << std::endl;
  83 + std::cerr << whoami << ": " << e.what() << '\n';
85 84 exit(2);
86 85 }
87 86 return 0;
... ...
examples/pdf-parse-content.cc
... ... @@ -12,10 +12,10 @@ static char const* whoami = nullptr;
12 12 void
13 13 usage()
14 14 {
15   - std::cerr << "Usage: " << whoami << " filename page-number" << std::endl
16   - << "Prints a dump of the objects in the content streams of the given page."
17   - << std::endl
18   - << "Pages are numbered from 1." << std::endl;
  15 + std::cerr << "Usage: " << whoami << " filename page-number\n"
  16 + << "Prints a dump of the objects in the content streams of the given page.\n"
  17 + << '\n'
  18 + << "Pages are numbered from 1.\n";
19 19 exit(2);
20 20 }
21 21  
... ... @@ -31,7 +31,7 @@ class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks
31 31 void
32 32 ParserCallbacks::contentSize(size_t size)
33 33 {
34   - std::cout << "content size: " << size << std::endl;
  34 + std::cout << "content size: " << size << '\n';
35 35 }
36 36  
37 37 void
... ... @@ -39,16 +39,16 @@ ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length
39 39 {
40 40 std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": ";
41 41 if (obj.isInlineImage()) {
42   - std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
  42 + std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << '\n';
43 43 } else {
44   - std::cout << obj.unparse() << std::endl;
  44 + std::cout << obj.unparse() << '\n';
45 45 }
46 46 }
47 47  
48 48 void
49 49 ParserCallbacks::handleEOF()
50 50 {
51   - std::cout << "-EOF-" << std::endl;
  51 + std::cout << "-EOF-\n";
52 52 }
53 53  
54 54 int
... ... @@ -74,7 +74,7 @@ main(int argc, char* argv[])
74 74 ParserCallbacks cb;
75 75 page.parseContents(&cb);
76 76 } catch (std::exception& e) {
77   - std::cerr << whoami << ": " << e.what() << std::endl;
  77 + std::cerr << whoami << ": " << e.what() << '\n';
78 78 exit(2);
79 79 }
80 80  
... ...
examples/pdf-set-form-values.cc
... ... @@ -11,8 +11,8 @@ static char const* whoami = nullptr;
11 11 void
12 12 usage()
13 13 {
14   - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" << std::endl
15   - << "Set the value of all text fields to a specified value" << std::endl;
  14 + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value\n"
  15 + << "Set the value of all text fields to a specified value\n";
16 16 exit(2);
17 17 }
18 18  
... ... @@ -68,7 +68,7 @@ main(int argc, char* argv[])
68 68 w.setStaticID(true); // for testing only
69 69 w.write();
70 70 } catch (std::exception& e) {
71   - std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
  71 + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << '\n';
72 72 exit(2);
73 73 }
74 74  
... ...
examples/pdf-split-pages.cc
... ... @@ -42,7 +42,7 @@ process(char const* whoami, char const* infile, std::string outprefix)
42 42 void
43 43 usage(char const* whoami)
44 44 {
45   - std::cerr << "Usage: " << whoami << " infile outprefix" << std::endl;
  45 + std::cerr << "Usage: " << whoami << " infile outprefix\n";
46 46 exit(2);
47 47 }
48 48  
... ... @@ -64,7 +64,7 @@ main(int argc, char* argv[])
64 64 try {
65 65 process(whoami, argv[1], argv[2]);
66 66 } catch (std::exception const& e) {
67   - std::cerr << whoami << ": exception: " << e.what() << std::endl;
  67 + std::cerr << whoami << ": exception: " << e.what() << '\n';
68 68 return 2;
69 69 }
70 70 return 0;
... ...
examples/qpdf-job.cc
... ... @@ -10,11 +10,10 @@ static char const* whoami = nullptr;
10 10 static void
11 11 usage()
12 12 {
13   - std::cerr << "Usage: " << whoami << std::endl
  13 + std::cerr << "Usage: " << whoami << '\n'
14 14 << "This program linearizes the first page of in.pdf to out1.pdf, out2.pdf, and"
15   - << std::endl
16   - << " out3.pdf, each demonstrating a different way to use the QPDFJob API"
17   - << std::endl;
  15 + << '\n'
  16 + << " out3.pdf, each demonstrating a different way to use the QPDFJob API" << '\n';
18 17 exit(2);
19 18 }
20 19  
... ... @@ -49,9 +48,9 @@ main(int argc, char* argv[])
49 48 ->compressStreams("n") // avoid dependency on zlib output
50 49 ->checkConfiguration();
51 50 j.run();
52   - std::cout << "out1 status: " << j.getExitCode() << std::endl;
  51 + std::cout << "out1 status: " << j.getExitCode() << '\n';
53 52 } catch (std::exception& e) {
54   - std::cerr << "exception: " << e.what() << std::endl;
  53 + std::cerr << "exception: " << e.what() << '\n';
55 54 return 2;
56 55 }
57 56  
... ... @@ -71,9 +70,9 @@ main(int argc, char* argv[])
71 70 QPDFJob j;
72 71 j.initializeFromArgv(new_argv);
73 72 j.run();
74   - std::cout << "out2 status: " << j.getExitCode() << std::endl;
  73 + std::cout << "out2 status: " << j.getExitCode() << '\n';
75 74 } catch (std::exception& e) {
76   - std::cerr << "exception: " << e.what() << std::endl;
  75 + std::cerr << "exception: " << e.what() << '\n';
77 76 return 2;
78 77 }
79 78  
... ... @@ -95,9 +94,9 @@ main(int argc, char* argv[])
95 94 }
96 95 )");
97 96 j.run();
98   - std::cout << "out3 status: " << j.getExitCode() << std::endl;
  97 + std::cout << "out3 status: " << j.getExitCode() << '\n';
99 98 } catch (std::exception& e) {
100   - std::cerr << "exception: " << e.what() << std::endl;
  99 + std::cerr << "exception: " << e.what() << '\n';
101 100 return 2;
102 101 }
103 102  
... ...
examples/qpdfjob-save-attachment.cc
... ... @@ -13,7 +13,7 @@ main(int argc, char* argv[])
13 13 auto whoami = QUtil::getWhoami(argv[0]);
14 14  
15 15 if (argc != 4) {
16   - std::cerr << "Usage: " << whoami << " file attachment-key outfile" << std::endl;
  16 + std::cerr << "Usage: " << whoami << " file attachment-key outfile" << '\n';
17 17 exit(2);
18 18 }
19 19  
... ... @@ -40,10 +40,10 @@ main(int argc, char* argv[])
40 40 j.initializeFromArgv(j_argv);
41 41 j.run();
42 42 } catch (std::exception& e) {
43   - std::cerr << whoami << ": " << e.what() << std::endl;
  43 + std::cerr << whoami << ": " << e.what() << '\n';
44 44 exit(2);
45 45 }
46 46  
47   - std::cout << whoami << ": wrote attachment to " << outfilename << std::endl;
  47 + std::cout << whoami << ": wrote attachment to " << outfilename << '\n';
48 48 return 0;
49 49 }
... ...
fuzz/ascii85_fuzzer.cc
... ... @@ -37,7 +37,7 @@ FuzzHelper::run()
37 37 try {
38 38 doChecks();
39 39 } catch (std::runtime_error const& e) {
40   - std::cerr << "runtime_error: " << e.what() << std::endl;
  40 + std::cerr << "runtime_error: " << e.what() << '\n';
41 41 }
42 42 }
43 43  
... ...
fuzz/dct_fuzzer.cc
... ... @@ -49,7 +49,7 @@ FuzzHelper::run()
49 49 try {
50 50 doChecks();
51 51 } catch (std::runtime_error const& e) {
52   - std::cerr << "runtime_error: " << e.what() << std::endl;
  52 + std::cerr << "runtime_error: " << e.what() << '\n';
53 53 }
54 54 }
55 55  
... ...
fuzz/flate_fuzzer.cc
... ... @@ -37,7 +37,7 @@ FuzzHelper::run()
37 37 try {
38 38 doChecks();
39 39 } catch (std::runtime_error const& e) {
40   - std::cerr << "runtime_error: " << e.what() << std::endl;
  40 + std::cerr << "runtime_error: " << e.what() << '\n';
41 41 }
42 42 }
43 43  
... ...
fuzz/hex_fuzzer.cc
... ... @@ -37,7 +37,7 @@ FuzzHelper::run()
37 37 try {
38 38 doChecks();
39 39 } catch (std::runtime_error const& e) {
40   - std::cerr << "runtime_error: " << e.what() << std::endl;
  40 + std::cerr << "runtime_error: " << e.what() << '\n';
41 41 }
42 42 }
43 43  
... ...
fuzz/json_fuzzer.cc
... ... @@ -30,7 +30,7 @@ FuzzHelper::doChecks()
30 30 try {
31 31 JSON::parse(std::string(reinterpret_cast<char const*>(data), size));
32 32 } catch (std::runtime_error& e) {
33   - std::cerr << "runtime_error parsing json: " << e.what() << std::endl;
  33 + std::cerr << "runtime_error parsing json: " << e.what() << '\n';
34 34 }
35 35 QPDF q;
36 36 q.setMaxWarnings(1000);
... ... @@ -45,7 +45,7 @@ FuzzHelper::run()
45 45 try {
46 46 doChecks();
47 47 } catch (std::runtime_error const& e) {
48   - std::cerr << "runtime_error: " << e.what() << std::endl;
  48 + std::cerr << "runtime_error: " << e.what() << '\n';
49 49 }
50 50 }
51 51  
... ...
fuzz/lzw_fuzzer.cc
... ... @@ -37,7 +37,7 @@ FuzzHelper::run()
37 37 try {
38 38 doChecks();
39 39 } catch (std::runtime_error const& e) {
40   - std::cerr << "runtime_error: " << e.what() << std::endl;
  40 + std::cerr << "runtime_error: " << e.what() << '\n';
41 41 }
42 42 }
43 43  
... ...
fuzz/pngpredictor_fuzzer.cc
... ... @@ -37,7 +37,7 @@ FuzzHelper::run()
37 37 try {
38 38 doChecks();
39 39 } catch (std::runtime_error const& e) {
40   - std::cerr << "runtime_error: " << e.what() << std::endl;
  40 + std::cerr << "runtime_error: " << e.what() << '\n';
41 41 }
42 42 }
43 43  
... ...
fuzz/qpdf_crypt_fuzzer.cc
... ... @@ -76,9 +76,9 @@ FuzzHelper::doWrite(std::shared_ptr&lt;QPDFWriter&gt; w)
76 76 try {
77 77 w->write();
78 78 } catch (QPDFExc const& e) {
79   - std::cerr << e.what() << std::endl;
  79 + std::cerr << e.what() << '\n';
80 80 } catch (std::runtime_error const& e) {
81   - std::cerr << e.what() << std::endl;
  81 + std::cerr << e.what() << '\n';
82 82 }
83 83 }
84 84  
... ... @@ -135,9 +135,9 @@ FuzzHelper::run()
135 135 try {
136 136 doChecks();
137 137 } catch (QPDFExc const& e) {
138   - std::cerr << "QPDFExc: " << e.what() << std::endl;
  138 + std::cerr << "QPDFExc: " << e.what() << '\n';
139 139 } catch (std::runtime_error const& e) {
140   - std::cerr << "runtime_error: " << e.what() << std::endl;
  140 + std::cerr << "runtime_error: " << e.what() << '\n';
141 141 }
142 142 }
143 143  
... ...
fuzz/qpdf_crypt_insecure_fuzzer.cc
... ... @@ -75,9 +75,9 @@ FuzzHelper::doWrite(std::shared_ptr&lt;QPDFWriter&gt; w)
75 75 try {
76 76 w->write();
77 77 } catch (QPDFExc const& e) {
78   - std::cerr << e.what() << std::endl;
  78 + std::cerr << e.what() << '\n';
79 79 } catch (std::runtime_error const& e) {
80   - std::cerr << e.what() << std::endl;
  80 + std::cerr << e.what() << '\n';
81 81 }
82 82 }
83 83  
... ... @@ -135,9 +135,9 @@ FuzzHelper::run()
135 135 try {
136 136 doChecks();
137 137 } catch (QPDFExc const& e) {
138   - std::cerr << "QPDFExc: " << e.what() << std::endl;
  138 + std::cerr << "QPDFExc: " << e.what() << '\n';
139 139 } catch (std::runtime_error const& e) {
140   - std::cerr << "runtime_error: " << e.what() << std::endl;
  140 + std::cerr << "runtime_error: " << e.what() << '\n';
141 141 }
142 142 }
143 143  
... ...
fuzz/qpdf_fuzzer.cc
... ... @@ -75,9 +75,9 @@ FuzzHelper::doWrite(std::shared_ptr&lt;QPDFWriter&gt; w)
75 75 try {
76 76 w->write();
77 77 } catch (QPDFExc const& e) {
78   - std::cerr << e.what() << std::endl;
  78 + std::cerr << e.what() << '\n';
79 79 } catch (std::runtime_error const& e) {
80   - std::cerr << e.what() << std::endl;
  80 + std::cerr << e.what() << '\n';
81 81 }
82 82 }
83 83  
... ... @@ -133,9 +133,9 @@ FuzzHelper::run()
133 133 try {
134 134 doChecks();
135 135 } catch (QPDFExc const& e) {
136   - std::cerr << "QPDFExc: " << e.what() << std::endl;
  136 + std::cerr << "QPDFExc: " << e.what() << '\n';
137 137 } catch (std::runtime_error const& e) {
138   - std::cerr << "runtime_error: " << e.what() << std::endl;
  138 + std::cerr << "runtime_error: " << e.what() << '\n';
139 139 }
140 140 }
141 141  
... ...
fuzz/qpdf_lin_fuzzer.cc
... ... @@ -75,9 +75,9 @@ FuzzHelper::doWrite(std::shared_ptr&lt;QPDFWriter&gt; w)
75 75 try {
76 76 w->write();
77 77 } catch (QPDFExc const& e) {
78   - std::cerr << e.what() << std::endl;
  78 + std::cerr << e.what() << '\n';
79 79 } catch (std::runtime_error const& e) {
80   - std::cerr << e.what() << std::endl;
  80 + std::cerr << e.what() << '\n';
81 81 }
82 82 }
83 83  
... ... @@ -134,9 +134,9 @@ FuzzHelper::run()
134 134 try {
135 135 doChecks();
136 136 } catch (QPDFExc const& e) {
137   - std::cerr << "QPDFExc: " << e.what() << std::endl;
  137 + std::cerr << "QPDFExc: " << e.what() << '\n';
138 138 } catch (std::runtime_error const& e) {
139   - std::cerr << "runtime_error: " << e.what() << std::endl;
  139 + std::cerr << "runtime_error: " << e.what() << '\n';
140 140 }
141 141 }
142 142  
... ...
fuzz/qpdf_outlines_fuzzer.cc
... ... @@ -111,9 +111,9 @@ FuzzHelper::run()
111 111 try {
112 112 doChecks();
113 113 } catch (QPDFExc const& e) {
114   - std::cerr << "QPDFExc: " << e.what() << std::endl;
  114 + std::cerr << "QPDFExc: " << e.what() << '\n';
115 115 } catch (std::runtime_error const& e) {
116   - std::cerr << "runtime_error: " << e.what() << std::endl;
  116 + std::cerr << "runtime_error: " << e.what() << '\n';
117 117 }
118 118 }
119 119  
... ...
fuzz/qpdf_pages_fuzzer.cc
... ... @@ -132,9 +132,9 @@ FuzzHelper::run()
132 132 try {
133 133 doChecks();
134 134 } catch (QPDFExc const& e) {
135   - std::cerr << "QPDFExc: " << e.what() << std::endl;
  135 + std::cerr << "QPDFExc: " << e.what() << '\n';
136 136 } catch (std::runtime_error const& e) {
137   - std::cerr << "runtime_error: " << e.what() << std::endl;
  137 + std::cerr << "runtime_error: " << e.what() << '\n';
138 138 }
139 139 }
140 140  
... ...
fuzz/runlength_fuzzer.cc
... ... @@ -38,7 +38,7 @@ FuzzHelper::run()
38 38 try {
39 39 doChecks();
40 40 } catch (std::runtime_error const& e) {
41   - std::cerr << "runtime_error: " << e.what() << std::endl;
  41 + std::cerr << "runtime_error: " << e.what() << '\n';
42 42 }
43 43 }
44 44  
... ...
fuzz/standalone_fuzz_target_runner.cc
... ... @@ -12,7 +12,7 @@ main(int argc, char** argv)
12 12 size_t size = 0;
13 13 QUtil::read_file_into_memory(argv[i], file_buf, size);
14 14 LLVMFuzzerTestOneInput(reinterpret_cast<unsigned char*>(file_buf.get()), size);
15   - std::cout << argv[i] << " successful" << std::endl;
  15 + std::cout << argv[i] << " successful" << '\n';
16 16 }
17 17 return 0;
18 18 }
... ...
fuzz/tiffpredictor_fuzzer.cc
... ... @@ -41,7 +41,7 @@ FuzzHelper::run()
41 41 try {
42 42 doChecks();
43 43 } catch (std::runtime_error const& e) {
44   - std::cerr << "runtime_error: " << e.what() << std::endl;
  44 + std::cerr << "runtime_error: " << e.what() << '\n';
45 45 }
46 46 }
47 47  
... ...
include/qpdf/ClosedFileInputSource.hh
... ... @@ -69,9 +69,9 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource
69 69 void after();
70 70  
71 71 std::string filename;
72   - qpdf_offset_t offset;
  72 + qpdf_offset_t offset{0};
73 73 std::shared_ptr<FileInputSource> fis;
74   - bool stay_open;
  74 + bool stay_open{false};
75 75 };
76 76  
77 77 #endif // QPDF_CLOSEDFILEINPUTSOURCE_HH
... ...
include/qpdf/QPDFAcroFormDocumentHelper.hh
... ... @@ -234,10 +234,10 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
234 234 ~Members() = default;
235 235  
236 236 private:
237   - Members();
  237 + Members() = default;
238 238 Members(Members const&) = delete;
239 239  
240   - bool cache_valid;
  240 + bool cache_valid{false};
241 241 std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations;
242 242 std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field;
243 243 std::map<QPDFObjGen, std::string> field_to_name;
... ...
include/qpdf/QPDFJob.hh
... ... @@ -158,10 +158,11 @@ class QPDFJob
158 158  
159 159 struct PageSpec
160 160 {
161   - PageSpec(std::string const& filename, char const* password, std::string const& range);
  161 + PageSpec(
  162 + std::string const& filename, std::string const& password, std::string const& range);
162 163  
163 164 std::string filename;
164   - std::shared_ptr<char> password;
  165 + std::string password;
165 166 std::string range;
166 167 };
167 168  
... ... @@ -450,7 +451,7 @@ class QPDFJob
450 451  
451 452 std::string which;
452 453 std::string filename;
453   - std::shared_ptr<char> password;
  454 + std::string password;
454 455 std::string to_nr;
455 456 std::string from_nr;
456 457 std::string repeat_nr;
... ... @@ -591,7 +592,7 @@ class QPDFJob
591 592 bool warnings{false};
592 593 unsigned long encryption_status{0};
593 594 bool verbose{false};
594   - std::shared_ptr<char> password;
  595 + std::string password;
595 596 bool linearize{false};
596 597 bool decrypt{false};
597 598 bool remove_restrictions{false};
... ... @@ -602,7 +603,7 @@ class QPDFJob
602 603 bool warnings_exit_zero{false};
603 604 bool copy_encryption{false};
604 605 std::string encryption_file;
605   - std::shared_ptr<char> encryption_file_password;
  606 + std::string encryption_file_password;
606 607 bool encrypt{false};
607 608 bool password_is_hex_key{false};
608 609 bool suppress_password_recovery{false};
... ... @@ -711,8 +712,9 @@ class QPDFJob
711 712 bool replace_input{false};
712 713 bool check_is_encrypted{false};
713 714 bool check_requires_password{false};
714   - std::shared_ptr<char> infilename;
715   - std::shared_ptr<char> outfilename;
  715 + std::string infilename;
  716 + bool empty_input{false};
  717 + std::string outfilename;
716 718 bool json_input{false};
717 719 bool json_output{false};
718 720 std::string update_from_json;
... ...
include/qpdf/QPDFObjGen.hh
... ... @@ -110,7 +110,7 @@ class QPDFObjGen
110 110 add(QPDFObjGen og)
111 111 {
112 112 if (og.isIndirect()) {
113   - if (count(og) > 0) {
  113 + if (count(og)) {
114 114 return false;
115 115 }
116 116 emplace(og);
... ...
libqpdf/AES_PDF_native.cc
... ... @@ -17,8 +17,7 @@ AES_PDF_native::AES_PDF_native(
17 17 unsigned char* cbc_block) :
18 18 encrypt(encrypt),
19 19 cbc_mode(cbc_mode),
20   - cbc_block(cbc_block),
21   - nrounds(0)
  20 + cbc_block(cbc_block)
22 21 {
23 22 size_t keybits = 8 * key_bytes;
24 23 this->key = std::make_unique<unsigned char[]>(key_bytes);
... ...
libqpdf/BitWriter.cc
... ... @@ -5,9 +5,7 @@
5 5 #include <qpdf/bits_functions.hh>
6 6  
7 7 BitWriter::BitWriter(Pipeline* pl) :
8   - pl(pl),
9   - ch(0),
10   - bit_offset(7)
  8 + pl(pl)
11 9 {
12 10 }
13 11  
... ...
libqpdf/ClosedFileInputSource.cc
... ... @@ -3,9 +3,7 @@
3 3 #include <qpdf/FileInputSource.hh>
4 4  
5 5 ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
6   - filename(filename),
7   - offset(0),
8   - stay_open(false)
  6 + filename(filename)
9 7 {
10 8 }
11 9  
... ...
libqpdf/ContentNormalizer.cc
... ... @@ -5,12 +5,6 @@
5 5  
6 6 using namespace qpdf;
7 7  
8   -ContentNormalizer::ContentNormalizer() :
9   - any_bad_tokens(false),
10   - last_token_was_bad(false)
11   -{
12   -}
13   -
14 8 void
15 9 ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
16 10 {
... ...
libqpdf/InsecureRandomDataProvider.cc
... ... @@ -4,11 +4,6 @@
4 4 #include <qpdf/qpdf-config.h>
5 5 #include <cstdlib>
6 6  
7   -InsecureRandomDataProvider::InsecureRandomDataProvider() :
8   - seeded_random(false)
9   -{
10   -}
11   -
12 7 void
13 8 InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len)
14 9 {
... ...
libqpdf/JSON.cc
... ... @@ -490,24 +490,18 @@ JSON::checkSchemaInternal(
490 490 }
491 491 }
492 492  
493   - if (sch_dict && (!pattern_key.empty())) {
  493 + if (sch_dict && !pattern_key.empty()) {
494 494 auto pattern_schema = sch_dict->members[pattern_key].m->value.get();
495   - for (auto const& iter: this_dict->members) {
496   - std::string const& key = iter.first;
  495 + for (auto const& [key, val]: this_dict->members) {
497 496 checkSchemaInternal(
498   - this_dict->members[key].m->value.get(),
499   - pattern_schema,
500   - flags,
501   - errors,
502   - prefix + "." + key);
  497 + val.m->value.get(), pattern_schema, flags, errors, prefix + "." + key);
503 498 }
504 499 } else if (sch_dict) {
505   - for (auto& iter: sch_dict->members) {
506   - std::string const& key = iter.first;
507   - if (this_dict->members.count(key)) {
  500 + for (auto& [key, val]: sch_dict->members) {
  501 + if (this_dict->members.contains(key)) {
508 502 checkSchemaInternal(
509 503 this_dict->members[key].m->value.get(),
510   - iter.second.m->value.get(),
  504 + val.m->value.get(),
511 505 flags,
512 506 errors,
513 507 prefix + "." + key);
... ... @@ -516,18 +510,17 @@ JSON::checkSchemaInternal(
516 510 QTC::TC("libtests", "JSON optional key");
517 511 } else {
518 512 QTC::TC("libtests", "JSON key missing in object");
519   - errors.push_back(
  513 + errors.emplace_back(
520 514 err_prefix + ": key \"" + key +
521 515 "\" is present in schema but missing in object");
522 516 }
523 517 }
524 518 }
525   - for (auto const& iter: this_dict->members) {
526   - std::string const& key = iter.first;
527   - if (sch_dict->members.count(key) == 0) {
  519 + for (auto const& item: this_dict->members) {
  520 + if (!sch_dict->members.contains(item.first)) {
528 521 QTC::TC("libtests", "JSON key extra in object");
529   - errors.push_back(
530   - err_prefix + ": key \"" + key +
  522 + errors.emplace_back(
  523 + err_prefix + ": key \"" + item.first +
531 524 "\" is not present in schema but appears in object");
532 525 }
533 526 }
... ... @@ -554,9 +547,9 @@ JSON::checkSchemaInternal(
554 547 checkSchemaInternal(
555 548 this_v, sch_arr->elements.at(0).m->value.get(), flags, errors, prefix);
556 549 }
557   - } else if (!this_arr || (this_arr->elements.size() != n_elements)) {
  550 + } else if (!this_arr || this_arr->elements.size() != n_elements) {
558 551 QTC::TC("libtests", "JSON schema array length mismatch");
559   - errors.push_back(
  552 + errors.emplace_back(
560 553 err_prefix + " is supposed to be an array of length " + std::to_string(n_elements));
561 554 return false;
562 555 } else {
... ... @@ -576,7 +569,7 @@ JSON::checkSchemaInternal(
576 569 }
577 570 } else if (!sch_str) {
578 571 QTC::TC("libtests", "JSON schema other type");
579   - errors.push_back(err_prefix + " schema value is not dictionary, array, or string");
  572 + errors.emplace_back(err_prefix + " schema value is not dictionary, array, or string");
580 573 return false;
581 574 }
582 575  
... ...
libqpdf/NNTree.cc
... ... @@ -28,8 +28,7 @@ error(QPDF&amp; qpdf, QPDFObjectHandle&amp; node, std::string const&amp; msg)
28 28 }
29 29  
30 30 NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) :
31   - impl(impl),
32   - item_number(-1)
  31 + impl(impl)
33 32 {
34 33 }
35 34  
... ... @@ -666,7 +665,6 @@ NNTreeImpl::NNTreeImpl(
666 665 NNTreeDetails const& details, QPDF& qpdf, QPDFObjectHandle& oh, bool auto_repair) :
667 666 details(details),
668 667 qpdf(qpdf),
669   - split_threshold(32),
670 668 oh(oh),
671 669 auto_repair(auto_repair)
672 670 {
... ...
libqpdf/Pl_Flate.cc
... ... @@ -29,7 +29,7 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) :
29 29 // Indirect through zdata to reach the z_stream so we don't have to include zlib.h in
30 30 // Pl_Flate.hh. This means people using shared library versions of qpdf don't have to have zlib
31 31 // development files available, which particularly helps in a Windows environment.
32   - this->zdata = new z_stream;
  32 + zdata = new z_stream;
33 33  
34 34 if (out_bufsize > UINT_MAX) {
35 35 throw std::runtime_error(
... ... @@ -52,8 +52,8 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) :
52 52  
53 53 Pl_Flate::Members::~Members()
54 54 {
55   - if (this->initialized) {
56   - z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
  55 + if (initialized) {
  56 + z_stream& zstream = *(static_cast<z_stream*>(zdata));
57 57 if (action == a_deflate) {
58 58 deflateEnd(&zstream);
59 59 } else {
... ... @@ -62,7 +62,7 @@ Pl_Flate::Members::~Members()
62 62 }
63 63  
64 64 delete static_cast<z_stream*>(this->zdata);
65   - this->zdata = nullptr;
  65 + zdata = nullptr;
66 66 }
67 67  
68 68 Pl_Flate::Pl_Flate(
... ... @@ -99,7 +99,7 @@ Pl_Flate::setWarnCallback(std::function&lt;void(char const*, int)&gt; callback)
99 99 void
100 100 Pl_Flate::warn(char const* msg, int code)
101 101 {
102   - if (m->callback != nullptr) {
  102 + if (m->callback) {
103 103 m->callback(msg, code);
104 104 }
105 105 }
... ... @@ -107,7 +107,7 @@ Pl_Flate::warn(char const* msg, int code)
107 107 void
108 108 Pl_Flate::write(unsigned char const* data, size_t len)
109 109 {
110   - if (m->outbuf == nullptr) {
  110 + if (!m->outbuf) {
111 111 throw std::logic_error(
112 112 this->identifier + ": Pl_Flate: write() called after finish() called");
113 113 }
... ... @@ -184,7 +184,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
184 184 // this error (including at least one in qpdf's test suite). In some cases, we want to
185 185 // know about this, because it indicates incorrect compression, so call a callback if
186 186 // provided.
187   - this->warn("input stream is complete but output may still be valid", err);
  187 + warn("input stream is complete but output may still be valid", err);
188 188 done = true;
189 189 break;
190 190  
... ... @@ -215,7 +215,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
215 215 break;
216 216  
217 217 default:
218   - this->checkError("data", err);
  218 + checkError("data", err);
219 219 break;
220 220 }
221 221 }
... ... @@ -271,7 +271,7 @@ Pl_Flate::checkError(char const* prefix, int error_code)
271 271 z_stream& zstream = *(static_cast<z_stream*>(m->zdata));
272 272 if (error_code != Z_OK) {
273 273 char const* action_str = (m->action == a_deflate ? "deflate" : "inflate");
274   - std::string msg = this->identifier + ": " + action_str + ": " + prefix + ": ";
  274 + std::string msg = identifier + ": " + action_str + ": " + prefix + ": ";
275 275  
276 276 if (zstream.msg) {
277 277 msg += zstream.msg;
... ...
libqpdf/Pl_PNGFilter.cc
... ... @@ -39,7 +39,7 @@ Pl_PNGFilter::Pl_PNGFilter(
39 39 throw std::runtime_error(
40 40 "PNGFilter created with invalid bits_per_sample not 1, 2, 4, 8, or 16");
41 41 }
42   - this->bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8;
  42 + bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8;
43 43 unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8;
44 44 if ((bpr == 0) || (bpr > (UINT_MAX - 1))) {
45 45 throw std::runtime_error("PNGFilter created with invalid columns value");
... ... @@ -47,16 +47,16 @@ Pl_PNGFilter::Pl_PNGFilter(
47 47 if (memory_limit > 0 && bpr > (memory_limit / 2U)) {
48 48 throw std::runtime_error("PNGFilter memory limit exceeded");
49 49 }
50   - this->bytes_per_row = bpr & UINT_MAX;
51   - this->buf1 = QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1);
52   - this->buf2 = QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1);
53   - memset(this->buf1.get(), 0, this->bytes_per_row + 1);
54   - memset(this->buf2.get(), 0, this->bytes_per_row + 1);
55   - this->cur_row = this->buf1.get();
56   - this->prev_row = this->buf2.get();
  50 + bytes_per_row = bpr & UINT_MAX;
  51 + buf1 = QUtil::make_shared_array<unsigned char>(bytes_per_row + 1);
  52 + buf2 = QUtil::make_shared_array<unsigned char>(bytes_per_row + 1);
  53 + memset(buf1.get(), 0, bytes_per_row + 1);
  54 + memset(buf2.get(), 0, bytes_per_row + 1);
  55 + cur_row = buf1.get();
  56 + prev_row = buf2.get();
57 57  
58 58 // number of bytes per incoming row
59   - this->incoming = (action == a_encode ? this->bytes_per_row : this->bytes_per_row + 1);
  59 + incoming = (action == a_encode ? bytes_per_row : bytes_per_row + 1);
60 60 }
61 61  
62 62 void
... ... @@ -68,34 +68,34 @@ Pl_PNGFilter::setMemoryLimit(unsigned long long limit)
68 68 void
69 69 Pl_PNGFilter::write(unsigned char const* data, size_t len)
70 70 {
71   - size_t left = this->incoming - this->pos;
  71 + size_t left = incoming - pos;
72 72 size_t offset = 0;
73 73 while (len >= left) {
74 74 // finish off current row
75   - memcpy(this->cur_row + this->pos, data + offset, left);
  75 + memcpy(cur_row + pos, data + offset, left);
76 76 offset += left;
77 77 len -= left;
78 78  
79 79 processRow();
80 80  
81 81 // Swap rows
82   - unsigned char* t = this->prev_row;
83   - this->prev_row = this->cur_row;
84   - this->cur_row = t ? t : this->buf2.get();
85   - memset(this->cur_row, 0, this->bytes_per_row + 1);
86   - left = this->incoming;
87   - this->pos = 0;
  82 + unsigned char* t = prev_row;
  83 + prev_row = cur_row;
  84 + cur_row = t ? t : buf2.get();
  85 + memset(cur_row, 0, bytes_per_row + 1);
  86 + left = incoming;
  87 + pos = 0;
88 88 }
89 89 if (len) {
90   - memcpy(this->cur_row + this->pos, data + offset, len);
  90 + memcpy(cur_row + pos, data + offset, len);
91 91 }
92   - this->pos += len;
  92 + pos += len;
93 93 }
94 94  
95 95 void
96 96 Pl_PNGFilter::processRow()
97 97 {
98   - if (this->action == a_encode) {
  98 + if (action == a_encode) {
99 99 encodeRow();
100 100 } else {
101 101 decodeRow();
... ... @@ -105,22 +105,22 @@ Pl_PNGFilter::processRow()
105 105 void
106 106 Pl_PNGFilter::decodeRow()
107 107 {
108   - int filter = this->cur_row[0];
109   - if (this->prev_row) {
  108 + int filter = cur_row[0];
  109 + if (prev_row) {
110 110 switch (filter) {
111 111 case 0:
112 112 break;
113 113 case 1:
114   - this->decodeSub();
  114 + decodeSub();
115 115 break;
116 116 case 2:
117   - this->decodeUp();
  117 + decodeUp();
118 118 break;
119 119 case 3:
120   - this->decodeAverage();
  120 + decodeAverage();
121 121 break;
122 122 case 4:
123   - this->decodePaeth();
  123 + decodePaeth();
124 124 break;
125 125 default:
126 126 // ignore
... ... @@ -128,17 +128,17 @@ Pl_PNGFilter::decodeRow()
128 128 }
129 129 }
130 130  
131   - next()->write(this->cur_row + 1, this->bytes_per_row);
  131 + next()->write(cur_row + 1, bytes_per_row);
132 132 }
133 133  
134 134 void
135 135 Pl_PNGFilter::decodeSub()
136 136 {
137 137 QTC::TC("libtests", "Pl_PNGFilter decodeSub");
138   - unsigned char* buffer = this->cur_row + 1;
139   - unsigned int bpp = this->bytes_per_pixel;
  138 + unsigned char* buffer = cur_row + 1;
  139 + unsigned int bpp = bytes_per_pixel;
140 140  
141   - for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
  141 + for (unsigned int i = 0; i < bytes_per_row; ++i) {
142 142 unsigned char left = 0;
143 143  
144 144 if (i >= bpp) {
... ... @@ -153,10 +153,10 @@ void
153 153 Pl_PNGFilter::decodeUp()
154 154 {
155 155 QTC::TC("libtests", "Pl_PNGFilter decodeUp");
156   - unsigned char* buffer = this->cur_row + 1;
157   - unsigned char* above_buffer = this->prev_row + 1;
  156 + unsigned char* buffer = cur_row + 1;
  157 + unsigned char* above_buffer = prev_row + 1;
158 158  
159   - for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
  159 + for (unsigned int i = 0; i < bytes_per_row; ++i) {
160 160 unsigned char up = above_buffer[i];
161 161 buffer[i] = static_cast<unsigned char>(buffer[i] + up);
162 162 }
... ... @@ -166,11 +166,11 @@ void
166 166 Pl_PNGFilter::decodeAverage()
167 167 {
168 168 QTC::TC("libtests", "Pl_PNGFilter decodeAverage");
169   - unsigned char* buffer = this->cur_row + 1;
170   - unsigned char* above_buffer = this->prev_row + 1;
171   - unsigned int bpp = this->bytes_per_pixel;
  169 + unsigned char* buffer = cur_row + 1;
  170 + unsigned char* above_buffer = prev_row + 1;
  171 + unsigned int bpp = bytes_per_pixel;
172 172  
173   - for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
  173 + for (unsigned int i = 0; i < bytes_per_row; ++i) {
174 174 int left = 0;
175 175 int up = 0;
176 176  
... ... @@ -187,11 +187,11 @@ void
187 187 Pl_PNGFilter::decodePaeth()
188 188 {
189 189 QTC::TC("libtests", "Pl_PNGFilter decodePaeth");
190   - unsigned char* buffer = this->cur_row + 1;
191   - unsigned char* above_buffer = this->prev_row + 1;
192   - unsigned int bpp = this->bytes_per_pixel;
  190 + unsigned char* buffer = cur_row + 1;
  191 + unsigned char* above_buffer = prev_row + 1;
  192 + unsigned int bpp = bytes_per_pixel;
193 193  
194   - for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
  194 + for (unsigned int i = 0; i < bytes_per_row; ++i) {
195 195 int left = 0;
196 196 int up = above_buffer[i];
197 197 int upper_left = 0;
... ... @@ -201,8 +201,7 @@ Pl_PNGFilter::decodePaeth()
201 201 upper_left = above_buffer[i - bpp];
202 202 }
203 203  
204   - buffer[i] =
205   - static_cast<unsigned char>(buffer[i] + this->PaethPredictor(left, up, upper_left));
  204 + buffer[i] = static_cast<unsigned char>(buffer[i] + PaethPredictor(left, up, upper_left));
206 205 }
207 206 }
208 207  
... ... @@ -229,27 +228,27 @@ Pl_PNGFilter::encodeRow()
229 228 // For now, hard-code to using UP filter.
230 229 unsigned char ch = 2;
231 230 next()->write(&ch, 1);
232   - if (this->prev_row) {
233   - for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
234   - ch = static_cast<unsigned char>(this->cur_row[i] - this->prev_row[i]);
  231 + if (prev_row) {
  232 + for (unsigned int i = 0; i < bytes_per_row; ++i) {
  233 + ch = static_cast<unsigned char>(cur_row[i] - prev_row[i]);
235 234 next()->write(&ch, 1);
236 235 }
237 236 } else {
238   - next()->write(this->cur_row, this->bytes_per_row);
  237 + next()->write(cur_row, bytes_per_row);
239 238 }
240 239 }
241 240  
242 241 void
243 242 Pl_PNGFilter::finish()
244 243 {
245   - if (this->pos) {
  244 + if (pos) {
246 245 // write partial row
247 246 processRow();
248 247 }
249   - this->prev_row = nullptr;
250   - this->cur_row = buf1.get();
251   - this->pos = 0;
252   - memset(this->cur_row, 0, this->bytes_per_row + 1);
  248 + prev_row = nullptr;
  249 + cur_row = buf1.get();
  250 + pos = 0;
  251 + memset(cur_row, 0, bytes_per_row + 1);
253 252  
254 253 next()->finish();
255 254 }
... ...
libqpdf/Pl_SHA2.cc
... ... @@ -5,8 +5,7 @@
5 5 #include <stdexcept>
6 6  
7 7 Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) :
8   - Pipeline("sha2", next),
9   - in_progress(false)
  8 + Pipeline("sha2", next)
10 9 {
11 10 if (bits) {
12 11 resetBits(bits);
... ...
libqpdf/QPDF.cc
... ... @@ -564,7 +564,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
564 564 obj_copier.to_copy.clear();
565 565  
566 566 auto og = foreign.getObjGen();
567   - if (!obj_copier.object_map.count(og)) {
  567 + if (!obj_copier.object_map.contains(og)) {
568 568 warn(damagedPDF(
569 569 other.getFilename() + " object " + og.unparse(' '),
570 570 foreign.getParsedOffset(),
... ... @@ -594,7 +594,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier&amp; obj_copier, bool top)
594 594 QTC::TC("qpdf", "QPDF loop reserving objects");
595 595 return;
596 596 }
597   - if (obj_copier.object_map.count(foreign_og) > 0) {
  597 + if (obj_copier.object_map.contains(foreign_og)) {
598 598 QTC::TC("qpdf", "QPDF already reserved object");
599 599 if (!(top && foreign.isPageObject() && obj_copier.object_map[foreign_og].isNull())) {
600 600 obj_copier.visiting.erase(foreign);
... ...
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -9,11 +9,6 @@
9 9  
10 10 using namespace qpdf;
11 11  
12   -QPDFAcroFormDocumentHelper::Members::Members() :
13   - cache_valid(false)
14   -{
15   -}
16   -
17 12 QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) :
18 13 QPDFDocumentHelper(qpdf),
19 14 m(new Members())
... ... @@ -85,7 +80,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(std::vector&lt;QPDFObjectHandle&gt;
85 80 // this field's /T is always at the end of the fully qualified name, appending to /T
86 81 // has the effect of appending the same thing to the fully qualified name.
87 82 std::string old_name = QPDFFormFieldObjectHelper(obj).getFullyQualifiedName();
88   - if (renames.count(old_name) == 0) {
  83 + if (!renames.contains(old_name)) {
89 84 std::string new_name = old_name;
90 85 int suffix = 0;
91 86 std::string append;
... ... @@ -145,7 +140,7 @@ QPDFAcroFormDocumentHelper::removeFormFields(std::set&lt;QPDFObjGen&gt; const&amp; to_remo
145 140 int i = 0;
146 141 while (i < fields.getArrayNItems()) {
147 142 auto field = fields.getArrayItem(i);
148   - if (to_remove.count(field.getObjGen())) {
  143 + if (to_remove.contains(field.getObjGen())) {
149 144 fields.eraseItem(i);
150 145 } else {
151 146 ++i;
... ... @@ -191,7 +186,7 @@ QPDFAcroFormDocumentHelper::getAnnotationsForField(QPDFFormFieldObjectHelper h)
191 186 analyze();
192 187 std::vector<QPDFAnnotationObjectHelper> result;
193 188 QPDFObjGen og(h.getObjectHandle().getObjGen());
194   - if (m->field_to_annotations.count(og)) {
  189 + if (m->field_to_annotations.contains(og)) {
195 190 result = m->field_to_annotations[og];
196 191 }
197 192 return result;
... ... @@ -228,7 +223,7 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h)
228 223 }
229 224 analyze();
230 225 QPDFObjGen og(oh.getObjGen());
231   - if (m->annotation_to_field.count(og)) {
  226 + if (m->annotation_to_field.contains(og)) {
232 227 result = m->annotation_to_field[og];
233 228 }
234 229 return result;
... ... @@ -271,7 +266,7 @@ QPDFAcroFormDocumentHelper::analyze()
271 266 for (auto const& iter: getWidgetAnnotationsForPage(ph)) {
272 267 QPDFObjectHandle annot(iter.getObjectHandle());
273 268 QPDFObjGen og(annot.getObjGen());
274   - if (m->annotation_to_field.count(og) == 0) {
  269 + if (!m->annotation_to_field.contains(og)) {
275 270 QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget");
276 271 // This is not supposed to happen, but it's easy enough for us to handle this case.
277 272 // Treat the annotation as its own field. This could allow qpdf to sensibly handle a
... ... @@ -542,7 +537,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const&amp; token)
542 537 bool wrote = false;
543 538 if (token.getType() == QPDFTokenizer::tt_name) {
544 539 std::string name = QPDFObjectHandle::newName(token.getValue()).getName();
545   - if (to_replace.count(name) && to_replace[name].count(offset)) {
  540 + if (to_replace.contains(name) && to_replace[name].contains(offset)) {
546 541 QTC::TC("qpdf", "QPDFAcroFormDocumentHelper replaced DA token");
547 542 write(to_replace[name][offset]);
548 543 wrote = true;
... ... @@ -675,7 +670,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream(
675 670 resources.mergeResources(merge_with, &dr_map);
676 671 // Remove empty subdictionaries
677 672 for (auto iter: resources.ditems()) {
678   - if (iter.second.isDictionary() && (iter.second.getKeys().size() == 0)) {
  673 + if (iter.second.isDictionary() && iter.second.getKeys().empty()) {
679 674 resources.removeKey(iter.first);
680 675 }
681 676 }
... ... @@ -807,7 +802,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
807 802 std::map<QPDFObjGen, QPDFObjectHandle> orig_to_copy;
808 803 auto maybe_copy_object = [&](QPDFObjectHandle& to_copy) {
809 804 auto og = to_copy.getObjGen();
810   - if (orig_to_copy.count(og)) {
  805 + if (orig_to_copy.contains(og)) {
811 806 to_copy = orig_to_copy[og];
812 807 return false;
813 808 } else {
... ... @@ -893,7 +888,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
893 888 auto parent = obj.getKey("/Parent");
894 889 if (parent.isIndirect()) {
895 890 auto parent_og = parent.getObjGen();
896   - if (orig_to_copy.count(parent_og)) {
  891 + if (orig_to_copy.contains(parent_og)) {
897 892 obj.replaceKey("/Parent", orig_to_copy[parent_og]);
898 893 } else {
899 894 parent.warnIfPossible(
... ...
libqpdf/QPDFArgParser.cc
... ... @@ -18,12 +18,7 @@ QPDFArgParser::Members::Members(int argc, char const* const argv[], char const*
18 18  
19 19 argc(argc),
20 20 argv(argv),
21   - progname_env(progname_env),
22   - cur_arg(0),
23   - bash_completion(false),
24   - zsh_completion(false),
25   - option_table(nullptr),
26   - final_check_handler(nullptr)
  21 + progname_env(progname_env)
27 22 {
28 23 auto tmp = QUtil::make_unique_cstr(argv[0]);
29 24 whoami = QUtil::getWhoami(tmp.get());
... ... @@ -71,7 +66,7 @@ QPDFArgParser::selectOptionTable(std::string const&amp; name)
71 66 void
72 67 QPDFArgParser::registerOptionTable(std::string const& name, bare_arg_handler_t end_handler)
73 68 {
74   - if (0 != m->option_tables.count(name)) {
  69 + if (m->option_tables.contains(name)) {
75 70 QTC::TC("libtests", "QPDFArgParser register registered table");
76 71 throw std::logic_error(
77 72 "QPDFArgParser: registering already registered option table " + name);
... ... @@ -84,7 +79,7 @@ QPDFArgParser::registerOptionTable(std::string const&amp; name, bare_arg_handler_t e
84 79 QPDFArgParser::OptionEntry&
85 80 QPDFArgParser::registerArg(std::string const& arg)
86 81 {
87   - if (0 != m->option_table->count(arg)) {
  82 + if (m->option_table->contains(arg)) {
88 83 QTC::TC("libtests", "QPDFArgParser duplicate handler");
89 84 throw std::logic_error(
90 85 "QPDFArgParser: adding a duplicate handler for option " + arg + " in " +
... ... @@ -198,13 +193,13 @@ QPDFArgParser::completionCommon(bool zsh)
198 193 if (!zsh) {
199 194 std::cout << " -o nospace";
200 195 }
201   - std::cout << " -C \"" << progname << "\" " << m->whoami << std::endl;
  196 + std::cout << " -C \"" << progname << "\" " << m->whoami << '\n';
202 197 // Put output before error so calling from zsh works properly
203 198 std::string path = progname;
204 199 size_t slash = path.find('/');
205 200 if ((slash != 0) && (slash != std::string::npos)) {
206 201 std::cerr << "WARNING: " << m->whoami << " completion enabled"
207   - << " using relative path to executable" << std::endl;
  202 + << " using relative path to executable" << '\n';
208 203 }
209 204 }
210 205  
... ... @@ -239,7 +234,7 @@ QPDFArgParser::handleArgFileArguments()
239 234 // Support reading arguments from files. Create a new argv. Ensure that argv itself as well as
240 235 // all its contents are automatically deleted by using shared pointers back to the pointers in
241 236 // argv.
242   - m->new_argv.push_back(QUtil::make_shared_cstr(m->argv[0]));
  237 + m->new_argv.emplace_back(m->argv[0]);
243 238 for (int i = 1; i < m->argc; ++i) {
244 239 char const* argfile = nullptr;
245 240 if ((strlen(m->argv[i]) > 1) && (m->argv[i][0] == '@')) {
... ... @@ -254,16 +249,16 @@ QPDFArgParser::handleArgFileArguments()
254 249 if (argfile) {
255 250 readArgsFromFile(1 + m->argv[i]);
256 251 } else {
257   - m->new_argv.push_back(QUtil::make_shared_cstr(m->argv[i]));
  252 + m->new_argv.emplace_back(m->argv[i]);
258 253 }
259 254 }
260   - m->argv_ph = QUtil::make_shared_array<char const*>(1 + m->new_argv.size());
261   - for (size_t i = 0; i < m->new_argv.size(); ++i) {
262   - m->argv_ph.get()[i] = m->new_argv.at(i).get();
  255 + m->argv_ph.reserve(1 + m->new_argv.size());
  256 + for (auto const& a: m->new_argv) {
  257 + m->argv_ph.push_back(a.data());
263 258 }
264 259 m->argc = QIntC::to_int(m->new_argv.size());
265   - m->argv_ph.get()[m->argc] = nullptr;
266   - m->argv = m->argv_ph.get();
  260 + m->argv_ph.push_back(nullptr);
  261 + m->argv = m->argv_ph.data();
267 262 }
268 263  
269 264 void
... ... @@ -290,7 +285,7 @@ QPDFArgParser::handleBashArguments()
290 285 case st_top:
291 286 if (util::is_space(ch)) {
292 287 if (!arg.empty()) {
293   - m->bash_argv.push_back(QUtil::make_shared_cstr(arg));
  288 + m->bash_argv.emplace_back(arg);
294 289 arg.clear();
295 290 }
296 291 } else if (ch == '"') {
... ... @@ -326,16 +321,16 @@ QPDFArgParser::handleBashArguments()
326 321 if (m->bash_argv.empty()) {
327 322 // This can't happen if properly invoked by bash, but ensure we have a valid argv[0]
328 323 // regardless.
329   - m->bash_argv.push_back(QUtil::make_shared_cstr(m->argv[0]));
  324 + m->bash_argv.emplace_back(m->argv[0]);
330 325 }
331 326 // Explicitly discard any non-space-terminated word. The "current word" is handled specially.
332   - m->bash_argv_ph = QUtil::make_shared_array<char const*>(1 + m->bash_argv.size());
333   - for (size_t i = 0; i < m->bash_argv.size(); ++i) {
334   - m->bash_argv_ph.get()[i] = m->bash_argv.at(i).get();
  327 + m->bash_argv_ph.reserve(1 + m->bash_argv.size());
  328 + for (auto const& a: m->bash_argv) {
  329 + m->bash_argv_ph.push_back(a.data());
335 330 }
336 331 m->argc = QIntC::to_int(m->bash_argv.size());
337   - m->bash_argv_ph.get()[m->argc] = nullptr;
338   - m->argv = m->bash_argv_ph.get();
  332 + m->bash_argv_ph.push_back(nullptr);
  333 + m->argv = m->bash_argv_ph.data();
339 334 }
340 335  
341 336 void
... ... @@ -360,7 +355,7 @@ QPDFArgParser::readArgsFromFile(std::string const&amp; filename)
360 355 lines = QUtil::read_lines_from_file(filename.c_str());
361 356 }
362 357 for (auto const& line: lines) {
363   - m->new_argv.push_back(QUtil::make_shared_cstr(line));
  358 + m->new_argv.emplace_back(line);
364 359 }
365 360 }
366 361  
... ... @@ -471,7 +466,7 @@ QPDFArgParser::parseArgs()
471 466 // positional arguments. Besides, it doesn't make sense to have an empty option.
472 467 arg_s = arg;
473 468 size_t equal_pos = std::string::npos;
474   - if (arg_s.length() > 0) {
  469 + if (!arg_s.empty()) {
475 470 equal_pos = arg_s.find('=', 1);
476 471 }
477 472 if (equal_pos != std::string::npos) {
... ... @@ -481,7 +476,7 @@ QPDFArgParser::parseArgs()
481 476 }
482 477  
483 478 if ((!m->bash_completion) && (m->argc == 2) && (m->cur_arg == 1) &&
484   - m->help_option_table.count(arg_s)) {
  479 + m->help_option_table.contains(arg_s)) {
485 480 // Handle help option, which is only valid as the sole option.
486 481 QTC::TC("libtests", "QPDFArgParser help option");
487 482 oep = m->help_option_table.find(arg_s);
... ... @@ -508,8 +503,8 @@ QPDFArgParser::parseArgs()
508 503 }
509 504  
510 505 OptionEntry& oe = oep->second;
511   - if ((oe.parameter_needed && (!have_parameter)) ||
512   - ((!oe.choices.empty() && have_parameter && (0 == oe.choices.count(parameter))))) {
  506 + if ((oe.parameter_needed && !have_parameter) ||
  507 + (!oe.choices.empty() && have_parameter && !oe.choices.contains(parameter))) {
513 508 std::string message = "--" + arg_s + " must be given as --" + arg_s + "=";
514 509 if (oe.invalid_choice_handler) {
515 510 oe.invalid_choice_handler(parameter);
... ... @@ -584,7 +579,7 @@ void
584 579 QPDFArgParser::addChoicesToCompletions(
585 580 option_table_t& option_table, std::string const& option, std::string const& extra_prefix)
586 581 {
587   - if (option_table.count(option) != 0) {
  582 + if (option_table.contains(option)) {
588 583 OptionEntry& oe = option_table[option];
589 584 for (auto const& choice: oe.choices) {
590 585 QTC::TC("libtests", "QPDFArgParser complete choices");
... ... @@ -666,7 +661,7 @@ QPDFArgParser::handleCompletion()
666 661 std::string prefix = extra_prefix + m->bash_cur;
667 662 for (auto const& iter: m->completions) {
668 663 if (prefix.empty() || (iter.substr(0, prefix.length()) == prefix)) {
669   - std::cout << iter << std::endl;
  664 + std::cout << iter << '\n';
670 665 }
671 666 }
672 667 exit(0);
... ... @@ -686,11 +681,11 @@ QPDFArgParser::addHelpTopic(
686 681 QTC::TC("libtests", "QPDFArgParser add reserved help topic");
687 682 throw std::logic_error("QPDFArgParser: can't register reserved help topic " + topic);
688 683 }
689   - if (!((topic.length() > 0) && (topic.at(0) != '-'))) {
  684 + if (topic.empty() || topic.at(0) == '-') {
690 685 QTC::TC("libtests", "QPDFArgParser bad topic for help");
691 686 throw std::logic_error("QPDFArgParser: help topics must not start with -");
692 687 }
693   - if (m->help_topics.count(topic)) {
  688 + if (m->help_topics.contains(topic)) {
694 689 QTC::TC("libtests", "QPDFArgParser add existing topic");
695 690 throw std::logic_error("QPDFArgParser: topic " + topic + " has already been added");
696 691 }
... ... @@ -710,7 +705,7 @@ QPDFArgParser::addOptionHelp(
710 705 QTC::TC("libtests", "QPDFArgParser bad option for help");
711 706 throw std::logic_error("QPDFArgParser: options for help must start with --");
712 707 }
713   - if (m->option_help.count(option_name)) {
  708 + if (m->option_help.contains(option_name)) {
714 709 QTC::TC("libtests", "QPDFArgParser duplicate option help");
715 710 throw std::logic_error("QPDFArgParser: option " + option_name + " already has help");
716 711 }
... ... @@ -729,13 +724,13 @@ QPDFArgParser::addOptionHelp(
729 724 void
730 725 QPDFArgParser::getTopHelp(std::ostringstream& msg)
731 726 {
732   - msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." << std::endl
733   - << "Run \"" << m->whoami << " --help=--option\" for help on an option." << std::endl
734   - << "Run \"" << m->whoami << " --help=all\" to see all available help." << std::endl
735   - << std::endl
736   - << "Topics:" << std::endl;
  727 + msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." << '\n'
  728 + << "Run \"" << m->whoami << " --help=--option\" for help on an option." << '\n'
  729 + << "Run \"" << m->whoami << " --help=all\" to see all available help." << '\n'
  730 + << '\n'
  731 + << "Topics:" << '\n';
737 732 for (auto const& i: m->help_topics) {
738   - msg << " " << i.first << ": " << i.second.short_text << std::endl;
  733 + msg << " " << i.first << ": " << i.second.short_text << '\n';
739 734 }
740 735 }
741 736  
... ... @@ -746,29 +741,27 @@ QPDFArgParser::getAllHelp(std::ostringstream&amp; msg)
746 741 auto show = [this, &msg](std::map<std::string, HelpTopic>& topics) {
747 742 for (auto const& i: topics) {
748 743 auto const& topic = i.first;
749   - msg << std::endl
750   - << "== " << topic << " (" << i.second.short_text << ") ==" << std::endl
751   - << std::endl;
  744 + msg << '\n' << "== " << topic << " (" << i.second.short_text << ") ==" << '\n' << '\n';
752 745 getTopicHelp(topic, i.second, msg);
753 746 }
754 747 };
755 748 show(m->help_topics);
756 749 show(m->option_help);
757   - msg << std::endl << "====" << std::endl;
  750 + msg << '\n' << "====" << '\n';
758 751 }
759 752  
760 753 void
761 754 QPDFArgParser::getTopicHelp(std::string const& name, HelpTopic const& ht, std::ostringstream& msg)
762 755 {
763 756 if (ht.long_text.empty()) {
764   - msg << ht.short_text << std::endl;
  757 + msg << ht.short_text << '\n';
765 758 } else {
766 759 msg << ht.long_text;
767 760 }
768 761 if (!ht.options.empty()) {
769   - msg << std::endl << "Related options:" << std::endl;
  762 + msg << '\n' << "Related options:" << '\n';
770 763 for (auto const& i: ht.options) {
771   - msg << " " << i << ": " << m->option_help[i].short_text << std::endl;
  764 + msg << " " << i << ": " << m->option_help[i].short_text << '\n';
772 765 }
773 766 }
774 767 }
... ... @@ -782,9 +775,9 @@ QPDFArgParser::getHelp(std::string const&amp; arg)
782 775 } else {
783 776 if (arg == "all") {
784 777 getAllHelp(msg);
785   - } else if (m->option_help.count(arg)) {
  778 + } else if (m->option_help.contains(arg)) {
786 779 getTopicHelp(arg, m->option_help[arg], msg);
787   - } else if (m->help_topics.count(arg)) {
  780 + } else if (m->help_topics.contains(arg)) {
788 781 getTopicHelp(arg, m->help_topics[arg], msg);
789 782 } else {
790 783 // should not be possible
... ...
libqpdf/QPDFCryptoProvider.cc
... ... @@ -88,7 +88,7 @@ QPDFCryptoProvider::registerImpl_internal(std::string const&amp; name, provider_fn f
88 88 void
89 89 QPDFCryptoProvider::setDefaultProvider_internal(std::string const& name)
90 90 {
91   - if (!m->providers.count(name)) {
  91 + if (!m->providers.contains(name)) {
92 92 throw std::logic_error(
93 93 "QPDFCryptoProvider: request to set default provider to unknown implementation \"" +
94 94 name + "\"");
... ...
libqpdf/QPDFJob.cc
... ... @@ -262,13 +262,11 @@ ImageOptimizer::provideStreamData(QPDFObjGen const&amp;, Pipeline* pipeline)
262 262 }
263 263  
264 264 QPDFJob::PageSpec::PageSpec(
265   - std::string const& filename, char const* password, std::string const& range) :
  265 + std::string const& filename, std::string const& password, std::string const& range) :
266 266 filename(filename),
  267 + password(password.empty() ? "" : password),
267 268 range(range)
268 269 {
269   - if (password) {
270   - this->password = QUtil::make_shared_cstr(password);
271   - }
272 270 }
273 271  
274 272 QPDFPageData::QPDFPageData(std::string const& filename, QPDF* qpdf, std::string const& range) :
... ... @@ -396,7 +394,7 @@ QPDFJob::parseRotationParameter(std::string const&amp; parameter)
396 394 } else {
397 395 angle_str = parameter;
398 396 }
399   - if (angle_str.length() > 0) {
  397 + if (!angle_str.empty()) {
400 398 char first = angle_str.at(0);
401 399 if ((first == '+') || (first == '-')) {
402 400 relative = ((first == '+') ? 1 : -1);
... ... @@ -440,7 +438,7 @@ QPDFJob::createQPDF()
440 438 checkConfiguration();
441 439 std::unique_ptr<QPDF> pdf_sp;
442 440 try {
443   - processFile(pdf_sp, m->infilename.get(), m->password.get(), true, true);
  441 + processFile(pdf_sp, m->infilename.data(), m->password.data(), true, true);
444 442 } catch (QPDFExc& e) {
445 443 if (e.getErrorCode() == qpdf_e_password) {
446 444 // Allow certain operations to work when an incorrect password is supplied.
... ... @@ -561,7 +559,7 @@ QPDFJob::hasWarnings() const
561 559 bool
562 560 QPDFJob::createsOutput() const
563 561 {
564   - return ((m->outfilename != nullptr) || m->replace_input);
  562 + return (!m->outfilename.empty() || m->replace_input);
565 563 }
566 564  
567 565 int
... ... @@ -604,34 +602,39 @@ QPDFJob::checkConfiguration()
604 602  
605 603 if (m->replace_input) {
606 604 // Check for --empty appears later after we have checked m->infilename.
607   - if (m->outfilename) {
  605 + if (!m->outfilename.empty()) {
608 606 usage("--replace-input may not be used when an output file is specified");
609   - } else if (m->split_pages) {
  607 + }
  608 + if (m->split_pages) {
610 609 usage("--split-pages may not be used with --replace-input");
611   - } else if (m->json_version) {
  610 + }
  611 + if (m->json_version) {
612 612 usage("--json may not be used with --replace-input");
613 613 }
614 614 }
615   - if (m->json_version && (m->outfilename == nullptr)) {
  615 + if (m->json_version && m->outfilename.empty()) {
616 616 // The output file is optional with --json for backward compatibility and defaults to
617 617 // standard output.
618   - m->outfilename = QUtil::make_shared_cstr("-");
  618 + m->outfilename = "-";
619 619 }
620   - if (m->infilename == nullptr) {
  620 + if (m->infilename.empty() && !m->empty_input) {
621 621 usage("an input file name is required");
622   - } else if (m->replace_input && (strlen(m->infilename.get()) == 0)) {
  622 + }
  623 + if (m->replace_input && m->infilename.empty()) {
623 624 usage("--replace-input may not be used with --empty");
624   - } else if (m->require_outfile && (m->outfilename == nullptr) && (!m->replace_input)) {
  625 + }
  626 + if (m->require_outfile && m->outfilename.empty() && !m->replace_input) {
625 627 usage("an output file name is required; use - for standard output");
626   - } else if ((!m->require_outfile) && ((m->outfilename != nullptr) || m->replace_input)) {
  628 + }
  629 + if (!m->require_outfile && (!m->outfilename.empty() || m->replace_input)) {
627 630 usage("no output file may be given for this option");
628 631 }
629 632 if (m->check_requires_password && m->check_is_encrypted) {
630 633 usage("--requires-password and --is-encrypted may not be given together");
631 634 }
632 635  
633   - if (m->encrypt && (!m->allow_insecure) &&
634   - (m->owner_password.empty() && (!m->user_password.empty()) && (m->keylen == 256))) {
  636 + if (m->encrypt && !m->allow_insecure && m->owner_password.empty() &&
  637 + !m->user_password.empty() && m->keylen == 256) {
635 638 // Note that empty owner passwords for R < 5 are copied from the user password, so this lack
636 639 // of security is not an issue for those files. Also we are consider only the ability to
637 640 // open the file without a password to be insecure. We are not concerned about whether the
... ... @@ -644,7 +647,7 @@ QPDFJob::checkConfiguration()
644 647 }
645 648  
646 649 bool save_to_stdout = false;
647   - if (m->require_outfile && m->outfilename && (strcmp(m->outfilename.get(), "-") == 0)) {
  650 + if (m->require_outfile && m->outfilename == "-") {
648 651 if (m->split_pages) {
649 652 usage("--split-pages may not be used when writing to standard output");
650 653 }
... ... @@ -656,7 +659,7 @@ QPDFJob::checkConfiguration()
656 659 if (save_to_stdout) {
657 660 m->log->saveToStandardOutput(true);
658 661 }
659   - if ((!m->split_pages) && QUtil::same_file(m->infilename.get(), m->outfilename.get())) {
  662 + if (!m->split_pages && QUtil::same_file(m->infilename.data(), m->outfilename.data())) {
660 663 QTC::TC("qpdf", "QPDFJob same file error");
661 664 usage(
662 665 "input file and output file are the same; use --replace-input to intentionally "
... ... @@ -664,11 +667,11 @@ QPDFJob::checkConfiguration()
664 667 }
665 668  
666 669 if (m->json_version == 1) {
667   - if (m->json_keys.count("qpdf")) {
  670 + if (m->json_keys.contains("qpdf")) {
668 671 usage("json key \"qpdf\" is only valid for json version > 1");
669 672 }
670 673 } else {
671   - if (m->json_keys.count("objectinfo") || m->json_keys.count("objects")) {
  674 + if (m->json_keys.contains("objectinfo") || m->json_keys.contains("objects")) {
672 675 usage("json keys \"objects\" and \"objectinfo\" are only valid for json version 1");
673 676 }
674 677 }
... ... @@ -781,7 +784,7 @@ QPDFJob::doCheck(QPDF&amp; pdf)
781 784 // may continue to perform additional checks after finding errors.
782 785 bool okay = true;
783 786 auto& cout = *m->log->getInfo();
784   - cout << "checking " << m->infilename.get() << "\n";
  787 + cout << "checking " << m->infilename << "\n";
785 788 QPDF::JobSetter::setCheckMode(pdf, true);
786 789 try {
787 790 int extension_level = pdf.getExtensionLevel();
... ... @@ -942,7 +945,7 @@ QPDFJob::doListAttachments(QPDF&amp; pdf)
942 945 });
943 946 }
944 947 } else {
945   - *m->log->getInfo() << m->infilename.get() << " has no embedded files\n";
  948 + *m->log->getInfo() << m->infilename << " has no embedded files\n";
946 949 }
947 950 }
948 951  
... ... @@ -1002,13 +1005,13 @@ QPDFJob::doJSONObjects(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1002 1005 for (auto& obj: pdf.getAllObjects()) {
1003 1006 std::string key = obj.unparse();
1004 1007  
1005   - if (all_objects || wanted_og.count(obj.getObjGen())) {
  1008 + if (all_objects || wanted_og.contains(obj.getObjGen())) {
1006 1009 JSON::writeDictionaryKey(p, first_object, obj.unparse(), 2);
1007 1010 obj.writeJSON(1, p, true, 2);
1008 1011 first_object = false;
1009 1012 }
1010 1013 }
1011   - if (all_objects || m->json_objects.count("trailer")) {
  1014 + if (all_objects || m->json_objects.contains("trailer")) {
1012 1015 JSON::writeDictionaryKey(p, first_object, "trailer", 2);
1013 1016 pdf.getTrailer().writeJSON(1, p, true, 2);
1014 1017 first_object = false;
... ... @@ -1016,7 +1019,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1016 1019 JSON::writeDictionaryClose(p, first_object, 1);
1017 1020 } else {
1018 1021 std::set<std::string> json_objects;
1019   - if (m->json_objects.count("trailer")) {
  1022 + if (m->json_objects.contains("trailer")) {
1020 1023 json_objects.insert("trailer");
1021 1024 }
1022 1025 for (auto og: getWantedJSONObjects()) {
... ... @@ -1043,7 +1046,7 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool&amp; first, QPDF&amp; pdf)
1043 1046 bool all_objects = m->json_objects.empty();
1044 1047 auto wanted_og = getWantedJSONObjects();
1045 1048 for (auto& obj: pdf.getAllObjects()) {
1046   - if (all_objects || wanted_og.count(obj.getObjGen())) {
  1049 + if (all_objects || wanted_og.contains(obj.getObjGen())) {
1047 1050 auto j_details = JSON::makeDictionary();
1048 1051 auto j_stream = j_details.addDictionaryMember("stream", JSON::makeDictionary());
1049 1052 bool is_stream = obj.isStream();
... ... @@ -1165,7 +1168,7 @@ QPDFJob::addOutlinesToJson(
1165 1168 JSON j_destpage = JSON::makeNull();
1166 1169 if (page.isIndirect()) {
1167 1170 QPDFObjGen og = page.getObjGen();
1168   - if (page_numbers.count(og)) {
  1171 + if (page_numbers.contains(og)) {
1169 1172 j_destpage = JSON::makeInt(page_numbers[og]);
1170 1173 }
1171 1174 }
... ... @@ -1384,190 +1387,201 @@ QPDFJob::json_schema(int json_version, std::set&lt;std::string&gt;* keys)
1384 1387 // mismatch is a bug in qpdf. This helps to enforce our policy of consistently providing a known
1385 1388 // structure where every documented key will always be present, which makes it easier to consume
1386 1389 // our JSON. This is discussed in more depth in the manual.
1387   - JSON schema = JSON::makeDictionary();
1388   - schema.addDictionaryMember(
1389   - "version",
1390   - JSON::makeString("JSON format serial number; increased for non-compatible changes"));
1391   - JSON j_params = schema.addDictionaryMember("parameters", JSON::parse(R"({
1392   - "decodelevel": "decode level used to determine stream filterability"
1393   -})"));
1394 1390  
1395   - bool all_keys = ((keys == nullptr) || keys->empty());
  1391 + static constexpr const char* objects_schema_v1 = R"({
  1392 + "<n n R|trailer>": "json representation of object"
  1393 + })";
1396 1394  
1397   - // The list of selectable top-level keys id duplicated in the following places: job.yml,
1398   - // QPDFJob::json_schema, and QPDFJob::doJSON.
1399   - if (json_version == 1) {
1400   - if (all_keys || keys->count("objects")) {
1401   - schema.addDictionaryMember("objects", JSON::parse(R"({
1402   - "<n n R|trailer>": "json representation of object"
1403   -})"));
1404   - }
1405   - if (all_keys || keys->count("objectinfo")) {
1406   - JSON objectinfo = schema.addDictionaryMember("objectinfo", JSON::parse(R"({
1407   - "<object-id>": {
1408   - "stream": {
1409   - "filter": "if stream, its filters, otherwise null",
1410   - "is": "whether the object is a stream",
1411   - "length": "if stream, its length, otherwise null"
1412   - }
1413   - }
1414   -})"));
  1395 + static constexpr const char* objectinfo_schema_v1 = R"({
  1396 + "<object-id>": {
  1397 + "stream": {
  1398 + "filter": "if stream, its filters, otherwise null",
  1399 + "is": "whether the object is a stream",
  1400 + "length": "if stream, its length, otherwise null"
1415 1401 }
1416   - } else {
1417   - if (all_keys || keys->count("qpdf")) {
1418   - schema.addDictionaryMember("qpdf", JSON::parse(R"([{
1419   - "jsonversion": "numeric JSON version",
1420   - "pdfversion": "PDF version as x.y",
1421   - "pushedinheritedpageresources": "whether inherited attributes were pushed to the page level",
1422   - "calledgetallpages": "whether getAllPages was called",
1423   - "maxobjectid": "highest object ID in output, ignored on input"
1424   -},
1425   -{
1426   - "<obj:n n R|trailer>": "json representation of object"
1427   -}])"));
1428   - }
1429   - }
1430   - if (all_keys || keys->count("pages")) {
1431   - JSON page = schema.addDictionaryMember("pages", JSON::parse(R"([
1432   - {
1433   - "contents": [
1434   - "reference to each content stream"
1435   - ],
1436   - "images": [
  1402 + }
  1403 + })";
  1404 +
  1405 + static constexpr const char* qpdf_schema = R"([{
  1406 + "jsonversion": "numeric JSON version",
  1407 + "pdfversion": "PDF version as x.y",
  1408 + "pushedinheritedpageresources": "whether inherited attributes were pushed to the page level",
  1409 + "calledgetallpages": "whether getAllPages was called",
  1410 + "maxobjectid": "highest object ID in output, ignored on input"
  1411 + },
  1412 + {
  1413 + "<obj:n n R|trailer>": "json representation of object"
  1414 + }])";
  1415 +
  1416 + static constexpr const char* pages_schema = R"([
1437 1417 {
1438   - "bitspercomponent": "bits per component",
1439   - "colorspace": "color space",
1440   - "decodeparms": [
1441   - "decode parameters for image data"
  1418 + "contents": [
  1419 + "reference to each content stream"
  1420 + ],
  1421 + "images": [
  1422 + {
  1423 + "bitspercomponent": "bits per component",
  1424 + "colorspace": "color space",
  1425 + "decodeparms": [
  1426 + "decode parameters for image data"
  1427 + ],
  1428 + "filter": [
  1429 + "filters applied to image data"
  1430 + ],
  1431 + "filterable": "whether image data can be decoded using the decode level qpdf was invoked with",
  1432 + "height": "image height",
  1433 + "name": "name of image in XObject table",
  1434 + "object": "reference to image stream",
  1435 + "width": "image width"
  1436 + }
1442 1437 ],
1443   - "filter": [
1444   - "filters applied to image data"
  1438 + "label": "page label dictionary, or null if none",
  1439 + "object": "reference to original page object",
  1440 + "outlines": [
  1441 + {
  1442 + "dest": "outline destination dictionary",
  1443 + "object": "reference to outline that targets this page",
  1444 + "title": "outline title"
  1445 + }
1445 1446 ],
1446   - "filterable": "whether image data can be decoded using the decode level qpdf was invoked with",
1447   - "height": "image height",
1448   - "name": "name of image in XObject table",
1449   - "object": "reference to image stream",
1450   - "width": "image width"
  1447 + "pageposfrom1": "position of page in document numbering from 1"
  1448 + }
  1449 + ])";
  1450 +
  1451 + static constexpr const char* pagelabels_schema = R"([
  1452 + {
  1453 + "index": "starting page position starting from zero",
  1454 + "label": "page label dictionary"
1451 1455 }
1452   - ],
1453   - "label": "page label dictionary, or null if none",
1454   - "object": "reference to original page object",
1455   - "outlines": [
  1456 + ])";
  1457 +
  1458 + static constexpr const char* outlines_schema = R"([
1456 1459 {
1457 1460 "dest": "outline destination dictionary",
1458   - "object": "reference to outline that targets this page",
  1461 + "destpageposfrom1": "position of destination page in document numbered from 1; null if not known",
  1462 + "kids": "array of descendent outlines",
  1463 + "object": "reference to this outline",
  1464 + "open": "whether the outline is displayed expanded",
1459 1465 "title": "outline title"
1460 1466 }
1461   - ],
1462   - "pageposfrom1": "position of page in document numbering from 1"
1463   - }
1464   -])"));
1465   - }
1466   - if (all_keys || keys->count("pagelabels")) {
1467   - JSON labels = schema.addDictionaryMember("pagelabels", JSON::parse(R"([
1468   - {
1469   - "index": "starting page position starting from zero",
1470   - "label": "page label dictionary"
1471   - }
1472   -])"));
1473   - }
1474   - if (all_keys || keys->count("outlines")) {
1475   - JSON outlines = schema.addDictionaryMember("outlines", JSON::parse(R"([
1476   - {
1477   - "dest": "outline destination dictionary",
1478   - "destpageposfrom1": "position of destination page in document numbered from 1; null if not known",
1479   - "kids": "array of descendent outlines",
1480   - "object": "reference to this outline",
1481   - "open": "whether the outline is displayed expanded",
1482   - "title": "outline title"
1483   - }
1484   -])"));
1485   - }
1486   - if (all_keys || keys->count("acroform")) {
1487   - JSON acroform = schema.addDictionaryMember("acroform", JSON::parse(R"({
1488   - "fields": [
1489   - {
1490   - "alternativename": "alternative name of field -- this is the one usually shown to users",
1491   - "annotation": {
1492   - "annotationflags": "annotation flags from /F -- see pdf_annotation_flag_e in qpdf/Constants.h",
1493   - "appearancestate": "appearance state -- can be used to determine value for checkboxes and radio buttons",
1494   - "object": "reference to the annotation object"
  1467 + ])";
  1468 +
  1469 + static constexpr const char* acroform_schema = R"({
  1470 + "fields": [
  1471 + {
  1472 + "alternativename": "alternative name of field -- this is the one usually shown to users",
  1473 + "annotation": {
  1474 + "annotationflags": "annotation flags from /F -- see pdf_annotation_flag_e in qpdf/Constants.h",
  1475 + "appearancestate": "appearance state -- can be used to determine value for checkboxes and radio buttons",
  1476 + "object": "reference to the annotation object"
  1477 + },
  1478 + "choices": "for choices fields, the list of choices presented to the user",
  1479 + "defaultvalue": "default value of field",
  1480 + "fieldflags": "form field flags from /Ff -- see pdf_form_field_flag_e in qpdf/Constants.h",
  1481 + "fieldtype": "field type",
  1482 + "fullname": "full name of field",
  1483 + "ischeckbox": "whether field is a checkbox",
  1484 + "ischoice": "whether field is a list, combo, or dropdown",
  1485 + "isradiobutton": "whether field is a radio button -- buttons in a single group share a parent",
  1486 + "istext": "whether field is a text field",
  1487 + "mappingname": "mapping name of field",
  1488 + "object": "reference to this form field",
  1489 + "pageposfrom1": "position of containing page numbered from 1",
  1490 + "parent": "reference to this field's parent",
  1491 + "partialname": "partial name of field",
  1492 + "quadding": "field quadding -- number indicating left, center, or right",
  1493 + "value": "value of field"
  1494 + }
  1495 + ],
  1496 + "hasacroform": "whether the document has interactive forms",
  1497 + "needappearances": "whether the form fields' appearance streams need to be regenerated"
  1498 + })";
  1499 +
  1500 + static constexpr const char* encrypt_schema1 = R"({
  1501 + "capabilities": {
  1502 + "accessibility": "allow extraction for accessibility?",
  1503 + "extract": "allow extraction?",
  1504 + ")";
  1505 +
  1506 + static constexpr const char* encrypt_schema2 = R"(": "allow modifying annotations?",
  1507 + "modify": "allow all modifications?",
  1508 + "modifyassembly": "allow modifying document assembly?",
  1509 + "modifyforms": "allow modifying forms?",
  1510 + "modifyother": "allow other modifications?",
  1511 + "printhigh": "allow high resolution printing?",
  1512 + "printlow": "allow low resolution printing?"
  1513 + },
  1514 + "encrypted": "whether the document is encrypted",
  1515 + "ownerpasswordmatched": "whether supplied password matched owner password; always false for non-encrypted files",
  1516 + "recovereduserpassword": "If the owner password was used to recover the user password, reveal user password; otherwise null",
  1517 + "parameters": {
  1518 + "P": "P value from Encrypt dictionary",
  1519 + "R": "R value from Encrypt dictionary",
  1520 + "V": "V value from Encrypt dictionary",
  1521 + "bits": "encryption key bit length",
  1522 + "filemethod": "encryption method for attachments",
  1523 + "key": "encryption key; will be null unless --show-encryption-key was specified",
  1524 + "method": "overall encryption method: none, mixed, RC4, AESv2, AESv3",
  1525 + "streammethod": "encryption method for streams",
  1526 + "stringmethod": "encryption method for string"
1495 1527 },
1496   - "choices": "for choices fields, the list of choices presented to the user",
1497   - "defaultvalue": "default value of field",
1498   - "fieldflags": "form field flags from /Ff -- see pdf_form_field_flag_e in qpdf/Constants.h",
1499   - "fieldtype": "field type",
1500   - "fullname": "full name of field",
1501   - "ischeckbox": "whether field is a checkbox",
1502   - "ischoice": "whether field is a list, combo, or dropdown",
1503   - "isradiobutton": "whether field is a radio button -- buttons in a single group share a parent",
1504   - "istext": "whether field is a text field",
1505   - "mappingname": "mapping name of field",
1506   - "object": "reference to this form field",
1507   - "pageposfrom1": "position of containing page numbered from 1",
1508   - "parent": "reference to this field's parent",
1509   - "partialname": "partial name of field",
1510   - "quadding": "field quadding -- number indicating left, center, or right",
1511   - "value": "value of field"
1512   - }
1513   - ],
1514   - "hasacroform": "whether the document has interactive forms",
1515   - "needappearances": "whether the form fields' appearance streams need to be regenerated"
  1528 + "userpasswordmatched": "whether supplied password matched user password; always false for non-encrypted files"
  1529 + })";
  1530 +
  1531 + static constexpr const char* attachments_schema = R"({
  1532 + "<attachment-key>": {
  1533 + "filespec": "object containing the file spec",
  1534 + "preferredcontents": "most preferred embedded file stream",
  1535 + "preferredname": "most preferred file name",
  1536 + "description": "description of attachment",
  1537 + "names": {
  1538 + "<name-key>": "file name for key"
  1539 + },
  1540 + "streams": {
  1541 + "<stream-key>": {
  1542 + "creationdate": "ISO-8601 creation date or null",
  1543 + "modificationdate": "ISO-8601 modification date or null",
  1544 + "mimetype": "mime type or null",
  1545 + "checksum": "MD5 checksum or null"
  1546 + }
  1547 + }
  1548 + }
  1549 + })";
  1550 +
  1551 + JSON schema = JSON::makeDictionary();
  1552 + schema.addDictionaryMember(
  1553 + "version",
  1554 + JSON::makeString("JSON format serial number; increased for non-compatible changes"));
  1555 + JSON j_params = schema.addDictionaryMember("parameters", JSON::parse(R"({
  1556 + "decodelevel": "decode level used to determine stream filterability"
1516 1557 })"));
  1558 +
  1559 + const bool all_keys = !keys || keys->empty();
  1560 +
  1561 + auto add_if_want_key = [&](std::string const& key, std::string const& json) -> void {
  1562 + if (all_keys || keys->contains(key)) {
  1563 + (void)schema.addDictionaryMember(key, JSON::parse(json));
  1564 + }
  1565 + };
  1566 +
  1567 + // The list of selectable top-level keys id duplicated in the following places: job.yml,
  1568 + // QPDFJob::json_schema, and QPDFJob::doJSON.
  1569 + if (json_version == 1) {
  1570 + add_if_want_key("objects", objects_schema_v1);
  1571 + add_if_want_key("objectinfo", objectinfo_schema_v1);
  1572 + } else {
  1573 + add_if_want_key("qpdf", qpdf_schema);
1517 1574 }
  1575 + add_if_want_key("pages", pages_schema);
  1576 + add_if_want_key("pagelabels", pagelabels_schema);
  1577 + add_if_want_key("outlines", outlines_schema);
  1578 + add_if_want_key("acroform", acroform_schema);
  1579 +
1518 1580 std::string MODIFY_ANNOTATIONS =
1519 1581 (json_version == 1 ? "moddifyannotations" : "modifyannotations");
1520   - if (all_keys || keys->count("encrypt")) {
1521   - JSON encrypt = schema.addDictionaryMember("encrypt", JSON::parse(R"({
1522   - "capabilities": {
1523   - "accessibility": "allow extraction for accessibility?",
1524   - "extract": "allow extraction?",
1525   - ")" + MODIFY_ANNOTATIONS + R"(": "allow modifying annotations?",
1526   - "modify": "allow all modifications?",
1527   - "modifyassembly": "allow modifying document assembly?",
1528   - "modifyforms": "allow modifying forms?",
1529   - "modifyother": "allow other modifications?",
1530   - "printhigh": "allow high resolution printing?",
1531   - "printlow": "allow low resolution printing?"
1532   - },
1533   - "encrypted": "whether the document is encrypted",
1534   - "ownerpasswordmatched": "whether supplied password matched owner password; always false for non-encrypted files",
1535   - "recovereduserpassword": "If the owner password was used to recover the user password, reveal user password; otherwise null",
1536   - "parameters": {
1537   - "P": "P value from Encrypt dictionary",
1538   - "R": "R value from Encrypt dictionary",
1539   - "V": "V value from Encrypt dictionary",
1540   - "bits": "encryption key bit length",
1541   - "filemethod": "encryption method for attachments",
1542   - "key": "encryption key; will be null unless --show-encryption-key was specified",
1543   - "method": "overall encryption method: none, mixed, RC4, AESv2, AESv3",
1544   - "streammethod": "encryption method for streams",
1545   - "stringmethod": "encryption method for string"
1546   - },
1547   - "userpasswordmatched": "whether supplied password matched user password; always false for non-encrypted files"
1548   -})"));
1549   - }
1550   - if (all_keys || keys->count("attachments")) {
1551   - JSON attachments = schema.addDictionaryMember("attachments", JSON::parse(R"({
1552   - "<attachment-key>": {
1553   - "filespec": "object containing the file spec",
1554   - "preferredcontents": "most preferred embedded file stream",
1555   - "preferredname": "most preferred file name",
1556   - "description": "description of attachment",
1557   - "names": {
1558   - "<name-key>": "file name for key"
1559   - },
1560   - "streams": {
1561   - "<stream-key>": {
1562   - "creationdate": "ISO-8601 creation date or null",
1563   - "modificationdate": "ISO-8601 modification date or null",
1564   - "mimetype": "mime type or null",
1565   - "checksum": "MD5 checksum or null"
1566   - }
1567   - }
1568   - }
1569   -})"));
1570   - }
  1582 + add_if_want_key("encrypt", encrypt_schema1 + MODIFY_ANNOTATIONS + encrypt_schema2);
  1583 + add_if_want_key("attachments", attachments_schema);
  1584 +
1571 1585 return schema;
1572 1586 }
1573 1587  
... ... @@ -1590,9 +1604,9 @@ QPDFJob::doJSON(QPDF&amp; pdf, Pipeline* p)
1590 1604 // are reserved for users.
1591 1605  
1592 1606 std::string captured_json;
1593   - std::shared_ptr<Pl_String> pl_str;
  1607 + std::unique_ptr<Pl_String> pl_str;
1594 1608 if (m->test_json_schema) {
1595   - pl_str = std::make_shared<Pl_String>("capture json", p, captured_json);
  1609 + pl_str = std::make_unique<Pl_String>("capture json", p, captured_json);
1596 1610 p = pl_str.get();
1597 1611 }
1598 1612  
... ... @@ -1626,43 +1640,49 @@ QPDFJob::doJSON(QPDF&amp; pdf, Pipeline* p)
1626 1640 j_params.addDictionaryMember("decodelevel", JSON::makeString(decode_level_str));
1627 1641 JSON::writeDictionaryItem(p, first, "parameters", j_params, 1);
1628 1642 }
1629   - bool all_keys = m->json_keys.empty();
  1643 +
  1644 + const bool all_keys = m->json_keys.empty();
  1645 +
  1646 + auto want_key = [&](std::string const& key) -> bool {
  1647 + return all_keys || m->json_keys.contains(key);
  1648 + };
  1649 +
1630 1650 // The list of selectable top-level keys id duplicated in the following places: job.yml,
1631 1651 // QPDFJob::json_schema, and QPDFJob::doJSON.
1632 1652  
1633 1653 // We do pages and pagelabels first since they have the side effect of repairing the pages tree,
1634 1654 // which could potentially impact object references in remaining items.
1635   - if (all_keys || m->json_keys.count("pages")) {
  1655 + if (want_key("pages")) {
1636 1656 doJSONPages(p, first, pdf);
1637 1657 }
1638   - if (all_keys || m->json_keys.count("pagelabels")) {
  1658 + if (want_key("pagelabels")) {
1639 1659 doJSONPageLabels(p, first, pdf);
1640 1660 }
1641 1661  
1642 1662 // The non-special keys are output in alphabetical order, but the order doesn't actually matter.
1643   - if (all_keys || m->json_keys.count("acroform")) {
  1663 + if (want_key("acroform")) {
1644 1664 doJSONAcroform(p, first, pdf);
1645 1665 }
1646   - if (all_keys || m->json_keys.count("attachments")) {
  1666 + if (want_key("attachments")) {
1647 1667 doJSONAttachments(p, first, pdf);
1648 1668 }
1649   - if (all_keys || m->json_keys.count("encrypt")) {
  1669 + if (want_key("encrypt")) {
1650 1670 doJSONEncrypt(p, first, pdf);
1651 1671 }
1652   - if (all_keys || m->json_keys.count("outlines")) {
  1672 + if (want_key("outlines")) {
1653 1673 doJSONOutlines(p, first, pdf);
1654 1674 }
1655 1675  
1656 1676 // We do objects last so their information is consistent with repairing the page tree. To see
1657 1677 // the original file with any page tree problems and the page tree not flattened, select
1658 1678 // qpdf/objects/objectinfo without other keys.
1659   - if (all_keys || m->json_keys.count("objects") || m->json_keys.count("qpdf")) {
  1679 + if (want_key("objects") || want_key("qpdf")) {
1660 1680 doJSONObjects(p, first, pdf);
1661 1681 }
1662 1682 if (m->json_version == 1) {
1663 1683 // "objectinfo" is not needed for version >1 since you can tell streams from other objects
1664 1684 // in "objects".
1665   - if (all_keys || m->json_keys.count("objectinfo")) {
  1685 + if (want_key("objectinfo")) {
1666 1686 doJSONObjectinfo(p, first, pdf);
1667 1687 }
1668 1688 }
... ... @@ -1700,9 +1720,9 @@ QPDFJob::doInspection(QPDF&amp; pdf)
1700 1720 }
1701 1721 if (m->check_linearization) {
1702 1722 if (!pdf.isLinearized()) {
1703   - cout << m->infilename.get() << " is not linearized\n";
  1723 + cout << m->infilename << " is not linearized\n";
1704 1724 } else if (pdf.checkLinearization()) {
1705   - cout << m->infilename.get() << ": no linearization errors\n";
  1725 + cout << m->infilename << ": no linearization errors\n";
1706 1726 } else {
1707 1727 m->warnings = true;
1708 1728 }
... ... @@ -1711,7 +1731,7 @@ QPDFJob::doInspection(QPDF&amp; pdf)
1711 1731 if (pdf.isLinearized()) {
1712 1732 pdf.showLinearizationData();
1713 1733 } else {
1714   - cout << m->infilename.get() << " is not linearized\n";
  1734 + cout << m->infilename << " is not linearized\n";
1715 1735 }
1716 1736 }
1717 1737 if (m->show_xref) {
... ... @@ -1748,7 +1768,7 @@ QPDFJob::doProcessOnce(
1748 1768 if (empty) {
1749 1769 pdf->emptyPDF();
1750 1770 } else if (main_input && m->json_input) {
1751   - pdf->createFromJSON(m->infilename.get());
  1771 + pdf->createFromJSON(m->infilename);
1752 1772 } else {
1753 1773 fn(pdf.get(), password);
1754 1774 }
... ... @@ -1862,7 +1882,7 @@ QPDFJob::validateUnderOverlay(QPDF&amp; pdf, UnderOverlay* uo)
1862 1882 {
1863 1883 QPDFPageDocumentHelper main_pdh(pdf);
1864 1884 int main_npages = QIntC::to_int(main_pdh.getAllPages().size());
1865   - processFile(uo->pdf, uo->filename.c_str(), uo->password.get(), true, false);
  1885 + processFile(uo->pdf, uo->filename.data(), uo->password.data(), true, false);
1866 1886 QPDFPageDocumentHelper uo_pdh(*(uo->pdf));
1867 1887 int uo_npages = QIntC::to_int(uo_pdh.getAllPages().size());
1868 1888 try {
... ... @@ -1891,7 +1911,7 @@ get_afdh_for_qpdf(
1891 1911 std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>& afdh_map, QPDF* q)
1892 1912 {
1893 1913 auto uid = q->getUniqueId();
1894   - if (!afdh_map.count(uid)) {
  1914 + if (!afdh_map.contains(uid)) {
1895 1915 afdh_map[uid] = std::make_shared<QPDFAcroFormDocumentHelper>(*q);
1896 1916 }
1897 1917 return afdh_map[uid].get();
... ... @@ -1909,7 +1929,7 @@ QPDFJob::doUnderOverlayForPage(
1909 1929 QPDFPageObjectHelper& dest_page)
1910 1930 {
1911 1931 int pageno = 1 + QIntC::to_int(page_idx);
1912   - if (!(pagenos.count(pageno) && pagenos[pageno].count(uo_idx))) {
  1932 + if (!(pagenos.contains(pageno) && pagenos[pageno].contains(uo_idx))) {
1913 1933 return "";
1914 1934 }
1915 1935  
... ... @@ -1928,7 +1948,7 @@ QPDFJob::doUnderOverlayForPage(
1928 1948 v << " " << uo.filename << " " << uo.which << " " << from_pageno << "\n";
1929 1949 });
1930 1950 auto from_page = pages.at(QIntC::to_size(from_pageno - 1));
1931   - if (fo[from_pageno].count(uo_idx) == 0) {
  1951 + if (!fo[from_pageno].contains(uo_idx)) {
1932 1952 fo[from_pageno][uo_idx] = pdf.copyForeignObject(from_page.getFormXObjectForPage());
1933 1953 }
1934 1954  
... ... @@ -2410,7 +2430,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2410 2430 // Handle "." as a shortcut for the input file
2411 2431 for (auto& page_spec: m->page_specs) {
2412 2432 if (page_spec.filename == ".") {
2413   - page_spec.filename = m->infilename.get();
  2433 + page_spec.filename = m->infilename;
2414 2434 }
2415 2435 if (page_spec.range.empty()) {
2416 2436 page_spec.range = "1-z";
... ... @@ -2436,11 +2456,11 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2436 2456 // Create a QPDF object for each file that we may take pages from.
2437 2457 std::map<std::string, QPDF*> page_spec_qpdfs;
2438 2458 std::map<std::string, ClosedFileInputSource*> page_spec_cfis;
2439   - page_spec_qpdfs[m->infilename.get()] = &pdf;
  2459 + page_spec_qpdfs[m->infilename] = &pdf;
2440 2460 std::vector<QPDFPageData> parsed_specs;
2441 2461 std::map<unsigned long long, std::set<QPDFObjGen>> copied_pages;
2442 2462 for (auto& page_spec: m->page_specs) {
2443   - if (page_spec_qpdfs.count(page_spec.filename) == 0) {
  2463 + if (!page_spec_qpdfs.contains(page_spec.filename)) {
2444 2464 // Open the PDF file and store the QPDF object. Throw a std::shared_ptr to the qpdf into
2445 2465 // a heap so that it survives through copying to the output but gets cleaned up
2446 2466 // automatically at the end. Do not canonicalize the file name. Using two different
... ... @@ -2448,11 +2468,11 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2448 2468 // you are using this an example of how to do this with the API, you can just create two
2449 2469 // different QPDF objects to the same underlying file with the same path to achieve the
2450 2470 // same effect.
2451   - char const* password = page_spec.password.get();
2452   - if ((!m->encryption_file.empty()) && (password == nullptr) &&
2453   - (page_spec.filename == m->encryption_file)) {
  2471 + auto password = page_spec.password;
  2472 + if (!m->encryption_file.empty() && password.empty() &&
  2473 + page_spec.filename == m->encryption_file) {
2454 2474 QTC::TC("qpdf", "QPDFJob pages encryption password");
2455   - password = m->encryption_file_password.get();
  2475 + password = m->encryption_file_password;
2456 2476 }
2457 2477 doIfVerbose([&](Pipeline& v, std::string const& prefix) {
2458 2478 v << prefix << ": processing " << page_spec.filename << "\n";
... ... @@ -2470,7 +2490,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2470 2490 is = std::shared_ptr<InputSource>(fis);
2471 2491 }
2472 2492 std::unique_ptr<QPDF> qpdf_sp;
2473   - processInputSource(qpdf_sp, is, password, true);
  2493 + processInputSource(qpdf_sp, is, password.data(), true);
2474 2494 page_spec_qpdfs[page_spec.filename] = qpdf_sp.get();
2475 2495 page_heap.push_back(std::move(qpdf_sp));
2476 2496 if (cis) {
... ... @@ -2490,13 +2510,13 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2490 2510 for (auto const& iter: page_spec_qpdfs) {
2491 2511 std::string const& filename = iter.first;
2492 2512 ClosedFileInputSource* cis = nullptr;
2493   - if (page_spec_cfis.count(filename)) {
  2513 + if (page_spec_cfis.contains(filename)) {
2494 2514 cis = page_spec_cfis[filename];
2495 2515 cis->stayOpen(true);
2496 2516 }
2497 2517 QPDF& other(*(iter.second));
2498 2518 auto other_uuid = other.getUniqueId();
2499   - if (remove_unreferenced.count(other_uuid) == 0) {
  2519 + if (!remove_unreferenced.contains(other_uuid)) {
2500 2520 remove_unreferenced[other_uuid] = shouldRemoveUnreferencedResources(other);
2501 2521 }
2502 2522 if (cis) {
... ... @@ -2563,7 +2583,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2563 2583 std::set<QPDFObjGen> referenced_fields;
2564 2584 for (auto& page_data: parsed_specs) {
2565 2585 ClosedFileInputSource* cis = nullptr;
2566   - if (page_spec_cfis.count(page_data.filename)) {
  2586 + if (page_spec_cfis.contains(page_data.filename)) {
2567 2587 cis = page_spec_cfis[page_data.filename];
2568 2588 cis->stayOpen(true);
2569 2589 }
... ... @@ -2582,7 +2602,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2582 2602 QPDFPageObjectHelper to_copy = page_data.orig_pages.at(QIntC::to_size(pageno));
2583 2603 QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen();
2584 2604 unsigned long long from_uuid = page_data.qpdf->getUniqueId();
2585   - if (copied_pages[from_uuid].count(to_copy_og)) {
  2605 + if (copied_pages[from_uuid].contains(to_copy_og)) {
2586 2606 QTC::TC(
2587 2607 "qpdf",
2588 2608 "QPDFJob copy same page more than once",
... ... @@ -2600,7 +2620,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2600 2620 if (this_file) {
2601 2621 // This is a page from the original file. Keep track of the fact that we are using
2602 2622 // it.
2603   - first_copy_from_orig = (selected_from_orig.count(pageno) == 0);
  2623 + first_copy_from_orig = (!selected_from_orig.contains(pageno));
2604 2624 selected_from_orig.insert(pageno);
2605 2625 }
2606 2626 auto new_page = added_page(pdf, to_copy);
... ... @@ -2645,7 +2665,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2645 2665 // sure we keep form fields from pages we preserved.
2646 2666 for (size_t pageno = 0; pageno < orig_pages.size(); ++pageno) {
2647 2667 auto page = orig_pages.at(pageno);
2648   - if (selected_from_orig.count(QIntC::to_int(pageno))) {
  2668 + if (selected_from_orig.contains(QIntC::to_int(pageno))) {
2649 2669 for (auto field: this_afdh->getFormFieldsForPage(page)) {
2650 2670 QTC::TC("qpdf", "QPDFJob pages keeping field from original");
2651 2671 referenced_fields.insert(field.getObjectHandle().getObjGen());
... ... @@ -2664,7 +2684,7 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2664 2684 new_fields = pdf.makeIndirectObject(new_fields);
2665 2685 }
2666 2686 for (auto const& field: fields.aitems()) {
2667   - if (referenced_fields.count(field.getObjGen())) {
  2687 + if (referenced_fields.contains(field.getObjGen())) {
2668 2688 new_fields.appendItem(field);
2669 2689 }
2670 2690 }
... ... @@ -2940,8 +2960,8 @@ QPDFJob::setWriterOptions(QPDFWriter&amp; w)
2940 2960 std::unique_ptr<QPDF> encryption_pdf;
2941 2961 processFile(
2942 2962 encryption_pdf,
2943   - m->encryption_file.c_str(),
2944   - m->encryption_file_password.get(),
  2963 + m->encryption_file.data(),
  2964 + m->encryption_file_password.data(),
2945 2965 false,
2946 2966 false);
2947 2967 w.copyEncryptionParameters(*encryption_pdf);
... ... @@ -2977,7 +2997,8 @@ QPDFJob::setWriterOptions(QPDFWriter&amp; w)
2977 2997 std::shared_ptr<QPDFWriter::ProgressReporter>(
2978 2998 new QPDFWriter::FunctionProgressReporter(m->progress_handler)));
2979 2999 } else {
2980   - char const* outfilename = m->outfilename ? m->outfilename.get() : "standard output";
  3000 + char const* outfilename =
  3001 + !m->outfilename.empty() ? m->outfilename.data() : "standard output";
2981 3002 w.registerProgressReporter(
2982 3003 std::shared_ptr<QPDFWriter::ProgressReporter>(
2983 3004 // line-break
... ... @@ -2992,20 +3013,20 @@ QPDFJob::doSplitPages(QPDF&amp; pdf)
2992 3013 // Generate output file pattern
2993 3014 std::string before;
2994 3015 std::string after;
2995   - size_t len = strlen(m->outfilename.get());
2996   - char* num_spot = strstr(const_cast<char*>(m->outfilename.get()), "%d");
2997   - if (num_spot != nullptr) {
  3016 + size_t len = m->outfilename.size();
  3017 + auto num_spot = m->outfilename.find("%d");
  3018 + if (num_spot != std::string::npos) {
2998 3019 QTC::TC("qpdf", "QPDFJob split-pages %d");
2999   - before = std::string(m->outfilename.get(), QIntC::to_size(num_spot - m->outfilename.get()));
3000   - after = num_spot + 2;
  3020 + before = m->outfilename.substr(0, num_spot);
  3021 + after = m->outfilename.substr(num_spot + 2);
3001 3022 } else if (
3002   - (len >= 4) && (QUtil::str_compare_nocase(m->outfilename.get() + len - 4, ".pdf") == 0)) {
  3023 + len >= 4 && QUtil::str_compare_nocase(m->outfilename.substr(len - 4).data(), ".pdf") == 0) {
3003 3024 QTC::TC("qpdf", "QPDFJob split-pages .pdf");
3004   - before = std::string(m->outfilename.get(), len - 4) + "-";
3005   - after = m->outfilename.get() + len - 4;
  3025 + before = std::string(m->outfilename.data(), len - 4) + "-";
  3026 + after = m->outfilename.data() + len - 4;
3006 3027 } else {
3007 3028 QTC::TC("qpdf", "QPDFJob split-pages other");
3008   - before = std::string(m->outfilename.get()) + "-";
  3029 + before = m->outfilename + "-";
3009 3030 }
3010 3031  
3011 3032 if (shouldRemoveUnreferencedResources(pdf)) {
... ... @@ -3064,7 +3085,7 @@ QPDFJob::doSplitPages(QPDF&amp; pdf)
3064 3085 page_range += "-" + QUtil::uint_to_string(last, QIntC::to_int(pageno_len));
3065 3086 }
3066 3087 std::string outfile = before + page_range + after;
3067   - if (QUtil::same_file(m->infilename.get(), outfile.c_str())) {
  3088 + if (QUtil::same_file(m->infilename.data(), outfile.data())) {
3068 3089 throw std::runtime_error("split pages would overwrite input file with " + outfile);
3069 3090 }
3070 3091 QPDFWriter w(outpdf, outfile.c_str());
... ... @@ -3079,15 +3100,15 @@ QPDFJob::doSplitPages(QPDF&amp; pdf)
3079 3100 void
3080 3101 QPDFJob::writeOutfile(QPDF& pdf)
3081 3102 {
3082   - std::shared_ptr<char> temp_out;
  3103 + std::string temp_out;
3083 3104 if (m->replace_input) {
3084 3105 // Append but don't prepend to the path to generate a temporary name. This saves us from
3085 3106 // having to split the path by directory and non-directory.
3086   - temp_out = QUtil::make_shared_cstr(std::string(m->infilename.get()) + ".~qpdf-temp#");
  3107 + temp_out = m->infilename + ".~qpdf-temp#";
3087 3108 // m->outfilename will be restored to 0 before temp_out goes out of scope.
3088 3109 m->outfilename = temp_out;
3089   - } else if (strcmp(m->outfilename.get(), "-") == 0) {
3090   - m->outfilename = nullptr;
  3110 + } else if (m->outfilename == "-") {
  3111 + m->outfilename.clear();
3091 3112 }
3092 3113 if (m->json_version) {
3093 3114 writeJSON(pdf);
... ... @@ -3095,8 +3116,8 @@ QPDFJob::writeOutfile(QPDF&amp; pdf)
3095 3116 // QPDFWriter must have block scope so the output file will be closed after write()
3096 3117 // finishes.
3097 3118 QPDFWriter w(pdf);
3098   - if (m->outfilename) {
3099   - w.setOutputFilename(m->outfilename.get());
  3119 + if (!m->outfilename.empty()) {
  3120 + w.setOutputFilename(m->outfilename.data());
3100 3121 } else {
3101 3122 // saveToStandardOutput has already been called, but calling it again is defensive and
3102 3123 // harmless.
... ... @@ -3106,24 +3127,24 @@ QPDFJob::writeOutfile(QPDF&amp; pdf)
3106 3127 setWriterOptions(w);
3107 3128 w.write();
3108 3129 }
3109   - if (m->outfilename) {
  3130 + if (!m->outfilename.empty()) {
3110 3131 doIfVerbose([&](Pipeline& v, std::string const& prefix) {
3111   - v << prefix << ": wrote file " << m->outfilename.get() << "\n";
  3132 + v << prefix << ": wrote file " << m->outfilename << "\n";
3112 3133 });
3113 3134 }
3114 3135 if (m->replace_input) {
3115   - m->outfilename = nullptr;
  3136 + m->outfilename.clear();
3116 3137 }
3117 3138 if (m->replace_input) {
3118 3139 // We must close the input before we can rename files
3119 3140 pdf.closeInputSource();
3120   - std::string backup = std::string(m->infilename.get()) + ".~qpdf-orig";
  3141 + std::string backup = m->infilename + ".~qpdf-orig";
3121 3142 bool warnings = pdf.anyWarnings();
3122 3143 if (!warnings) {
3123 3144 backup.append(1, '#');
3124 3145 }
3125   - QUtil::rename_file(m->infilename.get(), backup.c_str());
3126   - QUtil::rename_file(temp_out.get(), m->infilename.get());
  3146 + QUtil::rename_file(m->infilename.data(), backup.data());
  3147 + QUtil::rename_file(temp_out.data(), m->infilename.data());
3127 3148 if (warnings) {
3128 3149 *m->log->getError() << m->message_prefix
3129 3150 << ": there are warnings; original file kept in " << backup << "\n";
... ... @@ -3145,12 +3166,12 @@ QPDFJob::writeJSON(QPDF&amp; pdf)
3145 3166 // File pipeline must have block scope so it will be closed after write.
3146 3167 std::shared_ptr<QUtil::FileCloser> fc;
3147 3168 std::shared_ptr<Pipeline> fp;
3148   - if (m->outfilename.get()) {
  3169 + if (!m->outfilename.empty()) {
3149 3170 QTC::TC("qpdf", "QPDFJob write json to file");
3150 3171 if (m->json_stream_prefix.empty()) {
3151   - m->json_stream_prefix = m->outfilename.get();
  3172 + m->json_stream_prefix = m->outfilename;
3152 3173 }
3153   - fc = std::make_shared<QUtil::FileCloser>(QUtil::safe_fopen(m->outfilename.get(), "w"));
  3174 + fc = std::make_shared<QUtil::FileCloser>(QUtil::safe_fopen(m->outfilename.data(), "w"));
3154 3175 fp = std::make_shared<Pl_StdioFile>("json output", fc->f);
3155 3176 } else if ((m->json_stream_data == qpdf_sj_file) && m->json_stream_prefix.empty()) {
3156 3177 QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout");
... ...
libqpdf/QPDFJob_argv.cc
... ... @@ -58,25 +58,25 @@ void
58 58 ArgParser::initOptionTables()
59 59 {
60 60 #include <qpdf/auto_job_init.hh>
61   - this->ap.addFinalCheck([this]() { c_main->checkConfiguration(); });
  61 + ap.addFinalCheck([this]() { c_main->checkConfiguration(); });
62 62 // add_help is defined in auto_job_help.hh
63   - add_help(this->ap);
  63 + add_help(ap);
64 64 // Special case: ignore -- at the top level. This undocumented behavior is for backward
65 65 // compatibility; it was unintentionally the case prior to 10.6, and some users were relying on
66 66 // it.
67   - this->ap.selectMainOptionTable();
68   - this->ap.addBare("--", []() {});
  67 + ap.selectMainOptionTable();
  68 + ap.addBare("--", []() {});
69 69 }
70 70  
71 71 void
72 72 ArgParser::argPositional(std::string const& arg)
73 73 {
74   - if (!this->gave_input) {
  74 + if (!gave_input) {
75 75 c_main->inputFile(arg);
76   - this->gave_input = true;
77   - } else if (!this->gave_output) {
  76 + gave_input = true;
  77 + } else if (!gave_output) {
78 78 c_main->outputFile(arg);
79   - this->gave_output = true;
  79 + gave_output = true;
80 80 } else {
81 81 usage("unknown argument " + arg);
82 82 }
... ... @@ -86,20 +86,20 @@ void
86 86 ArgParser::argEmpty()
87 87 {
88 88 c_main->emptyInput();
89   - this->gave_input = true;
  89 + gave_input = true;
90 90 }
91 91  
92 92 void
93 93 ArgParser::argReplaceInput()
94 94 {
95 95 c_main->replaceInput();
96   - this->gave_output = true;
  96 + gave_output = true;
97 97 }
98 98  
99 99 void
100 100 ArgParser::argVersion()
101 101 {
102   - auto whoami = this->ap.getProgname();
  102 + auto whoami = ap.getProgname();
103 103 *QPDFLogger::defaultLogger()->getInfo()
104 104 << whoami << " version " << QPDF::QPDFVersion() << "\n"
105 105 << "Run " << whoami << " --copyright to see copyright and license information.\n";
... ... @@ -136,7 +136,7 @@ ArgParser::argCopyright()
136 136 // 1 2 3 4 5 6 7 8
137 137 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
138 138 *QPDFLogger::defaultLogger()->getInfo()
139   - << this->ap.getProgname()
  139 + << ap.getProgname()
140 140 << " version " << QPDF::QPDFVersion() << "\n"
141 141 << "\n"
142 142 << "Copyright (c) 2005-2021 Jay Berkenbilt\n"
... ... @@ -190,9 +190,9 @@ ArgParser::argShowCrypto()
190 190 void
191 191 ArgParser::argEncrypt()
192 192 {
193   - this->c_enc = c_main->encrypt(0, "", "");
194   - this->accumulated_args.clear();
195   - this->ap.selectOptionTable(O_ENCRYPTION);
  193 + c_enc = c_main->encrypt(0, "", "");
  194 + accumulated_args.clear();
  195 + ap.selectOptionTable(O_ENCRYPTION);
196 196 }
197 197  
198 198 void
... ... @@ -202,14 +202,14 @@ ArgParser::argEncPositional(std::string const&amp; arg)
202 202 usage("positional and dashed encryption arguments may not be mixed");
203 203 }
204 204  
205   - this->accumulated_args.push_back(arg);
206   - if (this->accumulated_args.size() < 3) {
  205 + accumulated_args.push_back(arg);
  206 + if (accumulated_args.size() < 3) {
207 207 return;
208 208 }
209   - user_password = this->accumulated_args.at(0);
210   - owner_password = this->accumulated_args.at(1);
211   - auto len_str = this->accumulated_args.at(2);
212   - this->accumulated_args.clear();
  209 + user_password = accumulated_args.at(0);
  210 + owner_password = accumulated_args.at(1);
  211 + auto len_str = accumulated_args.at(2);
  212 + accumulated_args.clear();
213 213 argEncBits(len_str);
214 214 }
215 215  
... ... @@ -219,8 +219,8 @@ ArgParser::argEncUserPassword(std::string const&amp; arg)
219 219 if (!accumulated_args.empty()) {
220 220 usage("positional and dashed encryption arguments may not be mixed");
221 221 }
222   - this->used_enc_password_args = true;
223   - this->user_password = arg;
  222 + used_enc_password_args = true;
  223 + user_password = arg;
224 224 }
225 225  
226 226 void
... ... @@ -229,8 +229,8 @@ ArgParser::argEncOwnerPassword(std::string const&amp; arg)
229 229 if (!accumulated_args.empty()) {
230 230 usage("positional and dashed encryption arguments may not be mixed");
231 231 }
232   - this->used_enc_password_args = true;
233   - this->owner_password = arg;
  232 + used_enc_password_args = true;
  233 + owner_password = arg;
234 234 }
235 235  
236 236 void
... ... @@ -242,25 +242,25 @@ ArgParser::argEncBits(std::string const&amp; arg)
242 242 int keylen = 0;
243 243 if (arg == "40") {
244 244 keylen = 40;
245   - this->ap.selectOptionTable(O_40_BIT_ENCRYPTION);
  245 + ap.selectOptionTable(O_40_BIT_ENCRYPTION);
246 246 } else if (arg == "128") {
247 247 keylen = 128;
248   - this->ap.selectOptionTable(O_128_BIT_ENCRYPTION);
  248 + ap.selectOptionTable(O_128_BIT_ENCRYPTION);
249 249 } else if (arg == "256") {
250 250 keylen = 256;
251   - this->ap.selectOptionTable(O_256_BIT_ENCRYPTION);
  251 + ap.selectOptionTable(O_256_BIT_ENCRYPTION);
252 252 } else {
253 253 usage("encryption key length must be 40, 128, or 256");
254 254 }
255   - this->c_enc = c_main->encrypt(keylen, user_password, owner_password);
  255 + c_enc = c_main->encrypt(keylen, user_password, owner_password);
256 256 }
257 257  
258 258 void
259 259 ArgParser::argPages()
260 260 {
261   - this->accumulated_args.clear();
262   - this->c_pages = c_main->pages();
263   - this->ap.selectOptionTable(O_PAGES);
  261 + accumulated_args.clear();
  262 + c_pages = c_main->pages();
  263 + ap.selectOptionTable(O_PAGES);
264 264 }
265 265  
266 266 void
... ... @@ -308,29 +308,29 @@ ArgParser::argEndPages()
308 308 void
309 309 ArgParser::argUnderlay()
310 310 {
311   - this->c_uo = c_main->underlay();
312   - this->ap.selectOptionTable(O_UNDERLAY_OVERLAY);
  311 + c_uo = c_main->underlay();
  312 + ap.selectOptionTable(O_UNDERLAY_OVERLAY);
313 313 }
314 314  
315 315 void
316 316 ArgParser::argOverlay()
317 317 {
318   - this->c_uo = c_main->overlay();
319   - this->ap.selectOptionTable(O_UNDERLAY_OVERLAY);
  318 + c_uo = c_main->overlay();
  319 + ap.selectOptionTable(O_UNDERLAY_OVERLAY);
320 320 }
321 321  
322 322 void
323 323 ArgParser::argAddAttachment()
324 324 {
325   - this->c_att = c_main->addAttachment();
326   - this->ap.selectOptionTable(O_ATTACHMENT);
  325 + c_att = c_main->addAttachment();
  326 + ap.selectOptionTable(O_ATTACHMENT);
327 327 }
328 328  
329 329 void
330 330 ArgParser::argCopyAttachmentsFrom()
331 331 {
332   - this->c_copy_att = c_main->copyAttachmentsFrom();
333   - this->ap.selectOptionTable(O_COPY_ATTACHMENT);
  332 + c_copy_att = c_main->copyAttachmentsFrom();
  333 + ap.selectOptionTable(O_COPY_ATTACHMENT);
334 334 }
335 335  
336 336 void
... ... @@ -400,7 +400,7 @@ ArgParser::argEndCopyAttachment()
400 400 void
401 401 ArgParser::argSetPageLabels()
402 402 {
403   - this->ap.selectOptionTable(O_SET_PAGE_LABELS);
  403 + ap.selectOptionTable(O_SET_PAGE_LABELS);
404 404 accumulated_args.clear();
405 405 }
406 406  
... ... @@ -427,14 +427,14 @@ ArgParser::argJobJsonHelp()
427 427 void
428 428 ArgParser::usage(std::string const& message)
429 429 {
430   - this->ap.usage(message);
  430 + ap.usage(message);
431 431 }
432 432  
433 433 void
434 434 ArgParser::parseOptions()
435 435 {
436 436 try {
437   - this->ap.parseArgs();
  437 + ap.parseArgs();
438 438 } catch (std::runtime_error& e) {
439 439 usage(e.what());
440 440 }
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -15,8 +15,8 @@ QPDFJob::Config::checkConfiguration()
15 15 QPDFJob::Config*
16 16 QPDFJob::Config::inputFile(std::string const& filename)
17 17 {
18   - if (o.m->infilename == nullptr) {
19   - o.m->infilename = QUtil::make_shared_cstr(filename);
  18 + if (o.m->infilename.empty()) {
  19 + o.m->infilename = filename;
20 20 } else {
21 21 usage("input file has already been given");
22 22 }
... ... @@ -26,13 +26,13 @@ QPDFJob::Config::inputFile(std::string const&amp; filename)
26 26 QPDFJob::Config*
27 27 QPDFJob::Config::emptyInput()
28 28 {
29   - if (o.m->infilename == nullptr) {
30   - // Various places in QPDFJob.cc know that the empty string for infile means empty. We set it
31   - // to something other than a null pointer as an indication that some input source has been
32   - // specified. This approach means that passing "" as the argument to inputFile in job JSON,
33   - // or equivalently using "" as a positional command-line argument would be the same as
34   - // --empty. This probably isn't worth blocking or coding around.
35   - o.m->infilename = QUtil::make_shared_cstr("");
  29 + if (o.m->infilename.empty()) {
  30 + // Various places in QPDFJob.cc used to know that the empty string for infile means empty.
  31 + // This approach meant that passing "" as the argument to inputFile in job JSON, or
  32 + // equivalently using "" as a positional command-line argument would be the same as
  33 + // --empty. This was deemed to be not worth blocking or coding around. This no longer holds
  34 + // from 12.3.
  35 + o.m->empty_input = true;
36 36 } else {
37 37 usage("empty input can't be used since input file has already been given");
38 38 }
... ... @@ -42,8 +42,8 @@ QPDFJob::Config::emptyInput()
42 42 QPDFJob::Config*
43 43 QPDFJob::Config::outputFile(std::string const& filename)
44 44 {
45   - if ((o.m->outfilename == nullptr) && (!o.m->replace_input)) {
46   - o.m->outfilename = QUtil::make_shared_cstr(filename);
  45 + if (o.m->outfilename.empty() && !o.m->replace_input) {
  46 + o.m->outfilename = filename;
47 47 } else {
48 48 usage("output file has already been given");
49 49 }
... ... @@ -53,7 +53,7 @@ QPDFJob::Config::outputFile(std::string const&amp; filename)
53 53 QPDFJob::Config*
54 54 QPDFJob::Config::replaceInput()
55 55 {
56   - if ((o.m->outfilename == nullptr) && (!o.m->replace_input)) {
  56 + if (o.m->outfilename.empty() && !o.m->replace_input) {
57 57 o.m->replace_input = true;
58 58 } else {
59 59 usage("replace-input can't be used since output file has already been given");
... ... @@ -175,7 +175,7 @@ QPDFJob::Config::deterministicId()
175 175 QPDFJob::Config*
176 176 QPDFJob::Config::encryptionFilePassword(std::string const& parameter)
177 177 {
178   - o.m->encryption_file_password = QUtil::make_shared_cstr(parameter);
  178 + o.m->encryption_file_password = parameter;
179 179 return this;
180 180 }
181 181  
... ... @@ -456,7 +456,7 @@ QPDFJob::Config::optimizeImages()
456 456 QPDFJob::Config*
457 457 QPDFJob::Config::password(std::string const& parameter)
458 458 {
459   - o.m->password = QUtil::make_shared_cstr(parameter);
  459 + o.m->password = parameter;
460 460 return this;
461 461 }
462 462  
... ... @@ -696,12 +696,12 @@ QPDFJob::Config::passwordFile(std::string const&amp; parameter)
696 696 QTC::TC("qpdf", "QPDFJob_config password file");
697 697 lines = QUtil::read_lines_from_file(parameter.c_str());
698 698 }
699   - if (lines.size() >= 1) {
700   - o.m->password = QUtil::make_shared_cstr(lines.front());
  699 + if (!lines.empty()) {
  700 + o.m->password = lines.front();
701 701  
702 702 if (lines.size() > 1) {
703 703 *QPDFLogger::defaultLogger()->getError()
704   - << this->o.m->message_prefix << ": WARNING: all but the first line of"
  704 + << o.m->message_prefix << ": WARNING: all but the first line of"
705 705 << " the password file are ignored\n";
706 706 }
707 707 }
... ... @@ -806,7 +806,7 @@ QPDFJob::Config::jobJsonFile(std::string const&amp; parameter)
806 806 } catch (std::exception& e) {
807 807 throw std::runtime_error(
808 808 "error with job-json file " + std::string(parameter) + ": " + e.what() + "\nRun " +
809   - this->o.m->message_prefix + " --job-json-help for information on the file format.");
  809 + o.m->message_prefix + " --job-json-help for information on the file format.");
810 810 }
811 811 return this;
812 812 }
... ... @@ -832,32 +832,32 @@ QPDFJob::CopyAttConfig::CopyAttConfig(Config* c) :
832 832 QPDFJob::CopyAttConfig*
833 833 QPDFJob::CopyAttConfig::file(std::string const& parameter)
834 834 {
835   - this->caf.path = parameter;
  835 + caf.path = parameter;
836 836 return this;
837 837 }
838 838  
839 839 QPDFJob::CopyAttConfig*
840 840 QPDFJob::CopyAttConfig::prefix(std::string const& parameter)
841 841 {
842   - this->caf.prefix = parameter;
  842 + caf.prefix = parameter;
843 843 return this;
844 844 }
845 845  
846 846 QPDFJob::CopyAttConfig*
847 847 QPDFJob::CopyAttConfig::password(std::string const& parameter)
848 848 {
849   - this->caf.password = parameter;
  849 + caf.password = parameter;
850 850 return this;
851 851 }
852 852  
853 853 QPDFJob::Config*
854 854 QPDFJob::CopyAttConfig::endCopyAttachmentsFrom()
855 855 {
856   - if (this->caf.path.empty()) {
  856 + if (caf.path.empty()) {
857 857 usage("copy attachments: no file specified");
858 858 }
859   - this->config->o.m->attachments_to_copy.push_back(this->caf);
860   - return this->config;
  859 + config->o.m->attachments_to_copy.push_back(caf);
  860 + return config;
861 861 }
862 862  
863 863 QPDFJob::AttConfig::AttConfig(Config* c) :
... ... @@ -874,21 +874,21 @@ QPDFJob::Config::addAttachment()
874 874 QPDFJob::AttConfig*
875 875 QPDFJob::AttConfig::file(std::string const& parameter)
876 876 {
877   - this->att.path = parameter;
  877 + att.path = parameter;
878 878 return this;
879 879 }
880 880  
881 881 QPDFJob::AttConfig*
882 882 QPDFJob::AttConfig::key(std::string const& parameter)
883 883 {
884   - this->att.key = parameter;
  884 + att.key = parameter;
885 885 return this;
886 886 }
887 887  
888 888 QPDFJob::AttConfig*
889 889 QPDFJob::AttConfig::filename(std::string const& parameter)
890 890 {
891   - this->att.filename = parameter;
  891 + att.filename = parameter;
892 892 return this;
893 893 }
894 894  
... ... @@ -898,7 +898,7 @@ QPDFJob::AttConfig::creationdate(std::string const&amp; parameter)
898 898 if (!QUtil::pdf_time_to_qpdf_time(parameter)) {
899 899 usage(std::string(parameter) + " is not a valid PDF timestamp");
900 900 }
901   - this->att.creationdate = parameter;
  901 + att.creationdate = parameter;
902 902 return this;
903 903 }
904 904  
... ... @@ -908,7 +908,7 @@ QPDFJob::AttConfig::moddate(std::string const&amp; parameter)
908 908 if (!QUtil::pdf_time_to_qpdf_time(parameter)) {
909 909 usage(std::string(parameter) + " is not a valid PDF timestamp");
910 910 }
911   - this->att.moddate = parameter;
  911 + att.moddate = parameter;
912 912 return this;
913 913 }
914 914  
... ... @@ -918,21 +918,21 @@ QPDFJob::AttConfig::mimetype(std::string const&amp; parameter)
918 918 if (parameter.find('/') == std::string::npos) {
919 919 usage("mime type should be specified as type/subtype");
920 920 }
921   - this->att.mimetype = parameter;
  921 + att.mimetype = parameter;
922 922 return this;
923 923 }
924 924  
925 925 QPDFJob::AttConfig*
926 926 QPDFJob::AttConfig::description(std::string const& parameter)
927 927 {
928   - this->att.description = parameter;
  928 + att.description = parameter;
929 929 return this;
930 930 }
931 931  
932 932 QPDFJob::AttConfig*
933 933 QPDFJob::AttConfig::replace()
934 934 {
935   - this->att.replace = true;
  935 + att.replace = true;
936 936 return this;
937 937 }
938 938  
... ... @@ -940,28 +940,28 @@ QPDFJob::Config*
940 940 QPDFJob::AttConfig::endAddAttachment()
941 941 {
942 942 static std::string now = QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time());
943   - if (this->att.path.empty()) {
  943 + if (att.path.empty()) {
944 944 usage("add attachment: no file specified");
945 945 }
946   - std::string last_element = QUtil::path_basename(this->att.path);
  946 + std::string last_element = QUtil::path_basename(att.path);
947 947 if (last_element.empty()) {
948 948 usage("file for --add-attachment may not be empty");
949 949 }
950   - if (this->att.filename.empty()) {
951   - this->att.filename = last_element;
  950 + if (att.filename.empty()) {
  951 + att.filename = last_element;
952 952 }
953   - if (this->att.key.empty()) {
954   - this->att.key = last_element;
  953 + if (att.key.empty()) {
  954 + att.key = last_element;
955 955 }
956   - if (this->att.creationdate.empty()) {
957   - this->att.creationdate = now;
  956 + if (att.creationdate.empty()) {
  957 + att.creationdate = now;
958 958 }
959   - if (this->att.moddate.empty()) {
960   - this->att.moddate = now;
  959 + if (att.moddate.empty()) {
  960 + att.moddate = now;
961 961 }
962 962  
963   - this->config->o.m->attachments_to_add.push_back(this->att);
964   - return this->config;
  963 + config->o.m->attachments_to_add.push_back(att);
  964 + return config;
965 965 }
966 966  
967 967 QPDFJob::PagesConfig::PagesConfig(Config* c) :
... ... @@ -985,21 +985,21 @@ QPDFJob::PagesConfig::endPages()
985 985 if (n_specs == 0) {
986 986 usage("--pages: no page specifications given");
987 987 }
988   - return this->config;
  988 + return config;
989 989 }
990 990  
991 991 QPDFJob::PagesConfig*
992 992 QPDFJob::PagesConfig::pageSpec(
993 993 std::string const& filename, std::string const& range, char const* password)
994 994 {
995   - this->config->o.m->page_specs.emplace_back(filename, password, range);
  995 + config->o.m->page_specs.emplace_back(filename, password, range);
996 996 return this;
997 997 }
998 998  
999 999 QPDFJob::PagesConfig*
1000 1000 QPDFJob::PagesConfig::file(std::string const& arg)
1001 1001 {
1002   - this->config->o.m->page_specs.emplace_back(arg, nullptr, "");
  1002 + config->o.m->page_specs.emplace_back(arg, "", "");
1003 1003 return this;
1004 1004 }
1005 1005  
... ... @@ -1027,11 +1027,11 @@ QPDFJob::PagesConfig::password(std::string const&amp; arg)
1027 1027 usage("in --pages, --password must follow a file name");
1028 1028 }
1029 1029 auto& last = config->o.m->page_specs.back();
1030   - if (last.password) {
  1030 + if (!last.password.empty()) {
1031 1031 QTC::TC("qpdf", "QPDFJob duplicated pages password");
1032 1032 usage("--password already specified for this file");
1033 1033 }
1034   - last.password = QUtil::make_shared_cstr(arg);
  1034 + last.password = arg;
1035 1035 return this;
1036 1036 }
1037 1037  
... ... @@ -1063,7 +1063,7 @@ QPDFJob::UOConfig::endUnderlayOverlay()
1063 1063 usage(config->o.m->under_overlay->which + " file not specified");
1064 1064 }
1065 1065 config->o.m->under_overlay = nullptr;
1066   - return this->config;
  1066 + return config;
1067 1067 }
1068 1068  
1069 1069 QPDFJob::UOConfig*
... ... @@ -1108,7 +1108,7 @@ QPDFJob::UOConfig::repeat(std::string const&amp; parameter)
1108 1108 QPDFJob::UOConfig*
1109 1109 QPDFJob::UOConfig::password(std::string const& parameter)
1110 1110 {
1111   - config->o.m->under_overlay->password = QUtil::make_shared_cstr(parameter);
  1111 + config->o.m->under_overlay->password = parameter;
1112 1112 return this;
1113 1113 }
1114 1114  
... ... @@ -1192,7 +1192,7 @@ QPDFJob::EncConfig::endEncrypt()
1192 1192 config->o.m->encrypt = true;
1193 1193 config->o.m->decrypt = false;
1194 1194 config->o.m->copy_encryption = false;
1195   - return this->config;
  1195 + return config;
1196 1196 }
1197 1197  
1198 1198 QPDFJob::EncConfig*
... ... @@ -1341,5 +1341,5 @@ QPDFJob::PageLabelsConfig::PageLabelsConfig(Config* c) :
1341 1341 QPDFJob::Config*
1342 1342 QPDFJob::PageLabelsConfig::endSetPageLabels()
1343 1343 {
1344   - return this->config;
  1344 + return config;
1345 1345 }
... ...
libqpdf/QPDFJob_json.cc
... ... @@ -630,7 +630,7 @@ QPDFJob::initializeFromJson(std::string const&amp; json, bool partial)
630 630 std::ostringstream msg;
631 631 msg << m->message_prefix << ": job json has errors:";
632 632 for (auto const& error: errors) {
633   - msg << std::endl << " " << error;
  633 + msg << "\n " << error;
634 634 }
635 635 throw std::runtime_error(msg.str());
636 636 }
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -467,7 +467,7 @@ BaseHandle::write_json(int json_version, JSON::Writer&amp; p) const
467 467 case ::ot_real:
468 468 {
469 469 auto const& val = std::get<QPDF_Real>(obj->value).val;
470   - if (val.length() == 0) {
  470 + if (val.empty()) {
471 471 // Can't really happen...
472 472 p << "0";
473 473 } else if (val.at(0) == '.') {
... ... @@ -1184,7 +1184,7 @@ QPDFObjectHandle::mergeResources(
1184 1184 initialized_maps = true;
1185 1185 }
1186 1186 auto rval_og = rval.getObjGen();
1187   - if (rval.isIndirect() && og_to_name.count(rval_og)) {
  1187 + if (rval.isIndirect() && og_to_name.contains(rval_og)) {
1188 1188 QTC::TC("qpdf", "QPDFObjectHandle merge reuse");
1189 1189 auto new_key = og_to_name[rval_og];
1190 1190 if (new_key != key) {
... ... @@ -1208,7 +1208,7 @@ QPDFObjectHandle::mergeResources(
1208 1208 }
1209 1209 for (auto other_item: other_val.aitems()) {
1210 1210 if (other_item.isScalar()) {
1211   - if (scalars.count(other_item.unparse()) == 0) {
  1211 + if (!scalars.contains(other_item.unparse())) {
1212 1212 QTC::TC("qpdf", "QPDFObjectHandle merge array");
1213 1213 this_val.appendItem(other_item);
1214 1214 } else {
... ... @@ -1247,7 +1247,7 @@ QPDFObjectHandle::getUniqueResourceName(
1247 1247 int max_suffix = min_suffix + QIntC::to_int(names.size());
1248 1248 while (min_suffix <= max_suffix) {
1249 1249 std::string candidate = prefix + std::to_string(min_suffix);
1250   - if (names.count(candidate) == 0) {
  1250 + if (!names.contains(candidate)) {
1251 1251 return candidate;
1252 1252 }
1253 1253 // Increment after return; min_suffix should be the value
... ...
libqpdf/QPDFOutlineDocumentHelper.cc
... ... @@ -56,7 +56,7 @@ QPDFOutlineDocumentHelper::getOutlinesForPage(QPDFObjGen og)
56 56 initializeByPage();
57 57 }
58 58 std::vector<QPDFOutlineObjectHelper> result;
59   - if (m->by_page.count(og)) {
  59 + if (m->by_page.contains(og)) {
60 60 result = m->by_page[og];
61 61 }
62 62 return result;
... ...
libqpdf/QPDFPageObjectHelper.cc
... ... @@ -593,7 +593,7 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
593 593 for (auto const& i1: to_filter) {
594 594 for (auto const& n_iter: names_by_rtype[i1]) {
595 595 std::string const& name = n_iter.first;
596   - if (!known_names.count(name)) {
  596 + if (!known_names.contains(name)) {
597 597 unresolved.insert(name);
598 598 local_unresolved.insert(name);
599 599 }
... ... @@ -624,10 +624,10 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
624 624  
625 625 for (auto& dict: rdicts) {
626 626 for (auto const& key: dict.getKeys()) {
627   - if (is_page && unresolved.count(key)) {
  627 + if (is_page && unresolved.contains(key)) {
628 628 // This name is referenced by some nested form xobject, so don't remove it.
629 629 QTC::TC("qpdf", "QPDFPageObjectHelper resolving unresolved");
630   - } else if (!rf.getNames().count(key)) {
  630 + } else if (!rf.getNames().contains(key)) {
631 631 dict.removeKey(key);
632 632 }
633 633 }
... ...
libqpdf/QPDFParser.cc
... ... @@ -354,9 +354,9 @@ QPDFParser::parseRemainder(bool content_stream)
354 354 fixMissingKeys();
355 355 }
356 356  
357   - if (!frame->contents_string.empty() && dict.count("/Type") &&
358   - dict["/Type"].isNameAndEquals("/Sig") && dict.count("/ByteRange") &&
359   - dict.count("/Contents") && dict["/Contents"].isString()) {
  357 + if (!frame->contents_string.empty() && dict.contains("/Type") &&
  358 + dict["/Type"].isNameAndEquals("/Sig") && dict.contains("/ByteRange") &&
  359 + dict.contains("/Contents") && dict["/Contents"].isString()) {
360 360 dict["/Contents"] = QPDFObjectHandle::newString(frame->contents_string);
361 361 dict["/Contents"].setParsedOffset(frame->contents_offset);
362 362 }
... ... @@ -560,7 +560,7 @@ QPDFParser::fixMissingKeys()
560 560 for (auto const& item: frame->olist) {
561 561 while (true) {
562 562 const std::string key = "/QPDFFake" + std::to_string(next_fake_key++);
563   - const bool found_fake = frame->dict.count(key) == 0 && names.count(key) == 0;
  563 + const bool found_fake = !frame->dict.contains(key) && !names.contains(key);
564 564 QTC::TC("qpdf", "QPDFParser found fake", (found_fake ? 0 : 1));
565 565 if (found_fake) {
566 566 warn(
... ...
libqpdf/QPDFWriter.cc
... ... @@ -271,7 +271,7 @@ void
271 271 QPDFWriter::setExtraHeaderText(std::string const& text)
272 272 {
273 273 m->extra_header_text = text;
274   - if ((m->extra_header_text.length() > 0) && (*(m->extra_header_text.rbegin()) != '\n')) {
  274 + if (!m->extra_header_text.empty() && *m->extra_header_text.rbegin() != '\n') {
275 275 QTC::TC("qpdf", "QPDFWriter extra header text add newline");
276 276 m->extra_header_text += "\n";
277 277 } else {
... ... @@ -1065,7 +1065,7 @@ void
1065 1065 QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen og)
1066 1066 {
1067 1067 int objid = og.getObj();
1068   - if ((og.getGen() != 0) || (m->object_stream_to_objects.count(objid) == 0)) {
  1068 + if ((og.getGen() != 0) || (!m->object_stream_to_objects.contains(objid))) {
1069 1069 // This is not an object stream.
1070 1070 return;
1071 1071 }
... ... @@ -1115,7 +1115,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
1115 1115 m->object_queue.push_back(object);
1116 1116 obj.renumber = m->next_objid++;
1117 1117  
1118   - if ((og.getGen() == 0) && m->object_stream_to_objects.count(og.getObj())) {
  1118 + if ((og.getGen() == 0) && m->object_stream_to_objects.contains(og.getObj())) {
1119 1119 // For linearized files, uncompressed objects go at end, and we take care of
1120 1120 // assigning numbers to them elsewhere.
1121 1121 if (!m->linearized) {
... ... @@ -1285,7 +1285,7 @@ QPDFWriter::willFilterStream(
1285 1285 filter = true;
1286 1286 compress_stream = false;
1287 1287 uncompress = true;
1288   - } else if (filter_on_write && m->normalize_content && m->normalized_streams.count(old_og)) {
  1288 + } else if (filter_on_write && m->normalize_content && m->normalized_streams.contains(old_og)) {
1289 1289 normalize = true;
1290 1290 filter = true;
1291 1291 } else if (filter_on_write && filter && m->compress_streams) {
... ... @@ -1415,11 +1415,11 @@ QPDFWriter::unparseObject(
1415 1415  
1416 1416 if (extensions) {
1417 1417 std::set<std::string> keys = extensions.getKeys();
1418   - if (keys.count("/ADBE") > 0) {
  1418 + if (keys.contains("/ADBE")) {
1419 1419 have_extensions_adbe = true;
1420 1420 keys.erase("/ADBE");
1421 1421 }
1422   - if (keys.size() > 0) {
  1422 + if (!keys.empty()) {
1423 1423 have_extensions_other = true;
1424 1424 }
1425 1425 }
... ... @@ -1807,12 +1807,12 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index)
1807 1807 indicateProgress(false, false);
1808 1808 auto new_id = m->obj[old_og].renumber;
1809 1809 if (m->qdf_mode) {
1810   - if (m->page_object_to_seq.count(old_og)) {
  1810 + if (m->page_object_to_seq.contains(old_og)) {
1811 1811 writeString("%% Page ");
1812 1812 writeString(std::to_string(m->page_object_to_seq[old_og]));
1813 1813 writeString("\n");
1814 1814 }
1815   - if (m->contents_to_page_seq.count(old_og)) {
  1815 + if (m->contents_to_page_seq.contains(old_og)) {
1816 1816 writeString("%% Contents for page ");
1817 1817 writeString(std::to_string(m->contents_to_page_seq[old_og]));
1818 1818 writeString("\n");
... ... @@ -2285,7 +2285,7 @@ QPDFWriter::write()
2285 2285 QPDFObjGen
2286 2286 QPDFWriter::getRenumberedObjGen(QPDFObjGen og)
2287 2287 {
2288   - return QPDFObjGen(m->obj[og].renumber, 0);
  2288 + return {m->obj[og].renumber, 0};
2289 2289 }
2290 2290  
2291 2291 std::map<QPDFObjGen, QPDFXRefEntry>
... ...
libqpdf/QPDF_Dictionary.cc
... ... @@ -20,7 +20,7 @@ bool
20 20 BaseDictionary::hasKey(std::string const& key) const
21 21 {
22 22 auto d = dict();
23   - return d->items.count(key) > 0 && !d->items[key].isNull();
  23 + return d->items.contains(key) && !d->items[key].null();
24 24 }
25 25  
26 26 QPDFObjectHandle
... ...
libqpdf/QPDF_encryption.cc
... ... @@ -702,17 +702,17 @@ QPDF::interpretCF(std::shared_ptr&lt;EncryptionParameters&gt; encp, QPDFObjectHandle c
702 702 {
703 703 if (cf.isName()) {
704 704 std::string filter = cf.getName();
705   - if (encp->crypt_filters.count(filter) != 0) {
706   - return encp->crypt_filters[filter];
707   - } else if (filter == "/Identity") {
  705 + auto it = encp->crypt_filters.find(filter);
  706 + if (it != encp->crypt_filters.end()) {
  707 + return it->second;
  708 + }
  709 + if (filter == "/Identity") {
708 710 return e_none;
709   - } else {
710   - return e_unknown;
711 711 }
712   - } else {
713   - // Default: /Identity
714   - return e_none;
  712 + return e_unknown;
715 713 }
  714 + // Default: /Identity
  715 + return e_none;
716 716 }
717 717  
718 718 void
... ...
libqpdf/QPDF_json.cc
... ... @@ -161,7 +161,7 @@ QPDF::test_json_validators()
161 161 auto check_fn = [&passed](char const* msg, bool expr) {
162 162 if (!expr) {
163 163 passed = false;
164   - std::cerr << msg << std::endl;
  164 + std::cerr << msg << '\n';
165 165 }
166 166 };
167 167 #define check(expr) check_fn(#expr, expr)
... ... @@ -192,7 +192,7 @@ QPDF::test_json_validators()
192 192 check(is_unicode_string("u:potato", str));
193 193 check(str == "potato");
194 194 check(is_unicode_string("u:", str));
195   - check(str == "");
  195 + check(str.empty());
196 196 check(!is_binary_string("", str));
197 197 check(!is_binary_string("x:", str));
198 198 check(!is_binary_string("b:1", str));
... ... @@ -889,7 +889,7 @@ QPDF::writeJSON(
889 889 for (auto& obj: getAllObjects()) {
890 890 auto const og = obj.getObjGen();
891 891 std::string key = "obj:" + og.unparse(' ') + " R";
892   - if (all_objects || wanted_objects.count(key)) {
  892 + if (all_objects || wanted_objects.contains(key)) {
893 893 if (first) {
894 894 jw << "\n \"" << key;
895 895 first = false;
... ... @@ -911,7 +911,7 @@ QPDF::writeJSON(
911 911 }
912 912 }
913 913 }
914   - if (all_objects || wanted_objects.count("trailer")) {
  914 + if (all_objects || wanted_objects.contains("trailer")) {
915 915 if (!first) {
916 916 jw << "\n },";
917 917 }
... ...
libqpdf/QPDF_linearization.cc
... ... @@ -10,7 +10,7 @@
10 10 #include <qpdf/Pl_Flate.hh>
11 11 #include <qpdf/Pl_String.hh>
12 12 #include <qpdf/QPDFExc.hh>
13   -#include <qpdf/QPDFLogger.hh>
  13 +#include <qpdf/QPDFObjectHandle_private.hh>
14 14 #include <qpdf/QPDFWriter_private.hh>
15 15 #include <qpdf/QTC.hh>
16 16 #include <qpdf/QUtil.hh>
... ... @@ -502,7 +502,7 @@ QPDF::checkLinearizationInternal()
502 502 qpdf_offset_t max_E = -1;
503 503 for (auto const& oh: m->part6) {
504 504 QPDFObjGen og(oh.getObjGen());
505   - if (m->obj_cache.count(og) == 0) {
  505 + if (!m->obj_cache.contains(og)) {
506 506 // All objects have to have been dereferenced to be classified.
507 507 throw std::logic_error("linearization part6 object not in cache");
508 508 }
... ... @@ -530,12 +530,12 @@ QPDF::checkLinearizationInternal()
530 530 qpdf_offset_t
531 531 QPDF::maxEnd(ObjUser const& ou)
532 532 {
533   - if (m->obj_user_to_objects.count(ou) == 0) {
  533 + if (!m->obj_user_to_objects.contains(ou)) {
534 534 stopOnError("no entry in object user table for requested object user");
535 535 }
536 536 qpdf_offset_t end = 0;
537 537 for (auto const& og: m->obj_user_to_objects[ou]) {
538   - if (!m->obj_cache.count(og)) {
  538 + if (!m->obj_cache.contains(og)) {
539 539 stopOnError("unknown object referenced in object user table");
540 540 }
541 541 end = std::max(end, m->obj_cache[og].end_after_space);
... ... @@ -568,7 +568,7 @@ QPDF::getLinearizationOffset(QPDFObjGen og)
568 568 QPDFObjectHandle
569 569 QPDF::getUncompressedObject(QPDFObjectHandle& obj, std::map<int, int> const& object_stream_data)
570 570 {
571   - if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) {
  571 + if (obj.null() || (!object_stream_data.contains(obj.getObjectID()))) {
572 572 return obj;
573 573 } else {
574 574 int repl = (*(object_stream_data.find(obj.getObjectID()))).second;
... ... @@ -593,11 +593,11 @@ QPDF::lengthNextN(int first_object, int n)
593 593 int length = 0;
594 594 for (int i = 0; i < n; ++i) {
595 595 QPDFObjGen og(first_object + i, 0);
596   - if (m->xref_table.count(og) == 0) {
  596 + if (!m->xref_table.contains(og)) {
597 597 linearizationWarning(
598 598 "no xref table entry for " + std::to_string(first_object + i) + " 0");
599 599 } else {
600   - if (m->obj_cache.count(og) == 0) {
  600 + if (!m->obj_cache.contains(og)) {
601 601 stopOnError("found unknown object while calculating length for linearization data");
602 602 }
603 603 length += toI(m->obj_cache[og].end_after_space - getLinearizationOffset(og));
... ... @@ -625,7 +625,7 @@ QPDF::checkHPageOffset(
625 625 int npages = toI(pages.size());
626 626 qpdf_offset_t table_offset = adjusted_offset(m->page_offset_hints.first_page_offset);
627 627 QPDFObjGen first_page_og(pages.at(0).getObjGen());
628   - if (m->xref_table.count(first_page_og) == 0) {
  628 + if (!m->xref_table.contains(first_page_og)) {
629 629 stopOnError("supposed first page object is not known");
630 630 }
631 631 qpdf_offset_t offset = getLinearizationOffset(first_page_og);
... ... @@ -636,7 +636,7 @@ QPDF::checkHPageOffset(
636 636 for (int pageno = 0; pageno < npages; ++pageno) {
637 637 QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen());
638 638 int first_object = page_og.getObj();
639   - if (m->xref_table.count(page_og) == 0) {
  639 + if (!m->xref_table.contains(page_og)) {
640 640 stopOnError("unknown object in page offset hint table");
641 641 }
642 642 offset = getLinearizationOffset(page_og);
... ... @@ -677,7 +677,7 @@ QPDF::checkHPageOffset(
677 677  
678 678 for (size_t i = 0; i < toS(he.nshared_objects); ++i) {
679 679 int idx = he.shared_identifiers.at(i);
680   - if (shared_idx_to_obj.count(idx) == 0) {
  680 + if (!shared_idx_to_obj.contains(idx)) {
681 681 stopOnError("unable to get object for item in shared objects hint table");
682 682 }
683 683 hint_shared.insert(shared_idx_to_obj[idx]);
... ... @@ -693,7 +693,7 @@ QPDF::checkHPageOffset(
693 693 }
694 694  
695 695 for (int iter: hint_shared) {
696   - if (!computed_shared.count(iter)) {
  696 + if (!computed_shared.contains(iter)) {
697 697 // pdlin puts thumbnails here even though it shouldn't
698 698 linearizationWarning(
699 699 "page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) +
... ... @@ -702,7 +702,7 @@ QPDF::checkHPageOffset(
702 702 }
703 703  
704 704 for (int iter: computed_shared) {
705   - if (!hint_shared.count(iter)) {
  705 + if (!hint_shared.contains(iter)) {
706 706 // Acrobat does not put some things including at least built-in fonts and procsets
707 707 // here, at least in some cases.
708 708 linearizationWarning(
... ... @@ -755,7 +755,7 @@ QPDF::checkHSharedObject(std::vector&lt;QPDFObjectHandle&gt; const&amp; pages, std::map&lt;in
755 755 cur_object = so.first_shared_obj;
756 756  
757 757 QPDFObjGen og(cur_object, 0);
758   - if (m->xref_table.count(og) == 0) {
  758 + if (!m->xref_table.contains(og)) {
759 759 stopOnError("unknown object in shared object hint table");
760 760 }
761 761 qpdf_offset_t offset = getLinearizationOffset(og);
... ... @@ -806,7 +806,7 @@ QPDF::checkHOutlines()
806 806 return;
807 807 }
808 808 QPDFObjGen og(outlines.getObjGen());
809   - if (m->xref_table.count(og) == 0) {
  809 + if (!m->xref_table.contains(og)) {
810 810 stopOnError("unknown object in outlines hint table");
811 811 }
812 812 qpdf_offset_t offset = getLinearizationOffset(og);
... ... @@ -1086,7 +1086,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1086 1086 break;
1087 1087  
1088 1088 case ObjUser::ou_root_key:
1089   - if (open_document_keys.count(ou.key) > 0) {
  1089 + if (open_document_keys.contains(ou.key)) {
1090 1090 in_open_document = true;
1091 1091 } else if (ou.key == "/Outlines") {
1092 1092 in_outlines = true;
... ... @@ -1187,7 +1187,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1187 1187 stopOnError("no pages found while calculating linearization data");
1188 1188 }
1189 1189 QPDFObjGen first_page_og(pages.at(0).getObjGen());
1190   - if (!lc_first_page_private.count(first_page_og)) {
  1190 + if (!lc_first_page_private.contains(first_page_og)) {
1191 1191 stopOnError(
1192 1192 "INTERNAL ERROR: QPDF::calculateLinearizationData: first page "
1193 1193 "object not in lc_first_page_private");
... ... @@ -1226,7 +1226,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1226 1226 // Place this page's page object
1227 1227  
1228 1228 QPDFObjGen page_og(pages.at(i).getObjGen());
1229   - if (!lc_other_page_private.count(page_og)) {
  1229 + if (!lc_other_page_private.contains(page_og)) {
1230 1230 stopOnError(
1231 1231 "INTERNAL ERROR: QPDF::calculateLinearizationData: page object for page " +
1232 1232 std::to_string(i) + " not in lc_other_page_private");
... ... @@ -1240,11 +1240,11 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1240 1240 m->c_page_offset_data.entries.at(i).nobjects = 1;
1241 1241  
1242 1242 ObjUser ou(ObjUser::ou_page, toI(i));
1243   - if (m->obj_user_to_objects.count(ou) == 0) {
  1243 + if (!m->obj_user_to_objects.contains(ou)) {
1244 1244 stopOnError("found unreferenced page while calculating linearization data");
1245 1245 }
1246 1246 for (auto const& og: m->obj_user_to_objects[ou]) {
1247   - if (lc_other_page_private.count(og)) {
  1247 + if (lc_other_page_private.contains(og)) {
1248 1248 lc_other_page_private.erase(og);
1249 1249 m->part7.push_back(getObject(og));
1250 1250 ++m->c_page_offset_data.entries.at(i).nobjects;
... ... @@ -1279,7 +1279,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1279 1279 stopOnError("found empty pages tree while calculating linearization data");
1280 1280 }
1281 1281 for (auto const& og: pages_ogs) {
1282   - if (lc_other.count(og)) {
  1282 + if (lc_other.contains(og)) {
1283 1283 lc_other.erase(og);
1284 1284 m->part9.push_back(getObject(og));
1285 1285 }
... ... @@ -1293,7 +1293,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1293 1293 if (!thumb.isNull()) {
1294 1294 // Output the thumbnail itself
1295 1295 QPDFObjGen thumb_og(thumb.getObjGen());
1296   - if (lc_thumbnail_private.count(thumb_og)) {
  1296 + if (lc_thumbnail_private.contains(thumb_og)) {
1297 1297 lc_thumbnail_private.erase(thumb_og);
1298 1298 m->part9.push_back(thumb);
1299 1299 } else {
... ... @@ -1304,7 +1304,7 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1304 1304 }
1305 1305 std::set<QPDFObjGen>& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))];
1306 1306 for (auto const& og: ogs) {
1307   - if (lc_thumbnail_private.count(og)) {
  1307 + if (lc_thumbnail_private.contains(og)) {
1308 1308 lc_thumbnail_private.erase(og);
1309 1309 m->part9.push_back(getObject(og));
1310 1310 }
... ... @@ -1384,11 +1384,11 @@ QPDF::calculateLinearizationData(T const&amp; object_stream_data)
1384 1384 for (size_t i = 1; i < toS(npages); ++i) {
1385 1385 CHPageOffsetEntry& pe = m->c_page_offset_data.entries.at(i);
1386 1386 ObjUser ou(ObjUser::ou_page, toI(i));
1387   - if (m->obj_user_to_objects.count(ou) == 0) {
  1387 + if (!m->obj_user_to_objects.contains(ou)) {
1388 1388 stopOnError("found unreferenced page while calculating linearization data");
1389 1389 }
1390 1390 for (auto const& og: m->obj_user_to_objects[ou]) {
1391   - if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.count(og.getObj()) > 0)) {
  1391 + if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.contains(og.getObj()))) {
1392 1392 int idx = obj_to_index[og.getObj()];
1393 1393 ++pe.nshared_objects;
1394 1394 pe.shared_identifiers.push_back(idx);
... ...
libqpdf/QPDF_objects.cc
... ... @@ -153,7 +153,7 @@ QPDF::parse(char const* password)
153 153  
154 154 initializeEncryption();
155 155 m->parsed = true;
156   - if (m->xref_table.size() > 0 && !getRoot().getKey("/Pages").isDictionary()) {
  156 + if (!m->xref_table.empty() && !getRoot().getKey("/Pages").isDictionary()) {
157 157 // QPDFs created from JSON have an empty xref table and no root object yet.
158 158 throw damagedPDF("", -1, "unable to find page tree");
159 159 }
... ... @@ -442,7 +442,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset, bool in_stream_recovery)
442 442 } else {
443 443 xref_offset = read_xrefStream(xref_offset, in_stream_recovery);
444 444 }
445   - if (visited.count(xref_offset) != 0) {
  445 + if (visited.contains(xref_offset)) {
446 446 QTC::TC("qpdf", "QPDF xref loop");
447 447 throw damagedPDF("", -1, "loop detected following xref tables");
448 448 }
... ... @@ -1020,7 +1020,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2)
1020 1020 return;
1021 1021 }
1022 1022  
1023   - if (m->deleted_objects.count(obj)) {
  1023 + if (m->deleted_objects.contains(obj)) {
1024 1024 QTC::TC("qpdf", "QPDF xref deleted object");
1025 1025 return;
1026 1026 }
... ... @@ -1056,7 +1056,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2)
1056 1056 void
1057 1057 QPDF::insertFreeXrefEntry(QPDFObjGen og)
1058 1058 {
1059   - if (!m->xref_table.count(og)) {
  1059 + if (!m->xref_table.contains(og)) {
1060 1060 m->deleted_objects.insert(og.getObj());
1061 1061 }
1062 1062 }
... ... @@ -1476,7 +1476,7 @@ QPDF::readObjectAtOffset(
1476 1476 if (try_recovery) {
1477 1477 // Try again after reconstructing xref table
1478 1478 reconstruct_xref(e);
1479   - if (m->xref_table.count(exp_og) && (m->xref_table[exp_og].getType() == 1)) {
  1479 + if (m->xref_table.contains(exp_og) && m->xref_table[exp_og].getType() == 1) {
1480 1480 qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset();
1481 1481 QPDFObjectHandle result =
1482 1482 readObjectAtOffset(false, new_offset, description, exp_og, og, false);
... ... @@ -1522,7 +1522,7 @@ QPDF::readObjectAtOffset(
1522 1522 }
1523 1523 }
1524 1524 qpdf_offset_t end_after_space = m->file->tell();
1525   - if (skip_cache_if_in_xref && m->xref_table.count(og)) {
  1525 + if (skip_cache_if_in_xref && m->xref_table.contains(og)) {
1526 1526 // Ordinarily, an object gets read here when resolved through xref table or stream. In
1527 1527 // the special case of the xref stream and linearization hint tables, the offset comes
1528 1528 // from another source. For the specific case of xref streams, the xref stream is read
... ... @@ -1564,7 +1564,7 @@ QPDF::resolve(QPDFObjGen og)
1564 1564 return m->obj_cache[og].object;
1565 1565 }
1566 1566  
1567   - if (m->resolving.count(og)) {
  1567 + if (m->resolving.contains(og)) {
1568 1568 // This can happen if an object references itself directly or indirectly in some key that
1569 1569 // has to be resolved during object parsing, such as stream length.
1570 1570 QTC::TC("qpdf", "QPDF recursion loop in resolve");
... ... @@ -1574,7 +1574,7 @@ QPDF::resolve(QPDFObjGen og)
1574 1574 }
1575 1575 ResolveRecorder rr(this, og);
1576 1576  
1577   - if (m->xref_table.count(og) != 0) {
  1577 + if (m->xref_table.contains(og)) {
1578 1578 QPDFXRefEntry const& entry = m->xref_table[og];
1579 1579 try {
1580 1580 switch (entry.getType()) {
... ... @@ -1628,7 +1628,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1628 1628 true};
1629 1629 };
1630 1630  
1631   - if (m->resolved_object_streams.count(obj_stream_number)) {
  1631 + if (m->resolved_object_streams.contains(obj_stream_number)) {
1632 1632 return;
1633 1633 }
1634 1634 m->resolved_object_streams.insert(obj_stream_number);
... ... @@ -1791,7 +1791,7 @@ QPDF::updateCache(
1791 1791 bool
1792 1792 QPDF::isCached(QPDFObjGen og)
1793 1793 {
1794   - return m->obj_cache.count(og) != 0;
  1794 + return m->obj_cache.contains(og);
1795 1795 }
1796 1796  
1797 1797 bool
... ... @@ -1807,7 +1807,7 @@ QPDF::nextObjGen()
1807 1807 if (max_objid == std::numeric_limits<int>::max()) {
1808 1808 throw std::range_error("max object id is too high to create new objects");
1809 1809 }
1810   - return QPDFObjGen(max_objid + 1, 0);
  1810 + return {max_objid + 1, 0};
1811 1811 }
1812 1812  
1813 1813 QPDFObjectHandle
... ... @@ -1835,7 +1835,7 @@ QPDF::getObjectForParser(int id, int gen, bool parse_pdf)
1835 1835 if (auto iter = m->obj_cache.find(og); iter != m->obj_cache.end()) {
1836 1836 return iter->second.object;
1837 1837 }
1838   - if (m->xref_table.count(og) || !m->parsed) {
  1838 + if (m->xref_table.contains(og) || !m->parsed) {
1839 1839 return m->obj_cache.insert({og, QPDFObject::create<QPDF_Unresolved>(this, og)})
1840 1840 .first->second.object;
1841 1841 }
... ... @@ -1852,7 +1852,7 @@ QPDF::getObjectForJSON(int id, int gen)
1852 1852 auto [it, inserted] = m->obj_cache.try_emplace(og);
1853 1853 auto& obj = it->second.object;
1854 1854 if (inserted) {
1855   - obj = (m->parsed && !m->xref_table.count(og))
  1855 + obj = (m->parsed && !m->xref_table.contains(og))
1856 1856 ? QPDFObject::create<QPDF_Null>(this, og)
1857 1857 : QPDFObject::create<QPDF_Unresolved>(this, og);
1858 1858 }
... ... @@ -1864,7 +1864,7 @@ QPDF::getObject(QPDFObjGen og)
1864 1864 {
1865 1865 if (auto it = m->obj_cache.find(og); it != m->obj_cache.end()) {
1866 1866 return {it->second.object};
1867   - } else if (m->parsed && !m->xref_table.count(og)) {
  1867 + } else if (m->parsed && !m->xref_table.contains(og)) {
1868 1868 return QPDFObject::create<QPDF_Null>();
1869 1869 } else {
1870 1870 auto result =
... ... @@ -1932,8 +1932,8 @@ QPDF::tableSize()
1932 1932 {
1933 1933 // If obj_cache is dense, accommodate all object in tables,else accommodate only original
1934 1934 // objects.
1935   - auto max_xref = m->xref_table.size() ? m->xref_table.crbegin()->first.getObj() : 0;
1936   - auto max_obj = m->obj_cache.size() ? m->obj_cache.crbegin()->first.getObj() : 0;
  1935 + auto max_xref = !m->xref_table.empty() ? m->xref_table.crbegin()->first.getObj() : 0;
  1936 + auto max_obj = !m->obj_cache.empty() ? m->obj_cache.crbegin()->first.getObj() : 0;
1937 1937 auto max_id = std::numeric_limits<int>::max() - 1;
1938 1938 if (max_obj >= max_id || max_xref >= max_id) {
1939 1939 // Temporary fix. Long-term solution is
... ...
libqpdf/QPDF_pages.cc
... ... @@ -303,7 +303,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
303 303 : 2); // insert in middle
304 304  
305 305 auto og = newpage.getObjGen();
306   - if (m->pageobj_to_pages_pos.count(og)) {
  306 + if (m->pageobj_to_pages_pos.contains(og)) {
307 307 QTC::TC("qpdf", "QPDF resolve duplicated page in insert");
308 308 newpage = makeIndirectObject(QPDFObjectHandle(newpage).shallowCopy());
309 309 }
... ...
libqpdf/QTC.cc
... ... @@ -39,7 +39,7 @@ QTC::TC_real(char const* const scope, char const* const ccase, int n)
39 39 }
40 40 #undef TC_ENV
41 41  
42   - if (cache.count(std::make_pair(ccase, n))) {
  42 + if (cache.contains(std::make_pair(ccase, n))) {
43 43 return;
44 44 }
45 45 cache.insert(std::make_pair(ccase, n));
... ...
libqpdf/QUtil.cc
... ... @@ -1395,7 +1395,7 @@ QUtil::parse_numrange(char const* range, int max)
1395 1395 work = last_group;
1396 1396 last_group.clear();
1397 1397 for (auto n: work) {
1398   - if (exclusions.count(n) == 0) {
  1398 + if (!exclusions.contains(n)) {
1399 1399 last_group.emplace_back(n);
1400 1400 }
1401 1401 }
... ... @@ -1886,7 +1886,7 @@ QUtil::possible_repaired_encodings(std::string supplied)
1886 1886 std::vector<std::string> t;
1887 1887 std::set<std::string> seen;
1888 1888 for (auto const& iter: result) {
1889   - if (!seen.count(iter)) {
  1889 + if (!seen.contains(iter)) {
1890 1890 seen.insert(iter);
1891 1891 t.push_back(iter);
1892 1892 }
... ... @@ -1988,7 +1988,7 @@ QUtil::get_max_memory_usage()
1988 1988 attrs[m2->str(1)] = m2->str(2);
1989 1989 }
1990 1990 if (tag == "total") {
1991   - if (attrs.count("size") > 0) {
  1991 + if (attrs.contains("size")) {
1992 1992 result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str()));
1993 1993 }
1994 1994 } else if (tag == "system" && attrs["type"] == "max") {
... ...
libqpdf/ResourceFinder.cc
1 1 #include <qpdf/ResourceFinder.hh>
2 2  
3   -ResourceFinder::ResourceFinder() :
4   - last_name_offset(0)
5   -{
6   -}
7   -
8 3 void
9 4 ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t)
10 5 {
... ...
libqpdf/qpdf/AES_PDF_native.hh
... ... @@ -25,7 +25,7 @@ class AES_PDF_native
25 25 unsigned char* cbc_block;
26 26 std::unique_ptr<unsigned char[]> key;
27 27 std::unique_ptr<uint32_t[]> rk;
28   - unsigned int nrounds;
  28 + unsigned int nrounds{0};
29 29 };
30 30  
31 31 #endif // AES_PDF_NATIVE_HH
... ...
libqpdf/qpdf/BitWriter.hh
... ... @@ -21,8 +21,8 @@ class BitWriter
21 21  
22 22 private:
23 23 Pipeline* pl;
24   - unsigned char ch;
25   - size_t bit_offset;
  24 + unsigned char ch{0};
  25 + size_t bit_offset{7};
26 26 };
27 27  
28 28 #endif // BITWRITER_HH
... ...
libqpdf/qpdf/ContentNormalizer.hh
... ... @@ -6,7 +6,7 @@
6 6 class ContentNormalizer final: public QPDFObjectHandle::TokenFilter
7 7 {
8 8 public:
9   - ContentNormalizer();
  9 + ContentNormalizer() = default;
10 10 ~ContentNormalizer() final = default;
11 11 void handleToken(QPDFTokenizer::Token const&) final;
12 12  
... ... @@ -22,8 +22,8 @@ class ContentNormalizer final: public QPDFObjectHandle::TokenFilter
22 22 }
23 23  
24 24 private:
25   - bool any_bad_tokens;
26   - bool last_token_was_bad;
  25 + bool any_bad_tokens{false};
  26 + bool last_token_was_bad{false};
27 27 };
28 28  
29 29 #endif // CONTENTNORMALIZER_HH
... ...
libqpdf/qpdf/InsecureRandomDataProvider.hh
... ... @@ -3,18 +3,18 @@
3 3  
4 4 #include <qpdf/RandomDataProvider.hh>
5 5  
6   -class InsecureRandomDataProvider: public RandomDataProvider
  6 +class InsecureRandomDataProvider final: public RandomDataProvider
7 7 {
8 8 public:
9   - InsecureRandomDataProvider();
10   - ~InsecureRandomDataProvider() override = default;
11   - void provideRandomData(unsigned char* data, size_t len) override;
  9 + InsecureRandomDataProvider() = default;
  10 + ~InsecureRandomDataProvider() final = default;
  11 + void provideRandomData(unsigned char* data, size_t len) final;
12 12 static RandomDataProvider* getInstance();
13 13  
14 14 private:
15 15 long random();
16 16  
17   - bool seeded_random;
  17 + bool seeded_random{false};
18 18 };
19 19  
20 20 #endif // INSECURERANDOMDATAPROVIDER_HH
... ...
libqpdf/qpdf/NNTree.hh
... ... @@ -84,7 +84,7 @@ class NNTreeIterator
84 84 NNTreeImpl& impl;
85 85 std::list<PathElement> path;
86 86 QPDFObjectHandle node;
87   - int item_number;
  87 + int item_number{-1};
88 88 value_type ivalue;
89 89 };
90 90  
... ... @@ -123,7 +123,7 @@ class NNTreeImpl
123 123  
124 124 NNTreeDetails const& details;
125 125 QPDF& qpdf;
126   - int split_threshold;
  126 + int split_threshold{32};
127 127 QPDFObjectHandle oh;
128 128 bool auto_repair;
129 129 };
... ...
libqpdf/qpdf/Pl_SHA2.hh
... ... @@ -25,7 +25,7 @@ class Pl_SHA2 final: public Pipeline
25 25 std::string getRawDigest();
26 26  
27 27 private:
28   - bool in_progress;
  28 + bool in_progress{false};
29 29 std::shared_ptr<QPDFCryptoImpl> crypto;
30 30 };
31 31  
... ...
libqpdf/qpdf/QPDFArgParser.hh
... ... @@ -206,9 +206,9 @@ class QPDFArgParser
206 206 char const* const* argv;
207 207 std::string whoami;
208 208 std::string progname_env;
209   - int cur_arg;
210   - bool bash_completion;
211   - bool zsh_completion;
  209 + int cur_arg{0};
  210 + bool bash_completion{false};
  211 + bool zsh_completion{false};
212 212 std::string bash_prev;
213 213 std::string bash_cur;
214 214 std::string bash_line;
... ... @@ -216,13 +216,13 @@ class QPDFArgParser
216 216 std::map<std::string, option_table_t> option_tables;
217 217 option_table_t main_option_table;
218 218 option_table_t help_option_table;
219   - option_table_t* option_table;
  219 + option_table_t* option_table{nullptr};
220 220 std::string option_table_name;
221   - bare_arg_handler_t final_check_handler;
222   - std::vector<std::shared_ptr<char const>> new_argv;
223   - std::vector<std::shared_ptr<char const>> bash_argv;
224   - std::shared_ptr<char const*> argv_ph;
225   - std::shared_ptr<char const*> bash_argv_ph;
  221 + bare_arg_handler_t final_check_handler{nullptr};
  222 + std::vector<std::string> new_argv;
  223 + std::vector<std::string> bash_argv;
  224 + std::vector<char const*> argv_ph;
  225 + std::vector<char const*> bash_argv_ph;
226 226 std::map<std::string, HelpTopic> help_topics;
227 227 std::map<std::string, HelpTopic> option_help;
228 228 std::string help_footer;
... ...
libqpdf/qpdf/QPDFCrypto_native.hh
... ... @@ -8,37 +8,38 @@
8 8 #include <qpdf/SHA2_native.hh>
9 9 #include <memory>
10 10  
11   -class QPDFCrypto_native: public QPDFCryptoImpl
  11 +class QPDFCrypto_native final: public QPDFCryptoImpl
12 12 {
13 13 public:
14 14 QPDFCrypto_native() = default;
15 15  
16   - virtual ~QPDFCrypto_native() = default;
  16 + ~QPDFCrypto_native() final = default;
17 17  
18   - virtual void provideRandomData(unsigned char* data, size_t len);
  18 + void provideRandomData(unsigned char* data, size_t len) final;
19 19  
20   - virtual void MD5_init();
21   - virtual void MD5_update(unsigned char const* data, size_t len);
22   - virtual void MD5_finalize();
23   - virtual void MD5_digest(MD5_Digest);
  20 + void MD5_init() final;
  21 + void MD5_update(unsigned char const* data, size_t len) final;
  22 + void MD5_finalize() final;
  23 + void MD5_digest(MD5_Digest) final;
24 24  
25   - virtual void RC4_init(unsigned char const* key_data, int key_len = -1);
26   - virtual void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
27   - virtual void RC4_finalize();
  25 + void RC4_init(unsigned char const* key_data, int key_len = -1) final;
  26 + void
  27 + RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr) final;
  28 + void RC4_finalize() final;
28 29  
29   - virtual void SHA2_init(int bits);
30   - virtual void SHA2_update(unsigned char const* data, size_t len);
31   - virtual void SHA2_finalize();
32   - virtual std::string SHA2_digest();
  30 + void SHA2_init(int bits) final;
  31 + void SHA2_update(unsigned char const* data, size_t len) final;
  32 + void SHA2_finalize() final;
  33 + std::string SHA2_digest() final;
33 34  
34   - virtual void rijndael_init(
  35 + void rijndael_init(
35 36 bool encrypt,
36 37 unsigned char const* key_data,
37 38 size_t key_len,
38 39 bool cbc_mode,
39   - unsigned char* cbc_block);
40   - virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data);
41   - virtual void rijndael_finalize();
  40 + unsigned char* cbc_block) final;
  41 + void rijndael_process(unsigned char* in_data, unsigned char* out_data) final;
  42 + void rijndael_finalize() final;
42 43  
43 44 private:
44 45 std::shared_ptr<MD5_native> md5;
... ...
libqpdf/qpdf/RC4_native.hh
... ... @@ -10,7 +10,7 @@ class RC4_native
10 10 RC4_native(unsigned char const* key_data, int key_len = -1);
11 11  
12 12 // out_data = 0 means to encrypt/decrypt in place
13   - void process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
  13 + void process(unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr);
14 14  
15 15 private:
16 16 class RC4Key
... ...
libqpdf/qpdf/ResourceFinder.hh
... ... @@ -3,20 +3,20 @@
3 3  
4 4 #include <qpdf/QPDFObjectHandle.hh>
5 5  
6   -class ResourceFinder: public QPDFObjectHandle::ParserCallbacks
  6 +class ResourceFinder final: public QPDFObjectHandle::ParserCallbacks
7 7 {
8 8 public:
9   - ResourceFinder();
10   - ~ResourceFinder() override = default;
11   - void handleObject(QPDFObjectHandle, size_t, size_t) override;
12   - void handleEOF() override;
  9 + ResourceFinder() = default;
  10 + ~ResourceFinder() final = default;
  11 + void handleObject(QPDFObjectHandle, size_t, size_t) final;
  12 + void handleEOF() final;
13 13 std::set<std::string> const& getNames() const;
14 14 std::map<std::string, std::map<std::string, std::set<size_t>>> const&
15 15 getNamesByResourceType() const;
16 16  
17 17 private:
18 18 std::string last_name;
19   - size_t last_name_offset;
  19 + size_t last_name_offset{0};
20 20 std::set<std::string> names;
21 21 std::map<std::string, std::map<std::string, std::set<size_t>>> names_by_resource_type;
22 22 };
... ...
libtests/aes.cc
... ... @@ -11,15 +11,15 @@
11 11 static void
12 12 usage()
13 13 {
14   - std::cerr << "Usage: aes options hex-key infile outfile" << std::endl
15   - << " -cbc -- disable CBC mode" << std::endl
16   - << " +cbc -- enable CBC mode" << std::endl
17   - << " -encrypt -- encrypt" << std::endl
18   - << " -decrypt -- decrypt CBC mode" << std::endl
19   - << " -zero-iv -- use zero initialization vector" << std::endl
20   - << " -static-iv -- use static initialization vector" << std::endl
21   - << " -no-padding -- disable padding" << std::endl
22   - << "Options must precede key and file names." << std::endl;
  14 + std::cerr << "Usage: aes options hex-key infile outfile" << '\n'
  15 + << " -cbc -- disable CBC mode" << '\n'
  16 + << " +cbc -- enable CBC mode" << '\n'
  17 + << " -encrypt -- encrypt" << '\n'
  18 + << " -decrypt -- decrypt CBC mode" << '\n'
  19 + << " -zero-iv -- use zero initialization vector" << '\n'
  20 + << " -static-iv -- use static initialization vector" << '\n'
  21 + << " -no-padding -- disable padding" << '\n'
  22 + << "Options must precede key and file names." << '\n';
23 23 exit(2);
24 24 }
25 25  
... ...
libtests/arg_parser.cc
... ... @@ -82,7 +82,7 @@ void
82 82 ArgParser::output(std::string const& msg)
83 83 {
84 84 if (!this->ap.isCompleting()) {
85   - std::cout << msg << std::endl;
  85 + std::cout << msg << '\n';
86 86 }
87 87 }
88 88  
... ... @@ -160,7 +160,7 @@ ArgParser::test_exceptions()
160 160 fn();
161 161 assert(msg == nullptr);
162 162 } catch (std::exception& e) {
163   - std::cout << msg << ": " << e.what() << std::endl;
  163 + std::cout << msg << ": " << e.what() << '\n';
164 164 }
165 165 };
166 166  
... ... @@ -196,10 +196,10 @@ main(int argc, char* argv[])
196 196 try {
197 197 ap.parseArgs();
198 198 } catch (QPDFUsage& e) {
199   - std::cerr << "usage: " << e.what() << std::endl;
  199 + std::cerr << "usage: " << e.what() << '\n';
200 200 exit(2);
201 201 } catch (std::exception& e) {
202   - std::cerr << "exception: " << e.what() << std::endl;
  202 + std::cerr << "exception: " << e.what() << '\n';
203 203 exit(3);
204 204 }
205 205 return 0;
... ...
libtests/ascii85.cc
... ... @@ -23,7 +23,7 @@ main()
23 23 }
24 24 decode.finish();
25 25 } catch (std::exception& e) {
26   - std::cerr << e.what() << std::endl;
  26 + std::cerr << e.what() << '\n';
27 27 exit(2);
28 28 }
29 29  
... ...
libtests/base64.cc
... ... @@ -20,7 +20,7 @@ write_some(FILE* f, size_t bytes, Pipeline* p)
20 20 }
21 21 if (len < bytes) {
22 22 if (ferror(f)) {
23   - std::cerr << "error reading file" << std::endl;
  23 + std::cerr << "error reading file" << '\n';
24 24 exit(2);
25 25 }
26 26 p->finish();
... ... @@ -32,7 +32,7 @@ write_some(FILE* f, size_t bytes, Pipeline* p)
32 32 static void
33 33 usage()
34 34 {
35   - std::cerr << "Usage: base64 encode|decode" << std::endl;
  35 + std::cerr << "Usage: base64 encode|decode" << '\n';
36 36 exit(2);
37 37 }
38 38  
... ... @@ -74,7 +74,7 @@ main(int argc, char* argv[])
74 74 }
75 75 }
76 76 } catch (std::exception& e) {
77   - std::cout << "exception: " << e.what() << std::endl;
  77 + std::cout << "exception: " << e.what() << '\n';
78 78 exit(2);
79 79 }
80 80  
... ...
libtests/bits.cc
... ... @@ -16,7 +16,7 @@ static void
16 16 print_values(long long byte_offset, size_t bit_offset, size_t bits_available)
17 17 {
18 18 std::cout << "byte offset = " << byte_offset << ", " << "bit offset = " << bit_offset << ", "
19   - << "bits available = " << bits_available << std::endl;
  19 + << "bits available = " << bits_available << '\n';
20 20 }
21 21  
22 22 static void
... ... @@ -29,7 +29,7 @@ test_read_bits(
29 29 {
30 30 unsigned long result = QIntC::to_ulong(read_bits(p, bit_offset, bits_available, bits_wanted));
31 31  
32   - std::cout << "bits read: " << bits_wanted << ", result = " << result << std::endl;
  32 + std::cout << "bits read: " << bits_wanted << ", result = " << result << '\n';
33 33 print_values(p - buf, bit_offset, bits_available);
34 34 }
35 35  
... ... @@ -39,7 +39,7 @@ test_write_bits(
39 39 {
40 40 write_bits(ch, bit_offset, val, bits, bp);
41 41 std::cout << "ch = " << QUtil::uint_to_string_base(ch, 16, 2) << ", bit_offset = " << bit_offset
42   - << std::endl;
  42 + << '\n';
43 43 }
44 44  
45 45 static void
... ... @@ -52,7 +52,7 @@ print_buffer(Pl_Buffer* bp)
52 52 for (unsigned long i = 0; i < l; ++i) {
53 53 std::cout << QUtil::uint_to_string_base(p[i], 16, 2) << ((i == l - 1) ? "\n" : " ");
54 54 }
55   - std::cout << std::endl;
  55 + std::cout << '\n';
56 56 delete b;
57 57 }
58 58  
... ... @@ -86,12 +86,12 @@ test()
86 86 try {
87 87 test_read_bits(buf, p, bit_offset, bits_available, 4);
88 88 } catch (std::exception& e) {
89   - std::cout << "exception: " << e.what() << std::endl;
  89 + std::cout << "exception: " << e.what() << '\n';
90 90 print_values(p - buf, bit_offset, bits_available);
91 91 }
92 92  
93 93 test_read_bits(buf, p, bit_offset, bits_available, 3);
94   - std::cout << std::endl;
  94 + std::cout << '\n';
95 95  
96 96 // 11110101 00010101 01100101 01111001: 00010010 10001001 01110101 01001011
97 97  
... ... @@ -101,29 +101,29 @@ test()
101 101 print_values(p - buf, bit_offset, bits_available);
102 102 test_read_bits(buf, p, bit_offset, bits_available, 32);
103 103 test_read_bits(buf, p, bit_offset, bits_available, 32);
104   - std::cout << std::endl;
  104 + std::cout << '\n';
105 105  
106 106 BitStream b(buf, 8);
107   - std::cout << b.getBits(32) << std::endl;
  107 + std::cout << b.getBits(32) << '\n';
108 108 b.reset();
109   - std::cout << b.getBits(32) << std::endl;
110   - std::cout << b.getBits(32) << std::endl;
111   - std::cout << std::endl;
  109 + std::cout << b.getBits(32) << '\n';
  110 + std::cout << b.getBits(32) << '\n';
  111 + std::cout << '\n';
112 112  
113 113 b.reset();
114   - std::cout << b.getBits(6) << std::endl;
  114 + std::cout << b.getBits(6) << '\n';
115 115 b.skipToNextByte();
116   - std::cout << b.getBits(8) << std::endl;
  116 + std::cout << b.getBits(8) << '\n';
117 117 b.skipToNextByte();
118   - std::cout << b.getBits(8) << std::endl;
119   - std::cout << std::endl;
  118 + std::cout << b.getBits(8) << '\n';
  119 + std::cout << '\n';
120 120 b.reset();
121   - std::cout << b.getBitsSigned(3) << std::endl;
122   - std::cout << b.getBitsSigned(6) << std::endl;
123   - std::cout << b.getBitsSigned(5) << std::endl;
124   - std::cout << b.getBitsSigned(1) << std::endl;
125   - std::cout << b.getBitsSigned(17) << std::endl;
126   - std::cout << std::endl;
  121 + std::cout << b.getBitsSigned(3) << '\n';
  122 + std::cout << b.getBitsSigned(6) << '\n';
  123 + std::cout << b.getBitsSigned(5) << '\n';
  124 + std::cout << b.getBitsSigned(1) << '\n';
  125 + std::cout << b.getBitsSigned(17) << '\n';
  126 + std::cout << '\n';
127 127  
128 128 // Write tests
129 129  
... ... @@ -176,9 +176,9 @@ main()
176 176 try {
177 177 test();
178 178 } catch (std::exception& e) {
179   - std::cout << "unexpected exception: " << e.what() << std::endl;
  179 + std::cout << "unexpected exception: " << e.what() << '\n';
180 180 exit(2);
181 181 }
182   - std::cout << "done" << std::endl;
  182 + std::cout << "done" << '\n';
183 183 return 0;
184 184 }
... ...
libtests/buffer.cc
... ... @@ -85,22 +85,22 @@ main()
85 85 bp1.write(uc("12345"), 5);
86 86 bp1.write(uc("67890"), 5);
87 87 bp1.finish();
88   - std::cout << "count: " << count.getCount() << std::endl;
  88 + std::cout << "count: " << count.getCount() << '\n';
89 89 bp1.write(uc("abcde"), 5);
90 90 bp1.write(uc("fghij"), 6);
91 91 bp1.finish();
92   - std::cout << "count: " << count.getCount() << std::endl;
  92 + std::cout << "count: " << count.getCount() << '\n';
93 93 Buffer* b = bp1.getBuffer();
94   - std::cout << "size: " << b->getSize() << std::endl;
95   - std::cout << "data: " << b->getBuffer() << std::endl;
  94 + std::cout << "size: " << b->getSize() << '\n';
  95 + std::cout << "data: " << b->getBuffer() << '\n';
96 96 delete b;
97 97 bp1.write(uc("qwert"), 5);
98 98 bp1.write(uc("yuiop"), 6);
99 99 bp1.finish();
100   - std::cout << "count: " << count.getCount() << std::endl;
  100 + std::cout << "count: " << count.getCount() << '\n';
101 101 b = bp1.getBuffer();
102   - std::cout << "size: " << b->getSize() << std::endl;
103   - std::cout << "data: " << b->getBuffer() << std::endl;
  102 + std::cout << "size: " << b->getSize() << '\n';
  103 + std::cout << "data: " << b->getBuffer() << '\n';
104 104 delete b;
105 105  
106 106 Pl_Buffer bp2("bp2");
... ... @@ -109,12 +109,12 @@ main()
109 109 try {
110 110 delete bp2.getBuffer();
111 111 } catch (std::exception& e) {
112   - std::cout << e.what() << std::endl;
  112 + std::cout << e.what() << '\n';
113 113 }
114 114 bp2.finish();
115 115 b = bp2.getBuffer();
116   - std::cout << "size: " << b->getSize() << std::endl;
117   - std::cout << "data: " << b->getBuffer() << std::endl;
  116 + std::cout << "size: " << b->getSize() << '\n';
  117 + std::cout << "data: " << b->getBuffer() << '\n';
118 118 delete b;
119 119  
120 120 unsigned char lbuf[10];
... ... @@ -125,17 +125,17 @@ main()
125 125  
126 126 Pl_Buffer bp3("bp3");
127 127 b = bp3.getBuffer();
128   - std::cout << "size: " << b->getSize() << std::endl;
  128 + std::cout << "size: " << b->getSize() << '\n';
129 129 delete b;
130 130 // Should be able to call getBuffer again and get an empty buffer
131 131 b = bp3.getBuffer();
132   - std::cout << "size: " << b->getSize() << std::endl;
  132 + std::cout << "size: " << b->getSize() << '\n';
133 133 delete b;
134 134 // Also can write 0 and do it.
135 135 bp3.write(uc(""), 0);
136 136 bp3.finish();
137 137 b = bp3.getBuffer();
138   - std::cout << "size: " << b->getSize() << std::endl;
  138 + std::cout << "size: " << b->getSize() << '\n';
139 139 delete b;
140 140  
141 141 // Malloc buffer should behave similarly.
... ... @@ -147,7 +147,7 @@ main()
147 147 bp4.getMallocBuffer(&mbuf, &len);
148 148 assert(false);
149 149 } catch (std::logic_error& e) {
150   - std::cout << "malloc buffer logic error: " << e.what() << std::endl;
  150 + std::cout << "malloc buffer logic error: " << e.what() << '\n';
151 151 }
152 152 bp4.finish();
153 153 bp4.getMallocBuffer(&mbuf, &len);
... ... @@ -160,10 +160,10 @@ main()
160 160 assert(mbuf == nullptr);
161 161 assert(len == 0);
162 162 } catch (std::exception& e) {
163   - std::cout << "unexpected exception: " << e.what() << std::endl;
  163 + std::cout << "unexpected exception: " << e.what() << '\n';
164 164 exit(2);
165 165 }
166 166  
167   - std::cout << "done" << std::endl;
  167 + std::cout << "done" << '\n';
168 168 return 0;
169 169 }
... ...
libtests/closed_file_input_source.cc
... ... @@ -8,7 +8,7 @@ void
8 8 check(std::string const& what, bool result)
9 9 {
10 10 if (!result) {
11   - std::cout << "FAIL: " << what << std::endl;
  11 + std::cout << "FAIL: " << what << '\n';
12 12 }
13 13 }
14 14  
... ... @@ -73,6 +73,6 @@ main()
73 73 std::cout << "testing with FileInputSource\n";
74 74 FileInputSource f("input");
75 75 do_tests(&f);
76   - std::cout << "all assertions passed" << std::endl;
  76 + std::cout << "all assertions passed" << '\n';
77 77 return 0;
78 78 }
... ...
libtests/concatenate.cc
... ... @@ -31,9 +31,9 @@ main(int argc, char* argv[])
31 31 auto b2_buf = b2.getBufferSharedPointer();
32 32 std::string result(reinterpret_cast<char*>(b2_buf->getBuffer()), b2_buf->getSize());
33 33 if (result == "-one--two-") {
34   - std::cout << "concatenate test passed" << std::endl;
  34 + std::cout << "concatenate test passed" << '\n';
35 35 } else {
36   - std::cout << "concatenate test failed: " << result << std::endl;
  36 + std::cout << "concatenate test failed: " << result << '\n';
37 37 }
38 38 return 0;
39 39 }
... ...
libtests/crypto_provider.cc
... ... @@ -47,7 +47,7 @@ class Potato: public QPDFCryptoImpl
47 47 std::string
48 48 SHA2_digest() override
49 49 {
50   - return std::string();
  50 + return {};
51 51 }
52 52 void
53 53 RC4_init(const unsigned char* key_data, int key_len) override
... ...
libtests/dct_compress.cc
... ... @@ -12,7 +12,7 @@
12 12 static void
13 13 usage()
14 14 {
15   - std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << std::endl;
  15 + std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << '\n';
16 16 exit(2);
17 17 }
18 18  
... ...
libtests/dct_uncompress.cc
... ... @@ -10,7 +10,7 @@ int
10 10 main(int argc, char* argv[])
11 11 {
12 12 if (argc != 3) {
13   - std::cerr << "Usage: dct_uncompress infile outfile" << std::endl;
  13 + std::cerr << "Usage: dct_uncompress infile outfile" << '\n';
14 14 exit(2);
15 15 }
16 16  
... ...
libtests/flate.cc
... ... @@ -53,7 +53,7 @@ run(char const* filename)
53 53  
54 54 def3->finish();
55 55  
56   - std::cout << "bytes written to o3: " << count3->getCount() << std::endl;
  56 + std::cout << "bytes written to o3: " << count3->getCount() << '\n';
57 57  
58 58 delete def3;
59 59 delete inf3;
... ... @@ -76,14 +76,14 @@ run(char const* filename)
76 76 // At this point, filename, filename.2, and filename.3 should have
77 77 // identical contents. filename.1 should be a compressed version.
78 78  
79   - std::cout << "done" << std::endl;
  79 + std::cout << "done" << '\n';
80 80 }
81 81  
82 82 int
83 83 main(int argc, char* argv[])
84 84 {
85 85 if (argc != 2) {
86   - std::cerr << "Usage: pipeline filename" << std::endl;
  86 + std::cerr << "Usage: pipeline filename" << '\n';
87 87 exit(2);
88 88 }
89 89 char* filename = argv[1];
... ... @@ -91,7 +91,7 @@ main(int argc, char* argv[])
91 91 try {
92 92 run(filename);
93 93 } catch (std::exception& e) {
94   - std::cout << e.what() << std::endl;
  94 + std::cout << e.what() << '\n';
95 95 }
96 96 return 0;
97 97 }
... ...
libtests/hex.cc
... ... @@ -23,7 +23,7 @@ main()
23 23 }
24 24 decode.finish();
25 25 } catch (std::exception& e) {
26   - std::cerr << e.what() << std::endl;
  26 + std::cerr << e.what() << '\n';
27 27 exit(2);
28 28 }
29 29  
... ...
libtests/input_source.cc
... ... @@ -47,7 +47,7 @@ Finder::check()
47 47 void
48 48 check(char const* description, bool expected, bool actual)
49 49 {
50   - std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") << std::endl;
  50 + std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") << '\n';
51 51 }
52 52  
53 53 int
... ...
libtests/json.cc
... ... @@ -186,12 +186,12 @@ static void
186 186 check_schema(JSON& obj, JSON& schema, unsigned long flags, bool exp, std::string const& description)
187 187 {
188 188 std::list<std::string> errors;
189   - std::cout << "--- " << description << std::endl;
  189 + std::cout << "--- " << description << '\n';
190 190 assert(exp == obj.checkSchema(schema, flags, errors));
191 191 for (auto const& error: errors) {
192   - std::cout << error << std::endl;
  192 + std::cout << error << '\n';
193 193 }
194   - std::cout << "---" << std::endl;
  194 + std::cout << "---" << '\n';
195 195 }
196 196  
197 197 static void
... ...
libtests/json_handler.cc
... ... @@ -8,43 +8,43 @@
8 8 static void
9 9 print_null(std::string const& path)
10 10 {
11   - std::cout << path << ": null" << std::endl;
  11 + std::cout << path << ": null" << '\n';
12 12 }
13 13  
14 14 static void
15 15 print_string(std::string const& path, std::string const& value)
16 16 {
17   - std::cout << path << ": string: " << value << std::endl;
  17 + std::cout << path << ": string: " << value << '\n';
18 18 }
19 19  
20 20 static void
21 21 print_number(std::string const& path, std::string const& value)
22 22 {
23   - std::cout << path << ": number: " << value << std::endl;
  23 + std::cout << path << ": number: " << value << '\n';
24 24 }
25 25  
26 26 static void
27 27 print_bool(std::string const& path, bool value)
28 28 {
29   - std::cout << path << ": bool: " << (value ? "true" : "false") << std::endl;
  29 + std::cout << path << ": bool: " << (value ? "true" : "false") << '\n';
30 30 }
31 31  
32 32 static void
33 33 print_json(std::string const& path, JSON value)
34 34 {
35   - std::cout << path << ": json: " << value.unparse() << std::endl;
  35 + std::cout << path << ": json: " << value.unparse() << '\n';
36 36 }
37 37  
38 38 static JSONHandler::void_handler_t
39 39 make_print_message(std::string msg)
40 40 {
41   - return [msg](std::string const& path) { std::cout << path << ": json: " << msg << std::endl; };
  41 + return [msg](std::string const& path) { std::cout << path << ": json: " << msg << '\n'; };
42 42 }
43 43  
44 44 static void
45 45 test_scalar()
46 46 {
47   - std::cout << "-- scalar --" << std::endl;
  47 + std::cout << "-- scalar --" << '\n';
48 48 JSONHandler h;
49 49 h.addStringHandler(print_string);
50 50 JSON j = JSON::parse("\"potato\"");
... ... @@ -97,7 +97,7 @@ make_all_handler()
97 97 static void
98 98 test_all()
99 99 {
100   - std::cout << "-- all --" << std::endl;
  100 + std::cout << "-- all --" << '\n';
101 101 auto h = make_all_handler();
102 102 /* cSpell: ignore phour */
103 103 JSON j = JSON::parse(R"({
... ... @@ -110,7 +110,7 @@ test_all()
110 110 "six": {"a": {"b": "quack", "Q": "baaa"}, "b": "moo"}
111 111 })");
112 112 h->handle(".", j);
113   - std::cerr << "-- fallback --" << std::endl;
  113 + std::cerr << "-- fallback --" << '\n';
114 114 j = JSON::parse(R"({
115 115 "five": "not-array"
116 116 })");
... ... @@ -120,14 +120,14 @@ test_all()
120 120 static void
121 121 test_errors()
122 122 {
123   - std::cout << "-- errors --" << std::endl;
  123 + std::cout << "-- errors --" << '\n';
124 124 auto h = make_all_handler();
125 125 auto t = [h](std::string const& msg, std::function<void()> fn) {
126 126 try {
127 127 fn();
128 128 assert(false);
129 129 } catch (QPDFUsage& e) {
130   - std::cout << msg << ": " << e.what() << std::endl;
  130 + std::cout << msg << ": " << e.what() << '\n';
131 131 }
132 132 };
133 133  
... ...
libtests/json_parse.cc
... ... @@ -26,13 +26,13 @@ namespace
26 26 void
27 27 Reactor::dictionaryStart()
28 28 {
29   - std::cout << "dictionary start" << std::endl;
  29 + std::cout << "dictionary start" << '\n';
30 30 }
31 31  
32 32 void
33 33 Reactor::arrayStart()
34 34 {
35   - std::cout << "array start" << std::endl;
  35 + std::cout << "array start" << '\n';
36 36 }
37 37  
38 38 void
... ... @@ -45,7 +45,7 @@ Reactor::containerEnd(JSON const&amp; value)
45 45 void
46 46 Reactor::topLevelScalar()
47 47 {
48   - std::cout << "top-level scalar" << std::endl;
  48 + std::cout << "top-level scalar" << '\n';
49 49 }
50 50  
51 51 bool
... ... @@ -74,13 +74,13 @@ Reactor::arrayItem(JSON const&amp; value)
74 74 void
75 75 Reactor::printItem(JSON const& j)
76 76 {
77   - std::cout << "[" << j.getStart() << ", " << j.getEnd() << "): " << j.unparse() << std::endl;
  77 + std::cout << "[" << j.getStart() << ", " << j.getEnd() << "): " << j.unparse() << '\n';
78 78 }
79 79  
80 80 static void
81 81 usage()
82 82 {
83   - std::cerr << "Usage: json_parse file [--react]" << std::endl;
  83 + std::cerr << "Usage: json_parse file [--react]" << '\n';
84 84 exit(2);
85 85 }
86 86  
... ... @@ -102,9 +102,9 @@ main(int argc, char* argv[])
102 102 }
103 103 try {
104 104 FileInputSource is(filename);
105   - std::cout << JSON::parse(is, reactor.get()).unparse() << std::endl;
  105 + std::cout << JSON::parse(is, reactor.get()).unparse() << '\n';
106 106 } catch (std::exception& e) {
107   - std::cerr << "exception: " << filename << ": " << e.what() << std::endl;
  107 + std::cerr << "exception: " << filename << ": " << e.what() << '\n';
108 108 return 2;
109 109 }
110 110 return 0;
... ...
libtests/lzw.cc
... ... @@ -15,7 +15,7 @@ main(int argc, char* argv[])
15 15 }
16 16  
17 17 if (argc < 3) {
18   - std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" << std::endl;
  18 + std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" << '\n';
19 19 exit(2);
20 20 }
21 21  
... ... @@ -41,7 +41,7 @@ main(int argc, char* argv[])
41 41 }
42 42 decode.finish();
43 43 } catch (std::exception& e) {
44   - std::cerr << e.what() << std::endl;
  44 + std::cerr << e.what() << '\n';
45 45 exit(2);
46 46 }
47 47  
... ...
libtests/main_from_wmain.cc
... ... @@ -8,7 +8,7 @@ wmain_test()
8 8 // writable args and function args
9 9 auto realmain = [](int argc, char* argv[]) {
10 10 for (int i = 0; i < argc; ++i) {
11   - std::cout << argv[i] << std::endl;
  11 + std::cout << argv[i] << '\n';
12 12 }
13 13 return 0;
14 14 };
... ... @@ -28,7 +28,7 @@ cwmain_test()
28 28 // const args and function args
29 29 auto realmain = [](int argc, char const* const argv[]) {
30 30 for (int i = 0; i < argc; ++i) {
31   - std::cout << "const " << argv[i] << std::endl;
  31 + std::cout << "const " << argv[i] << '\n';
32 32 }
33 33 return 0;
34 34 };
... ... @@ -49,7 +49,7 @@ main(int argc, char* argv[])
49 49 wmain_test();
50 50 cwmain_test();
51 51 } catch (std::exception& e) {
52   - std::cout << "unexpected exception: " << e.what() << std::endl;
  52 + std::cout << "unexpected exception: " << e.what() << '\n';
53 53 }
54 54 #endif // QPDF_NO_WCHAR_T
55 55  
... ...