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
... ... @@ -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  
... ...
libtests/matrix.cc
... ... @@ -9,7 +9,7 @@ check(QPDFMatrix const&amp; m, std::string const&amp; exp)
9 9 {
10 10 std::string u = m.unparse();
11 11 if (u != exp) {
12   - std::cout << "got " << u << ", wanted " << exp << std::endl;
  12 + std::cout << "got " << u << ", wanted " << exp << '\n';
13 13 }
14 14 }
15 15  
... ... @@ -18,7 +18,7 @@ check_xy(double x, double y, std::string const&amp; exp)
18 18 {
19 19 std::string u = (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2));
20 20 if (u != exp) {
21   - std::cout << "got " << u << ", wanted " << exp << std::endl;
  21 + std::cout << "got " << u << ", wanted " << exp << '\n';
22 22 }
23 23 }
24 24  
... ... @@ -32,7 +32,7 @@ check_rect(QPDFObjectHandle::Rectangle const&amp; r, double llx, double lly, double
32 32 (QUtil::double_to_string(llx, 2) + " " + QUtil::double_to_string(lly, 2) + " " +
33 33 QUtil::double_to_string(urx, 2) + " " + QUtil::double_to_string(ury, 2));
34 34 if (actual != wanted) {
35   - std::cout << "got " << actual << ", wanted " << wanted << std::endl;
  35 + std::cout << "got " << actual << ", wanted " << wanted << '\n';
36 36 }
37 37 }
38 38  
... ... @@ -78,6 +78,6 @@ main()
78 78 m.translate(200, -100);
79 79 check_rect(m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)), 50, 210, 80, 230);
80 80  
81   - std::cout << "matrix tests done" << std::endl;
  81 + std::cout << "matrix tests done" << '\n';
82 82 return 0;
83 83 }
... ...
libtests/md5.cc
... ... @@ -29,16 +29,16 @@ main(int, char*[])
29 29 "1234567890123456789012345678901234567890");
30 30 MD5 a;
31 31 a.encodeFile("md5.in");
32   - std::cout << a.unparse() << std::endl;
  32 + std::cout << a.unparse() << '\n';
33 33 MD5 b;
34 34 b.encodeFile("md5.in", 100);
35   - std::cout << b.unparse() << std::endl;
  35 + std::cout << b.unparse() << '\n';
36 36  
37   - std::cout << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl
38   - << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl
39   - << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl
40   - << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl
41   - << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") << std::endl;
  37 + std::cout << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) << '\n'
  38 + << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") << '\n'
  39 + << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") << '\n'
  40 + << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) << '\n'
  41 + << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") << '\n';
42 42  
43 43 Pl_Discard d;
44 44 Pl_MD5 p("MD5", &d);
... ... @@ -63,7 +63,7 @@ main(int, char*[])
63 63 p2.write(buf, len);
64 64 if (i == 1) {
65 65 // Partial digest -- resets after each call to write
66   - std::cout << p.getHexDigest() << std::endl;
  66 + std::cout << p.getHexDigest() << '\n';
67 67 }
68 68 }
69 69 }
... ... @@ -72,10 +72,10 @@ main(int, char*[])
72 72 p2.finish();
73 73 // Make sure calling getHexDigest twice with no intervening
74 74 // writes results in the same result each time.
75   - std::cout << p.getHexDigest() << std::endl;
76   - std::cout << p.getHexDigest() << std::endl;
  75 + std::cout << p.getHexDigest() << '\n';
  76 + std::cout << p.getHexDigest() << '\n';
77 77 }
78   - std::cout << p2.getHexDigest() << std::endl;
  78 + std::cout << p2.getHexDigest() << '\n';
79 79  
80 80 return 0;
81 81 }
... ...
libtests/nntree.cc
... ... @@ -20,7 +20,7 @@ report(QPDF&amp; q, QPDFObjectHandle oh, long long item, long long exp_item)
20 20 auto show = [&failed, &oh, &item]() {
21 21 if (!failed) {
22 22 failed = true;
23   - std::cout << "key = " << item << ", oh = " << oh.unparseResolved() << std::endl;
  23 + std::cout << "key = " << item << ", oh = " << oh.unparseResolved() << '\n';
24 24 }
25 25 };
26 26  
... ... @@ -37,11 +37,11 @@ report(QPDF&amp; q, QPDFObjectHandle oh, long long item, long long exp_item)
37 37  
38 38 if (i1_wanted != i1_actual) {
39 39 show();
40   - std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual << std::endl;
  40 + std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual << '\n';
41 41 }
42 42 if (i2_wanted != i2_actual) {
43 43 show();
44   - std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual << std::endl;
  44 + std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual << '\n';
45 45 }
46 46  
47 47 return failed;
... ... @@ -106,7 +106,7 @@ test_bsearch()
106 106 r(d, 25, 20);
107 107  
108 108 if (!any_failures) {
109   - std::cout << "bsearch tests passed" << std::endl;
  109 + std::cout << "bsearch tests passed" << '\n';
110 110 }
111 111 }
112 112  
... ... @@ -128,7 +128,7 @@ check_find(QPDFNameTreeObjectHelper&amp; nh, std::string const&amp; key, bool prev_if_no
128 128 } else {
129 129 std::cout << (*i).first << " -> " << (*i).second.unparse();
130 130 }
131   - std::cout << std::endl;
  131 + std::cout << '\n';
132 132 }
133 133  
134 134 void
... ... @@ -183,13 +183,13 @@ test_depth()
183 183 }
184 184  
185 185 QPDFNameTreeObjectHelper nh(n0, q);
186   - std::cout << "--- forward ---" << std::endl;
  186 + std::cout << "--- forward ---" << '\n';
187 187 for (auto i: nh) {
188   - std::cout << i.first << " -> " << i.second.unparse() << std::endl;
  188 + std::cout << i.first << " -> " << i.second.unparse() << '\n';
189 189 }
190   - std::cout << "--- backward ---" << std::endl;
  190 + std::cout << "--- backward ---" << '\n';
191 191 for (auto i = nh.last(); i.valid(); --i) {
192   - std::cout << (*i).first << " -> " << (*i).second.unparse() << std::endl;
  192 + std::cout << (*i).first << " -> " << (*i).second.unparse() << '\n';
193 193 }
194 194  
195 195 // Find
... ...
libtests/numrange.cc
... ... @@ -5,14 +5,14 @@ static void
5 5 test_numrange(char const* range)
6 6 {
7 7 if (range == nullptr) {
8   - std::cout << "null" << std::endl;
  8 + std::cout << "null" << '\n';
9 9 } else {
10 10 std::vector<int> result = QUtil::parse_numrange(range, 15);
11 11 std::cout << "numeric range " << range << " ->";
12 12 for (int i: result) {
13 13 std::cout << " " << i;
14 14 }
15   - std::cout << std::endl;
  15 + std::cout << '\n';
16 16 }
17 17 }
18 18  
... ... @@ -22,7 +22,7 @@ main(int argc, char* argv[])
22 22 try {
23 23 test_numrange(argv[1]);
24 24 } catch (std::exception& e) {
25   - std::cout << e.what() << std::endl;
  25 + std::cout << e.what() << '\n';
26 26 return 2;
27 27 }
28 28  
... ...
libtests/pdf_version.cc
... ... @@ -48,6 +48,6 @@ main()
48 48 assert(PDFVersion(2, 0) == PDFVersion(2, 0));
49 49 assert(PDFVersion(2, 0, 1) == PDFVersion(2, 0, 1));
50 50  
51   - std::cout << "PDFVersion assertions passed" << std::endl;
  51 + std::cout << "PDFVersion assertions passed" << '\n';
52 52 return 0;
53 53 }
... ...
libtests/pl_function.cc
... ... @@ -18,7 +18,7 @@ f(unsigned char const* data, size_t len, void* udata)
18 18 {
19 19 auto c = reinterpret_cast<Count*>(udata);
20 20 ++c->count;
21   - std::cout << "got " << data << "(" << len << ")" << std::endl;
  21 + std::cout << "got " << data << "(" << len << ")" << '\n';
22 22 if (c->count == 3) {
23 23 return 1;
24 24 }
... ... @@ -30,7 +30,7 @@ g(char const* data, size_t len, void* udata)
30 30 {
31 31 auto c = reinterpret_cast<Count*>(udata);
32 32 ++c->count;
33   - std::cout << "signed got " << data << "(" << len << ")" << std::endl;
  33 + std::cout << "signed got " << data << "(" << len << ")" << '\n';
34 34 if (c->count == 2) {
35 35 return 2;
36 36 }
... ... @@ -41,7 +41,7 @@ int
41 41 main(int argc, char* argv[])
42 42 {
43 43 Pl_Function p1("p1", nullptr, [](unsigned char const* data, size_t len) {
44   - std::cout << "p1: " << len << ": " << data << std::endl;
  44 + std::cout << "p1: " << len << ": " << data << '\n';
45 45 });
46 46 p1.write(reinterpret_cast<unsigned char const*>("potato"), 6);
47 47  
... ... @@ -49,7 +49,7 @@ main(int argc, char* argv[])
49 49 Pl_String ps("string", nullptr, s);
50 50 Pl_Base64 b("base64", &ps, Pl_Base64::a_encode);
51 51 Pl_Function p2("p2", &b, [](unsigned char const* data, size_t len) {
52   - std::cout << "p2: " << len << ": " << data << std::endl;
  52 + std::cout << "p2: " << len << ": " << data << '\n';
53 53 });
54 54 p2.write(reinterpret_cast<unsigned char const*>("salad"), 5);
55 55 p2.finish();
... ... @@ -63,7 +63,7 @@ main(int argc, char* argv[])
63 63 p3 << "three";
64 64 assert(false);
65 65 } catch (std::runtime_error& e) {
66   - std::cout << "three threw " << e.what() << std::endl;
  66 + std::cout << "three threw " << e.what() << '\n';
67 67 }
68 68 p3 << "four";
69 69 p3.finish();
... ... @@ -76,7 +76,7 @@ main(int argc, char* argv[])
76 76 p4 << "salad";
77 77 assert(false);
78 78 } catch (std::runtime_error& e) {
79   - std::cout << "salad threw " << e.what() << std::endl;
  79 + std::cout << "salad threw " << e.what() << '\n';
80 80 }
81 81 p4 << "quack";
82 82 p4.finish();
... ...
libtests/pointer_holder.cc
... ... @@ -26,24 +26,24 @@ int Object::next_id = 0;
26 26 Object::Object()
27 27 {
28 28 this->id = ++next_id;
29   - std::cout << "created Object, id " << this->id << std::endl;
  29 + std::cout << "created Object, id " << this->id << '\n';
30 30 }
31 31  
32 32 Object::~Object()
33 33 {
34   - std::cout << "destroyed Object, id " << this->id << std::endl;
  34 + std::cout << "destroyed Object, id " << this->id << '\n';
35 35 }
36 36  
37 37 void
38 38 Object::hello()
39 39 {
40   - std::cout << "calling Object::hello for " << this->id << std::endl;
  40 + std::cout << "calling Object::hello for " << this->id << '\n';
41 41 }
42 42  
43 43 void
44 44 Object::hello() const
45 45 {
46   - std::cout << "calling Object::hello const for " << this->id << std::endl;
  46 + std::cout << "calling Object::hello const for " << this->id << '\n';
47 47 }
48 48  
49 49 typedef PointerHolder<Object> ObjectHolder;
... ... @@ -71,27 +71,27 @@ test_ph()
71 71  
72 72 ObjectHolder oh0;
73 73 {
74   - std::cout << "hello" << std::endl;
  74 + std::cout << "hello" << '\n';
75 75 auto* o1 = new Object;
76 76 ObjectHolder oh1(o1);
77   - std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl;
  77 + std::cout << "oh1 refcount = " << oh1.getRefcount() << '\n';
78 78 ObjectHolder oh2(oh1);
79   - std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl;
80   - std::cout << "oh2 refcount = " << oh2.use_count() << std::endl;
  79 + std::cout << "oh1 refcount = " << oh1.getRefcount() << '\n';
  80 + std::cout << "oh2 refcount = " << oh2.use_count() << '\n';
81 81 ObjectHolder oh3(new Object);
82 82 ObjectHolder oh4;
83 83 ObjectHolder oh5;
84   - std::cout << "oh5 refcount = " << oh5.getRefcount() << std::endl;
  84 + std::cout << "oh5 refcount = " << oh5.getRefcount() << '\n';
85 85 if (oh4 == oh5) {
86   - std::cout << "nulls equal" << std::endl;
  86 + std::cout << "nulls equal" << '\n';
87 87 }
88 88 oh3 = oh1;
89 89 oh4 = oh2;
90 90 if (oh3 == oh4) {
91   - std::cout << "equal okay" << std::endl;
  91 + std::cout << "equal okay" << '\n';
92 92 }
93 93 if ((!(oh3 < oh4)) && (!(oh4 < oh3))) {
94   - std::cout << "less than okay" << std::endl;
  94 + std::cout << "less than okay" << '\n';
95 95 }
96 96 ol1.push_back(oh3);
97 97 ol1.push_back(oh3);
... ... @@ -107,9 +107,9 @@ test_ph()
107 107 callHello(ol1.front());
108 108 callHelloWithGet(ol1.front());
109 109 ol1.pop_front();
110   - std::cout << "array" << std::endl;
  110 + std::cout << "array" << '\n';
111 111 PointerHolder<Object> o_arr1_ph(true, new Object[2]);
112   - std::cout << "goodbye" << std::endl;
  112 + std::cout << "goodbye" << '\n';
113 113 }
114 114  
115 115 PointerHolder<Object>
... ... @@ -165,7 +165,7 @@ ph_sp_compat()
165 165 {
166 166 // Ensure bidirectional compatibility between PointerHolder and
167 167 // shared_ptr.
168   - std::cout << "compat" << std::endl;
  168 + std::cout << "compat" << '\n';
169 169 PointerHolder<Object> ph_from_ph = make_object_ph();
170 170 std::shared_ptr<Object> sp_from_ph = make_object_ph();
171 171 PointerHolder<Object> ph_from_sp = make_object_sp();
... ... @@ -184,21 +184,21 @@ ph_sp_compat()
184 184 hello_ph_const(sp_const_from_sp);
185 185 PointerHolder<Object> arr1_ph;
186 186 {
187   - std::cout << "initialize ph array from shared_ptr" << std::endl;
  187 + std::cout << "initialize ph array from shared_ptr" << '\n';
188 188 std::shared_ptr<Object> arr1(new Object[2], std::default_delete<Object[]>());
189 189 arr1_ph = arr1;
190 190 }
191   - std::cout << "delete ph array" << std::endl;
  191 + std::cout << "delete ph array" << '\n';
192 192 arr1_ph = nullptr;
193 193 std::shared_ptr<Object> arr2_sp;
194 194 {
195   - std::cout << "initialize sp array from PointerHolder" << std::endl;
  195 + std::cout << "initialize sp array from PointerHolder" << '\n';
196 196 PointerHolder<Object> arr2(true, new Object[2]);
197 197 arr2_sp = arr2;
198 198 }
199   - std::cout << "delete sp array" << std::endl;
  199 + std::cout << "delete sp array" << '\n';
200 200 arr2_sp = nullptr;
201   - std::cout << "end compat" << std::endl;
  201 + std::cout << "end compat" << '\n';
202 202 }
203 203  
204 204 std::list<PointerHolder<Object>>
... ... @@ -224,13 +224,13 @@ get_sp_list()
224 224 void
225 225 ph_sp_containers()
226 226 {
227   - std::cout << "containers" << std::endl;
  227 + std::cout << "containers" << '\n';
228 228 // Demonstrate that using auto makes it easy to switch interfaces
229 229 // from using a container of one shared pointer type to a
230 230 // container of the other.
231 231 auto phl1 = get_ph_list();
232 232 auto phl2 = get_sp_list();
233   - std::cout << "end containers" << std::endl;
  233 + std::cout << "end containers" << '\n';
234 234 }
235 235  
236 236 int
... ...
libtests/predictors.cc
... ... @@ -39,7 +39,7 @@ run(char const* filename,
39 39 samples_per_pixel,
40 40 bits_per_sample);
41 41 } else {
42   - std::cerr << "unknown filter " << filter << std::endl;
  42 + std::cerr << "unknown filter " << filter << '\n';
43 43 exit(2);
44 44 }
45 45 assert((2 * (columns + 1)) < 1024);
... ... @@ -69,7 +69,7 @@ run(char const* filename,
69 69 fclose(o1);
70 70 fclose(in);
71 71  
72   - std::cout << "done" << std::endl;
  72 + std::cout << "done" << '\n';
73 73 }
74 74  
75 75 int
... ... @@ -77,7 +77,7 @@ main(int argc, char* argv[])
77 77 {
78 78 if (argc != 7) {
79 79 std::cerr << "Usage: predictor {png|tiff} {en,de}code filename"
80   - << " columns samples-per-pixel bits-per-sample" << std::endl;
  80 + << " columns samples-per-pixel bits-per-sample" << '\n';
81 81 exit(2);
82 82 }
83 83 char* filter = argv[1];
... ... @@ -95,7 +95,7 @@ main(int argc, char* argv[])
95 95 QIntC::to_uint(bits_per_sample),
96 96 QIntC::to_uint(samples_per_pixel));
97 97 } catch (std::exception& e) {
98   - std::cout << e.what() << std::endl;
  98 + std::cout << e.what() << '\n';
99 99 }
100 100 return 0;
101 101 }
... ...
libtests/qintc.cc
... ... @@ -18,7 +18,7 @@ try_convert_real(char const* description, bool exp_pass, To (*fn)(From const&amp;),
18 18 std::cout << description << ": " << e.what();
19 19 passed = false;
20 20 }
21   - std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl;
  21 + std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << '\n';
22 22 }
23 23  
24 24 #define try_range_check(exp_pass, a, b) try_range_check_real(#a " + " #b, exp_pass, a, b)
... ... @@ -36,7 +36,7 @@ try_range_check_real(char const* description, bool exp_pass, T const&amp; a, T const
36 36 std::cout << description << ": " << e.what();
37 37 passed = false;
38 38 }
39   - std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl;
  39 + std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << '\n';
40 40 }
41 41  
42 42 #define try_range_check_subtract(exp_pass, a, b) \
... ... @@ -55,7 +55,7 @@ try_range_check_subtract_real(char const* description, bool exp_pass, T const&amp; a
55 55 std::cout << description << ": " << e.what();
56 56 passed = false;
57 57 }
58   - std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl;
  58 + std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << '\n';
59 59 }
60 60  
61 61 int
... ...
libtests/qutil.cc
... ... @@ -32,13 +32,13 @@ test_to_number(char const* str, int_T wanted, bool error, int_T (*fn)(char const
32 32 }
33 33 if (threw) {
34 34 if (error) {
35   - std::cout << str << " to int threw (" << msg << "): PASSED" << std::endl;
  35 + std::cout << str << " to int threw (" << msg << "): PASSED" << '\n';
36 36 } else {
37 37 std::cout << str << " to int threw but wanted " << wanted << std::endl;
38 38 }
39 39 } else {
40 40 if (worked) {
41   - std::cout << str << " to int: PASSED" << std::endl;
  41 + std::cout << str << " to int: PASSED" << '\n';
42 42 } else {
43 43 std::cout << str << " to int failed; got " << result << std::endl;
44 44 }
... ... @@ -97,51 +97,51 @@ string_conversion_test()
97 97 // Make sure the code produces consistent results even if we load
98 98 // a non-C locale.
99 99 set_locale();
100   - std::cout << QUtil::int_to_string(16059) << std::endl
101   - << QUtil::int_to_string(16059, 7) << std::endl
102   - << QUtil::int_to_string(16059, -7) << std::endl
103   - << QUtil::double_to_string(3.14159, 0, false) << std::endl
104   - << QUtil::double_to_string(3.14159, 3) << std::endl
105   - << QUtil::double_to_string(1000.123, -1024, false) << std::endl
106   - << QUtil::double_to_string(.1234, 5, false) << std::endl
107   - << QUtil::double_to_string(.0001234, 5) << std::endl
108   - << QUtil::double_to_string(.123456, 5) << std::endl
109   - << QUtil::double_to_string(.000123456, 5) << std::endl
110   - << QUtil::double_to_string(1.01020, 5, true) << std::endl
111   - << QUtil::double_to_string(1.00000, 5, true) << std::endl
112   - << QUtil::double_to_string(1, 5, true) << std::endl
113   - << QUtil::double_to_string(1, 5, false) << std::endl
114   - << QUtil::double_to_string(10, 2, false) << std::endl
115   - << QUtil::double_to_string(10, 2, true) << std::endl
116   - << QUtil::int_to_string_base(16059, 10) << std::endl
117   - << QUtil::int_to_string_base(16059, 8) << std::endl
118   - << QUtil::int_to_string_base(16059, 16) << std::endl
119   - << QUtil::int_to_string_base(5000093552LL, 10) << std::endl;
  100 + std::cout << QUtil::int_to_string(16059) << '\n'
  101 + << QUtil::int_to_string(16059, 7) << '\n'
  102 + << QUtil::int_to_string(16059, -7) << '\n'
  103 + << QUtil::double_to_string(3.14159, 0, false) << '\n'
  104 + << QUtil::double_to_string(3.14159, 3) << '\n'
  105 + << QUtil::double_to_string(1000.123, -1024, false) << '\n'
  106 + << QUtil::double_to_string(.1234, 5, false) << '\n'
  107 + << QUtil::double_to_string(.0001234, 5) << '\n'
  108 + << QUtil::double_to_string(.123456, 5) << '\n'
  109 + << QUtil::double_to_string(.000123456, 5) << '\n'
  110 + << QUtil::double_to_string(1.01020, 5, true) << '\n'
  111 + << QUtil::double_to_string(1.00000, 5, true) << '\n'
  112 + << QUtil::double_to_string(1, 5, true) << '\n'
  113 + << QUtil::double_to_string(1, 5, false) << '\n'
  114 + << QUtil::double_to_string(10, 2, false) << '\n'
  115 + << QUtil::double_to_string(10, 2, true) << '\n'
  116 + << QUtil::int_to_string_base(16059, 10) << '\n'
  117 + << QUtil::int_to_string_base(16059, 8) << '\n'
  118 + << QUtil::int_to_string_base(16059, 16) << '\n'
  119 + << QUtil::int_to_string_base(5000093552LL, 10) << '\n';
120 120  
121 121 std::string embedded_null = "one";
122 122 embedded_null += '\0';
123 123 embedded_null += "two";
124   - std::cout << embedded_null.c_str() << std::endl;
125   - std::cout << embedded_null.length() << std::endl;
  124 + std::cout << embedded_null.c_str() << '\n';
  125 + std::cout << embedded_null.length() << '\n';
126 126 char* tmp = QUtil::copy_string(embedded_null);
127 127 if (memcmp(tmp, embedded_null.c_str(), 7) == 0) {
128   - std::cout << "compare okay" << std::endl;
  128 + std::cout << "compare okay" << '\n';
129 129 } else {
130   - std::cout << "compare failed" << std::endl;
  130 + std::cout << "compare failed" << '\n';
131 131 }
132 132 delete[] tmp;
133 133 // Also test with make_shared_cstr and make_unique_cstr
134 134 auto tmp2 = QUtil::make_shared_cstr(embedded_null);
135 135 if (memcmp(tmp2.get(), embedded_null.c_str(), 7) == 0) {
136   - std::cout << "compare okay" << std::endl;
  136 + std::cout << "compare okay" << '\n';
137 137 } else {
138   - std::cout << "compare failed" << std::endl;
  138 + std::cout << "compare failed" << '\n';
139 139 }
140 140 auto tmp3 = QUtil::make_unique_cstr(embedded_null);
141 141 if (memcmp(tmp3.get(), embedded_null.c_str(), 7) == 0) {
142   - std::cout << "compare okay" << std::endl;
  142 + std::cout << "compare okay" << '\n';
143 143 } else {
144   - std::cout << "compare failed" << std::endl;
  144 + std::cout << "compare failed" << '\n';
145 145 }
146 146  
147 147 std::string int_max_str = QUtil::int_to_string(INT_MAX);
... ... @@ -171,11 +171,11 @@ void
171 171 os_wrapper_test()
172 172 {
173 173 try {
174   - std::cout << "before remove" << std::endl;
  174 + std::cout << "before remove" << '\n';
175 175 QUtil::os_wrapper("remove file", remove("/this/file/does/not/exist"));
176   - std::cout << "after remove" << std::endl;
  176 + std::cout << "after remove" << '\n';
177 177 } catch (std::runtime_error& s) {
178   - std::cout << "exception: " << s.what() << std::endl;
  178 + std::cout << "exception: " << s.what() << '\n';
179 179 }
180 180 }
181 181  
... ... @@ -183,12 +183,12 @@ void
183 183 fopen_wrapper_test()
184 184 {
185 185 try {
186   - std::cout << "before fopen" << std::endl;
  186 + std::cout << "before fopen" << '\n';
187 187 FILE* f = QUtil::safe_fopen("/this/file/does/not/exist", "r");
188   - std::cout << "after fopen" << std::endl;
  188 + std::cout << "after fopen" << '\n';
189 189 (void)fclose(f);
190 190 } catch (QPDFSystemError& s) {
191   - std::cout << "exception: " << s.what() << std::endl;
  191 + std::cout << "exception: " << s.what() << '\n';
192 192 assert(s.getErrno() != 0);
193 193 }
194 194  
... ... @@ -200,10 +200,9 @@ void
200 200 getenv_test()
201 201 {
202 202 std::string val;
203   - std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) << ": " << val
204   - << std::endl;
  203 + std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) << ": " << val << '\n';
205 204 // Hopefully this environment variable is not defined.
206   - std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") << std::endl;
  205 + std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") << '\n';
207 206 }
208 207  
209 208 static void
... ... @@ -223,7 +222,7 @@ print_utf8(unsigned long val)
223 222 static_cast<int>(static_cast<unsigned char>(ch)), 16, 2);
224 223 }
225 224 }
226   - std::cout << std::endl;
  225 + std::cout << '\n';
227 226  
228 227 // Boundary conditions for QUtil::get_next_utf8_codepoint, which is
229 228 // also tested indirectly through test_pdf_unicode.cc.
... ... @@ -264,7 +263,7 @@ to_utf8_test()
264 263 try {
265 264 print_utf8(0x80000000UL);
266 265 } catch (std::runtime_error& e) {
267   - std::cout << "0x80000000: " << e.what() << std::endl;
  266 + std::cout << "0x80000000: " << e.what() << '\n';
268 267 }
269 268  
270 269 // Overlong characters: characters represented by more bytes than necessary.
... ... @@ -296,7 +295,7 @@ print_utf16(unsigned long val)
296 295 << QUtil::int_to_string_base(
297 296 static_cast<int>(static_cast<unsigned char>(ch)), 16, 2);
298 297 }
299   - std::cout << std::endl;
  298 + std::cout << '\n';
300 299 }
301 300  
302 301 void
... ... @@ -311,24 +310,24 @@ to_utf16_test()
311 310 print_utf16(0x80000000UL);
312 311  
313 312 std::string s(QUtil::utf8_to_utf16("\xcf\x80"));
314   - std::cout << QUtil::utf16_to_utf8(s) << std::endl;
315   - std::cout << QUtil::utf16_to_utf8(s + ".") << std::endl;
316   - std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") << std::endl;
  313 + std::cout << QUtil::utf16_to_utf8(s) << '\n';
  314 + std::cout << QUtil::utf16_to_utf8(s + ".") << '\n';
  315 + std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") << '\n';
317 316 }
318 317  
319 318 void
320 319 utf8_to_ascii_test()
321 320 {
322 321 char const* input = "\302\277Does \317\200 have fingers?";
323   - std::cout << input << std::endl
324   - << QUtil::utf8_to_ascii(input) << std::endl
325   - << QUtil::utf8_to_ascii(input, '*') << std::endl;
  322 + std::cout << input << '\n'
  323 + << QUtil::utf8_to_ascii(input) << '\n'
  324 + << QUtil::utf8_to_ascii(input, '*') << '\n';
326 325 std::string a = QUtil::utf8_to_win_ansi(input, '*');
327 326 std::string b = QUtil::utf8_to_mac_roman(input, '*');
328 327 std::cout << "<" << QUtil::int_to_string_base(static_cast<unsigned char>(a.at(0)), 16, 2) << ">"
329   - << a.substr(1) << std::endl
  328 + << a.substr(1) << '\n'
330 329 << "<" << QUtil::int_to_string_base(static_cast<unsigned char>(b.at(0)), 16, 2) << ">"
331   - << b.substr(1) << std::endl;
  330 + << b.substr(1) << '\n';
332 331 }
333 332  
334 333 void
... ... @@ -349,7 +348,7 @@ transcoding_test(
349 348 back = (*from_utf8)(out, '?');
350 349 if (back != wanted) {
351 350 std::cout << i << ": " << in << " -> " << out << " -> " << back << " (wanted " << wanted
352   - << ")" << std::endl;
  351 + << ")" << '\n';
353 352 }
354 353 }
355 354 }
... ... @@ -363,7 +362,7 @@ check_analyze(std::string const&amp; str, bool has8bit, bool utf8, bool utf16)
363 362 QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16);
364 363 if (!((has_8bit_chars == has8bit) && (is_valid_utf8 == utf8) && (is_utf16 == utf16))) {
365 364 std::cout << "analysis failed: " << str << ": 8bit: " << has_8bit_chars
366   - << ", utf8: " << is_valid_utf8 << ", utf16: " << is_utf16 << std::endl;
  365 + << ", utf8: " << is_valid_utf8 << ", utf16: " << is_utf16 << '\n';
367 366 }
368 367 }
369 368  
... ... @@ -373,7 +372,7 @@ print_alternatives(std::string const&amp; str)
373 372 std::vector<std::string> result = QUtil::possible_repaired_encodings(str);
374 373 size_t n = result.size();
375 374 for (size_t i = 0; i < n; ++i) {
376   - std::cout << i << ": " << QUtil::hex_encode(result.at(i)) << std::endl;
  375 + std::cout << i << ": " << QUtil::hex_encode(result.at(i)) << '\n';
377 376 }
378 377 }
379 378  
... ... @@ -381,20 +380,20 @@ void
381 380 transcoding_test()
382 381 {
383 382 transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 127, 160, "\x9f");
384   - std::cout << "bidirectional pdf doc done" << std::endl;
  383 + std::cout << "bidirectional pdf doc done" << '\n';
385 384 transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 24, 31, "?");
386   - std::cout << "bidirectional pdf doc low done" << std::endl;
  385 + std::cout << "bidirectional pdf doc low done" << '\n';
387 386 transcoding_test(&QUtil::win_ansi_to_utf8, &QUtil::utf8_to_win_ansi, 128, 160, "?");
388   - std::cout << "bidirectional win ansi done" << std::endl;
  387 + std::cout << "bidirectional win ansi done" << '\n';
389 388 transcoding_test(&QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 128, 255, "?");
390   - std::cout << "bidirectional mac roman done" << std::endl;
  389 + std::cout << "bidirectional mac roman done" << '\n';
391 390 check_analyze("pi = \317\200", true, true, false);
392 391 check_analyze("pi != \317", true, false, false);
393 392 check_analyze("pi != 22/7", false, false, false);
394 393 check_analyze("\xE0\x80\x82", true, false, false);
395 394 check_analyze(std::string("\xfe\xff\x00\x51", 4), true, false, true);
396 395 check_analyze(std::string("\xff\xfe\x51\x00", 4), true, false, true);
397   - std::cout << "analysis done" << std::endl;
  396 + std::cout << "analysis done" << '\n';
398 397 std::string input1("a\302\277b");
399 398 std::string input2("a\317\200b");
400 399 std::string input3("ab");
... ... @@ -411,7 +410,7 @@ transcoding_test()
411 410 assert(QUtil::utf8_to_pdf_doc(input1, output));
412 411 assert(!QUtil::utf8_to_pdf_doc(input2, output));
413 412 assert(QUtil::utf8_to_pdf_doc(input3, output));
414   - std::cout << "alternatives" << std::endl;
  413 + std::cout << "alternatives" << '\n';
415 414 // char name mac win pdf-doc
416 415 // U+0192 florin 304 203 206
417 416 // U+00A9 copyright 251 251 251
... ... @@ -422,18 +421,18 @@ transcoding_test()
422 421 print_alternatives(pdfdoc);
423 422 print_alternatives(utf8);
424 423 print_alternatives("quack");
425   - std::cout << "done alternatives" << std::endl;
  424 + std::cout << "done alternatives" << '\n';
426 425 // These are characters are either valid in PDFDoc and invalid in
427 426 // UTF-8 or the other way around.
428 427 std::string other("w\x18w\x19w\x1aw\x1bw\x1cw\x1dw\x1ew\x1fw\x7fw");
429 428 // cSpell: ignore xadw
430 429 std::string other_doc = other + "\x9fw\xadw";
431   - std::cout << QUtil::pdf_doc_to_utf8(other_doc) << std::endl;
  430 + std::cout << QUtil::pdf_doc_to_utf8(other_doc) << '\n';
432 431 std::string other_utf8 = other + QUtil::toUTF8(0x9f) + "w" + QUtil::toUTF8(0xad) + "w";
433 432 std::string other_to_utf8;
434 433 assert(!QUtil::utf8_to_pdf_doc(other_utf8, other_to_utf8));
435   - std::cout << other_to_utf8 << std::endl;
436   - std::cout << "done other characters" << std::endl;
  434 + std::cout << other_to_utf8 << '\n';
  435 + std::cout << "done other characters" << '\n';
437 436 // These valid UTF8 strings when converted to PDFDoc would end up
438 437 // with a byte sequence that would be recognized as UTF-8 or
439 438 // UTF-16 rather than PDFDoc. A special case is required to store
... ... @@ -455,7 +454,7 @@ void
455 454 print_whoami(char const* str)
456 455 {
457 456 auto dup = QUtil::make_unique_cstr(str);
458   - std::cout << QUtil::getWhoami(dup.get()) << std::endl;
  457 + std::cout << QUtil::getWhoami(dup.get()) << '\n';
459 458 }
460 459  
461 460 void
... ... @@ -473,7 +472,7 @@ assert_same_file(char const* file1, char const* file2, bool expected)
473 472 bool actual = QUtil::same_file(file1, file2);
474 473 std::cout << "file1: -" << (file1 ? file1 : "(null)") << "-, file2: -"
475 474 << (file2 ? file2 : "(null)") << "-; same: " << actual << ": "
476   - << ((actual == expected) ? "PASS" : "FAIL") << std::endl;
  475 + << ((actual == expected) ? "PASS" : "FAIL") << '\n';
477 476 }
478 477  
479 478 void
... ... @@ -501,7 +500,7 @@ path_test()
501 500 auto check = [](bool print, std::string const& a, std::string const& b) {
502 501 auto result = QUtil::path_basename(a);
503 502 if (print) {
504   - std::cout << a << " -> " << result << std::endl;
  503 + std::cout << a << " -> " << result << '\n';
505 504 }
506 505 assert(result == b);
507 506 };
... ... @@ -523,7 +522,7 @@ read_from_file_test()
523 522 {
524 523 std::list<std::string> lines = QUtil::read_lines_from_file("other-file");
525 524 for (auto const& line: lines) {
526   - std::cout << line << std::endl;
  525 + std::cout << line << '\n';
527 526 }
528 527 // Test the other versions and make sure we get the same results
529 528 {
... ... @@ -561,7 +560,7 @@ read_from_file_test()
561 560 std::shared_ptr<char> buf;
562 561 size_t size = 0;
563 562 QUtil::read_file_into_memory("other-file", buf, size);
564   - std::cout << "read " << size << " bytes" << std::endl;
  563 + std::cout << "read " << size << " bytes" << '\n';
565 564 char const* p = buf.get();
566 565 assert(size == 24652);
567 566 assert(memcmp(p, "This file is used for qutil testing.", 36) == 0);
... ... @@ -575,7 +574,7 @@ read_from_file_test()
575 574 assert(memcmp(buf2->getBuffer(), p, size) == 0);
576 575  
577 576 auto s = QUtil::read_file_into_string("other-file");
578   - std::cout << "read " << s.size() << " bytes" << std::endl;
  577 + std::cout << "read " << s.size() << " bytes" << '\n';
579 578 assert(s.size() == 24652);
580 579 assert(s.substr(0, 36) == "This file is used for qutil testing.");
581 580 assert(s.substr(24641, 10) == "very long.");
... ... @@ -587,7 +586,7 @@ assert_hex_encode(std::string const&amp; input, std::string const&amp; expected)
587 586 std::string actual = QUtil::hex_encode(input);
588 587 if (expected != actual) {
589 588 std::cout << "hex encode " << input << ": expected = " << expected
590   - << "; actual = " << actual << std::endl;
  589 + << "; actual = " << actual << '\n';
591 590 }
592 591 }
593 592  
... ... @@ -597,7 +596,7 @@ assert_hex_decode(std::string const&amp; input, std::string const&amp; expected)
597 596 std::string actual = QUtil::hex_decode(input);
598 597 if (expected != actual) {
599 598 std::cout << "hex encode " << input << ": expected = " << expected
600   - << "; actual = " << actual << std::endl;
  599 + << "; actual = " << actual << '\n';
601 600 }
602 601 }
603 602  
... ... @@ -639,31 +638,31 @@ rename_delete_test()
639 638 } catch (QPDFSystemError&) {
640 639 }
641 640 assert_no_file("old\xcf\x80");
642   - std::cout << "create file" << std::endl;
  641 + std::cout << "create file" << '\n';
643 642 ;
644 643 FILE* f1 = QUtil::safe_fopen("old\xcf\x80", "w");
645 644 fprintf(f1, "one");
646 645 fclose(f1);
647 646 QUtil::read_file_into_memory("old\xcf\x80", buf, size);
648 647 assert(memcmp(buf.get(), "one", 3) == 0);
649   - std::cout << "rename file" << std::endl;
  648 + std::cout << "rename file" << '\n';
650 649 ;
651 650 QUtil::rename_file("old\xcf\x80", "old\xcf\x80.~tmp");
652 651 QUtil::read_file_into_memory("old\xcf\x80.~tmp", buf, size);
653 652 assert(memcmp(buf.get(), "one", 3) == 0);
654 653 assert_no_file("old\xcf\x80");
655   - std::cout << "create file" << std::endl;
  654 + std::cout << "create file" << '\n';
656 655 ;
657 656 f1 = QUtil::safe_fopen("old\xcf\x80", "w");
658 657 fprintf(f1, "two");
659 658 fclose(f1);
660   - std::cout << "rename over existing" << std::endl;
  659 + std::cout << "rename over existing" << '\n';
661 660 ;
662 661 QUtil::rename_file("old\xcf\x80", "old\xcf\x80.~tmp");
663 662 QUtil::read_file_into_memory("old\xcf\x80.~tmp", buf, size);
664 663 assert(memcmp(buf.get(), "two", 3) == 0);
665 664 assert_no_file("old\xcf\x80");
666   - std::cout << "delete file" << std::endl;
  665 + std::cout << "delete file" << '\n';
667 666 ;
668 667 QUtil::remove_file("old\xcf\x80.~tmp");
669 668 assert_no_file("old\xcf\x80");
... ... @@ -676,7 +675,7 @@ timestamp_test()
676 675 auto check = [](QUtil::QPDFTime const& t) {
677 676 std::string pdf = QUtil::qpdf_time_to_pdf_time(t);
678 677 std::string iso8601 = QUtil::qpdf_time_to_iso8601(t);
679   - std::cout << pdf << std::endl << iso8601 << std::endl;
  678 + std::cout << pdf << '\n' << iso8601 << '\n';
680 679 QUtil::QPDFTime t2;
681 680 std::string iso8601_2;
682 681 assert(QUtil::pdf_time_to_qpdf_time(pdf, &t2));
... ... @@ -704,7 +703,7 @@ is_long_long_test()
704 703 {
705 704 auto check = [](char const* s, bool v) {
706 705 if (QUtil::is_long_long(s) != v) {
707   - std::cout << "failed: " << s << std::endl;
  706 + std::cout << "failed: " << s << '\n';
708 707 }
709 708 };
710 709 check("12312312", true);
... ... @@ -719,7 +718,7 @@ is_long_long_test()
719 718 check("123123123123123123123123123123123123", false);
720 719 check("potato", false);
721 720 check("0123", false);
722   - std::cout << "done" << std::endl;
  721 + std::cout << "done" << '\n';
723 722 }
724 723  
725 724 void
... ... @@ -731,49 +730,49 @@ memory_usage_test()
731 730 auto u2 = QUtil::get_max_memory_usage();
732 731 assert(u2 > u1);
733 732 }
734   - std::cout << "memory usage okay" << std::endl;
  733 + std::cout << "memory usage okay" << '\n';
735 734 }
736 735  
737 736 int
738 737 main(int argc, char* argv[])
739 738 {
740 739 try {
741   - std::cout << "---- string conversion" << std::endl;
  740 + std::cout << "---- string conversion" << '\n';
742 741 string_conversion_test();
743   - std::cout << "---- os wrapper" << std::endl;
  742 + std::cout << "---- os wrapper" << '\n';
744 743 os_wrapper_test();
745   - std::cout << "---- fopen" << std::endl;
  744 + std::cout << "---- fopen" << '\n';
746 745 fopen_wrapper_test();
747   - std::cout << "---- getenv" << std::endl;
  746 + std::cout << "---- getenv" << '\n';
748 747 getenv_test();
749   - std::cout << "---- utf8" << std::endl;
  748 + std::cout << "---- utf8" << '\n';
750 749 to_utf8_test();
751   - std::cout << "---- utf16" << std::endl;
  750 + std::cout << "---- utf16" << '\n';
752 751 to_utf16_test();
753   - std::cout << "---- utf8_to_ascii" << std::endl;
  752 + std::cout << "---- utf8_to_ascii" << '\n';
754 753 utf8_to_ascii_test();
755   - std::cout << "---- transcoding" << std::endl;
  754 + std::cout << "---- transcoding" << '\n';
756 755 transcoding_test();
757   - std::cout << "---- whoami" << std::endl;
  756 + std::cout << "---- whoami" << '\n';
758 757 get_whoami_test();
759   - std::cout << "---- file" << std::endl;
  758 + std::cout << "---- file" << '\n';
760 759 same_file_test();
761   - std::cout << "---- path" << std::endl;
  760 + std::cout << "---- path" << '\n';
762 761 path_test();
763   - std::cout << "---- read from file" << std::endl;
  762 + std::cout << "---- read from file" << '\n';
764 763 read_from_file_test();
765   - std::cout << "---- hex encode/decode" << std::endl;
  764 + std::cout << "---- hex encode/decode" << '\n';
766 765 hex_encode_decode_test();
767   - std::cout << "---- rename/delete" << std::endl;
  766 + std::cout << "---- rename/delete" << '\n';
768 767 rename_delete_test();
769   - std::cout << "---- timestamp" << std::endl;
  768 + std::cout << "---- timestamp" << '\n';
770 769 timestamp_test();
771   - std::cout << "---- is_long_long" << std::endl;
  770 + std::cout << "---- is_long_long" << '\n';
772 771 is_long_long_test();
773   - std::cout << "---- memory usage" << std::endl;
  772 + std::cout << "---- memory usage" << '\n';
774 773 memory_usage_test();
775 774 } catch (std::exception& e) {
776   - std::cout << "unexpected exception: " << e.what() << std::endl;
  775 + std::cout << "unexpected exception: " << e.what() << '\n';
777 776 }
778 777  
779 778 return 0;
... ...
libtests/rc4.cc
... ... @@ -20,7 +20,7 @@ other_tests()
20 20 memcpy(data.get(), "potato", 6);
21 21 r.process(data.get(), 6, data.get());
22 22 assert(memcmp(data.get(), "\xa5\x6f\xe7\x27\x2b\x5c", 6) == 0);
23   - std::cout << "passed" << std::endl;
  23 + std::cout << "passed" << '\n';
24 24 }
25 25  
26 26 int
... ... @@ -32,7 +32,7 @@ main(int argc, char* argv[])
32 32 }
33 33  
34 34 if (argc != 4) {
35   - std::cerr << "Usage: rc4 hex-key infile outfile" << std::endl;
  35 + std::cerr << "Usage: rc4 hex-key infile outfile" << '\n';
36 36 exit(2);
37 37 }
38 38  
... ...
libtests/runlength.cc
... ... @@ -11,7 +11,7 @@ int
11 11 main(int argc, char* argv[])
12 12 {
13 13 if (argc != 4) {
14   - std::cerr << "Usage: runlength {-encode|-decode} infile outfile" << std::endl;
  14 + std::cerr << "Usage: runlength {-encode|-decode} infile outfile" << '\n';
15 15 exit(2);
16 16 }
17 17  
... ...
libtests/sparse_array.cc
... ... @@ -118,6 +118,6 @@ main()
118 118 } catch (std::logic_error&) {
119 119 }
120 120  
121   - std::cout << "sparse array tests done" << std::endl;
  121 + std::cout << "sparse array tests done" << '\n';
122 122 return 0;
123 123 }
... ...
qpdf/fix-qdf.cc
... ... @@ -81,7 +81,7 @@ QdfFixer::QdfFixer(std::string const&amp; filename, std::ostream&amp; out) :
81 81 void
82 82 QdfFixer::fatal(std::string const& msg)
83 83 {
84   - std::cerr << msg << std::endl;
  84 + std::cerr << msg << '\n';
85 85 exit(2);
86 86 }
87 87  
... ... @@ -380,7 +380,7 @@ realmain(int argc, char* argv[])
380 380 if (argc > 3) {
381 381 usage();
382 382 } else if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) {
383   - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl;
  383 + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << '\n';
384 384 return 0;
385 385 } else if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
386 386 usage();
... ... @@ -411,7 +411,7 @@ realmain(int argc, char* argv[])
411 411 QdfFixer qf(filename, out ? *out : std::cout);
412 412 qf.processLines(input);
413 413 } catch (std::exception& e) {
414   - std::cerr << whoami << ": error: " << e.what() << std::endl;
  414 + std::cerr << whoami << ": error: " << e.what() << '\n';
415 415 exit(qpdf_exit_error);
416 416 }
417 417 return 0;
... ...
qpdf/pdf_from_scratch.cc
... ... @@ -14,7 +14,7 @@ static char const* whoami = nullptr;
14 14 void
15 15 usage()
16 16 {
17   - std::cerr << "Usage: " << whoami << " n" << std::endl;
  17 + std::cerr << "Usage: " << whoami << " n\n";
18 18 exit(2);
19 19 }
20 20  
... ... @@ -77,7 +77,7 @@ runtest(int n)
77 77 throw std::runtime_error(std::string("invalid test ") + std::to_string(n));
78 78 }
79 79  
80   - std::cout << "test " << n << " done" << std::endl;
  80 + std::cout << "test " << n << " done\n";
81 81 }
82 82  
83 83 int
... ... @@ -98,7 +98,7 @@ main(int argc, char* argv[])
98 98 int n = QUtil::string_to_int(argv[1]);
99 99 runtest(n);
100 100 } catch (std::exception& e) {
101   - std::cerr << e.what() << std::endl;
  101 + std::cerr << e.what() << '\n';
102 102 exit(2);
103 103 }
104 104  
... ...
qpdf/qpdf.cc
... ... @@ -11,15 +11,15 @@ static char const* whoami = nullptr;
11 11 static void
12 12 usageExit(std::string const& msg)
13 13 {
14   - std::cerr << std::endl
15   - << whoami << ": " << msg << std::endl
16   - << std::endl
17   - << "For help:" << std::endl
18   - << " " << whoami << " --help=usage usage information" << std::endl
19   - << " " << whoami << " --help=topic help on a topic" << std::endl
20   - << " " << whoami << " --help=--option help on an option" << std::endl
21   - << " " << whoami << " --help general help and a topic list" << std::endl
22   - << std::endl;
  14 + std::cerr << '\n'
  15 + << whoami << ": " << msg << '\n'
  16 + << '\n'
  17 + << "For help:\n"
  18 + << " " << whoami << " --help=usage usage information\n"
  19 + << " " << whoami << " --help=topic help on a topic\n"
  20 + << " " << whoami << " --help=--option help on an option\n"
  21 + << " " << whoami << " --help general help and a topic list\n"
  22 + << '\n';
23 23 exit(QPDFJob::EXIT_ERROR);
24 24 }
25 25  
... ... @@ -37,7 +37,7 @@ realmain(int argc, char* argv[])
37 37 } catch (QPDFUsage& e) {
38 38 usageExit(e.what());
39 39 } catch (std::exception& e) {
40   - std::cerr << whoami << ": " << e.what() << std::endl;
  40 + std::cerr << whoami << ": " << e.what() << '\n';
41 41 return QPDFJob::EXIT_ERROR;
42 42 }
43 43 return j.getExitCode();
... ...
qpdf/test_driver.cc
... ... @@ -39,7 +39,7 @@ static char const* whoami = nullptr;
39 39 void
40 40 usage()
41 41 {
42   - std::cerr << "Usage: " << whoami << " n filename1 [arg2]" << std::endl;
  42 + std::cerr << "Usage: " << whoami << " n filename1 [arg2]" << '\n';
43 43 exit(2);
44 44 }
45 45  
... ... @@ -58,7 +58,7 @@ ExtendNameTree::ExtendNameTree(QPDFObjectHandle o, QPDF&amp; q) :
58 58  
59 59 ExtendNameTree::~ExtendNameTree()
60 60 {
61   - std::cout << "~ExtendNameTree called" << std::endl;
  61 + std::cout << "~ExtendNameTree called" << '\n';
62 62 }
63 63  
64 64 class Provider: public QPDFObjectHandle::StreamDataProvider
... ... @@ -104,30 +104,30 @@ class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks
104 104 void
105 105 ParserCallbacks::contentSize(size_t size)
106 106 {
107   - std::cout << "content size: " << size << std::endl;
  107 + std::cout << "content size: " << size << '\n';
108 108 }
109 109  
110 110 void
111 111 ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length)
112 112 {
113 113 if (obj.isName() && (obj.getName() == "/Abort")) {
114   - std::cout << "test suite: terminating parsing" << std::endl;
  114 + std::cout << "test suite: terminating parsing" << '\n';
115 115 terminateParsing();
116 116 }
117 117 std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": ";
118 118 if (obj.isInlineImage()) {
119 119 // Exercise getTypeCode
120 120 assert(obj.getTypeCode() == ::ot_inlineimage);
121   - std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
  121 + std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << '\n';
122 122 } else {
123   - std::cout << obj.unparse() << std::endl;
  123 + std::cout << obj.unparse() << '\n';
124 124 }
125 125 }
126 126  
127 127 void
128 128 ParserCallbacks::handleEOF()
129 129 {
130   - std::cout << "-EOF-" << std::endl;
  130 + std::cout << "-EOF-" << '\n';
131 131 }
132 132  
133 133 class TokenFilter: public QPDFObjectHandle::TokenFilter
... ... @@ -165,7 +165,7 @@ checkPageContents(QPDFObjectHandle page, std::string const&amp; wanted_string)
165 165 {
166 166 std::string contents = getPageContents(page);
167 167 if (contents.find(wanted_string) == std::string::npos) {
168   - std::cout << "didn't find " << wanted_string << " in " << contents << std::endl;
  168 + std::cout << "didn't find " << wanted_string << " in " << contents << '\n';
169 169 }
170 170 }
171 171  
... ... @@ -207,77 +207,77 @@ test_0_1(QPDF&amp; pdf, char const* arg2)
207 207 // any difference between a key that is present and null
208 208 // and a key that is absent.
209 209 QTC::TC("qpdf", "main QTest implicit");
210   - std::cout << "/QTest is implicit" << std::endl;
  210 + std::cout << "/QTest is implicit" << '\n';
211 211 }
212 212  
213 213 QTC::TC("qpdf", "main QTest indirect", qtest.isIndirect() ? 1 : 0);
214 214 std::cout << "/QTest is " << (qtest.isIndirect() ? "in" : "") << "direct and has type "
215   - << qtest.getTypeName() << " (" << qtest.getTypeCode() << ")" << std::endl;
  215 + << qtest.getTypeName() << " (" << qtest.getTypeCode() << ")" << '\n';
216 216  
217 217 if (qtest.isNull()) {
218 218 QTC::TC("qpdf", "main QTest null");
219   - std::cout << "/QTest is null" << std::endl;
  219 + std::cout << "/QTest is null" << '\n';
220 220 } else if (qtest.isBool()) {
221 221 QTC::TC("qpdf", "main QTest bool", qtest.getBoolValue() ? 1 : 0);
222 222 std::cout << "/QTest is Boolean with value " << (qtest.getBoolValue() ? "true" : "false")
223   - << std::endl;
  223 + << '\n';
224 224 } else if (qtest.isInteger()) {
225 225 QTC::TC("qpdf", "main QTest int");
226   - std::cout << "/QTest is an integer with value " << qtest.getIntValue() << std::endl;
  226 + std::cout << "/QTest is an integer with value " << qtest.getIntValue() << '\n';
227 227 } else if (qtest.isReal()) {
228 228 QTC::TC("qpdf", "main QTest real");
229   - std::cout << "/QTest is a real number with value " << qtest.getRealValue() << std::endl;
  229 + std::cout << "/QTest is a real number with value " << qtest.getRealValue() << '\n';
230 230 } else if (qtest.isName()) {
231 231 QTC::TC("qpdf", "main QTest name");
232   - std::cout << "/QTest is a name with value " << qtest.getName() << std::endl;
  232 + std::cout << "/QTest is a name with value " << qtest.getName() << '\n';
233 233 } else if (qtest.isString()) {
234 234 QTC::TC("qpdf", "main QTest string");
235   - std::cout << "/QTest is a string with value " << qtest.getStringValue() << std::endl;
  235 + std::cout << "/QTest is a string with value " << qtest.getStringValue() << '\n';
236 236 } else if (qtest.isArray()) {
237 237 QTC::TC("qpdf", "main QTest array");
238   - std::cout << "/QTest is an array with " << qtest.getArrayNItems() << " items" << std::endl;
  238 + std::cout << "/QTest is an array with " << qtest.getArrayNItems() << " items" << '\n';
239 239 int i = 0;
240 240 for (auto& iter: qtest.aitems()) {
241 241 QTC::TC("qpdf", "main QTest array indirect", iter.isIndirect() ? 1 : 0);
242 242 std::cout << " item " << i << " is " << (iter.isIndirect() ? "in" : "") << "direct"
243   - << std::endl;
  243 + << '\n';
244 244 ++i;
245 245 }
246 246 } else if (qtest.isDictionary()) {
247 247 QTC::TC("qpdf", "main QTest dictionary");
248   - std::cout << "/QTest is a dictionary" << std::endl;
  248 + std::cout << "/QTest is a dictionary" << '\n';
249 249 for (auto& iter: qtest.ditems()) {
250 250 QTC::TC("qpdf", "main QTest dictionary indirect", iter.second.isIndirect() ? 1 : 0);
251 251 std::cout << " " << iter.first << " is " << (iter.second.isIndirect() ? "in" : "")
252   - << "direct" << std::endl;
  252 + << "direct" << '\n';
253 253 }
254 254 } else if (qtest.isStream()) {
255 255 QTC::TC("qpdf", "main QTest stream");
256   - std::cout << "/QTest is a stream. Dictionary: " << qtest.getDict().unparse() << std::endl;
  256 + std::cout << "/QTest is a stream. Dictionary: " << qtest.getDict().unparse() << '\n';
257 257  
258   - std::cout << "Raw stream data:" << std::endl;
  258 + std::cout << "Raw stream data:" << '\n';
259 259 std::cout.flush();
260 260 QUtil::binary_stdout();
261 261 auto out = std::make_shared<Pl_StdioFile>("raw", stdout);
262 262 qtest.pipeStreamData(out.get(), 0, qpdf_dl_none);
263 263  
264   - std::cout << std::endl << "Uncompressed stream data:" << std::endl;
  264 + std::cout << '\n' << "Uncompressed stream data:" << '\n';
265 265 if (qtest.pipeStreamData(nullptr, 0, qpdf_dl_all)) {
266 266 std::cout.flush();
267 267 QUtil::binary_stdout();
268 268 out = std::make_shared<Pl_StdioFile>("filtered", stdout);
269 269 qtest.pipeStreamData(out.get(), 0, qpdf_dl_all);
270   - std::cout << std::endl << "End of stream data" << std::endl;
  270 + std::cout << '\n' << "End of stream data" << '\n';
271 271 } else {
272   - std::cout << "Stream data is not filterable." << std::endl;
  272 + std::cout << "Stream data is not filterable." << '\n';
273 273 }
274 274 } else {
275 275 // Should not happen!
276   - std::cout << "/QTest is an unknown object" << std::endl;
  276 + std::cout << "/QTest is an unknown object" << '\n';
277 277 }
278 278  
279   - std::cout << "unparse: " << qtest.unparse() << std::endl
280   - << "unparseResolved: " << qtest.unparseResolved() << std::endl;
  279 + std::cout << "unparse: " << qtest.unparse() << '\n'
  280 + << "unparseResolved: " << qtest.unparseResolved() << '\n';
281 281 }
282 282  
283 283 static void
... ... @@ -287,12 +287,12 @@ test_2(QPDF&amp; pdf, char const* arg2)
287 287 // PDF file.
288 288  
289 289 QPDFObjectHandle trailer = pdf.getTrailer();
290   - std::cout << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() << std::endl;
291   - std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() << std::endl;
  290 + std::cout << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() << '\n';
  291 + std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() << '\n';
292 292  
293 293 QPDFObjectHandle encrypt = trailer.getKey("/Encrypt");
294   - std::cout << encrypt.getKey("/O").unparse() << std::endl;
295   - std::cout << encrypt.getKey("/U").unparse() << std::endl;
  294 + std::cout << encrypt.getKey("/O").unparse() << '\n';
  295 + std::cout << encrypt.getKey("/U").unparse() << '\n';
296 296  
297 297 QPDFObjectHandle root = pdf.getRoot();
298 298 QPDFObjectHandle pages = root.getKey("/Pages");
... ... @@ -310,7 +310,7 @@ test_3(QPDF&amp; pdf, char const* arg2)
310 310 QPDFObjectHandle streams = pdf.getTrailer().getKey("/QStreams");
311 311 for (int i = 0; i < streams.getArrayNItems(); ++i) {
312 312 QPDFObjectHandle stream = streams.getArrayItem(i);
313   - std::cout << "-- stream " << i << " --" << std::endl;
  313 + std::cout << "-- stream " << i << " --" << '\n';
314 314 std::cout.flush();
315 315 QUtil::binary_stdout();
316 316 auto out = std::make_shared<Pl_StdioFile>("tokenized stream", stdout);
... ... @@ -374,44 +374,44 @@ test_5(QPDF&amp; pdf, char const* arg2)
374 374 int pageno = 0;
375 375 for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
376 376 ++pageno;
377   - std::cout << "page " << pageno << ":" << std::endl;
378   - std::cout << " images:" << std::endl;
  377 + std::cout << "page " << pageno << ":" << '\n';
  378 + std::cout << " images:" << '\n';
379 379 for (auto const& iter2: page.getImages()) {
380 380 std::string const& name = iter2.first;
381 381 QPDFObjectHandle image = iter2.second;
382 382 QPDFObjectHandle dict = image.getDict();
383 383 long long width = dict.getKey("/Width").getIntValue();
384 384 long long height = dict.getKey("/Height").getIntValue();
385   - std::cout << " " << name << ": " << width << " x " << height << std::endl;
  385 + std::cout << " " << name << ": " << width << " x " << height << '\n';
386 386 }
387 387  
388   - std::cout << " content:" << std::endl;
  388 + std::cout << " content:" << '\n';
389 389 std::vector<QPDFObjectHandle> content = page.getPageContents();
390 390 for (auto& iter2: content) {
391   - std::cout << " " << iter2.unparse() << std::endl;
  391 + std::cout << " " << iter2.unparse() << '\n';
392 392 }
393 393  
394   - std::cout << "end page " << pageno << std::endl;
  394 + std::cout << "end page " << pageno << '\n';
395 395 }
396 396  
397 397 QPDFObjectHandle root = pdf.getRoot();
398 398 QPDFObjectHandle qstrings = root.getKey("/QStrings");
399 399 if (qstrings.isArray()) {
400   - std::cout << "QStrings:" << std::endl;
  400 + std::cout << "QStrings:" << '\n';
401 401 int nitems = qstrings.getArrayNItems();
402 402 for (int i = 0; i < nitems; ++i) {
403   - std::cout << qstrings.getArrayItem(i).getUTF8Value() << std::endl;
  403 + std::cout << qstrings.getArrayItem(i).getUTF8Value() << '\n';
404 404 }
405 405 }
406 406  
407 407 QPDFObjectHandle qnumbers = root.getKey("/QNumbers");
408 408 if (qnumbers.isArray()) {
409   - std::cout << "QNumbers:" << std::endl;
  409 + std::cout << "QNumbers:" << '\n';
410 410 int nitems = qnumbers.getArrayNItems();
411 411 for (int i = 0; i < nitems; ++i) {
412 412 std::cout << QUtil::double_to_string(
413 413 qnumbers.getArrayItem(i).getNumericValue(), 3, false)
414   - << std::endl;
  414 + << '\n';
415 415 }
416 416 }
417 417 }
... ... @@ -432,7 +432,7 @@ test_6(QPDF&amp; pdf, char const* arg2)
432 432 cleartext = true;
433 433 }
434 434 std::cout << "encrypted=" << (pdf.isEncrypted() ? 1 : 0)
435   - << "; cleartext=" << (cleartext ? 1 : 0) << std::endl;
  435 + << "; cleartext=" << (cleartext ? 1 : 0) << '\n';
436 436 }
437 437  
438 438 static void
... ... @@ -483,9 +483,9 @@ test_8(QPDF&amp; pdf, char const* arg2)
483 483 provider->badLength(true);
484 484 try {
485 485 qstream.getStreamData();
486   - std::cout << "oops -- getStreamData didn't throw" << std::endl;
  486 + std::cout << "oops -- getStreamData didn't throw" << '\n';
487 487 } catch (std::exception const& e) {
488   - std::cout << "exception: " << e.what() << std::endl;
  488 + std::cout << "exception: " << e.what() << '\n';
489 489 }
490 490 }
491 491  
... ... @@ -501,9 +501,9 @@ test_9(QPDF&amp; pdf, char const* arg2)
501 501 QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf);
502 502 try {
503 503 rstream.getStreamData();
504   - std::cout << "oops -- getStreamData didn't throw" << std::endl;
  504 + std::cout << "oops -- getStreamData didn't throw" << '\n';
505 505 } catch (std::logic_error const& e) {
506   - std::cout << "exception: " << e.what() << std::endl;
  506 + std::cout << "exception: " << e.what() << '\n';
507 507 }
508 508 rstream.replaceStreamData(
509 509 "data for other stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
... ... @@ -539,10 +539,10 @@ test_11(QPDF&amp; pdf, char const* arg2)
539 539 std::shared_ptr<Buffer> b1 = qstream.getStreamData();
540 540 std::shared_ptr<Buffer> b2 = qstream.getRawStreamData();
541 541 if ((b1->getSize() == 7) && (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) {
542   - std::cout << "filtered stream data okay" << std::endl;
  542 + std::cout << "filtered stream data okay" << '\n';
543 543 }
544 544 if ((b2->getSize() == 15) && (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) {
545   - std::cout << "raw stream data okay" << std::endl;
  545 + std::cout << "raw stream data okay" << '\n';
546 546 }
547 547 }
548 548  
... ... @@ -580,9 +580,7 @@ test_13(QPDF&amp; pdf, char const* arg2)
580 580 # pragma GCC diagnostic pop
581 581 #endif
582 582 pdf.showLinearizationData();
583   - std::cout << "---output---" << std::endl
584   - << out.str() << "---error---" << std::endl
585   - << err.str();
  583 + std::cout << "---output---" << '\n' << out.str() << "---error---" << '\n' << err.str();
586 584 }
587 585  
588 586 static void
... ... @@ -614,27 +612,27 @@ test_14(QPDF&amp; pdf, char const* arg2)
614 612 // Do it wrong first...
615 613 pdf.replaceObject(qdict.getObjGen(), qdict);
616 614 } catch (std::logic_error const&) {
617   - std::cout << "caught logic error as expected" << std::endl;
  615 + std::cout << "caught logic error as expected" << '\n';
618 616 }
619 617 pdf.replaceObject(qdict.getObjGen(), new_dict);
620 618 // Now qdict points to the new dictionary
621   - std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() << std::endl;
  619 + std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() << '\n';
622 620 // Swap dict and array
623 621 pdf.swapObjects(qdict.getObjGen(), qarray.getObjGen());
624 622 // Now qarray will resolve to new object and qdict resolves to
625 623 // the array
626   - std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl;
627   - std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() << std::endl;
  624 + std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << '\n';
  625 + std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() << '\n';
628 626 // Reread qdict, still pointing to an array
629 627 qdict = pdf.getObjectByObjGen(qdict.getObjGen());
630   - std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl;
  628 + std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << '\n';
631 629  
632 630 // Exercise getAsMap and getAsArray
633 631 std::vector<QPDFObjectHandle> array_elements = qdict.getArrayAsVector();
634 632 std::map<std::string, QPDFObjectHandle> dict_items = qarray.getDictAsMap();
635 633 if ((array_elements.size() == 1) && (array_elements.at(0).getName() == "/Array") &&
636 634 (dict_items.size() == 1) && (dict_items["/NewDict"].getIntValue() == 2)) {
637   - std::cout << "array and dictionary contents are correct" << std::endl;
  635 + std::cout << "array and dictionary contents are correct" << '\n';
638 636 }
639 637  
640 638 // Exercise writing to memory buffer
... ... @@ -853,7 +851,7 @@ test_21(QPDF&amp; pdf, char const* arg2)
853 851 QPDFObjectHandle page = pages.at(0);
854 852 QPDFObjectHandle contents = page.getKey("/Contents");
855 853 contents.shallowCopy();
856   - std::cout << "you can't see this" << std::endl;
  854 + std::cout << "you can't see this" << '\n';
857 855 }
858 856  
859 857 static void
... ... @@ -865,7 +863,7 @@ test_22(QPDF&amp; pdf, char const* arg2)
865 863 QPDFPageObjectHelper& page = pages.at(0);
866 864 dh.removePage(page);
867 865 dh.removePage(page);
868   - std::cout << "you can't see this" << std::endl;
  866 + std::cout << "you can't see this" << '\n';
869 867 }
870 868  
871 869 static void
... ... @@ -895,44 +893,44 @@ test_24(QPDF&amp; pdf, char const* arg2)
895 893 // Make sure trying to ask questions about a reserved object
896 894 // doesn't break it.
897 895 if (res1.isArray()) {
898   - std::cout << "oops -- res1 is an array" << std::endl;
  896 + std::cout << "oops -- res1 is an array" << '\n';
899 897 }
900 898 if (res1.isReserved()) {
901   - std::cout << "res1 is still reserved after checking if array" << std::endl;
  899 + std::cout << "res1 is still reserved after checking if array" << '\n';
902 900 }
903 901 pdf.replaceReserved(res1, array1);
904 902 if (res1.isReserved()) {
905   - std::cout << "oops -- res1 is still reserved" << std::endl;
  903 + std::cout << "oops -- res1 is still reserved" << '\n';
906 904 } else {
907   - std::cout << "res1 is no longer reserved" << std::endl;
  905 + std::cout << "res1 is no longer reserved" << '\n';
908 906 }
909 907 res1.assertArray();
910   - std::cout << "res1 is an array" << std::endl;
  908 + std::cout << "res1 is an array" << '\n';
911 909  
912 910 try {
913 911 res2.unparseResolved();
914   - std::cout << "oops -- didn't throw" << std::endl;
  912 + std::cout << "oops -- didn't throw" << '\n';
915 913 } catch (std::logic_error const& e) {
916   - std::cout << "logic error: " << e.what() << std::endl;
  914 + std::cout << "logic error: " << e.what() << '\n';
917 915 }
918 916 try {
919 917 res2.makeDirect();
920   - std::cout << "oops -- didn't throw" << std::endl;
  918 + std::cout << "oops -- didn't throw" << '\n';
921 919 } catch (std::logic_error const& e) {
922   - std::cout << "logic error: " << e.what() << std::endl;
  920 + std::cout << "logic error: " << e.what() << '\n';
923 921 }
924 922  
925 923 pdf.replaceReserved(res2, array2);
926 924  
927 925 res2.assertArray();
928   - std::cout << "res2 is an array" << std::endl;
  926 + std::cout << "res2 is an array" << '\n';
929 927  
930 928 // Verify that the previously added reserved keys can be
931 929 // dereferenced properly now
932 930 int i1 = res1.getArrayItem(0).getArrayItem(1).getIntValueAsInt();
933 931 int i2 = res2.getArrayItem(0).getArrayItem(1).getIntValueAsInt();
934 932 if ((i1 == 2) && (i2 == 1)) {
935   - std::cout << "circular access and lazy resolution worked" << std::endl;
  933 + std::cout << "circular access and lazy resolution worked" << '\n';
936 934 }
937 935  
938 936 QPDFWriter w(pdf, "a.pdf");
... ... @@ -1078,15 +1076,15 @@ test_28(QPDF&amp; pdf, char const* arg2)
1078 1076 // Copy foreign object errors
1079 1077 try {
1080 1078 pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest"));
1081   - std::cout << "oops -- didn't throw" << std::endl;
  1079 + std::cout << "oops -- didn't throw" << '\n';
1082 1080 } catch (std::logic_error const& e) {
1083   - std::cout << "logic error: " << e.what() << std::endl;
  1081 + std::cout << "logic error: " << e.what() << '\n';
1084 1082 }
1085 1083 try {
1086 1084 pdf.copyForeignObject(QPDFObjectHandle::newInteger(1));
1087   - std::cout << "oops -- didn't throw" << std::endl;
  1085 + std::cout << "oops -- didn't throw" << '\n';
1088 1086 } catch (std::logic_error const& e) {
1089   - std::cout << "logic error: " << e.what() << std::endl;
  1087 + std::cout << "logic error: " << e.what() << '\n';
1090 1088 }
1091 1089 }
1092 1090  
... ... @@ -1111,9 +1109,9 @@ test_29(QPDF&amp; pdf, char const* arg2)
1111 1109 try {
1112 1110 QPDFWriter w(*other, "a.pdf");
1113 1111 w.write();
1114   - std::cout << "oops -- didn't throw" << std::endl;
  1112 + std::cout << "oops -- didn't throw" << '\n';
1115 1113 } catch (std::logic_error const& e) {
1116   - std::cout << "logic error: " << e.what() << std::endl;
  1114 + std::cout << "logic error: " << e.what() << '\n';
1117 1115 }
1118 1116  
1119 1117 // Make sure deleting the other source doesn't prevent detection.
... ... @@ -1126,9 +1124,9 @@ test_29(QPDF&amp; pdf, char const* arg2)
1126 1124 try {
1127 1125 QPDFWriter w(*other, "a.pdf");
1128 1126 w.write();
1129   - std::cout << "oops -- didn't throw" << std::endl;
  1127 + std::cout << "oops -- didn't throw" << '\n';
1130 1128 } catch (std::logic_error const& e) {
1131   - std::cout << "logic error: " << e.what() << std::endl;
  1129 + std::cout << "logic error: " << e.what() << '\n';
1132 1130 }
1133 1131  
1134 1132 // Detect adding a foreign object
... ... @@ -1137,7 +1135,7 @@ test_29(QPDF&amp; pdf, char const* arg2)
1137 1135 try {
1138 1136 root1.replaceKey("/Oops", root2);
1139 1137 } catch (std::logic_error const& e) {
1140   - std::cout << "logic error: " << e.what() << std::endl;
  1138 + std::cout << "logic error: " << e.what() << '\n';
1141 1139 }
1142 1140 }
1143 1141  
... ... @@ -1160,10 +1158,10 @@ test_30(QPDF&amp; pdf, char const* arg2)
1160 1158 pages = final.getAllPages();
1161 1159 std::string new_contents = getPageContents(pages.at(0));
1162 1160 if (orig_contents != new_contents) {
1163   - std::cout << "oops -- page contents don't match" << std::endl
  1161 + std::cout << "oops -- page contents don't match" << '\n'
1164 1162 << "original:\n"
1165 1163 << orig_contents << "new:\n"
1166   - << new_contents << std::endl;
  1164 + << new_contents << '\n';
1167 1165 }
1168 1166 }
1169 1167  
... ... @@ -1172,20 +1170,20 @@ test_31(QPDF&amp; pdf, char const* arg2)
1172 1170 {
1173 1171 auto o1 = "[/name 16059 3.14159 false\n"
1174 1172 " << /key true /other [ (string1) (string2) ] >> null]"_qpdf;
1175   - std::cout << o1.unparse() << std::endl;
  1173 + std::cout << o1.unparse() << '\n';
1176 1174 QPDFObjectHandle o2 = QPDFObjectHandle::parse(" 12345 \f ");
1177 1175 assert(o2.isInteger() && (o2.getIntValue() == 12345));
1178 1176 try {
1179 1177 QPDFObjectHandle::parse("[1 0 R]", "indirect test");
1180   - std::cout << "oops -- didn't throw" << std::endl;
  1178 + std::cout << "oops -- didn't throw" << '\n';
1181 1179 } catch (std::logic_error const& e) {
1182   - std::cout << "logic error parsing indirect: " << e.what() << std::endl;
  1180 + std::cout << "logic error parsing indirect: " << e.what() << '\n';
1183 1181 }
1184 1182 try {
1185 1183 QPDFObjectHandle::parse("0 trailing", "trailing test");
1186   - std::cout << "oops -- didn't throw" << std::endl;
  1184 + std::cout << "oops -- didn't throw" << '\n';
1187 1185 } catch (std::runtime_error const& e) {
1188   - std::cout << "trailing data: " << e.what() << std::endl;
  1186 + std::cout << "trailing data: " << e.what() << '\n';
1189 1187 }
1190 1188 assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger());
1191 1189 assert(!QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isDirectNull());
... ... @@ -1218,9 +1216,9 @@ test_32(QPDF&amp; pdf, char const* arg2)
1218 1216 bool newline = ((i & 2) != 0);
1219 1217 QPDFWriter w(pdf, filenames[i]);
1220 1218 w.setStaticID(true);
1221   - std::cout << "file: " << filenames[i] << std::endl
1222   - << "linearized: " << (linearized ? "yes" : "no") << std::endl
1223   - << "newline: " << (newline ? "yes" : "no") << std::endl;
  1219 + std::cout << "file: " << filenames[i] << '\n'
  1220 + << "linearized: " << (linearized ? "yes" : "no") << '\n'
  1221 + << "newline: " << (newline ? "yes" : "no") << '\n';
1224 1222 w.setLinearization(linearized);
1225 1223 if (linearized) {
1226 1224 w.setCompressStreams(false); // avoid dependency on zlib's output
... ... @@ -1249,14 +1247,14 @@ static void
1249 1247 test_34(QPDF& pdf, char const* arg2)
1250 1248 {
1251 1249 // Look at Extensions dictionary
1252   - std::cout << "version: " << pdf.getPDFVersion() << std::endl
1253   - << "extension level: " << pdf.getExtensionLevel() << std::endl
1254   - << pdf.getRoot().getKey("/Extensions").unparse() << std::endl;
  1250 + std::cout << "version: " << pdf.getPDFVersion() << '\n'
  1251 + << "extension level: " << pdf.getExtensionLevel() << '\n'
  1252 + << pdf.getRoot().getKey("/Extensions").unparse() << '\n';
1255 1253 auto v = pdf.getVersionAsPDFVersion();
1256 1254 std::string v_string;
1257 1255 int extension_level;
1258 1256 v.getVersion(v_string, extension_level);
1259   - std::cout << "As PDFVersion: " << v_string << "/" << extension_level << std::endl;
  1257 + std::cout << "As PDFVersion: " << v_string << "/" << extension_level << '\n';
1260 1258 }
1261 1259  
1262 1260 static void
... ... @@ -1350,7 +1348,7 @@ test_38(QPDF&amp; pdf, char const* arg2)
1350 1348 // Designed for override-compressed-object.pdf
1351 1349 QPDFObjectHandle qtest = pdf.getRoot().getKey("/QTest");
1352 1350 for (int i = 0; i < qtest.getArrayNItems(); ++i) {
1353   - std::cout << qtest.getArrayItem(i).unparseResolved() << std::endl;
  1351 + std::cout << qtest.getArrayItem(i).unparseResolved() << '\n';
1354 1352 }
1355 1353 }
1356 1354  
... ... @@ -1360,13 +1358,13 @@ test_39(QPDF&amp; pdf, char const* arg2)
1360 1358 // Display image filter and color set for each image on each page
1361 1359 int pageno = 0;
1362 1360 for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1363   - std::cout << "page " << ++pageno << std::endl;
  1361 + std::cout << "page " << ++pageno << '\n';
1364 1362 std::map<std::string, QPDFObjectHandle> images = page.getImages();
1365 1363 for (auto& i_iter: images) {
1366 1364 QPDFObjectHandle image_dict = i_iter.second.getDict();
1367 1365 std::cout << "filter: " << image_dict.getKey("/Filter").unparseResolved()
1368 1366 << ", color space: " << image_dict.getKey("/ColorSpace").unparseResolved()
1369   - << std::endl;
  1367 + << '\n';
1370 1368 }
1371 1369 }
1372 1370 }
... ... @@ -1442,7 +1440,7 @@ test_42(QPDF&amp; pdf, char const* arg2)
1442 1440 assert(i == di.end());
1443 1441 assert(!i_value.second);
1444 1442 }
1445   - assert("" == qtest.getStringValue());
  1443 + assert(qtest.getStringValue().empty());
1446 1444 array.getArrayItem(-1).assertNull();
1447 1445 array.getArrayItem(16059).assertNull();
1448 1446 integer.getArrayItem(0).assertNull();
... ... @@ -1578,51 +1576,51 @@ test_43(QPDF&amp; pdf, char const* arg2)
1578 1576 }
1579 1577 std::cout << "iterating over form fields\n";
1580 1578 for (auto& ffh: afdh.getFormFields()) {
1581   - std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
  1579 + std::cout << "Field: " << ffh.getObjectHandle().unparse() << '\n';
1582 1580 QPDFFormFieldObjectHelper node = ffh;
1583 1581 while (!node.isNull()) {
1584 1582 QPDFFormFieldObjectHelper parent(node.getParent());
1585 1583 std::cout << " Parent: "
1586 1584 << (parent.isNull() ? std::string("none")
1587 1585 : parent.getObjectHandle().unparse())
1588   - << std::endl;
  1586 + << '\n';
1589 1587 node = parent;
1590 1588 }
1591   - std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() << std::endl;
1592   - std::cout << " Partial name: " << ffh.getPartialName() << std::endl;
1593   - std::cout << " Alternative name: " << ffh.getAlternativeName() << std::endl;
1594   - std::cout << " Mapping name: " << ffh.getMappingName() << std::endl;
1595   - std::cout << " Field type: " << ffh.getFieldType() << std::endl;
1596   - std::cout << " Value: " << ffh.getValue().unparse() << std::endl;
1597   - std::cout << " Value as string: " << ffh.getValueAsString() << std::endl;
1598   - std::cout << " Default value: " << ffh.getDefaultValue().unparse() << std::endl;
1599   - std::cout << " Default value as string: " << ffh.getDefaultValueAsString() << std::endl;
1600   - std::cout << " Default appearance: " << ffh.getDefaultAppearance() << std::endl;
1601   - std::cout << " Quadding: " << ffh.getQuadding() << std::endl;
  1589 + std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() << '\n';
  1590 + std::cout << " Partial name: " << ffh.getPartialName() << '\n';
  1591 + std::cout << " Alternative name: " << ffh.getAlternativeName() << '\n';
  1592 + std::cout << " Mapping name: " << ffh.getMappingName() << '\n';
  1593 + std::cout << " Field type: " << ffh.getFieldType() << '\n';
  1594 + std::cout << " Value: " << ffh.getValue().unparse() << '\n';
  1595 + std::cout << " Value as string: " << ffh.getValueAsString() << '\n';
  1596 + std::cout << " Default value: " << ffh.getDefaultValue().unparse() << '\n';
  1597 + std::cout << " Default value as string: " << ffh.getDefaultValueAsString() << '\n';
  1598 + std::cout << " Default appearance: " << ffh.getDefaultAppearance() << '\n';
  1599 + std::cout << " Quadding: " << ffh.getQuadding() << '\n';
1602 1600 std::vector<QPDFAnnotationObjectHelper> annotations = afdh.getAnnotationsForField(ffh);
1603 1601 for (auto& aoh: annotations) {
1604   - std::cout << " Annotation: " << aoh.getObjectHandle().unparse() << std::endl;
  1602 + std::cout << " Annotation: " << aoh.getObjectHandle().unparse() << '\n';
1605 1603 }
1606 1604 }
1607 1605 std::cout << "iterating over annotations per page\n";
1608 1606 for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
1609   - std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
  1607 + std::cout << "Page: " << page.getObjectHandle().unparse() << '\n';
1610 1608 for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) {
1611   - std::cout << " Annotation: " << ah.getObjectHandle().unparse() << std::endl;
  1609 + std::cout << " Annotation: " << ah.getObjectHandle().unparse() << '\n';
1612 1610 std::cout << " Field: "
1613   - << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) << std::endl;
1614   - std::cout << " Subtype: " << ah.getSubtype() << std::endl;
  1611 + << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) << '\n';
  1612 + std::cout << " Subtype: " << ah.getSubtype() << '\n';
1615 1613 std::cout << " Rect: ";
1616 1614 print_rect(std::cout, ah.getRect());
1617   - std::cout << std::endl;
  1615 + std::cout << '\n';
1618 1616 std::string state = ah.getAppearanceState();
1619 1617 if (!state.empty()) {
1620   - std::cout << " Appearance state: " << state << std::endl;
  1618 + std::cout << " Appearance state: " << state << '\n';
1621 1619 }
1622 1620 std::cout << " Appearance stream (/N): " << ah.getAppearanceStream("/N").unparse()
1623   - << std::endl;
  1621 + << '\n';
1624 1622 std::cout << " Appearance stream (/N, /3): "
1625   - << ah.getAppearanceStream("/N", "/3").unparse() << std::endl;
  1623 + << ah.getAppearanceStream("/N", "/3").unparse() << '\n';
1626 1624 }
1627 1625 }
1628 1626 }
... ... @@ -1637,7 +1635,7 @@ test_44(QPDF&amp; pdf, char const* arg2)
1637 1635 // \xc3\xb7 is utf-8 for U+00F7 (divided by)
1638 1636 field.setV("3.14 \xc3\xb7 0");
1639 1637 std::cout << "Set field value: " << field.getFullyQualifiedName() << " -> "
1640   - << field.getValueAsString() << std::endl;
  1638 + << field.getValueAsString() << '\n';
1641 1639 }
1642 1640 }
1643 1641 QPDFWriter w(pdf, "a.pdf");
... ... @@ -1669,11 +1667,11 @@ test_46(QPDF&amp; pdf, char const* arg2)
1669 1667 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
1670 1668 QPDFNumberTreeObjectHelper ntoh(qtest, pdf);
1671 1669 for (auto& iter: ntoh) {
1672   - std::cout << iter.first << " " << iter.second.getStringValue() << std::endl;
  1670 + std::cout << iter.first << " " << iter.second.getStringValue() << '\n';
1673 1671 }
1674 1672 QPDFNumberTreeObjectHelper::idx_map ntoh_map = ntoh.getAsMap();
1675 1673 for (auto& iter: ntoh_map) {
1676   - std::cout << iter.first << " " << iter.second.getStringValue() << std::endl;
  1674 + std::cout << iter.first << " " << iter.second.getStringValue() << '\n';
1677 1675 }
1678 1676 assert(1 == ntoh.getMin());
1679 1677 assert(29 == ntoh.getMax());
... ... @@ -1719,7 +1717,7 @@ test_46(QPDF&amp; pdf, char const* arg2)
1719 1717 --iter1;
1720 1718 assert(iter1->first == 2);
1721 1719  
1722   - std::cout << "insertAfter" << std::endl;
  1720 + std::cout << "insertAfter" << '\n';
1723 1721 auto new2 = QPDFNumberTreeObjectHelper::newEmpty(pdf);
1724 1722 auto iter2 = new2.begin();
1725 1723 assert(iter2 == new2.end());
... ... @@ -1728,23 +1726,23 @@ test_46(QPDF&amp; pdf, char const* arg2)
1728 1726 iter2.insertAfter(4, QPDFObjectHandle::newString("4!"));
1729 1727 assert(iter2->first == 4);
1730 1728 for (auto& i: new2) {
1731   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  1729 + std::cout << i.first << " " << i.second.unparse() << '\n';
1732 1730 }
1733 1731  
1734   - std::cout << "/Bad1" << std::endl;
  1732 + std::cout << "/Bad1" << '\n';
1735 1733 auto bad1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf);
1736 1734 assert(bad1.begin() == bad1.end());
1737 1735 assert(bad1.last() == bad1.end());
1738 1736  
1739   - std::cout << "/Bad2" << std::endl;
  1737 + std::cout << "/Bad2" << '\n';
1740 1738 auto bad2 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf);
1741 1739 for (auto& i: bad2) {
1742   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  1740 + std::cout << i.first << " " << i.second.unparse() << '\n';
1743 1741 }
1744 1742  
1745 1743 std::vector<std::string> empties = {"/Empty1", "/Empty2"};
1746 1744 for (auto const& k: empties) {
1747   - std::cout << k << std::endl;
  1745 + std::cout << k << '\n';
1748 1746 auto empty = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey(k), pdf);
1749 1747 assert(empty.begin() == empty.end());
1750 1748 assert(empty.last() == empty.end());
... ... @@ -1765,37 +1763,37 @@ test_46(QPDF&amp; pdf, char const* arg2)
1765 1763 assert(empty.last()->first == 6);
1766 1764 assert(empty.last()->second.getStringValue() == "6");
1767 1765 }
1768   - std::cout << "Insert into invalid" << std::endl;
  1766 + std::cout << "Insert into invalid" << '\n';
1769 1767 auto invalid1 = QPDFNumberTreeObjectHelper(QPDFObjectHandle::newDictionary(), pdf);
1770 1768 try {
1771 1769 invalid1.insert(1, QPDFObjectHandle::newNull());
1772 1770 } catch (QPDFExc& e) {
1773   - std::cout << e.what() << std::endl;
  1771 + std::cout << e.what() << '\n';
1774 1772 }
1775 1773  
1776   - std::cout << "/Bad3, no repair" << std::endl;
  1774 + std::cout << "/Bad3, no repair" << '\n';
1777 1775 auto bad3_oh = pdf.getTrailer().getKey("/Bad3");
1778 1776 auto bad3 = QPDFNumberTreeObjectHelper(bad3_oh, pdf, false);
1779 1777 for (auto& i: bad3) {
1780   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  1778 + std::cout << i.first << " " << i.second.unparse() << '\n';
1781 1779 }
1782 1780 assert(!bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect());
1783 1781  
1784   - std::cout << "/Bad3, repair" << std::endl;
  1782 + std::cout << "/Bad3, repair" << '\n';
1785 1783 bad3 = QPDFNumberTreeObjectHelper(bad3_oh, pdf, true);
1786 1784 for (auto& i: bad3) {
1787   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  1785 + std::cout << i.first << " " << i.second.unparse() << '\n';
1788 1786 }
1789 1787 assert(bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect());
1790 1788  
1791   - std::cout << "/Bad4 -- missing limits" << std::endl;
  1789 + std::cout << "/Bad4 -- missing limits" << '\n';
1792 1790 auto bad4 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf);
1793 1791 bad4.insert(5, QPDFObjectHandle::newString("5"));
1794 1792 for (auto& i: bad4) {
1795   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  1793 + std::cout << i.first << " " << i.second.unparse() << '\n';
1796 1794 }
1797 1795  
1798   - std::cout << "/Bad5 -- limit errors" << std::endl;
  1796 + std::cout << "/Bad5 -- limit errors" << '\n';
1799 1797 auto bad5 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf);
1800 1798 assert(bad5.find(10) == bad5.end());
1801 1799 }
... ... @@ -1810,7 +1808,7 @@ test_47(QPDF&amp; pdf, char const* arg2)
1810 1808 pldh.getLabelsForPageRange(0, npages - 1, 1, labels);
1811 1809 assert(labels.size() % 2 == 0);
1812 1810 for (size_t i = 0; i < labels.size(); i += 2) {
1813   - std::cout << labels.at(i).getIntValue() << " " << labels.at(i + 1).unparse() << std::endl;
  1811 + std::cout << labels.at(i).getIntValue() << " " << labels.at(i + 1).unparse() << '\n';
1814 1812 }
1815 1813 }
1816 1814  
... ... @@ -1822,11 +1820,11 @@ test_48(QPDF&amp; pdf, char const* arg2)
1822 1820 QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
1823 1821 QPDFNameTreeObjectHelper ntoh(qtest, pdf);
1824 1822 for (auto& iter: ntoh) {
1825   - std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl;
  1823 + std::cout << iter.first << " -> " << iter.second.getStringValue() << '\n';
1826 1824 }
1827 1825 std::map<std::string, QPDFObjectHandle> ntoh_map = ntoh.getAsMap();
1828 1826 for (auto& iter: ntoh_map) {
1829   - std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl;
  1827 + std::cout << iter.first << " -> " << iter.second.getStringValue() << '\n';
1830 1828 }
1831 1829 assert(ntoh.hasName("11 elephant"));
1832 1830 assert(ntoh.hasName("07 sev\xe2\x80\xa2n"));
... ... @@ -1869,7 +1867,7 @@ test_48(QPDF&amp; pdf, char const* arg2)
1869 1867 --iter1;
1870 1868 assert(iter1->first == "2");
1871 1869  
1872   - std::cout << "insertAfter" << std::endl;
  1870 + std::cout << "insertAfter" << '\n';
1873 1871 auto new2 = QPDFNameTreeObjectHelper::newEmpty(pdf);
1874 1872 auto iter2 = new2.begin();
1875 1873 assert(iter2 == new2.end());
... ... @@ -1878,12 +1876,12 @@ test_48(QPDF&amp; pdf, char const* arg2)
1878 1876 iter2.insertAfter("4", QPDFObjectHandle::newString("4!"));
1879 1877 assert(iter2->first == "4");
1880 1878 for (auto& i: new2) {
1881   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  1879 + std::cout << i.first << " " << i.second.unparse() << '\n';
1882 1880 }
1883 1881  
1884 1882 std::vector<std::string> empties = {"/Empty1", "/Empty2"};
1885 1883 for (auto const& k: empties) {
1886   - std::cout << k << std::endl;
  1884 + std::cout << k << '\n';
1887 1885 auto empty = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey(k), pdf);
1888 1886 assert(empty.begin() == empty.end());
1889 1887 assert(empty.last() == empty.end());
... ... @@ -1905,36 +1903,36 @@ test_48(QPDF&amp; pdf, char const* arg2)
1905 1903 assert(empty.last()->second.getStringValue() == "6");
1906 1904 }
1907 1905  
1908   - std::cout << "/Bad1 -- wrong key type" << std::endl;
  1906 + std::cout << "/Bad1 -- wrong key type" << '\n';
1909 1907 auto bad1 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf);
1910 1908 assert(bad1.find("G", true)->first == "A");
1911 1909 for (auto const& i: bad1) {
1912   - std::cout << i.first << std::endl;
  1910 + std::cout << i.first << '\n';
1913 1911 }
1914 1912  
1915   - std::cout << "/Bad2 -- invalid kid" << std::endl;
  1913 + std::cout << "/Bad2 -- invalid kid" << '\n';
1916 1914 auto bad2 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf);
1917 1915 assert(bad2.find("G", true)->first == "B");
1918 1916 for (auto const& i: bad2) {
1919   - std::cout << i.first << std::endl;
  1917 + std::cout << i.first << '\n';
1920 1918 }
1921 1919  
1922   - std::cout << "/Bad3 -- invalid kid" << std::endl;
  1920 + std::cout << "/Bad3 -- invalid kid" << '\n';
1923 1921 auto bad3 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad3"), pdf);
1924 1922 assert(bad3.find("G", true) == bad3.end());
1925 1923  
1926   - std::cout << "/Bad4 -- invalid kid" << std::endl;
  1924 + std::cout << "/Bad4 -- invalid kid" << '\n';
1927 1925 auto bad4 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf);
1928 1926 assert(bad4.find("F", true)->first == "C");
1929 1927 for (auto const& i: bad4) {
1930   - std::cout << i.first << std::endl;
  1928 + std::cout << i.first << '\n';
1931 1929 }
1932 1930  
1933   - std::cout << "/Bad5 -- loop in find" << std::endl;
  1931 + std::cout << "/Bad5 -- loop in find" << '\n';
1934 1932 auto bad5 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf);
1935 1933 assert(bad5.find("F", true)->first == "D");
1936 1934  
1937   - std::cout << "/Bad6 -- bad limits" << std::endl;
  1935 + std::cout << "/Bad6 -- bad limits" << '\n';
1938 1936 auto bad6 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad6"), pdf);
1939 1937 assert(bad6.insert("H", QPDFObjectHandle::newNull())->first == "H");
1940 1938 }
... ... @@ -1949,7 +1947,7 @@ test_49(QPDF&amp; pdf, char const* arg2)
1949 1947 auto outlines = odh.getOutlinesForPage(page.getObjectHandle().getObjGen());
1950 1948 for (auto& ol: outlines) {
1951 1949 std::cout << "page " << pageno << ": " << ol.getTitle() << " -> "
1952   - << ol.getDest().unparseResolved() << std::endl;
  1950 + << ol.getDest().unparseResolved() << '\n';
1953 1951 }
1954 1952 ++pageno;
1955 1953 }
... ... @@ -1963,11 +1961,11 @@ test_50(QPDF&amp; pdf, char const* arg2)
1963 1961 QPDFObjectHandle d1 = pdf.getTrailer().getKey("/Dict1");
1964 1962 QPDFObjectHandle d2 = pdf.getTrailer().getKey("/Dict2");
1965 1963 d1.mergeResources(d2);
1966   - std::cout << d1.getJSON(JSON::LATEST).unparse() << std::endl;
  1964 + std::cout << d1.getJSON(JSON::LATEST).unparse() << '\n';
1967 1965 // Top-level type mismatch
1968 1966 d1.mergeResources(d2.getKey("/k1"));
1969 1967 for (auto const& name: d1.getResourceNames()) {
1970   - std::cout << name << std::endl;
  1968 + std::cout << name << '\n';
1971 1969 }
1972 1970 }
1973 1971  
... ... @@ -2047,10 +2045,10 @@ test_53(QPDF&amp; pdf, char const* arg2)
2047 2045 QPDFObjectHandle root = pdf.getRoot();
2048 2046 auto new_obj = pdf.makeIndirectObject(QPDFObjectHandle::newString("potato"));
2049 2047 root.replaceKey("/Q1", new_obj);
2050   - std::cout << "new object: " << new_obj.unparse() << std::endl;
2051   - std::cout << "all objects" << std::endl;
  2048 + std::cout << "new object: " << new_obj.unparse() << '\n';
  2049 + std::cout << "all objects" << '\n';
2052 2050 for (auto& obj: pdf.getAllObjects()) {
2053   - std::cout << obj.unparse() << std::endl;
  2051 + std::cout << obj.unparse() << '\n';
2054 2052 }
2055 2053  
2056 2054 QPDFWriter w(pdf, "a.pdf");
... ... @@ -2068,7 +2066,7 @@ test_54(QPDF&amp; pdf, char const* arg2)
2068 2066 assert(pdf.getPDFVersion() != "1.5");
2069 2067 w.setObjectStreamMode(qpdf_o_generate);
2070 2068 if (w.getFinalVersion() != "1.5") {
2071   - std::cout << "oops: " << w.getFinalVersion() << std::endl;
  2069 + std::cout << "oops: " << w.getFinalVersion() << '\n';
2072 2070 }
2073 2071 }
2074 2072  
... ... @@ -2193,11 +2191,11 @@ test_60(QPDF&amp; pdf, char const* arg2)
2193 2191  
2194 2192 std::map<std::string, std::map<std::string, std::string>> conflicts;
2195 2193 auto show_conflicts = [&](std::string const& msg) {
2196   - std::cout << msg << std::endl;
  2194 + std::cout << msg << '\n';
2197 2195 for (auto const& i1: conflicts) {
2198   - std::cout << i1.first << ":" << std::endl;
  2196 + std::cout << i1.first << ":" << '\n';
2199 2197 for (auto const& i2: i1.second) {
2200   - std::cout << " " << i2.first << " -> " << i2.second << std::endl;
  2198 + std::cout << " " << i2.first << " -> " << i2.second << '\n';
2201 2199 }
2202 2200 }
2203 2201 };
... ... @@ -2242,22 +2240,22 @@ test_61(QPDF&amp; pdf, char const* arg2)
2242 2240 try {
2243 2241 pdf.processMemoryFile("empty", "", 0);
2244 2242 } catch (QPDFExc const&) {
2245   - std::cout << "Caught QPDFExc as expected" << std::endl;
  2243 + std::cout << "Caught QPDFExc as expected" << '\n';
2246 2244 }
2247 2245 try {
2248 2246 QUtil::safe_fopen("/does/not/exist", "r");
2249 2247 } catch (QPDFSystemError const&) {
2250   - std::cout << "Caught QPDFSystemError as expected" << std::endl;
  2248 + std::cout << "Caught QPDFSystemError as expected" << '\n';
2251 2249 }
2252 2250 try {
2253 2251 QUtil::int_to_string_base(0, 12);
2254 2252 } catch (std::logic_error const&) {
2255   - std::cout << "Caught logic_error as expected" << std::endl;
  2253 + std::cout << "Caught logic_error as expected" << '\n';
2256 2254 }
2257 2255 try {
2258 2256 QUtil::toUTF8(0xffffffff);
2259 2257 } catch (std::runtime_error const&) {
2260   - std::cout << "Caught runtime_error as expected" << std::endl;
  2258 + std::cout << "Caught runtime_error as expected" << '\n';
2261 2259 }
2262 2260  
2263 2261 // Spot check RTTI for dynamic cast. We intend to have pipelines
... ... @@ -2389,18 +2387,18 @@ test_68(QPDF&amp; pdf, char const* arg2)
2389 2387 QPDFObjectHandle qstream = root.getKey("/QStream");
2390 2388 try {
2391 2389 qstream.getStreamData();
2392   - std::cout << "oops -- didn't throw" << std::endl;
  2390 + std::cout << "oops -- didn't throw" << '\n';
2393 2391 } catch (std::exception& e) {
2394   - std::cout << "get unfilterable stream: " << e.what() << std::endl;
  2392 + std::cout << "get unfilterable stream: " << e.what() << '\n';
2395 2393 }
2396 2394 std::shared_ptr<Buffer> b1 = qstream.getStreamData(qpdf_dl_all);
2397 2395 if ((b1->getSize() > 10) && (memcmp(b1->getBuffer(), "wwwwwwwww", 9) == 0)) {
2398   - std::cout << "filtered stream data okay" << std::endl;
  2396 + std::cout << "filtered stream data okay" << '\n';
2399 2397 }
2400 2398 std::shared_ptr<Buffer> b2 = qstream.getRawStreamData();
2401 2399 if ((b2->getSize() > 10) &&
2402 2400 (memcmp(b2->getBuffer(), "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) == 0)) {
2403   - std::cout << "raw stream data okay" << std::endl;
  2401 + std::cout << "raw stream data okay" << '\n';
2404 2402 }
2405 2403 }
2406 2404  
... ... @@ -2436,42 +2434,42 @@ static void
2436 2434 test_71(QPDF& pdf, char const* arg2)
2437 2435 {
2438 2436 auto show = [](QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key) {
2439   - std::cout << xobj_dict.unparse() << " -> " << key << " -> " << obj.unparse() << std::endl;
  2437 + std::cout << xobj_dict.unparse() << " -> " << key << " -> " << obj.unparse() << '\n';
2440 2438 };
2441 2439 auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0);
2442   - std::cout << "--- recursive, all ---" << std::endl;
  2440 + std::cout << "--- recursive, all ---" << '\n';
2443 2441 page.forEachXObject(true, show);
2444   - std::cout << "--- non-recursive, all ---" << std::endl;
  2442 + std::cout << "--- non-recursive, all ---" << '\n';
2445 2443 page.forEachXObject(false, show);
2446   - std::cout << "--- recursive, images ---" << std::endl;
  2444 + std::cout << "--- recursive, images ---" << '\n';
2447 2445 page.forEachImage(true, show);
2448   - std::cout << "--- non-recursive, images ---" << std::endl;
  2446 + std::cout << "--- non-recursive, images ---" << '\n';
2449 2447 page.forEachImage(false, show);
2450   - std::cout << "--- recursive, form XObjects ---" << std::endl;
  2448 + std::cout << "--- recursive, form XObjects ---" << '\n';
2451 2449 page.forEachFormXObject(true, show);
2452   - std::cout << "--- non-recursive, form XObjects ---" << std::endl;
  2450 + std::cout << "--- non-recursive, form XObjects ---" << '\n';
2453 2451 page.forEachFormXObject(false, show);
2454 2452 auto fx1 = QPDFPageObjectHelper(
2455 2453 page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1"));
2456   - std::cout << "--- recursive, all, from fx1 ---" << std::endl;
  2454 + std::cout << "--- recursive, all, from fx1 ---" << '\n';
2457 2455 fx1.forEachXObject(true, show);
2458   - std::cout << "--- non-recursive, all, from fx1 ---" << std::endl;
  2456 + std::cout << "--- non-recursive, all, from fx1 ---" << '\n';
2459 2457 fx1.forEachXObject(false, show);
2460   - std::cout << "--- get images, page ---" << std::endl;
  2458 + std::cout << "--- get images, page ---" << '\n';
2461 2459 for (auto& i: page.getImages()) {
2462   - std::cout << i.first << " -> " << i.second.unparse() << std::endl;
  2460 + std::cout << i.first << " -> " << i.second.unparse() << '\n';
2463 2461 }
2464   - std::cout << "--- get images, fx ---" << std::endl;
  2462 + std::cout << "--- get images, fx ---" << '\n';
2465 2463 for (auto& i: fx1.getImages()) {
2466   - std::cout << i.first << " -> " << i.second.unparse() << std::endl;
  2464 + std::cout << i.first << " -> " << i.second.unparse() << '\n';
2467 2465 }
2468   - std::cout << "--- get form XObjects, page ---" << std::endl;
  2466 + std::cout << "--- get form XObjects, page ---" << '\n';
2469 2467 for (auto& i: page.getFormXObjects()) {
2470   - std::cout << i.first << " -> " << i.second.unparse() << std::endl;
  2468 + std::cout << i.first << " -> " << i.second.unparse() << '\n';
2471 2469 }
2472   - std::cout << "--- get form XObjects, fx ---" << std::endl;
  2470 + std::cout << "--- get form XObjects, fx ---" << '\n';
2473 2471 for (auto& i: fx1.getFormXObjects()) {
2474   - std::cout << i.first << " -> " << i.second.unparse() << std::endl;
  2472 + std::cout << i.first << " -> " << i.second.unparse() << '\n';
2475 2473 }
2476 2474 }
2477 2475  
... ... @@ -2482,7 +2480,7 @@ test_72(QPDF&amp; pdf, char const* arg2)
2482 2480 auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0);
2483 2481 auto fx1 = QPDFPageObjectHelper(
2484 2482 page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1"));
2485   - std::cout << "--- parseContents ---" << std::endl;
  2483 + std::cout << "--- parseContents ---" << '\n';
2486 2484 ParserCallbacks cb;
2487 2485 fx1.parseContents(&cb);
2488 2486 // Do this once with addContentTokenFilter and once with
... ... @@ -2511,7 +2509,7 @@ test_73(QPDF&amp; pdf, char const* arg2)
2511 2509 QPDF pdf2;
2512 2510 pdf2.getRoot();
2513 2511 } catch (std::exception& e) {
2514   - std::cerr << "getRoot: " << e.what() << std::endl;
  2512 + std::cerr << "getRoot: " << e.what() << '\n';
2515 2513 }
2516 2514  
2517 2515 pdf.closeInputSource();
... ... @@ -2522,7 +2520,7 @@ static void
2522 2520 test_74(QPDF& pdf, char const* arg2)
2523 2521 {
2524 2522 // This test is crafted to work with split-nntree.pdf
2525   - std::cout << "/Split1" << std::endl;
  2523 + std::cout << "/Split1" << '\n';
2526 2524 auto split1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Split1"), pdf);
2527 2525 split1.setSplitThreshold(4);
2528 2526 auto check_split1 = [&split1](int k) {
... ... @@ -2533,10 +2531,10 @@ test_74(QPDF&amp; pdf, char const* arg2)
2533 2531 check_split1(35);
2534 2532 check_split1(125);
2535 2533 for (auto const& i: split1) {
2536   - std::cout << i.first << std::endl;
  2534 + std::cout << i.first << '\n';
2537 2535 }
2538 2536  
2539   - std::cout << "/Split2" << std::endl;
  2537 + std::cout << "/Split2" << '\n';
2540 2538 auto split2 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split2"), pdf);
2541 2539 split2.setSplitThreshold(4);
2542 2540 auto check_split2 = [](QPDFNameTreeObjectHelper& noh, std::string const& k) {
... ... @@ -2545,16 +2543,16 @@ test_74(QPDF&amp; pdf, char const* arg2)
2545 2543 };
2546 2544 check_split2(split2, "C");
2547 2545 for (auto const& i: split2) {
2548   - std::cout << i.first << std::endl;
  2546 + std::cout << i.first << '\n';
2549 2547 }
2550 2548  
2551   - std::cout << "/Split3" << std::endl;
  2549 + std::cout << "/Split3" << '\n';
2552 2550 auto split3 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split3"), pdf);
2553 2551 split3.setSplitThreshold(4);
2554 2552 check_split2(split3, "P");
2555 2553 check_split2(split3, "\xcf\x80");
2556 2554 for (auto& i: split3) {
2557   - std::cout << i.first << " " << i.second.unparse() << std::endl;
  2555 + std::cout << i.first << " " << i.second.unparse() << '\n';
2558 2556 }
2559 2557  
2560 2558 QPDFWriter w(pdf, "a.pdf");
... ... @@ -2655,7 +2653,7 @@ test_76(QPDF&amp; pdf, char const* arg2)
2655 2653 assert(QUtil::hex_encode(efs2.getChecksum()) == "2fce9c8228e360ba9b04a1bd1bf63d6b");
2656 2654  
2657 2655 for (auto const& iter: efdh.getEmbeddedFiles()) {
2658   - std::cout << iter.first << " -> " << iter.second->getFilename() << std::endl;
  2656 + std::cout << iter.first << " -> " << iter.second->getFilename() << '\n';
2659 2657 }
2660 2658 assert(efdh.getEmbeddedFile("att1")->getFilename() == "att1.txt");
2661 2659 assert(!efdh.getEmbeddedFile("potato"));
... ... @@ -2689,17 +2687,17 @@ test_78(QPDF&amp; pdf, char const* arg2)
2689 2687 p->finish();
2690 2688 };
2691 2689 auto f2 = [](Pipeline* p, bool suppress_warnings, bool will_retry) {
2692   - std::cerr << "f2" << std::endl;
  2690 + std::cerr << "f2" << '\n';
2693 2691 if (will_retry) {
2694   - std::cerr << "failing" << std::endl;
  2692 + std::cerr << "failing" << '\n';
2695 2693 return false;
2696 2694 }
2697 2695 if (!suppress_warnings) {
2698   - std::cerr << "warning" << std::endl;
  2696 + std::cerr << "warning" << '\n';
2699 2697 }
2700 2698 p->writeCStr("salad");
2701 2699 p->finish();
2702   - std::cerr << "f2 done" << std::endl;
  2700 + std::cerr << "f2 done" << '\n';
2703 2701 return true;
2704 2702 };
2705 2703  
... ... @@ -2709,11 +2707,11 @@ test_78(QPDF&amp; pdf, char const* arg2)
2709 2707 auto s2 = QPDFObjectHandle::newStream(&pdf);
2710 2708 s2.replaceStreamData(f2, null, null);
2711 2709 pdf.getTrailer().replaceKey("/Streams", QPDFObjectHandle::newArray({s1, s2}));
2712   - std::cout << "piping with warning suppression" << std::endl;
  2710 + std::cout << "piping with warning suppression" << '\n';
2713 2711 Pl_Discard d;
2714 2712 s2.pipeStreamData(&d, nullptr, 0, qpdf_dl_all, true, false);
2715 2713  
2716   - std::cout << "writing" << std::endl;
  2714 + std::cout << "writing" << '\n';
2717 2715 QPDFWriter w(pdf, "a.pdf");
2718 2716 w.setStaticID(true);
2719 2717 w.setQDFMode(true);
... ... @@ -2890,13 +2888,13 @@ test_83(QPDF&amp; pdf, char const* arg2)
2890 2888 size_t size;
2891 2889 QUtil::read_file_into_memory(arg2, file_buf, size);
2892 2890 try {
2893   - std::cout << "calling initializeFromJson" << std::endl;
  2891 + std::cout << "calling initializeFromJson" << '\n';
2894 2892 j.initializeFromJson(std::string(file_buf.get(), size));
2895   - std::cout << "called initializeFromJson" << std::endl;
  2893 + std::cout << "called initializeFromJson" << '\n';
2896 2894 } catch (QPDFUsage& e) {
2897   - std::cerr << "usage: " << e.what() << std::endl;
  2895 + std::cerr << "usage: " << e.what() << '\n';
2898 2896 } catch (std::exception& e) {
2899   - std::cerr << "exception: " << e.what() << std::endl;
  2897 + std::cerr << "exception: " << e.what() << '\n';
2900 2898 }
2901 2899 }
2902 2900  
... ... @@ -2905,7 +2903,7 @@ test_84(QPDF&amp; pdf, char const* arg2)
2905 2903 {
2906 2904 // Test QPDFJob API
2907 2905  
2908   - std::cout << "normal" << std::endl;
  2906 + std::cout << "normal" << '\n';
2909 2907 {
2910 2908 QPDFJob j;
2911 2909 j.config()
... ... @@ -2922,11 +2920,11 @@ test_84(QPDF&amp; pdf, char const* arg2)
2922 2920 assert(j.getEncryptionStatus() == 0);
2923 2921 }
2924 2922  
2925   - std::cout << "custom progress reporter" << std::endl;
  2923 + std::cout << "custom progress reporter" << '\n';
2926 2924 {
2927 2925 QPDFJob j;
2928 2926 j.registerProgressReporter(
2929   - [](int p) { std::cout << "custom write progress: " << p << "%" << std::endl; });
  2927 + [](int p) { std::cout << "custom write progress: " << p << "%" << '\n'; });
2930 2928 j.config()
2931 2929 ->inputFile("minimal.pdf")
2932 2930 ->outputFile("a.pdf")
... ... @@ -2941,29 +2939,29 @@ test_84(QPDF&amp; pdf, char const* arg2)
2941 2939 assert(j.getEncryptionStatus() == 0);
2942 2940 }
2943 2941  
2944   - std::cout << "error caught by check" << std::endl;
  2942 + std::cout << "error caught by check" << '\n';
2945 2943 try {
2946 2944 QPDFJob j;
2947 2945 j.config()->outputFile("a.pdf")->qdf();
2948   - std::cout << "finished config" << std::endl;
  2946 + std::cout << "finished config" << '\n';
2949 2947 j.checkConfiguration();
2950 2948 assert(false);
2951 2949 } catch (QPDFUsage& e) {
2952   - std::cout << "usage: " << e.what() << std::endl;
  2950 + std::cout << "usage: " << e.what() << '\n';
2953 2951 }
2954 2952  
2955   - std::cout << "error caught by run" << std::endl;
  2953 + std::cout << "error caught by run" << '\n';
2956 2954 try {
2957 2955 QPDFJob j;
2958 2956 j.config()->outputFile("a.pdf")->qdf();
2959   - std::cout << "finished config" << std::endl;
  2957 + std::cout << "finished config" << '\n';
2960 2958 j.run();
2961 2959 assert(false);
2962 2960 } catch (QPDFUsage& e) {
2963   - std::cout << "usage: " << e.what() << std::endl;
  2961 + std::cout << "usage: " << e.what() << '\n';
2964 2962 }
2965 2963  
2966   - std::cout << "output capture" << std::endl;
  2964 + std::cout << "output capture" << '\n';
2967 2965 std::ostringstream cout;
2968 2966 std::ostringstream cerr;
2969 2967 {
... ... @@ -2980,11 +2978,11 @@ test_84(QPDF&amp; pdf, char const* arg2)
2980 2978 # pragma GCC diagnostic pop
2981 2979 #endif
2982 2980 j.config()->inputFile("bad2.pdf")->showObject("4,0")->checkConfiguration();
2983   - std::cout << "calling run" << std::endl;
  2981 + std::cout << "calling run" << '\n';
2984 2982 j.run();
2985   - std::cout << "captured stdout" << std::endl;
  2983 + std::cout << "captured stdout" << '\n';
2986 2984 std::cout << cout.str();
2987   - std::cout << "captured stderr" << std::endl;
  2985 + std::cout << "captured stderr" << '\n';
2988 2986 std::cout << cerr.str();
2989 2987 }
2990 2988 }
... ... @@ -3111,7 +3109,7 @@ test_87(QPDF&amp; pdf, char const* arg2)
3111 3109 assert(dict.getKeys() == std::set<std::string>({"/A"}));
3112 3110 dict.replaceKey("/A", QPDFObjectHandle::newNull());
3113 3111 assert(dict.unparse() == "<< >>");
3114   - assert(dict.getKeys() == std::set<std::string>());
  3112 + assert(dict.getKeys().empty());
3115 3113 dict = QPDFObjectHandle::newDictionary({
3116 3114 {"/A", "2"_qpdf},
3117 3115 {"/B", QPDFObjectHandle::newNull()},
... ... @@ -3478,7 +3476,7 @@ test_99(QPDF&amp; pdf, char const* arg2)
3478 3476 // Designed for no-space-compressed-object.pdf
3479 3477 QPDFObjectHandle qtest = pdf.getRoot().getKey("/QTest");
3480 3478 for (int i = 0; i < qtest.getArrayNItems(); ++i) {
3481   - std::cout << qtest.getArrayItem(i).unparseResolved() << std::endl;
  3479 + std::cout << qtest.getArrayItem(i).unparseResolved() << '\n';
3482 3480 }
3483 3481 }
3484 3482  
... ... @@ -3621,7 +3619,7 @@ runtest(int n, char const* filename1, char const* arg2)
3621 3619 p[i] = static_cast<char>(p[i] ^ 0xcc);
3622 3620 }
3623 3621 pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), p, size);
3624   - } else if (ignore_filename.count(n)) {
  3622 + } else if (ignore_filename.contains(n)) {
3625 3623 // Ignore filename argument entirely
3626 3624 } else if (n == 89) {
3627 3625 pdf.createFromJSON(filename1);
... ... @@ -3669,7 +3667,7 @@ runtest(int n, char const* filename1, char const* arg2)
3669 3667 if (filep) {
3670 3668 fclose(filep);
3671 3669 }
3672   - std::cout << "test " << n << " done" << std::endl;
  3670 + std::cout << "test " << n << " done" << '\n';
3673 3671 }
3674 3672  
3675 3673 int
... ... @@ -3692,7 +3690,7 @@ main(int argc, char* argv[])
3692 3690 char const* arg2 = argv[3];
3693 3691 runtest(n, filename1, arg2);
3694 3692 } catch (std::exception& e) {
3695   - std::cerr << e.what() << std::endl;
  3693 + std::cerr << e.what() << '\n';
3696 3694 exit(2);
3697 3695 }
3698 3696  
... ...
qpdf/test_large_file.cc
... ... @@ -94,7 +94,7 @@ void
94 94 ImageChecker::finish()
95 95 {
96 96 if (!okay) {
97   - std::cout << "errors found checking image data for page " << n << std::endl;
  97 + std::cout << "errors found checking image data for page " << n << '\n';
98 98 }
99 99 }
100 100  
... ... @@ -120,7 +120,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline)
120 120 if (buf == nullptr) {
121 121 buf = new unsigned char[width * stripesize];
122 122 }
123   - std::cout << "page " << n << " of " << npages << std::endl;
  123 + std::cout << "page " << n << " of " << npages << '\n';
124 124 for (size_t y = 0; y < nstripes; ++y) {
125 125 unsigned char color = get_pixel_color(n, y);
126 126 memset(buf, color, width * stripesize);
... ... @@ -132,7 +132,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline)
132 132 void
133 133 usage()
134 134 {
135   - std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" << std::endl;
  135 + std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" << '\n';
136 136 exit(2);
137 137 }
138 138  
... ... @@ -247,7 +247,7 @@ check_page_contents(size_t pageno, QPDFObjectHandle page)
247 247 std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
248 248 std::string expected_contents = generate_page_contents(pageno);
249 249 if (expected_contents != actual_contents) {
250   - std::cout << "page contents wrong for page " << pageno << std::endl
  250 + std::cout << "page contents wrong for page " << pageno << '\n'
251 251 << "ACTUAL: " << actual_contents << "EXPECTED: " << expected_contents << "----\n";
252 252 }
253 253 }
... ... @@ -269,7 +269,7 @@ check_pdf(char const* filename)
269 269 assert(pages.size() == QIntC::to_size(npages));
270 270 for (size_t i = 0; i < npages; ++i) {
271 271 size_t pageno = i + 1;
272   - std::cout << "page " << pageno << " of " << npages << std::endl;
  272 + std::cout << "page " << pageno << " of " << npages << '\n';
273 273 check_page_contents(pageno, pages.at(i));
274 274 check_image(pageno, pages.at(i));
275 275 }
... ... @@ -316,7 +316,7 @@ main(int argc, char* argv[])
316 316 check_pdf(filename);
317 317 }
318 318 } catch (std::exception& e) {
319   - std::cerr << e.what() << std::endl;
  319 + std::cerr << e.what() << '\n';
320 320 exit(2);
321 321 }
322 322  
... ...
qpdf/test_many_nulls.cc
... ... @@ -10,7 +10,7 @@ main(int argc, char* argv[])
10 10 {
11 11 auto whoami = QUtil::getWhoami(argv[0]);
12 12 if (argc != 2) {
13   - std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl;
  13 + std::cerr << "Usage: " << whoami << " outfile.pdf" << '\n';
14 14 exit(2);
15 15 }
16 16 char const* outfile = argv[1];
... ...
qpdf/test_parsedoffset.cc
... ... @@ -13,7 +13,7 @@
13 13 void
14 14 usage()
15 15 {
16   - std::cerr << "Usage: test_parsedoffset INPUT.pdf" << std::endl;
  16 + std::cerr << "Usage: test_parsedoffset INPUT.pdf" << '\n';
17 17 }
18 18  
19 19 std::string
... ... @@ -77,9 +77,9 @@ process(std::string fn, std::vector&lt;std::vector&lt;std::pair&lt;qpdf_offset_t, std::st
77 77 std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
78 78  
79 79 for (auto const& oh: qpdf.getAllObjects()) {
80   - if (xrefs.count(oh.getObjGen()) == 0) {
  80 + if (!xrefs.contains(oh.getObjGen())) {
81 81 std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
82   - << " is not found in xref table" << std::endl;
  82 + << " is not found in xref table" << '\n';
83 83 std::exit(2);
84 84 }
85 85  
... ... @@ -89,7 +89,7 @@ process(std::string fn, std::vector&lt;std::vector&lt;std::pair&lt;qpdf_offset_t, std::st
89 89 switch (xref.getType()) {
90 90 case 0:
91 91 std::cerr << oh.getObjectID() << "/" << oh.getGeneration() << " xref entry is free"
92   - << std::endl;
  92 + << '\n';
93 93 std::exit(2);
94 94 case 1:
95 95 stream_number = 0;
... ... @@ -98,7 +98,7 @@ process(std::string fn, std::vector&lt;std::vector&lt;std::pair&lt;qpdf_offset_t, std::st
98 98 stream_number = static_cast<size_t>(xref.getObjStreamNumber());
99 99 break;
100 100 default:
101   - std::cerr << "unknown xref entry type" << std::endl;
  101 + std::cerr << "unknown xref entry type" << '\n';
102 102 std::exit(2);
103 103 }
104 104  
... ... @@ -120,25 +120,25 @@ main(int argc, char* argv[])
120 120 process(argv[1], table);
121 121  
122 122 for (size_t i = 0; i < table.size(); ++i) {
123   - if (table[i].size() == 0) {
  123 + if (table[i].empty()) {
124 124 continue;
125 125 }
126 126  
127 127 std::sort(table[i].begin(), table[i].end());
128 128 if (i == 0) {
129   - std::cout << "--- objects not in streams ---" << std::endl;
  129 + std::cout << "--- objects not in streams ---" << '\n';
130 130 } else {
131   - std::cout << "--- objects in stream " << i << " ---" << std::endl;
  131 + std::cout << "--- objects in stream " << i << " ---" << '\n';
132 132 }
133 133  
134 134 for (auto const& iter: table[i]) {
135   - std::cout << iter.second << std::endl;
  135 + std::cout << iter.second << '\n';
136 136 }
137 137 }
138 138  
139   - std::cout << "succeeded" << std::endl;
  139 + std::cout << "succeeded" << '\n';
140 140 } catch (std::exception& e) {
141   - std::cerr << e.what() << std::endl;
  141 + std::cerr << e.what() << '\n';
142 142 std::exit(2);
143 143 }
144 144  
... ...
qpdf/test_pdf_doc_encoding.cc
... ... @@ -9,7 +9,7 @@ static char const* whoami = nullptr;
9 9 void
10 10 usage()
11 11 {
12   - std::cerr << "Usage: " << whoami << " infile" << std::endl;
  12 + std::cerr << "Usage: " << whoami << " infile" << '\n';
13 13 exit(2);
14 14 }
15 15  
... ... @@ -28,7 +28,7 @@ main(int argc, char* argv[])
28 28 char const* infilename = argv[1];
29 29 for (auto const& line: QUtil::read_lines_from_file(infilename)) {
30 30 QPDFObjectHandle str = QPDFObjectHandle::newString(line);
31   - std::cout << str.getUTF8Value() << std::endl;
  31 + std::cout << str.getUTF8Value() << '\n';
32 32 }
33 33 return 0;
34 34 }
... ...
qpdf/test_pdf_unicode.cc
... ... @@ -9,7 +9,7 @@ static char const* whoami = nullptr;
9 9 void
10 10 usage()
11 11 {
12   - std::cerr << "Usage: " << whoami << " infile" << std::endl;
  12 + std::cerr << "Usage: " << whoami << " infile" << '\n';
13 13 exit(2);
14 14 }
15 15  
... ... @@ -28,7 +28,7 @@ main(int argc, char* argv[])
28 28 char const* infilename = argv[1];
29 29 for (auto const& line: QUtil::read_lines_from_file(infilename)) {
30 30 QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
31   - std::cout << str.getUTF8Value() << " // " << str.unparseBinary() << std::endl;
  31 + std::cout << str.getUTF8Value() << " // " << str.unparseBinary() << '\n';
32 32 }
33 33 return 0;
34 34 }
... ...
qpdf/test_renumber.cc
... ... @@ -14,11 +14,11 @@
14 14 void
15 15 usage()
16 16 {
17   - std::cerr << "Usage: test_renumber [OPTION] INPUT.pdf" << std::endl
18   - << "Option:" << std::endl
19   - << " --object-streams=preserve|disable|generate" << std::endl
20   - << " --linearize" << std::endl
21   - << " --preserve-unreferenced" << std::endl;
  17 + std::cerr << "Usage: test_renumber [OPTION] INPUT.pdf" << '\n'
  18 + << "Option:" << '\n'
  19 + << " --object-streams=preserve|disable|generate" << '\n'
  20 + << " --linearize" << '\n'
  21 + << " --preserve-unreferenced" << '\n';
22 22 }
23 23  
24 24 bool
... ... @@ -26,45 +26,45 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
26 26 {
27 27 static std::set<QPDFObjGen> visited;
28 28 if (a.isIndirect()) {
29   - if (visited.count(a.getObjGen())) {
  29 + if (visited.contains(a.getObjGen())) {
30 30 return true;
31 31 }
32 32 visited.insert(a.getObjGen());
33 33 }
34 34  
35 35 if (a.getTypeCode() != b.getTypeCode()) {
36   - std::cerr << "different type code" << std::endl;
  36 + std::cerr << "different type code" << '\n';
37 37 return false;
38 38 }
39 39  
40 40 switch (a.getTypeCode()) {
41 41 case ::ot_boolean:
42 42 if (a.getBoolValue() != b.getBoolValue()) {
43   - std::cerr << "different boolean" << std::endl;
  43 + std::cerr << "different boolean" << '\n';
44 44 return false;
45 45 }
46 46 break;
47 47 case ::ot_integer:
48 48 if (a.getIntValue() != b.getIntValue()) {
49   - std::cerr << "different integer" << std::endl;
  49 + std::cerr << "different integer" << '\n';
50 50 return false;
51 51 }
52 52 break;
53 53 case ::ot_real:
54 54 if (a.getRealValue() != b.getRealValue()) {
55   - std::cerr << "different real" << std::endl;
  55 + std::cerr << "different real" << '\n';
56 56 return false;
57 57 }
58 58 break;
59 59 case ::ot_string:
60 60 if (a.getStringValue() != b.getStringValue()) {
61   - std::cerr << "different string" << std::endl;
  61 + std::cerr << "different string" << '\n';
62 62 return false;
63 63 }
64 64 break;
65 65 case ::ot_name:
66 66 if (a.getName() != b.getName()) {
67   - std::cerr << "different name" << std::endl;
  67 + std::cerr << "different name" << '\n';
68 68 return false;
69 69 }
70 70 break;
... ... @@ -74,13 +74,13 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
74 74 std::vector<QPDFObjectHandle> objs_b = b.getArrayAsVector();
75 75 size_t items = objs_a.size();
76 76 if (items != objs_b.size()) {
77   - std::cerr << "different array size" << std::endl;
  77 + std::cerr << "different array size" << '\n';
78 78 return false;
79 79 }
80 80  
81 81 for (size_t i = 0; i < items; ++i) {
82 82 if (!compare(objs_a[i], objs_b[i])) {
83   - std::cerr << "different array item" << std::endl;
  83 + std::cerr << "different array item" << '\n';
84 84 return false;
85 85 }
86 86 }
... ... @@ -91,13 +91,13 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
91 91 std::set<std::string> keys_a = a.getKeys();
92 92 std::set<std::string> keys_b = b.getKeys();
93 93 if (keys_a != keys_b) {
94   - std::cerr << "different dictionary keys" << std::endl;
  94 + std::cerr << "different dictionary keys" << '\n';
95 95 return false;
96 96 }
97 97  
98 98 for (auto const& key: keys_a) {
99 99 if (!compare(a.getKey(key), b.getKey(key))) {
100   - std::cerr << "different dictionary item" << std::endl;
  100 + std::cerr << "different dictionary item" << '\n';
101 101 return false;
102 102 }
103 103 }
... ... @@ -106,10 +106,10 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
106 106 case ::ot_null:
107 107 break;
108 108 case ::ot_stream:
109   - std::cout << "stream objects are not compared" << std::endl;
  109 + std::cout << "stream objects are not compared" << '\n';
110 110 break;
111 111 default:
112   - std::cerr << "unknown object type" << std::endl;
  112 + std::cerr << "unknown object type" << '\n';
113 113 std::exit(2);
114 114 }
115 115  
... ... @@ -120,23 +120,22 @@ bool
120 120 compare_xref_table(std::map<QPDFObjGen, QPDFXRefEntry> a, std::map<QPDFObjGen, QPDFXRefEntry> b)
121 121 {
122 122 if (a.size() != b.size()) {
123   - std::cerr << "different size" << std::endl;
  123 + std::cerr << "different size" << '\n';
124 124 return false;
125 125 }
126 126  
127 127 for (auto const& iter: a) {
128   - std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen()
129   - << std::endl;
  128 + std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen() << '\n';
130 129  
131   - if (b.count(iter.first) == 0) {
132   - std::cerr << "not found" << std::endl;
  130 + if (!b.contains(iter.first)) {
  131 + std::cerr << "not found" << '\n';
133 132 return false;
134 133 }
135 134  
136 135 QPDFXRefEntry xref_a = iter.second;
137 136 QPDFXRefEntry xref_b = b[iter.first];
138 137 if (xref_a.getType() != xref_b.getType()) {
139   - std::cerr << "different xref entry type" << std::endl;
  138 + std::cerr << "different xref entry type" << '\n';
140 139 return false;
141 140 }
142 141  
... ... @@ -145,19 +144,19 @@ compare_xref_table(std::map&lt;QPDFObjGen, QPDFXRefEntry&gt; a, std::map&lt;QPDFObjGen, Q
145 144 break;
146 145 case 1:
147 146 if (xref_a.getOffset() != xref_a.getOffset()) {
148   - std::cerr << "different offset" << std::endl;
  147 + std::cerr << "different offset" << '\n';
149 148 return false;
150 149 }
151 150 break;
152 151 case 2:
153 152 if (xref_a.getObjStreamNumber() != xref_a.getObjStreamNumber() ||
154 153 xref_a.getObjStreamIndex() != xref_a.getObjStreamIndex()) {
155   - std::cerr << "different stream number or index" << std::endl;
  154 + std::cerr << "different stream number or index" << '\n';
156 155 return false;
157 156 }
158 157 break;
159 158 default:
160   - std::cerr << "unknown xref entry type" << std::endl;
  159 + std::cerr << "unknown xref entry type" << '\n';
161 160 std::exit(2);
162 161 }
163 162 }
... ... @@ -223,36 +222,36 @@ main(int argc, char* argv[])
223 222 "renumbered", reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
224 223 std::map<QPDFObjGen, QPDFXRefEntry> xrefs_ren = qpdf_ren.getXRefTable();
225 224  
226   - std::cout << "--- compare between input and renumbered objects ---" << std::endl;
  225 + std::cout << "--- compare between input and renumbered objects ---" << '\n';
227 226 for (auto const& iter: objs_in) {
228 227 QPDFObjGen og_in = iter.getObjGen();
229 228 QPDFObjGen og_ren = w.getRenumberedObjGen(og_in);
230 229  
231 230 std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() << " -> renumbered "
232   - << og_ren.getObj() << "/" << og_ren.getGen() << std::endl;
  231 + << og_ren.getObj() << "/" << og_ren.getGen() << '\n';
233 232  
234 233 if (og_ren.getObj() == 0) {
235   - std::cout << "deleted" << std::endl;
  234 + std::cout << "deleted" << '\n';
236 235 continue;
237 236 }
238 237  
239 238 if (!compare(iter, qpdf_ren.getObjectByObjGen(og_ren))) {
240   - std::cerr << "different" << std::endl;
  239 + std::cerr << "different" << '\n';
241 240 std::exit(2);
242 241 }
243 242 }
244   - std::cout << "complete" << std::endl;
  243 + std::cout << "complete" << '\n';
245 244  
246   - std::cout << "--- compare between written and reloaded xref tables ---" << std::endl;
  245 + std::cout << "--- compare between written and reloaded xref tables ---" << '\n';
247 246 if (!compare_xref_table(xrefs_w, xrefs_ren)) {
248   - std::cerr << "different" << std::endl;
  247 + std::cerr << "different" << '\n';
249 248 std::exit(2);
250 249 }
251   - std::cout << "complete" << std::endl;
  250 + std::cout << "complete" << '\n';
252 251  
253   - std::cout << "succeeded" << std::endl;
  252 + std::cout << "succeeded" << '\n';
254 253 } catch (std::exception& e) {
255   - std::cerr << e.what() << std::endl;
  254 + std::cerr << e.what() << '\n';
256 255 std::exit(2);
257 256 }
258 257  
... ...
qpdf/test_shell_glob.cc
... ... @@ -32,11 +32,11 @@ realmain(int argc, char* argv[])
32 32 bool passed = (found_star && (argc == 2));
33 33 #endif
34 34 if (passed) {
35   - std::cout << "PASSED" << std::endl;
  35 + std::cout << "PASSED" << '\n';
36 36 } else {
37   - std::cout << "FAILED" << std::endl;
  37 + std::cout << "FAILED" << '\n';
38 38 for (int i = 1; i < argc; ++i) {
39   - std::cout << argv[i] << std::endl;
  39 + std::cout << argv[i] << '\n';
40 40 }
41 41 }
42 42 return 0;
... ...
qpdf/test_tokenizer.cc
... ... @@ -16,7 +16,7 @@ static char const* whoami = nullptr;
16 16 void
17 17 usage()
18 18 {
19   - std::cerr << "Usage: " << whoami << " [-maxlen len | -no-ignorable] filename" << std::endl;
  19 + std::cerr << "Usage: " << whoami << " [-maxlen len | -no-ignorable] filename" << '\n';
20 20 exit(2);
21 21 }
22 22  
... ... @@ -115,10 +115,10 @@ try_skipping(
115 115 char const* what,
116 116 Finder& f)
117 117 {
118   - std::cout << "skipping to " << what << std::endl;
  118 + std::cout << "skipping to " << what << '\n';
119 119 qpdf_offset_t offset = is->tell();
120 120 if (!is->findFirst(what, offset, 0, f)) {
121   - std::cout << what << " not found" << std::endl;
  121 + std::cout << what << " not found" << '\n';
122 122 is->seek(offset, SEEK_SET);
123 123 }
124 124 }
... ... @@ -133,7 +133,7 @@ dump_tokens(
133 133 bool skip_inline_images)
134 134 {
135 135 Finder f1(is, "endstream");
136   - std::cout << "--- BEGIN " << label << " ---" << std::endl;
  136 + std::cout << "--- BEGIN " << label << " ---" << '\n';
137 137 bool done = false;
138 138 QPDFTokenizer tokenizer;
139 139 tokenizer.allowEOF();
... ... @@ -145,7 +145,7 @@ dump_tokens(
145 145 QPDFTokenizer::Token token =
146 146 tokenizer.readToken(is, "test", true, inline_image_offset ? 0 : max_len);
147 147 if (inline_image_offset && (token.getType() == QPDFTokenizer::tt_bad)) {
148   - std::cout << "EI not found; resuming normal scanning" << std::endl;
  148 + std::cout << "EI not found; resuming normal scanning" << '\n';
149 149 is->seek(inline_image_offset, SEEK_SET);
150 150 inline_image_offset = 0;
151 151 continue;
... ... @@ -163,7 +163,7 @@ dump_tokens(
163 163 if (!token.getErrorMessage().empty()) {
164 164 std::cout << " (" << token.getErrorMessage() << ")";
165 165 }
166   - std::cout << std::endl;
  166 + std::cout << '\n';
167 167 if (skip_streams && (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))) {
168 168 try_skipping(tokenizer, is, max_len, "endstream", f1);
169 169 } else if (
... ... @@ -176,7 +176,7 @@ dump_tokens(
176 176 done = true;
177 177 }
178 178 }
179   - std::cout << "--- END " << label << " ---" << std::endl;
  179 + std::cout << "--- END " << label << " ---" << '\n';
180 180 }
181 181  
182 182 static void
... ...
qpdf/test_unicode_filenames.cc
... ... @@ -13,7 +13,7 @@ static void
13 13 do_copy(FILE* in, FILE* out)
14 14 {
15 15 if ((in == nullptr) || (out == nullptr)) {
16   - std::cerr << "errors opening files" << std::endl;
  16 + std::cerr << "errors opening files" << '\n';
17 17 exit(2);
18 18 }
19 19 char buf[10240];
... ... @@ -22,7 +22,7 @@ do_copy(FILE* in, FILE* out)
22 22 fwrite(buf, 1, len, out);
23 23 }
24 24 if (len != 0) {
25   - std::cerr << "errors reading or writing" << std::endl;
  25 + std::cerr << "errors reading or writing" << '\n';
26 26 exit(2);
27 27 }
28 28 fclose(in);
... ... @@ -76,7 +76,7 @@ main(int argc, char* argv[])
76 76 char const* f2 = "auto-\xc3\xb6\xcf\x80.pdf";
77 77 copy(f1);
78 78 copy(f2);
79   - std::cout << "created Unicode filenames" << std::endl;
  79 + std::cout << "created Unicode filenames" << '\n';
80 80 return 0;
81 81 }
82 82  
... ...
qpdf/test_xref.cc
... ... @@ -8,7 +8,7 @@ int
8 8 main(int argc, char* argv[])
9 9 {
10 10 if (argc != 2) {
11   - std::cerr << "usage: test_xref INPUT.pdf" << std::endl;
  11 + std::cerr << "usage: test_xref INPUT.pdf" << '\n';
12 12 std::exit(2);
13 13 }
14 14  
... ... @@ -20,23 +20,23 @@ main(int argc, char* argv[])
20 20 std::cout << iter.first.getObj() << "/" << iter.first.getGen() << ", ";
21 21 switch (iter.second.getType()) {
22 22 case 0:
23   - std::cout << "free entry" << std::endl;
  23 + std::cout << "free entry" << '\n';
24 24 break;
25 25 case 1:
26 26 std::cout << "uncompressed, offset = " << iter.second.getOffset() << " (0x"
27   - << std::hex << iter.second.getOffset() << std::dec << ")" << std::endl;
  27 + << std::hex << iter.second.getOffset() << std::dec << ")" << '\n';
28 28 break;
29 29 case 2:
30 30 std::cout << "compressed, stream number = " << iter.second.getObjStreamNumber()
31   - << ", stream index = " << iter.second.getObjStreamIndex() << std::endl;
  31 + << ", stream index = " << iter.second.getObjStreamIndex() << '\n';
32 32 break;
33 33 default:
34   - std::cerr << "unknown" << std::endl;
  34 + std::cerr << "unknown" << '\n';
35 35 std::exit(2);
36 36 }
37 37 }
38 38 } catch (std::exception& e) {
39   - std::cerr << e.what() << std::endl;
  39 + std::cerr << e.what() << '\n';
40 40 std::exit(2);
41 41 }
42 42  
... ...
zlib-flate/zlib-flate.cc
... ... @@ -13,11 +13,10 @@ static char const* whoami = nullptr;
13 13 void
14 14 usage()
15 15 {
16   - std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" << std::endl
17   - << "If n is specified with -compress, it is a zlib compression level from"
18   - << std::endl
19   - << "1 to 9 where lower numbers are faster and less compressed and higher" << std::endl
20   - << "numbers are slower and more compressed" << std::endl;
  16 + std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" << '\n'
  17 + << "If n is specified with -compress, it is a zlib compression level from" << '\n'
  18 + << "1 to 9 where lower numbers are faster and less compressed and higher" << '\n'
  19 + << "numbers are slower and more compressed" << '\n';
21 20 exit(2);
22 21 }
23 22  
... ... @@ -31,7 +30,7 @@ main(int argc, char* argv[])
31 30 }
32 31  
33 32 if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
34   - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl;
  33 + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << '\n';
35 34 exit(0);
36 35 }
37 36  
... ... @@ -53,7 +52,7 @@ main(int argc, char* argv[])
53 52 // Undocumented option, but that doesn't mean someone doesn't use it...
54 53 // This is primarily here to support the test suite.
55 54 std::cout << (Pl_Flate::zopfli_supported() ? "1" : "0")
56   - << (Pl_Flate::zopfli_enabled() ? "1" : "0") << std::endl;
  55 + << (Pl_Flate::zopfli_enabled() ? "1" : "0") << '\n';
57 56 return 0;
58 57 } else {
59 58 usage();
... ... @@ -68,8 +67,7 @@ main(int argc, char* argv[])
68 67 auto flate = std::make_shared<Pl_Flate>("flate", out.get(), action);
69 68 flate->setWarnCallback([&warn](char const* msg, int code) {
70 69 warn = true;
71   - std::cerr << whoami << ": WARNING: zlib code " << code << ", msg = " << msg
72   - << std::endl;
  70 + std::cerr << whoami << ": WARNING: zlib code " << code << ", msg = " << msg << '\n';
73 71 });
74 72  
75 73 unsigned char buf[10000];
... ... @@ -84,7 +82,7 @@ main(int argc, char* argv[])
84 82 }
85 83 flate->finish();
86 84 } catch (std::exception& e) {
87   - std::cerr << whoami << ": " << e.what() << std::endl;
  85 + std::cerr << whoami << ": " << e.what() << '\n';
88 86 exit(2);
89 87 }
90 88  
... ...