diff --git a/compare-for-test/qpdf-test-compare.cc b/compare-for-test/qpdf-test-compare.cc index 5d3e6e2..04f3b80 100644 --- a/compare-for-test/qpdf-test-compare.cc +++ b/compare-for-test/qpdf-test-compare.cc @@ -13,18 +13,14 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " actual expected" << std::endl - << R"(Where "actual" is the actual output and "expected" is the expected)" - << std::endl - << "output of a test, compare the two PDF files. The files are considered" - << std::endl - << "to match if all their objects are identical except that, if a stream is" - << std::endl - << "compressed with FlateDecode, the uncompressed data must match." << std::endl - << std::endl - << "If the files match, the output is the expected file. Otherwise, it is" - << std::endl - << "the actual file. Read comments in the code for rationale." << std::endl; + std::cerr << "Usage: " << whoami << " actual expected" << '\n' + << R"(Where "actual" is the actual output and "expected" is the expected)" << '\n' + << "output of a test, compare the two PDF files. The files are considered" << '\n' + << "to match if all their objects are identical except that, if a stream is" << '\n' + << "compressed with FlateDecode, the uncompressed data must match." << '\n' + << '\n' + << "If the files match, the output is the expected file. Otherwise, it is" << '\n' + << "the actual file. Read comments in the code for rationale." << '\n'; exit(2); } @@ -187,7 +183,7 @@ main(int argc, char* argv[]) } if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) { - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl; + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << '\n'; exit(0); } @@ -211,7 +207,7 @@ main(int argc, char* argv[]) to_output = expected; } else { if (show_why) { - std::cerr << difference << std::endl; + std::cerr << difference << '\n'; exit(2); } // The files differ; write the actual file. If it is determined that the actual file @@ -237,7 +233,7 @@ main(int argc, char* argv[]) exit(2); } } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } return 0; diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc index be3ca25..6f3659b 100644 --- a/examples/pdf-attach-file.cc +++ b/examples/pdf-attach-file.cc @@ -19,15 +19,15 @@ static char const* whoami = nullptr; static void usage(std::string const& msg) { - std::cerr << msg << std::endl - << std::endl - << "Usage: " << whoami << " options" << std::endl - << "Options:" << std::endl - << " --infile infile.pdf" << std::endl - << " --outfile outfile.pdf" << std::endl - << " --attachment attachment" << std::endl - << " [--password infile-password]" << std::endl - << " [--mimetype attachment mime type]" << std::endl; + std::cerr << msg << '\n' + << '\n' + << "Usage: " << whoami << " options\n" + << "Options:\n" + << " --infile infile.pdf\n" + << " --outfile outfile.pdf\n" + << " --attachment attachment\n" + << " [--password infile-password]\n" + << " [--mimetype attachment mime type]\n"; exit(2); } @@ -69,7 +69,7 @@ process( // Create a file spec. std::string key = QUtil::path_basename(attachment); - std::cout << whoami << ": attaching " << attachment << " as " << key << std::endl; + std::cout << whoami << ": attaching " << attachment << " as " << key << '\n'; auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment); if (mimetype) { @@ -208,7 +208,7 @@ main(int argc, char* argv[]) try { process(infilename, password, attachment, mimetype, outfilename); } catch (std::exception& e) { - std::cerr << whoami << " exception: " << e.what() << std::endl; + std::cerr << whoami << " exception: " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-bookmarks.cc b/examples/pdf-bookmarks.cc index 00558a3..665ac0f 100644 --- a/examples/pdf-bookmarks.cc +++ b/examples/pdf-bookmarks.cc @@ -23,12 +23,12 @@ static std::map page_map; void usage() { - std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl - << "Options:" << std::endl - << " --numbers give bookmarks outline-style numbers" << std::endl - << " --lines draw lines to show bookmark hierarchy" << std::endl - << " --show-open indicate whether a bookmark is initially open" << std::endl - << " --show-targets show target if possible" << std::endl; + std::cerr << "Usage: " << whoami << " [options] file.pdf [password]\n" + << "Options:\n" + << " --numbers give bookmarks outline-style numbers\n" + << " --lines draw lines to show bookmark hierarchy\n" + << " --show-open indicate whether a bookmark is initially open\n" + << " --show-targets show target if possible\n"; exit(2); } @@ -74,7 +74,7 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector numbers) case st_lines: QTC::TC("examples", "pdf-bookmarks lines"); print_lines(numbers); - std::cout << "|" << std::endl; + std::cout << "|\n"; print_lines(numbers); std::cout << "+-+ "; break; @@ -136,7 +136,7 @@ main(int argc, char* argv[]) whoami = QUtil::getWhoami(argv[0]); if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) { - std::cout << whoami << " version 1.5" << std::endl; + std::cout << whoami << " version 1.5\n"; exit(0); } @@ -185,10 +185,10 @@ main(int argc, char* argv[]) } extract_bookmarks(odh.getTopLevelOutlines(), numbers); } else { - std::cout << filename << " has no bookmarks" << std::endl; + std::cout << filename << " has no bookmarks\n"; } } catch (std::exception& e) { - std::cerr << whoami << " processing file " << filename << ": " << e.what() << std::endl; + std::cerr << whoami << " processing file " << filename << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-count-strings.cc b/examples/pdf-count-strings.cc index 2b5b557..c262459 100644 --- a/examples/pdf-count-strings.cc +++ b/examples/pdf-count-strings.cc @@ -18,8 +18,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile" << std::endl - << "Applies token filters to infile" << std::endl; + std::cerr << "Usage: " << whoami << " infile\n" + << "Applies token filters to infile\n"; exit(2); } @@ -88,14 +88,14 @@ main(int argc, char* argv[]) } else { // Write output to stdout for even pages. Pl_StdioFile out("stdout", stdout); - std::cout << "% Contents of page " << pageno << std::endl; + std::cout << "% Contents of page " << pageno << '\n'; page.filterContents(&counter, &out); - std::cout << "\n% end " << pageno << std::endl; + std::cout << "\n% end " << pageno << '\n'; } - std::cout << "Page " << pageno << ": strings = " << counter.getCount() << std::endl; + std::cout << "Page " << pageno << ": strings = " << counter.getCount() << '\n'; } } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index c44e5f5..f09d8c4 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -117,8 +117,8 @@ ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) void usage() { - std::cerr << "Usage: " << whoami << " filename" << std::endl - << "Creates a simple PDF and writes it to filename" << std::endl; + std::cerr << "Usage: " << whoami << " filename\n" + << "Creates a simple PDF and writes it to filename\n"; exit(2); } @@ -257,12 +257,12 @@ check( if (!filter.isNameAndEquals(desired_filter)) { this_errors = errors = true; std::cout << "page " << pageno << ": expected filter " << desired_filter - << "; actual filter = " << filter.unparse() << std::endl; + << "; actual filter = " << filter.unparse() << '\n'; } if (!color_space.isNameAndEquals(desired_color_space)) { this_errors = errors = true; std::cout << "page " << pageno << ": expected color space " << desired_color_space - << "; actual color space = " << color_space.unparse() << std::endl; + << "; actual color space = " << color_space.unparse() << '\n'; } if (!this_errors) { @@ -275,7 +275,7 @@ check( std::shared_ptr desired_data(b_p.getBuffer()); if (desired_data->getSize() != actual_data->getSize()) { - std::cout << "page " << pageno << ": image data length mismatch" << std::endl; + std::cout << "page " << pageno << ": image data length mismatch\n"; this_errors = errors = true; } else { // Compare bytes. For JPEG, allow a certain number of the bytes to be off desired by @@ -297,7 +297,7 @@ check( if (mismatches > threshold) { std::cout << "page " << pageno << ": " << desired_color_space << ", " << desired_filter << ": mismatches: " << mismatches << " of " << len - << std::endl; + << '\n'; this_errors = errors = true; } } @@ -308,7 +308,7 @@ check( if (errors) { throw std::logic_error("errors found"); } else { - std::cout << "all checks passed" << std::endl; + std::cout << "all checks passed\n"; } } @@ -366,7 +366,7 @@ main(int argc, char* argv[]) try { create_pdf(filename); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc index ac949a1..2cc4199 100644 --- a/examples/pdf-custom-filter.cc +++ b/examples/pdf-custom-filter.cc @@ -116,7 +116,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) this->key = buf->getBuffer()[0]; return true; } catch (std::exception& e) { - std::cerr << "Error extracting key for /XORDecode: " << e.what() << std::endl; + std::cerr << "Error extracting key for /XORDecode: " << e.what() << '\n'; } return false; } @@ -361,15 +361,13 @@ process(char const* infilename, char const* outfilename, bool decode_specialized // For the test suite, use static IDs. w.setStaticID(true); // for testing only w.write(); - std::cout << whoami << ": new file written to " << outfilename << std::endl; + std::cout << whoami << ": new file written to " << outfilename << '\n'; } static void usage() { - std::cerr << "\n" - << "Usage: " << whoami << " [--decode-specialized] infile outfile\n" - << std::endl; + std::cerr << '\n' << "Usage: " << whoami << " [--decode-specialized] infile outfile\n" << '\n'; exit(2); } @@ -404,7 +402,7 @@ main(int argc, char* argv[]) // Do the actual processing. process(infilename, outfilename, decode_specialized); } catch (std::exception& e) { - std::cerr << whoami << ": exception: " << e.what() << std::endl; + std::cerr << whoami << ": exception: " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc index 289c4d1..12bd094 100644 --- a/examples/pdf-double-page-size.cc +++ b/examples/pdf-double-page-size.cc @@ -13,8 +13,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl - << "Double size of all pages in infile.pdf; write output to outfile.pdf" << std::endl; + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]\n" + << "Double size of all pages in infile.pdf; write output to outfile.pdf\n"; exit(2); } @@ -87,9 +87,9 @@ main(int argc, char* argv[]) w.setStreamDataMode(qpdf_s_uncompress); } w.write(); - std::cout << whoami << ": new file written to " << outfilename << std::endl; + std::cout << whoami << ": new file written to " << outfilename << '\n'; } catch (std::exception& e) { - std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-filter-tokens.cc b/examples/pdf-filter-tokens.cc index 4a06bcd..12dc178 100644 --- a/examples/pdf-filter-tokens.cc +++ b/examples/pdf-filter-tokens.cc @@ -20,8 +20,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile outfile" << std::endl - << "Applies token filters to infile and writes outfile" << std::endl; + std::cerr << "Usage: " << whoami << " infile outfile\n" + << "Applies token filters to infile and writes outfile\n"; exit(2); } @@ -184,7 +184,7 @@ main(int argc, char* argv[]) w.setQDFMode(true); w.write(); } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc index de2da9b..c02627b 100644 --- a/examples/pdf-invert-images.cc +++ b/examples/pdf-invert-images.cc @@ -14,8 +14,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl - << "Invert some images in infile.pdf; write output to outfile.pdf" << std::endl; + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]\n" + << "Invert some images in infile.pdf; write output to outfile.pdf\n"; exit(2); } @@ -137,9 +137,9 @@ main(int argc, char* argv[]) w.setStaticID(true); // for testing only } w.write(); - std::cout << whoami << ": new file written to " << outfilename << std::endl; + std::cout << whoami << ": new file written to " << outfilename << '\n'; } catch (std::exception& e) { - std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc index c9fffa6..2fd559a 100644 --- a/examples/pdf-mod-info.cc +++ b/examples/pdf-mod-info.cc @@ -39,7 +39,7 @@ dumpInfoDict(QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = " { val = it.second.unparseResolved(); } - os << it.first.substr(1) << sep << val << std::endl; // skip '/' + os << it.first.substr(1) << sep << val << '\n'; // skip '/' } } } @@ -52,7 +52,7 @@ pdfDumpInfoDict(char const* fname) pdf.processFile(fname); dumpInfoDict(pdf); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } } @@ -66,7 +66,7 @@ main(int argc, char* argv[]) whoami = QUtil::getWhoami(argv[0]); if ((argc == 2) && (!strcmp(argv[1], "--version"))) { - std::cout << whoami << " version " << version << std::endl; + std::cout << whoami << " version " << version << '\n'; exit(0); } if ((argc == 3) && (!strcmp(argv[1], "--dump"))) { @@ -155,7 +155,7 @@ main(int argc, char* argv[]) w.setStaticID(static_id); // for testing only w.write(); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } @@ -164,7 +164,7 @@ main(int argc, char* argv[]) QUtil::os_wrapper( "rename " + fl_tmp + " " + std::string(fl_out), rename(fl_tmp.c_str(), fl_out)); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-name-number-tree.cc b/examples/pdf-name-number-tree.cc index 7701e70..667f973 100644 --- a/examples/pdf-name-number-tree.cc +++ b/examples/pdf-name-number-tree.cc @@ -10,8 +10,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl - << "Create some name/number trees and write to a file" << std::endl; + std::cerr << "Usage: " << whoami << " outfile.pdf" << '\n' + << "Create some name/number trees and write to a file\n"; exit(2); } @@ -57,64 +57,63 @@ main(int argc, char* argv[]) name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight")); auto iter = name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn")); // Look at the iterator - std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << std::endl; + std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << '\n'; --iter; - std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << std::endl; + std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << '\n'; ++iter; ++iter; - std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << std::endl; + std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << '\n'; // Use range-for iteration - std::cout << "Name tree items:" << std::endl; + std::cout << "Name tree items:\n"; for (auto i: name_tree) { - std::cout << " " << i.first << " -> " << i.second.unparse() << std::endl; + std::cout << " " << i.first << " -> " << i.second.unparse() << '\n'; } // This is a small tree, so everything will be at the root. We can look at it using dictionary // and array iterators. - std::cout << "Keys in name tree object:" << std::endl; + std::cout << "Keys in name tree object:\n"; QPDFObjectHandle names; for (auto const& i: name_tree_oh.ditems()) { - std::cout << i.first << std::endl; + std::cout << i.first << '\n'; if (i.first == "/Names") { names = i.second; } } // Values in names array: - std::cout << "Values in names:" << std::endl; + std::cout << "Values in names:\n"; for (auto& i: names.aitems()) { - std::cout << " " << i.unparse() << std::endl; + std::cout << " " << i.unparse() << '\n'; } // pre 10.2 API - std::cout << "Has Q?: " << name_tree.hasName("Q") << std::endl; - std::cout << "Has W?: " << name_tree.hasName("W") << std::endl; + std::cout << "Has Q?: " << name_tree.hasName("Q") << '\n'; + std::cout << "Has W?: " << name_tree.hasName("W") << '\n'; QPDFObjectHandle obj; - std::cout << "Found W?: " << name_tree.findObject("W", obj) << std::endl; - std::cout << "Found Q?: " << name_tree.findObject("Q", obj) << std::endl; - std::cout << "Q: " << obj.unparse() << std::endl; + std::cout << "Found W?: " << name_tree.findObject("W", obj) << '\n'; + std::cout << "Found Q?: " << name_tree.findObject("Q", obj) << '\n'; + std::cout << "Q: " << obj.unparse() << '\n'; // 10.2 API iter = name_tree.find("Q"); - std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << std::endl; + std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << '\n'; iter = name_tree.find("W"); - std::cout << "W found: " << (iter != name_tree.end()) << std::endl; + std::cout << "W found: " << (iter != name_tree.end()) << '\n'; // Allow find to return predecessor iter = name_tree.find("W", true); - std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse() - << std::endl; + std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse() << '\n'; // We can also remove items - std::cout << "Remove P: " << name_tree.remove("P", &obj) << std::endl; - std::cout << "Value removed: " << obj.unparse() << std::endl; - std::cout << "Has P?: " << name_tree.hasName("P") << std::endl; + std::cout << "Remove P: " << name_tree.remove("P", &obj) << '\n'; + std::cout << "Value removed: " << obj.unparse() << '\n'; + std::cout << "Has P?: " << name_tree.hasName("P") << '\n'; // Or we can remove using an iterator iter = name_tree.find("K"); - std::cout << "Find K: " << iter->second.unparse() << std::endl; + std::cout << "Find K: " << iter->second.unparse() << '\n'; iter.remove(); std::cout << "Iter after removing K: " << iter->first << " -> " << iter->second.unparse() - << std::endl; - std::cout << "Has K?: " << name_tree.hasName("K") << std::endl; + << '\n'; + std::cout << "Has K?: " << name_tree.hasName("K") << '\n'; // Illustrate some more advanced usage using number trees. These calls work for name trees too. @@ -129,14 +128,14 @@ main(int argc, char* argv[]) for (int i = 7; i <= 350; i += 7) { iter2.insertAfter(i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-")); } - std::cout << "Numbers:" << std::endl; + std::cout << "Numbers:\n"; int n = 1; for (auto& i: number_tree) { std::cout << i.first << " -> " << i.second.getUTF8Value(); if (n % 5) { std::cout << ", "; } else { - std::cout << std::endl; + std::cout << '\n'; } ++n; } @@ -151,14 +150,14 @@ main(int argc, char* argv[]) ++iter2; } } - std::cout << "Numbers after filtering:" << std::endl; + std::cout << "Numbers after filtering:\n"; n = 1; for (auto& i: number_tree) { std::cout << i.first << " -> " << i.second.getUTF8Value(); if (n % 5) { std::cout << ", "; } else { - std::cout << std::endl; + std::cout << '\n'; } ++n; } diff --git a/examples/pdf-npages.cc b/examples/pdf-npages.cc index 59598cf..b216204 100644 --- a/examples/pdf-npages.cc +++ b/examples/pdf-npages.cc @@ -10,8 +10,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " filename" << std::endl - << "Prints the number of pages in filename" << std::endl; + std::cerr << "Usage: " << whoami << " filename\n" + << "Prints the number of pages in filename\n"; exit(2); } @@ -21,7 +21,7 @@ main(int argc, char* argv[]) whoami = QUtil::getWhoami(argv[0]); if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) { - std::cout << whoami << " version 1.3" << std::endl; + std::cout << whoami << " version 1.3\n"; exit(0); } @@ -36,9 +36,9 @@ main(int argc, char* argv[]) QPDFObjectHandle root = pdf.getRoot(); QPDFObjectHandle pages = root.getKey("/Pages"); QPDFObjectHandle count = pages.getKey("/Count"); - std::cout << count.getIntValue() << std::endl; + std::cout << count.getIntValue() << '\n'; } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-overlay-page.cc b/examples/pdf-overlay-page.cc index 97ee802..d4da647 100644 --- a/examples/pdf-overlay-page.cc +++ b/examples/pdf-overlay-page.cc @@ -15,9 +15,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile pagefile outfile" << std::endl - << "Stamp page 1 of pagefile on every page of infile, writing to outfile" - << std::endl; + std::cerr << "Usage: " << whoami << " infile pagefile outfile\n" + << "Stamp page 1 of pagefile on every page of infile, writing to outfile\n"; exit(2); } @@ -81,7 +80,7 @@ main(int argc, char* argv[]) try { stamp_page(infile, stampfile, outfile); } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } return 0; diff --git a/examples/pdf-parse-content.cc b/examples/pdf-parse-content.cc index b60693f..fd758f3 100644 --- a/examples/pdf-parse-content.cc +++ b/examples/pdf-parse-content.cc @@ -12,10 +12,10 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " filename page-number" << std::endl - << "Prints a dump of the objects in the content streams of the given page." - << std::endl - << "Pages are numbered from 1." << std::endl; + std::cerr << "Usage: " << whoami << " filename page-number\n" + << "Prints a dump of the objects in the content streams of the given page.\n" + << '\n' + << "Pages are numbered from 1.\n"; exit(2); } @@ -31,7 +31,7 @@ class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks void ParserCallbacks::contentSize(size_t size) { - std::cout << "content size: " << size << std::endl; + std::cout << "content size: " << size << '\n'; } void @@ -39,16 +39,16 @@ ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length { std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": "; if (obj.isInlineImage()) { - std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl; + std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << '\n'; } else { - std::cout << obj.unparse() << std::endl; + std::cout << obj.unparse() << '\n'; } } void ParserCallbacks::handleEOF() { - std::cout << "-EOF-" << std::endl; + std::cout << "-EOF-\n"; } int @@ -74,7 +74,7 @@ main(int argc, char* argv[]) ParserCallbacks cb; page.parseContents(&cb); } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-set-form-values.cc b/examples/pdf-set-form-values.cc index 810b9fa..5f86f84 100644 --- a/examples/pdf-set-form-values.cc +++ b/examples/pdf-set-form-values.cc @@ -11,8 +11,8 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" << std::endl - << "Set the value of all text fields to a specified value" << std::endl; + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value\n" + << "Set the value of all text fields to a specified value\n"; exit(2); } @@ -68,7 +68,7 @@ main(int argc, char* argv[]) w.setStaticID(true); // for testing only w.write(); } catch (std::exception& e) { - std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << '\n'; exit(2); } diff --git a/examples/pdf-split-pages.cc b/examples/pdf-split-pages.cc index fde4bc1..54a4521 100644 --- a/examples/pdf-split-pages.cc +++ b/examples/pdf-split-pages.cc @@ -42,7 +42,7 @@ process(char const* whoami, char const* infile, std::string outprefix) void usage(char const* whoami) { - std::cerr << "Usage: " << whoami << " infile outprefix" << std::endl; + std::cerr << "Usage: " << whoami << " infile outprefix\n"; exit(2); } @@ -64,7 +64,7 @@ main(int argc, char* argv[]) try { process(whoami, argv[1], argv[2]); } catch (std::exception const& e) { - std::cerr << whoami << ": exception: " << e.what() << std::endl; + std::cerr << whoami << ": exception: " << e.what() << '\n'; return 2; } return 0; diff --git a/examples/qpdf-job.cc b/examples/qpdf-job.cc index c2952ee..bfcc4ba 100644 --- a/examples/qpdf-job.cc +++ b/examples/qpdf-job.cc @@ -10,11 +10,10 @@ static char const* whoami = nullptr; static void usage() { - std::cerr << "Usage: " << whoami << std::endl + std::cerr << "Usage: " << whoami << '\n' << "This program linearizes the first page of in.pdf to out1.pdf, out2.pdf, and" - << std::endl - << " out3.pdf, each demonstrating a different way to use the QPDFJob API" - << std::endl; + << '\n' + << " out3.pdf, each demonstrating a different way to use the QPDFJob API" << '\n'; exit(2); } @@ -49,9 +48,9 @@ main(int argc, char* argv[]) ->compressStreams("n") // avoid dependency on zlib output ->checkConfiguration(); j.run(); - std::cout << "out1 status: " << j.getExitCode() << std::endl; + std::cout << "out1 status: " << j.getExitCode() << '\n'; } catch (std::exception& e) { - std::cerr << "exception: " << e.what() << std::endl; + std::cerr << "exception: " << e.what() << '\n'; return 2; } @@ -71,9 +70,9 @@ main(int argc, char* argv[]) QPDFJob j; j.initializeFromArgv(new_argv); j.run(); - std::cout << "out2 status: " << j.getExitCode() << std::endl; + std::cout << "out2 status: " << j.getExitCode() << '\n'; } catch (std::exception& e) { - std::cerr << "exception: " << e.what() << std::endl; + std::cerr << "exception: " << e.what() << '\n'; return 2; } @@ -95,9 +94,9 @@ main(int argc, char* argv[]) } )"); j.run(); - std::cout << "out3 status: " << j.getExitCode() << std::endl; + std::cout << "out3 status: " << j.getExitCode() << '\n'; } catch (std::exception& e) { - std::cerr << "exception: " << e.what() << std::endl; + std::cerr << "exception: " << e.what() << '\n'; return 2; } diff --git a/examples/qpdfjob-save-attachment.cc b/examples/qpdfjob-save-attachment.cc index 790d808..51d2314 100644 --- a/examples/qpdfjob-save-attachment.cc +++ b/examples/qpdfjob-save-attachment.cc @@ -13,7 +13,7 @@ main(int argc, char* argv[]) auto whoami = QUtil::getWhoami(argv[0]); if (argc != 4) { - std::cerr << "Usage: " << whoami << " file attachment-key outfile" << std::endl; + std::cerr << "Usage: " << whoami << " file attachment-key outfile" << '\n'; exit(2); } @@ -40,10 +40,10 @@ main(int argc, char* argv[]) j.initializeFromArgv(j_argv); j.run(); } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); } - std::cout << whoami << ": wrote attachment to " << outfilename << std::endl; + std::cout << whoami << ": wrote attachment to " << outfilename << '\n'; return 0; } diff --git a/fuzz/ascii85_fuzzer.cc b/fuzz/ascii85_fuzzer.cc index daf6628..3fdc94c 100644 --- a/fuzz/ascii85_fuzzer.cc +++ b/fuzz/ascii85_fuzzer.cc @@ -37,7 +37,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/dct_fuzzer.cc b/fuzz/dct_fuzzer.cc index a99e9e0..f51c53f 100644 --- a/fuzz/dct_fuzzer.cc +++ b/fuzz/dct_fuzzer.cc @@ -49,7 +49,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/flate_fuzzer.cc b/fuzz/flate_fuzzer.cc index 97e10dd..ca6fc7a 100644 --- a/fuzz/flate_fuzzer.cc +++ b/fuzz/flate_fuzzer.cc @@ -37,7 +37,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/hex_fuzzer.cc b/fuzz/hex_fuzzer.cc index 0ce7b2e..ea759bc 100644 --- a/fuzz/hex_fuzzer.cc +++ b/fuzz/hex_fuzzer.cc @@ -37,7 +37,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/json_fuzzer.cc b/fuzz/json_fuzzer.cc index 8b46a0a..272a206 100644 --- a/fuzz/json_fuzzer.cc +++ b/fuzz/json_fuzzer.cc @@ -30,7 +30,7 @@ FuzzHelper::doChecks() try { JSON::parse(std::string(reinterpret_cast(data), size)); } catch (std::runtime_error& e) { - std::cerr << "runtime_error parsing json: " << e.what() << std::endl; + std::cerr << "runtime_error parsing json: " << e.what() << '\n'; } QPDF q; q.setMaxWarnings(1000); @@ -45,7 +45,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/lzw_fuzzer.cc b/fuzz/lzw_fuzzer.cc index 5e01750..ab13c52 100644 --- a/fuzz/lzw_fuzzer.cc +++ b/fuzz/lzw_fuzzer.cc @@ -37,7 +37,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/pngpredictor_fuzzer.cc b/fuzz/pngpredictor_fuzzer.cc index 7a39c8e..b30ec6a 100644 --- a/fuzz/pngpredictor_fuzzer.cc +++ b/fuzz/pngpredictor_fuzzer.cc @@ -37,7 +37,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/qpdf_crypt_fuzzer.cc b/fuzz/qpdf_crypt_fuzzer.cc index f310b50..9d0128f 100644 --- a/fuzz/qpdf_crypt_fuzzer.cc +++ b/fuzz/qpdf_crypt_fuzzer.cc @@ -76,9 +76,9 @@ FuzzHelper::doWrite(std::shared_ptr w) try { w->write(); } catch (QPDFExc const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } } @@ -135,9 +135,9 @@ FuzzHelper::run() try { doChecks(); } catch (QPDFExc const& e) { - std::cerr << "QPDFExc: " << e.what() << std::endl; + std::cerr << "QPDFExc: " << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/qpdf_crypt_insecure_fuzzer.cc b/fuzz/qpdf_crypt_insecure_fuzzer.cc index 76d1337..8b6c9b3 100644 --- a/fuzz/qpdf_crypt_insecure_fuzzer.cc +++ b/fuzz/qpdf_crypt_insecure_fuzzer.cc @@ -75,9 +75,9 @@ FuzzHelper::doWrite(std::shared_ptr w) try { w->write(); } catch (QPDFExc const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } } @@ -135,9 +135,9 @@ FuzzHelper::run() try { doChecks(); } catch (QPDFExc const& e) { - std::cerr << "QPDFExc: " << e.what() << std::endl; + std::cerr << "QPDFExc: " << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/qpdf_fuzzer.cc b/fuzz/qpdf_fuzzer.cc index 65aac38..d43c756 100644 --- a/fuzz/qpdf_fuzzer.cc +++ b/fuzz/qpdf_fuzzer.cc @@ -75,9 +75,9 @@ FuzzHelper::doWrite(std::shared_ptr w) try { w->write(); } catch (QPDFExc const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } } @@ -133,9 +133,9 @@ FuzzHelper::run() try { doChecks(); } catch (QPDFExc const& e) { - std::cerr << "QPDFExc: " << e.what() << std::endl; + std::cerr << "QPDFExc: " << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/qpdf_lin_fuzzer.cc b/fuzz/qpdf_lin_fuzzer.cc index 3be6a7d..a6b9c31 100644 --- a/fuzz/qpdf_lin_fuzzer.cc +++ b/fuzz/qpdf_lin_fuzzer.cc @@ -75,9 +75,9 @@ FuzzHelper::doWrite(std::shared_ptr w) try { w->write(); } catch (QPDFExc const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; } } @@ -134,9 +134,9 @@ FuzzHelper::run() try { doChecks(); } catch (QPDFExc const& e) { - std::cerr << "QPDFExc: " << e.what() << std::endl; + std::cerr << "QPDFExc: " << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/qpdf_outlines_fuzzer.cc b/fuzz/qpdf_outlines_fuzzer.cc index 7a2f791..669395b 100644 --- a/fuzz/qpdf_outlines_fuzzer.cc +++ b/fuzz/qpdf_outlines_fuzzer.cc @@ -111,9 +111,9 @@ FuzzHelper::run() try { doChecks(); } catch (QPDFExc const& e) { - std::cerr << "QPDFExc: " << e.what() << std::endl; + std::cerr << "QPDFExc: " << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/qpdf_pages_fuzzer.cc b/fuzz/qpdf_pages_fuzzer.cc index 66c8439..4dd7ae5 100644 --- a/fuzz/qpdf_pages_fuzzer.cc +++ b/fuzz/qpdf_pages_fuzzer.cc @@ -132,9 +132,9 @@ FuzzHelper::run() try { doChecks(); } catch (QPDFExc const& e) { - std::cerr << "QPDFExc: " << e.what() << std::endl; + std::cerr << "QPDFExc: " << e.what() << '\n'; } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/runlength_fuzzer.cc b/fuzz/runlength_fuzzer.cc index b19cd30..c185f51 100644 --- a/fuzz/runlength_fuzzer.cc +++ b/fuzz/runlength_fuzzer.cc @@ -38,7 +38,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/fuzz/standalone_fuzz_target_runner.cc b/fuzz/standalone_fuzz_target_runner.cc index 9d57481..5437e33 100644 --- a/fuzz/standalone_fuzz_target_runner.cc +++ b/fuzz/standalone_fuzz_target_runner.cc @@ -12,7 +12,7 @@ main(int argc, char** argv) size_t size = 0; QUtil::read_file_into_memory(argv[i], file_buf, size); LLVMFuzzerTestOneInput(reinterpret_cast(file_buf.get()), size); - std::cout << argv[i] << " successful" << std::endl; + std::cout << argv[i] << " successful" << '\n'; } return 0; } diff --git a/fuzz/tiffpredictor_fuzzer.cc b/fuzz/tiffpredictor_fuzzer.cc index 21b7f61..5811a0f 100644 --- a/fuzz/tiffpredictor_fuzzer.cc +++ b/fuzz/tiffpredictor_fuzzer.cc @@ -41,7 +41,7 @@ FuzzHelper::run() try { doChecks(); } catch (std::runtime_error const& e) { - std::cerr << "runtime_error: " << e.what() << std::endl; + std::cerr << "runtime_error: " << e.what() << '\n'; } } diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc index 9433793..9490fa5 100644 --- a/libqpdf/QPDFArgParser.cc +++ b/libqpdf/QPDFArgParser.cc @@ -198,13 +198,13 @@ QPDFArgParser::completionCommon(bool zsh) if (!zsh) { std::cout << " -o nospace"; } - std::cout << " -C \"" << progname << "\" " << m->whoami << std::endl; + std::cout << " -C \"" << progname << "\" " << m->whoami << '\n'; // Put output before error so calling from zsh works properly std::string path = progname; size_t slash = path.find('/'); if ((slash != 0) && (slash != std::string::npos)) { std::cerr << "WARNING: " << m->whoami << " completion enabled" - << " using relative path to executable" << std::endl; + << " using relative path to executable" << '\n'; } } @@ -666,7 +666,7 @@ QPDFArgParser::handleCompletion() std::string prefix = extra_prefix + m->bash_cur; for (auto const& iter: m->completions) { if (prefix.empty() || (iter.substr(0, prefix.length()) == prefix)) { - std::cout << iter << std::endl; + std::cout << iter << '\n'; } } exit(0); @@ -729,13 +729,13 @@ QPDFArgParser::addOptionHelp( void QPDFArgParser::getTopHelp(std::ostringstream& msg) { - msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." << std::endl - << "Run \"" << m->whoami << " --help=--option\" for help on an option." << std::endl - << "Run \"" << m->whoami << " --help=all\" to see all available help." << std::endl - << std::endl - << "Topics:" << std::endl; + msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." << '\n' + << "Run \"" << m->whoami << " --help=--option\" for help on an option." << '\n' + << "Run \"" << m->whoami << " --help=all\" to see all available help." << '\n' + << '\n' + << "Topics:" << '\n'; for (auto const& i: m->help_topics) { - msg << " " << i.first << ": " << i.second.short_text << std::endl; + msg << " " << i.first << ": " << i.second.short_text << '\n'; } } @@ -746,29 +746,27 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) auto show = [this, &msg](std::map& topics) { for (auto const& i: topics) { auto const& topic = i.first; - msg << std::endl - << "== " << topic << " (" << i.second.short_text << ") ==" << std::endl - << std::endl; + msg << '\n' << "== " << topic << " (" << i.second.short_text << ") ==" << '\n' << '\n'; getTopicHelp(topic, i.second, msg); } }; show(m->help_topics); show(m->option_help); - msg << std::endl << "====" << std::endl; + msg << '\n' << "====" << '\n'; } void QPDFArgParser::getTopicHelp(std::string const& name, HelpTopic const& ht, std::ostringstream& msg) { if (ht.long_text.empty()) { - msg << ht.short_text << std::endl; + msg << ht.short_text << '\n'; } else { msg << ht.long_text; } if (!ht.options.empty()) { - msg << std::endl << "Related options:" << std::endl; + msg << '\n' << "Related options:" << '\n'; for (auto const& i: ht.options) { - msg << " " << i << ": " << m->option_help[i].short_text << std::endl; + msg << " " << i << ": " << m->option_help[i].short_text << '\n'; } } } diff --git a/libqpdf/QPDFJob_json.cc b/libqpdf/QPDFJob_json.cc index eb24bd3..c4333d0 100644 --- a/libqpdf/QPDFJob_json.cc +++ b/libqpdf/QPDFJob_json.cc @@ -630,7 +630,7 @@ QPDFJob::initializeFromJson(std::string const& json, bool partial) std::ostringstream msg; msg << m->message_prefix << ": job json has errors:"; for (auto const& error: errors) { - msg << std::endl << " " << error; + msg << "\n " << error; } throw std::runtime_error(msg.str()); } diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 3c3d86b..a820f7b 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -161,7 +161,7 @@ QPDF::test_json_validators() auto check_fn = [&passed](char const* msg, bool expr) { if (!expr) { passed = false; - std::cerr << msg << std::endl; + std::cerr << msg << '\n'; } }; #define check(expr) check_fn(#expr, expr) diff --git a/libtests/aes.cc b/libtests/aes.cc index 370cd65..ad1e9f8 100644 --- a/libtests/aes.cc +++ b/libtests/aes.cc @@ -11,15 +11,15 @@ static void usage() { - std::cerr << "Usage: aes options hex-key infile outfile" << std::endl - << " -cbc -- disable CBC mode" << std::endl - << " +cbc -- enable CBC mode" << std::endl - << " -encrypt -- encrypt" << std::endl - << " -decrypt -- decrypt CBC mode" << std::endl - << " -zero-iv -- use zero initialization vector" << std::endl - << " -static-iv -- use static initialization vector" << std::endl - << " -no-padding -- disable padding" << std::endl - << "Options must precede key and file names." << std::endl; + std::cerr << "Usage: aes options hex-key infile outfile" << '\n' + << " -cbc -- disable CBC mode" << '\n' + << " +cbc -- enable CBC mode" << '\n' + << " -encrypt -- encrypt" << '\n' + << " -decrypt -- decrypt CBC mode" << '\n' + << " -zero-iv -- use zero initialization vector" << '\n' + << " -static-iv -- use static initialization vector" << '\n' + << " -no-padding -- disable padding" << '\n' + << "Options must precede key and file names." << '\n'; exit(2); } diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc index ad9d85e..872fbad 100644 --- a/libtests/arg_parser.cc +++ b/libtests/arg_parser.cc @@ -82,7 +82,7 @@ void ArgParser::output(std::string const& msg) { if (!this->ap.isCompleting()) { - std::cout << msg << std::endl; + std::cout << msg << '\n'; } } @@ -160,7 +160,7 @@ ArgParser::test_exceptions() fn(); assert(msg == nullptr); } catch (std::exception& e) { - std::cout << msg << ": " << e.what() << std::endl; + std::cout << msg << ": " << e.what() << '\n'; } }; @@ -196,10 +196,10 @@ main(int argc, char* argv[]) try { ap.parseArgs(); } catch (QPDFUsage& e) { - std::cerr << "usage: " << e.what() << std::endl; + std::cerr << "usage: " << e.what() << '\n'; exit(2); } catch (std::exception& e) { - std::cerr << "exception: " << e.what() << std::endl; + std::cerr << "exception: " << e.what() << '\n'; exit(3); } return 0; diff --git a/libtests/ascii85.cc b/libtests/ascii85.cc index dad0c30..ded081d 100644 --- a/libtests/ascii85.cc +++ b/libtests/ascii85.cc @@ -23,7 +23,7 @@ main() } decode.finish(); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/libtests/base64.cc b/libtests/base64.cc index 41dc676..f65af1b 100644 --- a/libtests/base64.cc +++ b/libtests/base64.cc @@ -20,7 +20,7 @@ write_some(FILE* f, size_t bytes, Pipeline* p) } if (len < bytes) { if (ferror(f)) { - std::cerr << "error reading file" << std::endl; + std::cerr << "error reading file" << '\n'; exit(2); } p->finish(); @@ -32,7 +32,7 @@ write_some(FILE* f, size_t bytes, Pipeline* p) static void usage() { - std::cerr << "Usage: base64 encode|decode" << std::endl; + std::cerr << "Usage: base64 encode|decode" << '\n'; exit(2); } @@ -74,7 +74,7 @@ main(int argc, char* argv[]) } } } catch (std::exception& e) { - std::cout << "exception: " << e.what() << std::endl; + std::cout << "exception: " << e.what() << '\n'; exit(2); } diff --git a/libtests/bits.cc b/libtests/bits.cc index bba1fd4..b9b5547 100644 --- a/libtests/bits.cc +++ b/libtests/bits.cc @@ -16,7 +16,7 @@ static void print_values(long long byte_offset, size_t bit_offset, size_t bits_available) { std::cout << "byte offset = " << byte_offset << ", " << "bit offset = " << bit_offset << ", " - << "bits available = " << bits_available << std::endl; + << "bits available = " << bits_available << '\n'; } static void @@ -29,7 +29,7 @@ test_read_bits( { unsigned long result = QIntC::to_ulong(read_bits(p, bit_offset, bits_available, bits_wanted)); - std::cout << "bits read: " << bits_wanted << ", result = " << result << std::endl; + std::cout << "bits read: " << bits_wanted << ", result = " << result << '\n'; print_values(p - buf, bit_offset, bits_available); } @@ -39,7 +39,7 @@ test_write_bits( { write_bits(ch, bit_offset, val, bits, bp); std::cout << "ch = " << QUtil::uint_to_string_base(ch, 16, 2) << ", bit_offset = " << bit_offset - << std::endl; + << '\n'; } static void @@ -52,7 +52,7 @@ print_buffer(Pl_Buffer* bp) for (unsigned long i = 0; i < l; ++i) { std::cout << QUtil::uint_to_string_base(p[i], 16, 2) << ((i == l - 1) ? "\n" : " "); } - std::cout << std::endl; + std::cout << '\n'; delete b; } @@ -86,12 +86,12 @@ test() try { test_read_bits(buf, p, bit_offset, bits_available, 4); } catch (std::exception& e) { - std::cout << "exception: " << e.what() << std::endl; + std::cout << "exception: " << e.what() << '\n'; print_values(p - buf, bit_offset, bits_available); } test_read_bits(buf, p, bit_offset, bits_available, 3); - std::cout << std::endl; + std::cout << '\n'; // 11110101 00010101 01100101 01111001: 00010010 10001001 01110101 01001011 @@ -101,29 +101,29 @@ test() print_values(p - buf, bit_offset, bits_available); test_read_bits(buf, p, bit_offset, bits_available, 32); test_read_bits(buf, p, bit_offset, bits_available, 32); - std::cout << std::endl; + std::cout << '\n'; BitStream b(buf, 8); - std::cout << b.getBits(32) << std::endl; + std::cout << b.getBits(32) << '\n'; b.reset(); - std::cout << b.getBits(32) << std::endl; - std::cout << b.getBits(32) << std::endl; - std::cout << std::endl; + std::cout << b.getBits(32) << '\n'; + std::cout << b.getBits(32) << '\n'; + std::cout << '\n'; b.reset(); - std::cout << b.getBits(6) << std::endl; + std::cout << b.getBits(6) << '\n'; b.skipToNextByte(); - std::cout << b.getBits(8) << std::endl; + std::cout << b.getBits(8) << '\n'; b.skipToNextByte(); - std::cout << b.getBits(8) << std::endl; - std::cout << std::endl; + std::cout << b.getBits(8) << '\n'; + std::cout << '\n'; b.reset(); - std::cout << b.getBitsSigned(3) << std::endl; - std::cout << b.getBitsSigned(6) << std::endl; - std::cout << b.getBitsSigned(5) << std::endl; - std::cout << b.getBitsSigned(1) << std::endl; - std::cout << b.getBitsSigned(17) << std::endl; - std::cout << std::endl; + std::cout << b.getBitsSigned(3) << '\n'; + std::cout << b.getBitsSigned(6) << '\n'; + std::cout << b.getBitsSigned(5) << '\n'; + std::cout << b.getBitsSigned(1) << '\n'; + std::cout << b.getBitsSigned(17) << '\n'; + std::cout << '\n'; // Write tests @@ -176,9 +176,9 @@ main() try { test(); } catch (std::exception& e) { - std::cout << "unexpected exception: " << e.what() << std::endl; + std::cout << "unexpected exception: " << e.what() << '\n'; exit(2); } - std::cout << "done" << std::endl; + std::cout << "done" << '\n'; return 0; } diff --git a/libtests/buffer.cc b/libtests/buffer.cc index 4326901..295597c 100644 --- a/libtests/buffer.cc +++ b/libtests/buffer.cc @@ -85,22 +85,22 @@ main() bp1.write(uc("12345"), 5); bp1.write(uc("67890"), 5); bp1.finish(); - std::cout << "count: " << count.getCount() << std::endl; + std::cout << "count: " << count.getCount() << '\n'; bp1.write(uc("abcde"), 5); bp1.write(uc("fghij"), 6); bp1.finish(); - std::cout << "count: " << count.getCount() << std::endl; + std::cout << "count: " << count.getCount() << '\n'; Buffer* b = bp1.getBuffer(); - std::cout << "size: " << b->getSize() << std::endl; - std::cout << "data: " << b->getBuffer() << std::endl; + std::cout << "size: " << b->getSize() << '\n'; + std::cout << "data: " << b->getBuffer() << '\n'; delete b; bp1.write(uc("qwert"), 5); bp1.write(uc("yuiop"), 6); bp1.finish(); - std::cout << "count: " << count.getCount() << std::endl; + std::cout << "count: " << count.getCount() << '\n'; b = bp1.getBuffer(); - std::cout << "size: " << b->getSize() << std::endl; - std::cout << "data: " << b->getBuffer() << std::endl; + std::cout << "size: " << b->getSize() << '\n'; + std::cout << "data: " << b->getBuffer() << '\n'; delete b; Pl_Buffer bp2("bp2"); @@ -109,12 +109,12 @@ main() try { delete bp2.getBuffer(); } catch (std::exception& e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; } bp2.finish(); b = bp2.getBuffer(); - std::cout << "size: " << b->getSize() << std::endl; - std::cout << "data: " << b->getBuffer() << std::endl; + std::cout << "size: " << b->getSize() << '\n'; + std::cout << "data: " << b->getBuffer() << '\n'; delete b; unsigned char lbuf[10]; @@ -125,17 +125,17 @@ main() Pl_Buffer bp3("bp3"); b = bp3.getBuffer(); - std::cout << "size: " << b->getSize() << std::endl; + std::cout << "size: " << b->getSize() << '\n'; delete b; // Should be able to call getBuffer again and get an empty buffer b = bp3.getBuffer(); - std::cout << "size: " << b->getSize() << std::endl; + std::cout << "size: " << b->getSize() << '\n'; delete b; // Also can write 0 and do it. bp3.write(uc(""), 0); bp3.finish(); b = bp3.getBuffer(); - std::cout << "size: " << b->getSize() << std::endl; + std::cout << "size: " << b->getSize() << '\n'; delete b; // Malloc buffer should behave similarly. @@ -147,7 +147,7 @@ main() bp4.getMallocBuffer(&mbuf, &len); assert(false); } catch (std::logic_error& e) { - std::cout << "malloc buffer logic error: " << e.what() << std::endl; + std::cout << "malloc buffer logic error: " << e.what() << '\n'; } bp4.finish(); bp4.getMallocBuffer(&mbuf, &len); @@ -160,10 +160,10 @@ main() assert(mbuf == nullptr); assert(len == 0); } catch (std::exception& e) { - std::cout << "unexpected exception: " << e.what() << std::endl; + std::cout << "unexpected exception: " << e.what() << '\n'; exit(2); } - std::cout << "done" << std::endl; + std::cout << "done" << '\n'; return 0; } diff --git a/libtests/closed_file_input_source.cc b/libtests/closed_file_input_source.cc index 8825335..c215d03 100644 --- a/libtests/closed_file_input_source.cc +++ b/libtests/closed_file_input_source.cc @@ -8,7 +8,7 @@ void check(std::string const& what, bool result) { if (!result) { - std::cout << "FAIL: " << what << std::endl; + std::cout << "FAIL: " << what << '\n'; } } @@ -73,6 +73,6 @@ main() std::cout << "testing with FileInputSource\n"; FileInputSource f("input"); do_tests(&f); - std::cout << "all assertions passed" << std::endl; + std::cout << "all assertions passed" << '\n'; return 0; } diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc index 380d8cd..a3d4895 100644 --- a/libtests/concatenate.cc +++ b/libtests/concatenate.cc @@ -31,9 +31,9 @@ main(int argc, char* argv[]) auto b2_buf = b2.getBufferSharedPointer(); std::string result(reinterpret_cast(b2_buf->getBuffer()), b2_buf->getSize()); if (result == "-one--two-") { - std::cout << "concatenate test passed" << std::endl; + std::cout << "concatenate test passed" << '\n'; } else { - std::cout << "concatenate test failed: " << result << std::endl; + std::cout << "concatenate test failed: " << result << '\n'; } return 0; } diff --git a/libtests/dct_compress.cc b/libtests/dct_compress.cc index 93979bd..46e1ab5 100644 --- a/libtests/dct_compress.cc +++ b/libtests/dct_compress.cc @@ -12,7 +12,7 @@ static void usage() { - std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << std::endl; + std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << '\n'; exit(2); } diff --git a/libtests/dct_uncompress.cc b/libtests/dct_uncompress.cc index c4255b5..fd2c812 100644 --- a/libtests/dct_uncompress.cc +++ b/libtests/dct_uncompress.cc @@ -10,7 +10,7 @@ int main(int argc, char* argv[]) { if (argc != 3) { - std::cerr << "Usage: dct_uncompress infile outfile" << std::endl; + std::cerr << "Usage: dct_uncompress infile outfile" << '\n'; exit(2); } diff --git a/libtests/flate.cc b/libtests/flate.cc index a14612c..7d8f821 100644 --- a/libtests/flate.cc +++ b/libtests/flate.cc @@ -53,7 +53,7 @@ run(char const* filename) def3->finish(); - std::cout << "bytes written to o3: " << count3->getCount() << std::endl; + std::cout << "bytes written to o3: " << count3->getCount() << '\n'; delete def3; delete inf3; @@ -76,14 +76,14 @@ run(char const* filename) // At this point, filename, filename.2, and filename.3 should have // identical contents. filename.1 should be a compressed version. - std::cout << "done" << std::endl; + std::cout << "done" << '\n'; } int main(int argc, char* argv[]) { if (argc != 2) { - std::cerr << "Usage: pipeline filename" << std::endl; + std::cerr << "Usage: pipeline filename" << '\n'; exit(2); } char* filename = argv[1]; @@ -91,7 +91,7 @@ main(int argc, char* argv[]) try { run(filename); } catch (std::exception& e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; } return 0; } diff --git a/libtests/hex.cc b/libtests/hex.cc index 5f11f87..98a1178 100644 --- a/libtests/hex.cc +++ b/libtests/hex.cc @@ -23,7 +23,7 @@ main() } decode.finish(); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/libtests/input_source.cc b/libtests/input_source.cc index 4111fd6..c1baeb5 100644 --- a/libtests/input_source.cc +++ b/libtests/input_source.cc @@ -47,7 +47,7 @@ Finder::check() void check(char const* description, bool expected, bool actual) { - std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") << std::endl; + std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") << '\n'; } int diff --git a/libtests/json.cc b/libtests/json.cc index aa726d6..7e49fa7 100644 --- a/libtests/json.cc +++ b/libtests/json.cc @@ -186,12 +186,12 @@ static void check_schema(JSON& obj, JSON& schema, unsigned long flags, bool exp, std::string const& description) { std::list errors; - std::cout << "--- " << description << std::endl; + std::cout << "--- " << description << '\n'; assert(exp == obj.checkSchema(schema, flags, errors)); for (auto const& error: errors) { - std::cout << error << std::endl; + std::cout << error << '\n'; } - std::cout << "---" << std::endl; + std::cout << "---" << '\n'; } static void diff --git a/libtests/json_handler.cc b/libtests/json_handler.cc index 2d3f986..255a8c0 100644 --- a/libtests/json_handler.cc +++ b/libtests/json_handler.cc @@ -8,43 +8,43 @@ static void print_null(std::string const& path) { - std::cout << path << ": null" << std::endl; + std::cout << path << ": null" << '\n'; } static void print_string(std::string const& path, std::string const& value) { - std::cout << path << ": string: " << value << std::endl; + std::cout << path << ": string: " << value << '\n'; } static void print_number(std::string const& path, std::string const& value) { - std::cout << path << ": number: " << value << std::endl; + std::cout << path << ": number: " << value << '\n'; } static void print_bool(std::string const& path, bool value) { - std::cout << path << ": bool: " << (value ? "true" : "false") << std::endl; + std::cout << path << ": bool: " << (value ? "true" : "false") << '\n'; } static void print_json(std::string const& path, JSON value) { - std::cout << path << ": json: " << value.unparse() << std::endl; + std::cout << path << ": json: " << value.unparse() << '\n'; } static JSONHandler::void_handler_t make_print_message(std::string msg) { - return [msg](std::string const& path) { std::cout << path << ": json: " << msg << std::endl; }; + return [msg](std::string const& path) { std::cout << path << ": json: " << msg << '\n'; }; } static void test_scalar() { - std::cout << "-- scalar --" << std::endl; + std::cout << "-- scalar --" << '\n'; JSONHandler h; h.addStringHandler(print_string); JSON j = JSON::parse("\"potato\""); @@ -97,7 +97,7 @@ make_all_handler() static void test_all() { - std::cout << "-- all --" << std::endl; + std::cout << "-- all --" << '\n'; auto h = make_all_handler(); /* cSpell: ignore phour */ JSON j = JSON::parse(R"({ @@ -110,7 +110,7 @@ test_all() "six": {"a": {"b": "quack", "Q": "baaa"}, "b": "moo"} })"); h->handle(".", j); - std::cerr << "-- fallback --" << std::endl; + std::cerr << "-- fallback --" << '\n'; j = JSON::parse(R"({ "five": "not-array" })"); @@ -120,14 +120,14 @@ test_all() static void test_errors() { - std::cout << "-- errors --" << std::endl; + std::cout << "-- errors --" << '\n'; auto h = make_all_handler(); auto t = [h](std::string const& msg, std::function fn) { try { fn(); assert(false); } catch (QPDFUsage& e) { - std::cout << msg << ": " << e.what() << std::endl; + std::cout << msg << ": " << e.what() << '\n'; } }; diff --git a/libtests/json_parse.cc b/libtests/json_parse.cc index 757b698..1a737bf 100644 --- a/libtests/json_parse.cc +++ b/libtests/json_parse.cc @@ -26,13 +26,13 @@ namespace void Reactor::dictionaryStart() { - std::cout << "dictionary start" << std::endl; + std::cout << "dictionary start" << '\n'; } void Reactor::arrayStart() { - std::cout << "array start" << std::endl; + std::cout << "array start" << '\n'; } void @@ -45,7 +45,7 @@ Reactor::containerEnd(JSON const& value) void Reactor::topLevelScalar() { - std::cout << "top-level scalar" << std::endl; + std::cout << "top-level scalar" << '\n'; } bool @@ -74,13 +74,13 @@ Reactor::arrayItem(JSON const& value) void Reactor::printItem(JSON const& j) { - std::cout << "[" << j.getStart() << ", " << j.getEnd() << "): " << j.unparse() << std::endl; + std::cout << "[" << j.getStart() << ", " << j.getEnd() << "): " << j.unparse() << '\n'; } static void usage() { - std::cerr << "Usage: json_parse file [--react]" << std::endl; + std::cerr << "Usage: json_parse file [--react]" << '\n'; exit(2); } @@ -102,9 +102,9 @@ main(int argc, char* argv[]) } try { FileInputSource is(filename); - std::cout << JSON::parse(is, reactor.get()).unparse() << std::endl; + std::cout << JSON::parse(is, reactor.get()).unparse() << '\n'; } catch (std::exception& e) { - std::cerr << "exception: " << filename << ": " << e.what() << std::endl; + std::cerr << "exception: " << filename << ": " << e.what() << '\n'; return 2; } return 0; diff --git a/libtests/lzw.cc b/libtests/lzw.cc index 3d255b2..19d0997 100644 --- a/libtests/lzw.cc +++ b/libtests/lzw.cc @@ -15,7 +15,7 @@ main(int argc, char* argv[]) } if (argc < 3) { - std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" << std::endl; + std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" << '\n'; exit(2); } @@ -41,7 +41,7 @@ main(int argc, char* argv[]) } decode.finish(); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/libtests/main_from_wmain.cc b/libtests/main_from_wmain.cc index b2290b2..bb8051e 100644 --- a/libtests/main_from_wmain.cc +++ b/libtests/main_from_wmain.cc @@ -8,7 +8,7 @@ wmain_test() // writable args and function args auto realmain = [](int argc, char* argv[]) { for (int i = 0; i < argc; ++i) { - std::cout << argv[i] << std::endl; + std::cout << argv[i] << '\n'; } return 0; }; @@ -28,7 +28,7 @@ cwmain_test() // const args and function args auto realmain = [](int argc, char const* const argv[]) { for (int i = 0; i < argc; ++i) { - std::cout << "const " << argv[i] << std::endl; + std::cout << "const " << argv[i] << '\n'; } return 0; }; @@ -49,7 +49,7 @@ main(int argc, char* argv[]) wmain_test(); cwmain_test(); } catch (std::exception& e) { - std::cout << "unexpected exception: " << e.what() << std::endl; + std::cout << "unexpected exception: " << e.what() << '\n'; } #endif // QPDF_NO_WCHAR_T diff --git a/libtests/matrix.cc b/libtests/matrix.cc index 70380f0..35f7ca0 100644 --- a/libtests/matrix.cc +++ b/libtests/matrix.cc @@ -9,7 +9,7 @@ check(QPDFMatrix const& m, std::string const& exp) { std::string u = m.unparse(); if (u != exp) { - std::cout << "got " << u << ", wanted " << exp << std::endl; + std::cout << "got " << u << ", wanted " << exp << '\n'; } } @@ -18,7 +18,7 @@ check_xy(double x, double y, std::string const& exp) { std::string u = (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2)); if (u != exp) { - std::cout << "got " << u << ", wanted " << exp << std::endl; + std::cout << "got " << u << ", wanted " << exp << '\n'; } } @@ -32,7 +32,7 @@ check_rect(QPDFObjectHandle::Rectangle const& r, double llx, double lly, double (QUtil::double_to_string(llx, 2) + " " + QUtil::double_to_string(lly, 2) + " " + QUtil::double_to_string(urx, 2) + " " + QUtil::double_to_string(ury, 2)); if (actual != wanted) { - std::cout << "got " << actual << ", wanted " << wanted << std::endl; + std::cout << "got " << actual << ", wanted " << wanted << '\n'; } } @@ -78,6 +78,6 @@ main() m.translate(200, -100); check_rect(m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)), 50, 210, 80, 230); - std::cout << "matrix tests done" << std::endl; + std::cout << "matrix tests done" << '\n'; return 0; } diff --git a/libtests/md5.cc b/libtests/md5.cc index 93bfe58..afbc643 100644 --- a/libtests/md5.cc +++ b/libtests/md5.cc @@ -29,16 +29,16 @@ main(int, char*[]) "1234567890123456789012345678901234567890"); MD5 a; a.encodeFile("md5.in"); - std::cout << a.unparse() << std::endl; + std::cout << a.unparse() << '\n'; MD5 b; b.encodeFile("md5.in", 100); - std::cout << b.unparse() << std::endl; + std::cout << b.unparse() << '\n'; - std::cout << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl - << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl - << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl - << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl - << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") << std::endl; + std::cout << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) << '\n' + << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") << '\n' + << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") << '\n' + << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) << '\n' + << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") << '\n'; Pl_Discard d; Pl_MD5 p("MD5", &d); @@ -63,7 +63,7 @@ main(int, char*[]) p2.write(buf, len); if (i == 1) { // Partial digest -- resets after each call to write - std::cout << p.getHexDigest() << std::endl; + std::cout << p.getHexDigest() << '\n'; } } } @@ -72,10 +72,10 @@ main(int, char*[]) p2.finish(); // Make sure calling getHexDigest twice with no intervening // writes results in the same result each time. - std::cout << p.getHexDigest() << std::endl; - std::cout << p.getHexDigest() << std::endl; + std::cout << p.getHexDigest() << '\n'; + std::cout << p.getHexDigest() << '\n'; } - std::cout << p2.getHexDigest() << std::endl; + std::cout << p2.getHexDigest() << '\n'; return 0; } diff --git a/libtests/nntree.cc b/libtests/nntree.cc index c2b35dc..ac6ff98 100644 --- a/libtests/nntree.cc +++ b/libtests/nntree.cc @@ -20,7 +20,7 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item) auto show = [&failed, &oh, &item]() { if (!failed) { failed = true; - std::cout << "key = " << item << ", oh = " << oh.unparseResolved() << std::endl; + std::cout << "key = " << item << ", oh = " << oh.unparseResolved() << '\n'; } }; @@ -37,11 +37,11 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item) if (i1_wanted != i1_actual) { show(); - std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual << std::endl; + std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual << '\n'; } if (i2_wanted != i2_actual) { show(); - std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual << std::endl; + std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual << '\n'; } return failed; @@ -106,7 +106,7 @@ test_bsearch() r(d, 25, 20); if (!any_failures) { - std::cout << "bsearch tests passed" << std::endl; + std::cout << "bsearch tests passed" << '\n'; } } @@ -128,7 +128,7 @@ check_find(QPDFNameTreeObjectHelper& nh, std::string const& key, bool prev_if_no } else { std::cout << (*i).first << " -> " << (*i).second.unparse(); } - std::cout << std::endl; + std::cout << '\n'; } void @@ -183,13 +183,13 @@ test_depth() } QPDFNameTreeObjectHelper nh(n0, q); - std::cout << "--- forward ---" << std::endl; + std::cout << "--- forward ---" << '\n'; for (auto i: nh) { - std::cout << i.first << " -> " << i.second.unparse() << std::endl; + std::cout << i.first << " -> " << i.second.unparse() << '\n'; } - std::cout << "--- backward ---" << std::endl; + std::cout << "--- backward ---" << '\n'; for (auto i = nh.last(); i.valid(); --i) { - std::cout << (*i).first << " -> " << (*i).second.unparse() << std::endl; + std::cout << (*i).first << " -> " << (*i).second.unparse() << '\n'; } // Find diff --git a/libtests/numrange.cc b/libtests/numrange.cc index ded0332..b3ae05d 100644 --- a/libtests/numrange.cc +++ b/libtests/numrange.cc @@ -5,14 +5,14 @@ static void test_numrange(char const* range) { if (range == nullptr) { - std::cout << "null" << std::endl; + std::cout << "null" << '\n'; } else { std::vector result = QUtil::parse_numrange(range, 15); std::cout << "numeric range " << range << " ->"; for (int i: result) { std::cout << " " << i; } - std::cout << std::endl; + std::cout << '\n'; } } @@ -22,7 +22,7 @@ main(int argc, char* argv[]) try { test_numrange(argv[1]); } catch (std::exception& e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; return 2; } diff --git a/libtests/pdf_version.cc b/libtests/pdf_version.cc index 5db444b..42b20c2 100644 --- a/libtests/pdf_version.cc +++ b/libtests/pdf_version.cc @@ -48,6 +48,6 @@ main() assert(PDFVersion(2, 0) == PDFVersion(2, 0)); assert(PDFVersion(2, 0, 1) == PDFVersion(2, 0, 1)); - std::cout << "PDFVersion assertions passed" << std::endl; + std::cout << "PDFVersion assertions passed" << '\n'; return 0; } diff --git a/libtests/pl_function.cc b/libtests/pl_function.cc index 2829671..bfde64d 100644 --- a/libtests/pl_function.cc +++ b/libtests/pl_function.cc @@ -18,7 +18,7 @@ f(unsigned char const* data, size_t len, void* udata) { auto c = reinterpret_cast(udata); ++c->count; - std::cout << "got " << data << "(" << len << ")" << std::endl; + std::cout << "got " << data << "(" << len << ")" << '\n'; if (c->count == 3) { return 1; } @@ -30,7 +30,7 @@ g(char const* data, size_t len, void* udata) { auto c = reinterpret_cast(udata); ++c->count; - std::cout << "signed got " << data << "(" << len << ")" << std::endl; + std::cout << "signed got " << data << "(" << len << ")" << '\n'; if (c->count == 2) { return 2; } @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) { Pl_Function p1("p1", nullptr, [](unsigned char const* data, size_t len) { - std::cout << "p1: " << len << ": " << data << std::endl; + std::cout << "p1: " << len << ": " << data << '\n'; }); p1.write(reinterpret_cast("potato"), 6); @@ -49,7 +49,7 @@ main(int argc, char* argv[]) Pl_String ps("string", nullptr, s); Pl_Base64 b("base64", &ps, Pl_Base64::a_encode); Pl_Function p2("p2", &b, [](unsigned char const* data, size_t len) { - std::cout << "p2: " << len << ": " << data << std::endl; + std::cout << "p2: " << len << ": " << data << '\n'; }); p2.write(reinterpret_cast("salad"), 5); p2.finish(); @@ -63,7 +63,7 @@ main(int argc, char* argv[]) p3 << "three"; assert(false); } catch (std::runtime_error& e) { - std::cout << "three threw " << e.what() << std::endl; + std::cout << "three threw " << e.what() << '\n'; } p3 << "four"; p3.finish(); @@ -76,7 +76,7 @@ main(int argc, char* argv[]) p4 << "salad"; assert(false); } catch (std::runtime_error& e) { - std::cout << "salad threw " << e.what() << std::endl; + std::cout << "salad threw " << e.what() << '\n'; } p4 << "quack"; p4.finish(); diff --git a/libtests/pointer_holder.cc b/libtests/pointer_holder.cc index 641cd0b..f86b01c 100644 --- a/libtests/pointer_holder.cc +++ b/libtests/pointer_holder.cc @@ -26,24 +26,24 @@ int Object::next_id = 0; Object::Object() { this->id = ++next_id; - std::cout << "created Object, id " << this->id << std::endl; + std::cout << "created Object, id " << this->id << '\n'; } Object::~Object() { - std::cout << "destroyed Object, id " << this->id << std::endl; + std::cout << "destroyed Object, id " << this->id << '\n'; } void Object::hello() { - std::cout << "calling Object::hello for " << this->id << std::endl; + std::cout << "calling Object::hello for " << this->id << '\n'; } void Object::hello() const { - std::cout << "calling Object::hello const for " << this->id << std::endl; + std::cout << "calling Object::hello const for " << this->id << '\n'; } typedef PointerHolder ObjectHolder; @@ -71,27 +71,27 @@ test_ph() ObjectHolder oh0; { - std::cout << "hello" << std::endl; + std::cout << "hello" << '\n'; auto* o1 = new Object; ObjectHolder oh1(o1); - std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl; + std::cout << "oh1 refcount = " << oh1.getRefcount() << '\n'; ObjectHolder oh2(oh1); - std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl; - std::cout << "oh2 refcount = " << oh2.use_count() << std::endl; + std::cout << "oh1 refcount = " << oh1.getRefcount() << '\n'; + std::cout << "oh2 refcount = " << oh2.use_count() << '\n'; ObjectHolder oh3(new Object); ObjectHolder oh4; ObjectHolder oh5; - std::cout << "oh5 refcount = " << oh5.getRefcount() << std::endl; + std::cout << "oh5 refcount = " << oh5.getRefcount() << '\n'; if (oh4 == oh5) { - std::cout << "nulls equal" << std::endl; + std::cout << "nulls equal" << '\n'; } oh3 = oh1; oh4 = oh2; if (oh3 == oh4) { - std::cout << "equal okay" << std::endl; + std::cout << "equal okay" << '\n'; } if ((!(oh3 < oh4)) && (!(oh4 < oh3))) { - std::cout << "less than okay" << std::endl; + std::cout << "less than okay" << '\n'; } ol1.push_back(oh3); ol1.push_back(oh3); @@ -107,9 +107,9 @@ test_ph() callHello(ol1.front()); callHelloWithGet(ol1.front()); ol1.pop_front(); - std::cout << "array" << std::endl; + std::cout << "array" << '\n'; PointerHolder o_arr1_ph(true, new Object[2]); - std::cout << "goodbye" << std::endl; + std::cout << "goodbye" << '\n'; } PointerHolder @@ -165,7 +165,7 @@ ph_sp_compat() { // Ensure bidirectional compatibility between PointerHolder and // shared_ptr. - std::cout << "compat" << std::endl; + std::cout << "compat" << '\n'; PointerHolder ph_from_ph = make_object_ph(); std::shared_ptr sp_from_ph = make_object_ph(); PointerHolder ph_from_sp = make_object_sp(); @@ -184,21 +184,21 @@ ph_sp_compat() hello_ph_const(sp_const_from_sp); PointerHolder arr1_ph; { - std::cout << "initialize ph array from shared_ptr" << std::endl; + std::cout << "initialize ph array from shared_ptr" << '\n'; std::shared_ptr arr1(new Object[2], std::default_delete()); arr1_ph = arr1; } - std::cout << "delete ph array" << std::endl; + std::cout << "delete ph array" << '\n'; arr1_ph = nullptr; std::shared_ptr arr2_sp; { - std::cout << "initialize sp array from PointerHolder" << std::endl; + std::cout << "initialize sp array from PointerHolder" << '\n'; PointerHolder arr2(true, new Object[2]); arr2_sp = arr2; } - std::cout << "delete sp array" << std::endl; + std::cout << "delete sp array" << '\n'; arr2_sp = nullptr; - std::cout << "end compat" << std::endl; + std::cout << "end compat" << '\n'; } std::list> @@ -224,13 +224,13 @@ get_sp_list() void ph_sp_containers() { - std::cout << "containers" << std::endl; + std::cout << "containers" << '\n'; // Demonstrate that using auto makes it easy to switch interfaces // from using a container of one shared pointer type to a // container of the other. auto phl1 = get_ph_list(); auto phl2 = get_sp_list(); - std::cout << "end containers" << std::endl; + std::cout << "end containers" << '\n'; } int diff --git a/libtests/predictors.cc b/libtests/predictors.cc index f41cf5c..25e4a5a 100644 --- a/libtests/predictors.cc +++ b/libtests/predictors.cc @@ -39,7 +39,7 @@ run(char const* filename, samples_per_pixel, bits_per_sample); } else { - std::cerr << "unknown filter " << filter << std::endl; + std::cerr << "unknown filter " << filter << '\n'; exit(2); } assert((2 * (columns + 1)) < 1024); @@ -69,7 +69,7 @@ run(char const* filename, fclose(o1); fclose(in); - std::cout << "done" << std::endl; + std::cout << "done" << '\n'; } int @@ -77,7 +77,7 @@ main(int argc, char* argv[]) { if (argc != 7) { std::cerr << "Usage: predictor {png|tiff} {en,de}code filename" - << " columns samples-per-pixel bits-per-sample" << std::endl; + << " columns samples-per-pixel bits-per-sample" << '\n'; exit(2); } char* filter = argv[1]; @@ -95,7 +95,7 @@ main(int argc, char* argv[]) QIntC::to_uint(bits_per_sample), QIntC::to_uint(samples_per_pixel)); } catch (std::exception& e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; } return 0; } diff --git a/libtests/qintc.cc b/libtests/qintc.cc index d7711c2..f548324 100644 --- a/libtests/qintc.cc +++ b/libtests/qintc.cc @@ -18,7 +18,7 @@ try_convert_real(char const* description, bool exp_pass, To (*fn)(From const&), std::cout << description << ": " << e.what(); passed = false; } - std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl; + std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << '\n'; } #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& a, T const std::cout << description << ": " << e.what(); passed = false; } - std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl; + std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << '\n'; } #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& a std::cout << description << ": " << e.what(); passed = false; } - std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl; + std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << '\n'; } int diff --git a/libtests/qutil.cc b/libtests/qutil.cc index 78ae82c..30dcd1e 100644 --- a/libtests/qutil.cc +++ b/libtests/qutil.cc @@ -32,13 +32,13 @@ test_to_number(char const* str, int_T wanted, bool error, int_T (*fn)(char const } if (threw) { if (error) { - std::cout << str << " to int threw (" << msg << "): PASSED" << std::endl; + std::cout << str << " to int threw (" << msg << "): PASSED" << '\n'; } else { std::cout << str << " to int threw but wanted " << wanted << std::endl; } } else { if (worked) { - std::cout << str << " to int: PASSED" << std::endl; + std::cout << str << " to int: PASSED" << '\n'; } else { std::cout << str << " to int failed; got " << result << std::endl; } @@ -97,51 +97,51 @@ string_conversion_test() // Make sure the code produces consistent results even if we load // a non-C locale. set_locale(); - std::cout << QUtil::int_to_string(16059) << std::endl - << QUtil::int_to_string(16059, 7) << std::endl - << QUtil::int_to_string(16059, -7) << std::endl - << QUtil::double_to_string(3.14159, 0, false) << std::endl - << QUtil::double_to_string(3.14159, 3) << std::endl - << QUtil::double_to_string(1000.123, -1024, false) << std::endl - << QUtil::double_to_string(.1234, 5, false) << std::endl - << QUtil::double_to_string(.0001234, 5) << std::endl - << QUtil::double_to_string(.123456, 5) << std::endl - << QUtil::double_to_string(.000123456, 5) << std::endl - << QUtil::double_to_string(1.01020, 5, true) << std::endl - << QUtil::double_to_string(1.00000, 5, true) << std::endl - << QUtil::double_to_string(1, 5, true) << std::endl - << QUtil::double_to_string(1, 5, false) << std::endl - << QUtil::double_to_string(10, 2, false) << std::endl - << QUtil::double_to_string(10, 2, true) << std::endl - << QUtil::int_to_string_base(16059, 10) << std::endl - << QUtil::int_to_string_base(16059, 8) << std::endl - << QUtil::int_to_string_base(16059, 16) << std::endl - << QUtil::int_to_string_base(5000093552LL, 10) << std::endl; + std::cout << QUtil::int_to_string(16059) << '\n' + << QUtil::int_to_string(16059, 7) << '\n' + << QUtil::int_to_string(16059, -7) << '\n' + << QUtil::double_to_string(3.14159, 0, false) << '\n' + << QUtil::double_to_string(3.14159, 3) << '\n' + << QUtil::double_to_string(1000.123, -1024, false) << '\n' + << QUtil::double_to_string(.1234, 5, false) << '\n' + << QUtil::double_to_string(.0001234, 5) << '\n' + << QUtil::double_to_string(.123456, 5) << '\n' + << QUtil::double_to_string(.000123456, 5) << '\n' + << QUtil::double_to_string(1.01020, 5, true) << '\n' + << QUtil::double_to_string(1.00000, 5, true) << '\n' + << QUtil::double_to_string(1, 5, true) << '\n' + << QUtil::double_to_string(1, 5, false) << '\n' + << QUtil::double_to_string(10, 2, false) << '\n' + << QUtil::double_to_string(10, 2, true) << '\n' + << QUtil::int_to_string_base(16059, 10) << '\n' + << QUtil::int_to_string_base(16059, 8) << '\n' + << QUtil::int_to_string_base(16059, 16) << '\n' + << QUtil::int_to_string_base(5000093552LL, 10) << '\n'; std::string embedded_null = "one"; embedded_null += '\0'; embedded_null += "two"; - std::cout << embedded_null.c_str() << std::endl; - std::cout << embedded_null.length() << std::endl; + std::cout << embedded_null.c_str() << '\n'; + std::cout << embedded_null.length() << '\n'; char* tmp = QUtil::copy_string(embedded_null); if (memcmp(tmp, embedded_null.c_str(), 7) == 0) { - std::cout << "compare okay" << std::endl; + std::cout << "compare okay" << '\n'; } else { - std::cout << "compare failed" << std::endl; + std::cout << "compare failed" << '\n'; } delete[] tmp; // Also test with make_shared_cstr and make_unique_cstr auto tmp2 = QUtil::make_shared_cstr(embedded_null); if (memcmp(tmp2.get(), embedded_null.c_str(), 7) == 0) { - std::cout << "compare okay" << std::endl; + std::cout << "compare okay" << '\n'; } else { - std::cout << "compare failed" << std::endl; + std::cout << "compare failed" << '\n'; } auto tmp3 = QUtil::make_unique_cstr(embedded_null); if (memcmp(tmp3.get(), embedded_null.c_str(), 7) == 0) { - std::cout << "compare okay" << std::endl; + std::cout << "compare okay" << '\n'; } else { - std::cout << "compare failed" << std::endl; + std::cout << "compare failed" << '\n'; } std::string int_max_str = QUtil::int_to_string(INT_MAX); @@ -171,11 +171,11 @@ void os_wrapper_test() { try { - std::cout << "before remove" << std::endl; + std::cout << "before remove" << '\n'; QUtil::os_wrapper("remove file", remove("/this/file/does/not/exist")); - std::cout << "after remove" << std::endl; + std::cout << "after remove" << '\n'; } catch (std::runtime_error& s) { - std::cout << "exception: " << s.what() << std::endl; + std::cout << "exception: " << s.what() << '\n'; } } @@ -183,12 +183,12 @@ void fopen_wrapper_test() { try { - std::cout << "before fopen" << std::endl; + std::cout << "before fopen" << '\n'; FILE* f = QUtil::safe_fopen("/this/file/does/not/exist", "r"); - std::cout << "after fopen" << std::endl; + std::cout << "after fopen" << '\n'; (void)fclose(f); } catch (QPDFSystemError& s) { - std::cout << "exception: " << s.what() << std::endl; + std::cout << "exception: " << s.what() << '\n'; assert(s.getErrno() != 0); } @@ -200,10 +200,9 @@ void getenv_test() { std::string val; - std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) << ": " << val - << std::endl; + std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) << ": " << val << '\n'; // Hopefully this environment variable is not defined. - std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") << std::endl; + std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") << '\n'; } static void @@ -223,7 +222,7 @@ print_utf8(unsigned long val) static_cast(static_cast(ch)), 16, 2); } } - std::cout << std::endl; + std::cout << '\n'; // Boundary conditions for QUtil::get_next_utf8_codepoint, which is // also tested indirectly through test_pdf_unicode.cc. @@ -264,7 +263,7 @@ to_utf8_test() try { print_utf8(0x80000000UL); } catch (std::runtime_error& e) { - std::cout << "0x80000000: " << e.what() << std::endl; + std::cout << "0x80000000: " << e.what() << '\n'; } // Overlong characters: characters represented by more bytes than necessary. @@ -296,7 +295,7 @@ print_utf16(unsigned long val) << QUtil::int_to_string_base( static_cast(static_cast(ch)), 16, 2); } - std::cout << std::endl; + std::cout << '\n'; } void @@ -311,24 +310,24 @@ to_utf16_test() print_utf16(0x80000000UL); std::string s(QUtil::utf8_to_utf16("\xcf\x80")); - std::cout << QUtil::utf16_to_utf8(s) << std::endl; - std::cout << QUtil::utf16_to_utf8(s + ".") << std::endl; - std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") << std::endl; + std::cout << QUtil::utf16_to_utf8(s) << '\n'; + std::cout << QUtil::utf16_to_utf8(s + ".") << '\n'; + std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") << '\n'; } void utf8_to_ascii_test() { char const* input = "\302\277Does \317\200 have fingers?"; - std::cout << input << std::endl - << QUtil::utf8_to_ascii(input) << std::endl - << QUtil::utf8_to_ascii(input, '*') << std::endl; + std::cout << input << '\n' + << QUtil::utf8_to_ascii(input) << '\n' + << QUtil::utf8_to_ascii(input, '*') << '\n'; std::string a = QUtil::utf8_to_win_ansi(input, '*'); std::string b = QUtil::utf8_to_mac_roman(input, '*'); std::cout << "<" << QUtil::int_to_string_base(static_cast(a.at(0)), 16, 2) << ">" - << a.substr(1) << std::endl + << a.substr(1) << '\n' << "<" << QUtil::int_to_string_base(static_cast(b.at(0)), 16, 2) << ">" - << b.substr(1) << std::endl; + << b.substr(1) << '\n'; } void @@ -349,7 +348,7 @@ transcoding_test( back = (*from_utf8)(out, '?'); if (back != wanted) { std::cout << i << ": " << in << " -> " << out << " -> " << back << " (wanted " << wanted - << ")" << std::endl; + << ")" << '\n'; } } } @@ -363,7 +362,7 @@ check_analyze(std::string const& str, bool has8bit, bool utf8, bool utf16) QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16); if (!((has_8bit_chars == has8bit) && (is_valid_utf8 == utf8) && (is_utf16 == utf16))) { std::cout << "analysis failed: " << str << ": 8bit: " << has_8bit_chars - << ", utf8: " << is_valid_utf8 << ", utf16: " << is_utf16 << std::endl; + << ", utf8: " << is_valid_utf8 << ", utf16: " << is_utf16 << '\n'; } } @@ -373,7 +372,7 @@ print_alternatives(std::string const& str) std::vector result = QUtil::possible_repaired_encodings(str); size_t n = result.size(); for (size_t i = 0; i < n; ++i) { - std::cout << i << ": " << QUtil::hex_encode(result.at(i)) << std::endl; + std::cout << i << ": " << QUtil::hex_encode(result.at(i)) << '\n'; } } @@ -381,20 +380,20 @@ void transcoding_test() { transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 127, 160, "\x9f"); - std::cout << "bidirectional pdf doc done" << std::endl; + std::cout << "bidirectional pdf doc done" << '\n'; transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 24, 31, "?"); - std::cout << "bidirectional pdf doc low done" << std::endl; + std::cout << "bidirectional pdf doc low done" << '\n'; transcoding_test(&QUtil::win_ansi_to_utf8, &QUtil::utf8_to_win_ansi, 128, 160, "?"); - std::cout << "bidirectional win ansi done" << std::endl; + std::cout << "bidirectional win ansi done" << '\n'; transcoding_test(&QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 128, 255, "?"); - std::cout << "bidirectional mac roman done" << std::endl; + std::cout << "bidirectional mac roman done" << '\n'; check_analyze("pi = \317\200", true, true, false); check_analyze("pi != \317", true, false, false); check_analyze("pi != 22/7", false, false, false); check_analyze("\xE0\x80\x82", true, false, false); check_analyze(std::string("\xfe\xff\x00\x51", 4), true, false, true); check_analyze(std::string("\xff\xfe\x51\x00", 4), true, false, true); - std::cout << "analysis done" << std::endl; + std::cout << "analysis done" << '\n'; std::string input1("a\302\277b"); std::string input2("a\317\200b"); std::string input3("ab"); @@ -411,7 +410,7 @@ transcoding_test() assert(QUtil::utf8_to_pdf_doc(input1, output)); assert(!QUtil::utf8_to_pdf_doc(input2, output)); assert(QUtil::utf8_to_pdf_doc(input3, output)); - std::cout << "alternatives" << std::endl; + std::cout << "alternatives" << '\n'; // char name mac win pdf-doc // U+0192 florin 304 203 206 // U+00A9 copyright 251 251 251 @@ -422,18 +421,18 @@ transcoding_test() print_alternatives(pdfdoc); print_alternatives(utf8); print_alternatives("quack"); - std::cout << "done alternatives" << std::endl; + std::cout << "done alternatives" << '\n'; // These are characters are either valid in PDFDoc and invalid in // UTF-8 or the other way around. std::string other("w\x18w\x19w\x1aw\x1bw\x1cw\x1dw\x1ew\x1fw\x7fw"); // cSpell: ignore xadw std::string other_doc = other + "\x9fw\xadw"; - std::cout << QUtil::pdf_doc_to_utf8(other_doc) << std::endl; + std::cout << QUtil::pdf_doc_to_utf8(other_doc) << '\n'; std::string other_utf8 = other + QUtil::toUTF8(0x9f) + "w" + QUtil::toUTF8(0xad) + "w"; std::string other_to_utf8; assert(!QUtil::utf8_to_pdf_doc(other_utf8, other_to_utf8)); - std::cout << other_to_utf8 << std::endl; - std::cout << "done other characters" << std::endl; + std::cout << other_to_utf8 << '\n'; + std::cout << "done other characters" << '\n'; // These valid UTF8 strings when converted to PDFDoc would end up // with a byte sequence that would be recognized as UTF-8 or // UTF-16 rather than PDFDoc. A special case is required to store @@ -455,7 +454,7 @@ void print_whoami(char const* str) { auto dup = QUtil::make_unique_cstr(str); - std::cout << QUtil::getWhoami(dup.get()) << std::endl; + std::cout << QUtil::getWhoami(dup.get()) << '\n'; } void @@ -473,7 +472,7 @@ assert_same_file(char const* file1, char const* file2, bool expected) bool actual = QUtil::same_file(file1, file2); std::cout << "file1: -" << (file1 ? file1 : "(null)") << "-, file2: -" << (file2 ? file2 : "(null)") << "-; same: " << actual << ": " - << ((actual == expected) ? "PASS" : "FAIL") << std::endl; + << ((actual == expected) ? "PASS" : "FAIL") << '\n'; } void @@ -501,7 +500,7 @@ path_test() auto check = [](bool print, std::string const& a, std::string const& b) { auto result = QUtil::path_basename(a); if (print) { - std::cout << a << " -> " << result << std::endl; + std::cout << a << " -> " << result << '\n'; } assert(result == b); }; @@ -523,7 +522,7 @@ read_from_file_test() { std::list lines = QUtil::read_lines_from_file("other-file"); for (auto const& line: lines) { - std::cout << line << std::endl; + std::cout << line << '\n'; } // Test the other versions and make sure we get the same results { @@ -561,7 +560,7 @@ read_from_file_test() std::shared_ptr buf; size_t size = 0; QUtil::read_file_into_memory("other-file", buf, size); - std::cout << "read " << size << " bytes" << std::endl; + std::cout << "read " << size << " bytes" << '\n'; char const* p = buf.get(); assert(size == 24652); assert(memcmp(p, "This file is used for qutil testing.", 36) == 0); @@ -575,7 +574,7 @@ read_from_file_test() assert(memcmp(buf2->getBuffer(), p, size) == 0); auto s = QUtil::read_file_into_string("other-file"); - std::cout << "read " << s.size() << " bytes" << std::endl; + std::cout << "read " << s.size() << " bytes" << '\n'; assert(s.size() == 24652); assert(s.substr(0, 36) == "This file is used for qutil testing."); assert(s.substr(24641, 10) == "very long."); @@ -587,7 +586,7 @@ assert_hex_encode(std::string const& input, std::string const& expected) std::string actual = QUtil::hex_encode(input); if (expected != actual) { std::cout << "hex encode " << input << ": expected = " << expected - << "; actual = " << actual << std::endl; + << "; actual = " << actual << '\n'; } } @@ -597,7 +596,7 @@ assert_hex_decode(std::string const& input, std::string const& expected) std::string actual = QUtil::hex_decode(input); if (expected != actual) { std::cout << "hex encode " << input << ": expected = " << expected - << "; actual = " << actual << std::endl; + << "; actual = " << actual << '\n'; } } @@ -639,31 +638,31 @@ rename_delete_test() } catch (QPDFSystemError&) { } assert_no_file("old\xcf\x80"); - std::cout << "create file" << std::endl; + std::cout << "create file" << '\n'; ; FILE* f1 = QUtil::safe_fopen("old\xcf\x80", "w"); fprintf(f1, "one"); fclose(f1); QUtil::read_file_into_memory("old\xcf\x80", buf, size); assert(memcmp(buf.get(), "one", 3) == 0); - std::cout << "rename file" << std::endl; + std::cout << "rename file" << '\n'; ; QUtil::rename_file("old\xcf\x80", "old\xcf\x80.~tmp"); QUtil::read_file_into_memory("old\xcf\x80.~tmp", buf, size); assert(memcmp(buf.get(), "one", 3) == 0); assert_no_file("old\xcf\x80"); - std::cout << "create file" << std::endl; + std::cout << "create file" << '\n'; ; f1 = QUtil::safe_fopen("old\xcf\x80", "w"); fprintf(f1, "two"); fclose(f1); - std::cout << "rename over existing" << std::endl; + std::cout << "rename over existing" << '\n'; ; QUtil::rename_file("old\xcf\x80", "old\xcf\x80.~tmp"); QUtil::read_file_into_memory("old\xcf\x80.~tmp", buf, size); assert(memcmp(buf.get(), "two", 3) == 0); assert_no_file("old\xcf\x80"); - std::cout << "delete file" << std::endl; + std::cout << "delete file" << '\n'; ; QUtil::remove_file("old\xcf\x80.~tmp"); assert_no_file("old\xcf\x80"); @@ -676,7 +675,7 @@ timestamp_test() auto check = [](QUtil::QPDFTime const& t) { std::string pdf = QUtil::qpdf_time_to_pdf_time(t); std::string iso8601 = QUtil::qpdf_time_to_iso8601(t); - std::cout << pdf << std::endl << iso8601 << std::endl; + std::cout << pdf << '\n' << iso8601 << '\n'; QUtil::QPDFTime t2; std::string iso8601_2; assert(QUtil::pdf_time_to_qpdf_time(pdf, &t2)); @@ -704,7 +703,7 @@ is_long_long_test() { auto check = [](char const* s, bool v) { if (QUtil::is_long_long(s) != v) { - std::cout << "failed: " << s << std::endl; + std::cout << "failed: " << s << '\n'; } }; check("12312312", true); @@ -719,7 +718,7 @@ is_long_long_test() check("123123123123123123123123123123123123", false); check("potato", false); check("0123", false); - std::cout << "done" << std::endl; + std::cout << "done" << '\n'; } void @@ -731,49 +730,49 @@ memory_usage_test() auto u2 = QUtil::get_max_memory_usage(); assert(u2 > u1); } - std::cout << "memory usage okay" << std::endl; + std::cout << "memory usage okay" << '\n'; } int main(int argc, char* argv[]) { try { - std::cout << "---- string conversion" << std::endl; + std::cout << "---- string conversion" << '\n'; string_conversion_test(); - std::cout << "---- os wrapper" << std::endl; + std::cout << "---- os wrapper" << '\n'; os_wrapper_test(); - std::cout << "---- fopen" << std::endl; + std::cout << "---- fopen" << '\n'; fopen_wrapper_test(); - std::cout << "---- getenv" << std::endl; + std::cout << "---- getenv" << '\n'; getenv_test(); - std::cout << "---- utf8" << std::endl; + std::cout << "---- utf8" << '\n'; to_utf8_test(); - std::cout << "---- utf16" << std::endl; + std::cout << "---- utf16" << '\n'; to_utf16_test(); - std::cout << "---- utf8_to_ascii" << std::endl; + std::cout << "---- utf8_to_ascii" << '\n'; utf8_to_ascii_test(); - std::cout << "---- transcoding" << std::endl; + std::cout << "---- transcoding" << '\n'; transcoding_test(); - std::cout << "---- whoami" << std::endl; + std::cout << "---- whoami" << '\n'; get_whoami_test(); - std::cout << "---- file" << std::endl; + std::cout << "---- file" << '\n'; same_file_test(); - std::cout << "---- path" << std::endl; + std::cout << "---- path" << '\n'; path_test(); - std::cout << "---- read from file" << std::endl; + std::cout << "---- read from file" << '\n'; read_from_file_test(); - std::cout << "---- hex encode/decode" << std::endl; + std::cout << "---- hex encode/decode" << '\n'; hex_encode_decode_test(); - std::cout << "---- rename/delete" << std::endl; + std::cout << "---- rename/delete" << '\n'; rename_delete_test(); - std::cout << "---- timestamp" << std::endl; + std::cout << "---- timestamp" << '\n'; timestamp_test(); - std::cout << "---- is_long_long" << std::endl; + std::cout << "---- is_long_long" << '\n'; is_long_long_test(); - std::cout << "---- memory usage" << std::endl; + std::cout << "---- memory usage" << '\n'; memory_usage_test(); } catch (std::exception& e) { - std::cout << "unexpected exception: " << e.what() << std::endl; + std::cout << "unexpected exception: " << e.what() << '\n'; } return 0; diff --git a/libtests/rc4.cc b/libtests/rc4.cc index 306d088..d540347 100644 --- a/libtests/rc4.cc +++ b/libtests/rc4.cc @@ -20,7 +20,7 @@ other_tests() memcpy(data.get(), "potato", 6); r.process(data.get(), 6, data.get()); assert(memcmp(data.get(), "\xa5\x6f\xe7\x27\x2b\x5c", 6) == 0); - std::cout << "passed" << std::endl; + std::cout << "passed" << '\n'; } int @@ -32,7 +32,7 @@ main(int argc, char* argv[]) } if (argc != 4) { - std::cerr << "Usage: rc4 hex-key infile outfile" << std::endl; + std::cerr << "Usage: rc4 hex-key infile outfile" << '\n'; exit(2); } diff --git a/libtests/runlength.cc b/libtests/runlength.cc index 293aee2..d1b4cfa 100644 --- a/libtests/runlength.cc +++ b/libtests/runlength.cc @@ -11,7 +11,7 @@ int main(int argc, char* argv[]) { if (argc != 4) { - std::cerr << "Usage: runlength {-encode|-decode} infile outfile" << std::endl; + std::cerr << "Usage: runlength {-encode|-decode} infile outfile" << '\n'; exit(2); } diff --git a/libtests/sparse_array.cc b/libtests/sparse_array.cc index 7bbdc23..449cfd8 100644 --- a/libtests/sparse_array.cc +++ b/libtests/sparse_array.cc @@ -118,6 +118,6 @@ main() } catch (std::logic_error&) { } - std::cout << "sparse array tests done" << std::endl; + std::cout << "sparse array tests done" << '\n'; return 0; } diff --git a/qpdf/fix-qdf.cc b/qpdf/fix-qdf.cc index a05a038..087cd20 100644 --- a/qpdf/fix-qdf.cc +++ b/qpdf/fix-qdf.cc @@ -81,7 +81,7 @@ QdfFixer::QdfFixer(std::string const& filename, std::ostream& out) : void QdfFixer::fatal(std::string const& msg) { - std::cerr << msg << std::endl; + std::cerr << msg << '\n'; exit(2); } @@ -380,7 +380,7 @@ realmain(int argc, char* argv[]) if (argc > 3) { usage(); } else if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl; + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << '\n'; return 0; } else if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { usage(); @@ -411,7 +411,7 @@ realmain(int argc, char* argv[]) QdfFixer qf(filename, out ? *out : std::cout); qf.processLines(input); } catch (std::exception& e) { - std::cerr << whoami << ": error: " << e.what() << std::endl; + std::cerr << whoami << ": error: " << e.what() << '\n'; exit(qpdf_exit_error); } return 0; diff --git a/qpdf/pdf_from_scratch.cc b/qpdf/pdf_from_scratch.cc index 2c54d5e..cccc207 100644 --- a/qpdf/pdf_from_scratch.cc +++ b/qpdf/pdf_from_scratch.cc @@ -14,7 +14,7 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " n" << std::endl; + std::cerr << "Usage: " << whoami << " n\n"; exit(2); } @@ -77,7 +77,7 @@ runtest(int n) throw std::runtime_error(std::string("invalid test ") + std::to_string(n)); } - std::cout << "test " << n << " done" << std::endl; + std::cout << "test " << n << " done\n"; } int @@ -98,7 +98,7 @@ main(int argc, char* argv[]) int n = QUtil::string_to_int(argv[1]); runtest(n); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index dc9c6f2..1f20f10 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -11,15 +11,15 @@ static char const* whoami = nullptr; static void usageExit(std::string const& msg) { - std::cerr << std::endl - << whoami << ": " << msg << std::endl - << std::endl - << "For help:" << std::endl - << " " << whoami << " --help=usage usage information" << std::endl - << " " << whoami << " --help=topic help on a topic" << std::endl - << " " << whoami << " --help=--option help on an option" << std::endl - << " " << whoami << " --help general help and a topic list" << std::endl - << std::endl; + std::cerr << '\n' + << whoami << ": " << msg << '\n' + << '\n' + << "For help:\n" + << " " << whoami << " --help=usage usage information\n" + << " " << whoami << " --help=topic help on a topic\n" + << " " << whoami << " --help=--option help on an option\n" + << " " << whoami << " --help general help and a topic list\n" + << '\n'; exit(QPDFJob::EXIT_ERROR); } @@ -37,7 +37,7 @@ realmain(int argc, char* argv[]) } catch (QPDFUsage& e) { usageExit(e.what()); } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; return QPDFJob::EXIT_ERROR; } return j.getExitCode(); diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 445a38f..b2cb985 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -39,7 +39,7 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " n filename1 [arg2]" << std::endl; + std::cerr << "Usage: " << whoami << " n filename1 [arg2]" << '\n'; exit(2); } @@ -58,7 +58,7 @@ ExtendNameTree::ExtendNameTree(QPDFObjectHandle o, QPDF& q) : ExtendNameTree::~ExtendNameTree() { - std::cout << "~ExtendNameTree called" << std::endl; + std::cout << "~ExtendNameTree called" << '\n'; } class Provider: public QPDFObjectHandle::StreamDataProvider @@ -104,30 +104,30 @@ class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks void ParserCallbacks::contentSize(size_t size) { - std::cout << "content size: " << size << std::endl; + std::cout << "content size: " << size << '\n'; } void ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length) { if (obj.isName() && (obj.getName() == "/Abort")) { - std::cout << "test suite: terminating parsing" << std::endl; + std::cout << "test suite: terminating parsing" << '\n'; terminateParsing(); } std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": "; if (obj.isInlineImage()) { // Exercise getTypeCode assert(obj.getTypeCode() == ::ot_inlineimage); - std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl; + std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << '\n'; } else { - std::cout << obj.unparse() << std::endl; + std::cout << obj.unparse() << '\n'; } } void ParserCallbacks::handleEOF() { - std::cout << "-EOF-" << std::endl; + std::cout << "-EOF-" << '\n'; } class TokenFilter: public QPDFObjectHandle::TokenFilter @@ -165,7 +165,7 @@ checkPageContents(QPDFObjectHandle page, std::string const& wanted_string) { std::string contents = getPageContents(page); if (contents.find(wanted_string) == std::string::npos) { - std::cout << "didn't find " << wanted_string << " in " << contents << std::endl; + std::cout << "didn't find " << wanted_string << " in " << contents << '\n'; } } @@ -207,77 +207,77 @@ test_0_1(QPDF& pdf, char const* arg2) // any difference between a key that is present and null // and a key that is absent. QTC::TC("qpdf", "main QTest implicit"); - std::cout << "/QTest is implicit" << std::endl; + std::cout << "/QTest is implicit" << '\n'; } QTC::TC("qpdf", "main QTest indirect", qtest.isIndirect() ? 1 : 0); std::cout << "/QTest is " << (qtest.isIndirect() ? "in" : "") << "direct and has type " - << qtest.getTypeName() << " (" << qtest.getTypeCode() << ")" << std::endl; + << qtest.getTypeName() << " (" << qtest.getTypeCode() << ")" << '\n'; if (qtest.isNull()) { QTC::TC("qpdf", "main QTest null"); - std::cout << "/QTest is null" << std::endl; + std::cout << "/QTest is null" << '\n'; } else if (qtest.isBool()) { QTC::TC("qpdf", "main QTest bool", qtest.getBoolValue() ? 1 : 0); std::cout << "/QTest is Boolean with value " << (qtest.getBoolValue() ? "true" : "false") - << std::endl; + << '\n'; } else if (qtest.isInteger()) { QTC::TC("qpdf", "main QTest int"); - std::cout << "/QTest is an integer with value " << qtest.getIntValue() << std::endl; + std::cout << "/QTest is an integer with value " << qtest.getIntValue() << '\n'; } else if (qtest.isReal()) { QTC::TC("qpdf", "main QTest real"); - std::cout << "/QTest is a real number with value " << qtest.getRealValue() << std::endl; + std::cout << "/QTest is a real number with value " << qtest.getRealValue() << '\n'; } else if (qtest.isName()) { QTC::TC("qpdf", "main QTest name"); - std::cout << "/QTest is a name with value " << qtest.getName() << std::endl; + std::cout << "/QTest is a name with value " << qtest.getName() << '\n'; } else if (qtest.isString()) { QTC::TC("qpdf", "main QTest string"); - std::cout << "/QTest is a string with value " << qtest.getStringValue() << std::endl; + std::cout << "/QTest is a string with value " << qtest.getStringValue() << '\n'; } else if (qtest.isArray()) { QTC::TC("qpdf", "main QTest array"); - std::cout << "/QTest is an array with " << qtest.getArrayNItems() << " items" << std::endl; + std::cout << "/QTest is an array with " << qtest.getArrayNItems() << " items" << '\n'; int i = 0; for (auto& iter: qtest.aitems()) { QTC::TC("qpdf", "main QTest array indirect", iter.isIndirect() ? 1 : 0); std::cout << " item " << i << " is " << (iter.isIndirect() ? "in" : "") << "direct" - << std::endl; + << '\n'; ++i; } } else if (qtest.isDictionary()) { QTC::TC("qpdf", "main QTest dictionary"); - std::cout << "/QTest is a dictionary" << std::endl; + std::cout << "/QTest is a dictionary" << '\n'; for (auto& iter: qtest.ditems()) { QTC::TC("qpdf", "main QTest dictionary indirect", iter.second.isIndirect() ? 1 : 0); std::cout << " " << iter.first << " is " << (iter.second.isIndirect() ? "in" : "") - << "direct" << std::endl; + << "direct" << '\n'; } } else if (qtest.isStream()) { QTC::TC("qpdf", "main QTest stream"); - std::cout << "/QTest is a stream. Dictionary: " << qtest.getDict().unparse() << std::endl; + std::cout << "/QTest is a stream. Dictionary: " << qtest.getDict().unparse() << '\n'; - std::cout << "Raw stream data:" << std::endl; + std::cout << "Raw stream data:" << '\n'; std::cout.flush(); QUtil::binary_stdout(); auto out = std::make_shared("raw", stdout); qtest.pipeStreamData(out.get(), 0, qpdf_dl_none); - std::cout << std::endl << "Uncompressed stream data:" << std::endl; + std::cout << '\n' << "Uncompressed stream data:" << '\n'; if (qtest.pipeStreamData(nullptr, 0, qpdf_dl_all)) { std::cout.flush(); QUtil::binary_stdout(); out = std::make_shared("filtered", stdout); qtest.pipeStreamData(out.get(), 0, qpdf_dl_all); - std::cout << std::endl << "End of stream data" << std::endl; + std::cout << '\n' << "End of stream data" << '\n'; } else { - std::cout << "Stream data is not filterable." << std::endl; + std::cout << "Stream data is not filterable." << '\n'; } } else { // Should not happen! - std::cout << "/QTest is an unknown object" << std::endl; + std::cout << "/QTest is an unknown object" << '\n'; } - std::cout << "unparse: " << qtest.unparse() << std::endl - << "unparseResolved: " << qtest.unparseResolved() << std::endl; + std::cout << "unparse: " << qtest.unparse() << '\n' + << "unparseResolved: " << qtest.unparseResolved() << '\n'; } static void @@ -287,12 +287,12 @@ test_2(QPDF& pdf, char const* arg2) // PDF file. QPDFObjectHandle trailer = pdf.getTrailer(); - std::cout << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() << std::endl; - std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() << std::endl; + std::cout << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() << '\n'; + std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() << '\n'; QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); - std::cout << encrypt.getKey("/O").unparse() << std::endl; - std::cout << encrypt.getKey("/U").unparse() << std::endl; + std::cout << encrypt.getKey("/O").unparse() << '\n'; + std::cout << encrypt.getKey("/U").unparse() << '\n'; QPDFObjectHandle root = pdf.getRoot(); QPDFObjectHandle pages = root.getKey("/Pages"); @@ -310,7 +310,7 @@ test_3(QPDF& pdf, char const* arg2) QPDFObjectHandle streams = pdf.getTrailer().getKey("/QStreams"); for (int i = 0; i < streams.getArrayNItems(); ++i) { QPDFObjectHandle stream = streams.getArrayItem(i); - std::cout << "-- stream " << i << " --" << std::endl; + std::cout << "-- stream " << i << " --" << '\n'; std::cout.flush(); QUtil::binary_stdout(); auto out = std::make_shared("tokenized stream", stdout); @@ -374,44 +374,44 @@ test_5(QPDF& pdf, char const* arg2) int pageno = 0; for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { ++pageno; - std::cout << "page " << pageno << ":" << std::endl; - std::cout << " images:" << std::endl; + std::cout << "page " << pageno << ":" << '\n'; + std::cout << " images:" << '\n'; for (auto const& iter2: page.getImages()) { std::string const& name = iter2.first; QPDFObjectHandle image = iter2.second; QPDFObjectHandle dict = image.getDict(); long long width = dict.getKey("/Width").getIntValue(); long long height = dict.getKey("/Height").getIntValue(); - std::cout << " " << name << ": " << width << " x " << height << std::endl; + std::cout << " " << name << ": " << width << " x " << height << '\n'; } - std::cout << " content:" << std::endl; + std::cout << " content:" << '\n'; std::vector content = page.getPageContents(); for (auto& iter2: content) { - std::cout << " " << iter2.unparse() << std::endl; + std::cout << " " << iter2.unparse() << '\n'; } - std::cout << "end page " << pageno << std::endl; + std::cout << "end page " << pageno << '\n'; } QPDFObjectHandle root = pdf.getRoot(); QPDFObjectHandle qstrings = root.getKey("/QStrings"); if (qstrings.isArray()) { - std::cout << "QStrings:" << std::endl; + std::cout << "QStrings:" << '\n'; int nitems = qstrings.getArrayNItems(); for (int i = 0; i < nitems; ++i) { - std::cout << qstrings.getArrayItem(i).getUTF8Value() << std::endl; + std::cout << qstrings.getArrayItem(i).getUTF8Value() << '\n'; } } QPDFObjectHandle qnumbers = root.getKey("/QNumbers"); if (qnumbers.isArray()) { - std::cout << "QNumbers:" << std::endl; + std::cout << "QNumbers:" << '\n'; int nitems = qnumbers.getArrayNItems(); for (int i = 0; i < nitems; ++i) { std::cout << QUtil::double_to_string( qnumbers.getArrayItem(i).getNumericValue(), 3, false) - << std::endl; + << '\n'; } } } @@ -432,7 +432,7 @@ test_6(QPDF& pdf, char const* arg2) cleartext = true; } std::cout << "encrypted=" << (pdf.isEncrypted() ? 1 : 0) - << "; cleartext=" << (cleartext ? 1 : 0) << std::endl; + << "; cleartext=" << (cleartext ? 1 : 0) << '\n'; } static void @@ -483,9 +483,9 @@ test_8(QPDF& pdf, char const* arg2) provider->badLength(true); try { qstream.getStreamData(); - std::cout << "oops -- getStreamData didn't throw" << std::endl; + std::cout << "oops -- getStreamData didn't throw" << '\n'; } catch (std::exception const& e) { - std::cout << "exception: " << e.what() << std::endl; + std::cout << "exception: " << e.what() << '\n'; } } @@ -501,9 +501,9 @@ test_9(QPDF& pdf, char const* arg2) QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); try { rstream.getStreamData(); - std::cout << "oops -- getStreamData didn't throw" << std::endl; + std::cout << "oops -- getStreamData didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "exception: " << e.what() << std::endl; + std::cout << "exception: " << e.what() << '\n'; } rstream.replaceStreamData( "data for other stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); @@ -539,10 +539,10 @@ test_11(QPDF& pdf, char const* arg2) std::shared_ptr b1 = qstream.getStreamData(); std::shared_ptr b2 = qstream.getRawStreamData(); if ((b1->getSize() == 7) && (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) { - std::cout << "filtered stream data okay" << std::endl; + std::cout << "filtered stream data okay" << '\n'; } if ((b2->getSize() == 15) && (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) { - std::cout << "raw stream data okay" << std::endl; + std::cout << "raw stream data okay" << '\n'; } } @@ -580,9 +580,7 @@ test_13(QPDF& pdf, char const* arg2) # pragma GCC diagnostic pop #endif pdf.showLinearizationData(); - std::cout << "---output---" << std::endl - << out.str() << "---error---" << std::endl - << err.str(); + std::cout << "---output---" << '\n' << out.str() << "---error---" << '\n' << err.str(); } static void @@ -614,27 +612,27 @@ test_14(QPDF& pdf, char const* arg2) // Do it wrong first... pdf.replaceObject(qdict.getObjGen(), qdict); } catch (std::logic_error const&) { - std::cout << "caught logic error as expected" << std::endl; + std::cout << "caught logic error as expected" << '\n'; } pdf.replaceObject(qdict.getObjGen(), new_dict); // Now qdict points to the new dictionary - std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() << std::endl; + std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() << '\n'; // Swap dict and array pdf.swapObjects(qdict.getObjGen(), qarray.getObjGen()); // Now qarray will resolve to new object and qdict resolves to // the array - std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl; - std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() << std::endl; + std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << '\n'; + std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() << '\n'; // Reread qdict, still pointing to an array qdict = pdf.getObjectByObjGen(qdict.getObjGen()); - std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl; + std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << '\n'; // Exercise getAsMap and getAsArray std::vector array_elements = qdict.getArrayAsVector(); std::map dict_items = qarray.getDictAsMap(); if ((array_elements.size() == 1) && (array_elements.at(0).getName() == "/Array") && (dict_items.size() == 1) && (dict_items["/NewDict"].getIntValue() == 2)) { - std::cout << "array and dictionary contents are correct" << std::endl; + std::cout << "array and dictionary contents are correct" << '\n'; } // Exercise writing to memory buffer @@ -853,7 +851,7 @@ test_21(QPDF& pdf, char const* arg2) QPDFObjectHandle page = pages.at(0); QPDFObjectHandle contents = page.getKey("/Contents"); contents.shallowCopy(); - std::cout << "you can't see this" << std::endl; + std::cout << "you can't see this" << '\n'; } static void @@ -865,7 +863,7 @@ test_22(QPDF& pdf, char const* arg2) QPDFPageObjectHelper& page = pages.at(0); dh.removePage(page); dh.removePage(page); - std::cout << "you can't see this" << std::endl; + std::cout << "you can't see this" << '\n'; } static void @@ -895,44 +893,44 @@ test_24(QPDF& pdf, char const* arg2) // Make sure trying to ask questions about a reserved object // doesn't break it. if (res1.isArray()) { - std::cout << "oops -- res1 is an array" << std::endl; + std::cout << "oops -- res1 is an array" << '\n'; } if (res1.isReserved()) { - std::cout << "res1 is still reserved after checking if array" << std::endl; + std::cout << "res1 is still reserved after checking if array" << '\n'; } pdf.replaceReserved(res1, array1); if (res1.isReserved()) { - std::cout << "oops -- res1 is still reserved" << std::endl; + std::cout << "oops -- res1 is still reserved" << '\n'; } else { - std::cout << "res1 is no longer reserved" << std::endl; + std::cout << "res1 is no longer reserved" << '\n'; } res1.assertArray(); - std::cout << "res1 is an array" << std::endl; + std::cout << "res1 is an array" << '\n'; try { res2.unparseResolved(); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } try { res2.makeDirect(); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } pdf.replaceReserved(res2, array2); res2.assertArray(); - std::cout << "res2 is an array" << std::endl; + std::cout << "res2 is an array" << '\n'; // Verify that the previously added reserved keys can be // dereferenced properly now int i1 = res1.getArrayItem(0).getArrayItem(1).getIntValueAsInt(); int i2 = res2.getArrayItem(0).getArrayItem(1).getIntValueAsInt(); if ((i1 == 2) && (i2 == 1)) { - std::cout << "circular access and lazy resolution worked" << std::endl; + std::cout << "circular access and lazy resolution worked" << '\n'; } QPDFWriter w(pdf, "a.pdf"); @@ -1078,15 +1076,15 @@ test_28(QPDF& pdf, char const* arg2) // Copy foreign object errors try { pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest")); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } try { pdf.copyForeignObject(QPDFObjectHandle::newInteger(1)); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } } @@ -1111,9 +1109,9 @@ test_29(QPDF& pdf, char const* arg2) try { QPDFWriter w(*other, "a.pdf"); w.write(); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } // Make sure deleting the other source doesn't prevent detection. @@ -1126,9 +1124,9 @@ test_29(QPDF& pdf, char const* arg2) try { QPDFWriter w(*other, "a.pdf"); w.write(); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } // Detect adding a foreign object @@ -1137,7 +1135,7 @@ test_29(QPDF& pdf, char const* arg2) try { root1.replaceKey("/Oops", root2); } catch (std::logic_error const& e) { - std::cout << "logic error: " << e.what() << std::endl; + std::cout << "logic error: " << e.what() << '\n'; } } @@ -1160,10 +1158,10 @@ test_30(QPDF& pdf, char const* arg2) pages = final.getAllPages(); std::string new_contents = getPageContents(pages.at(0)); if (orig_contents != new_contents) { - std::cout << "oops -- page contents don't match" << std::endl + std::cout << "oops -- page contents don't match" << '\n' << "original:\n" << orig_contents << "new:\n" - << new_contents << std::endl; + << new_contents << '\n'; } } @@ -1172,20 +1170,20 @@ test_31(QPDF& pdf, char const* arg2) { auto o1 = "[/name 16059 3.14159 false\n" " << /key true /other [ (string1) (string2) ] >> null]"_qpdf; - std::cout << o1.unparse() << std::endl; + std::cout << o1.unparse() << '\n'; QPDFObjectHandle o2 = QPDFObjectHandle::parse(" 12345 \f "); assert(o2.isInteger() && (o2.getIntValue() == 12345)); try { QPDFObjectHandle::parse("[1 0 R]", "indirect test"); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::logic_error const& e) { - std::cout << "logic error parsing indirect: " << e.what() << std::endl; + std::cout << "logic error parsing indirect: " << e.what() << '\n'; } try { QPDFObjectHandle::parse("0 trailing", "trailing test"); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::runtime_error const& e) { - std::cout << "trailing data: " << e.what() << std::endl; + std::cout << "trailing data: " << e.what() << '\n'; } assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger()); assert(!QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isDirectNull()); @@ -1218,9 +1216,9 @@ test_32(QPDF& pdf, char const* arg2) bool newline = ((i & 2) != 0); QPDFWriter w(pdf, filenames[i]); w.setStaticID(true); - std::cout << "file: " << filenames[i] << std::endl - << "linearized: " << (linearized ? "yes" : "no") << std::endl - << "newline: " << (newline ? "yes" : "no") << std::endl; + std::cout << "file: " << filenames[i] << '\n' + << "linearized: " << (linearized ? "yes" : "no") << '\n' + << "newline: " << (newline ? "yes" : "no") << '\n'; w.setLinearization(linearized); if (linearized) { w.setCompressStreams(false); // avoid dependency on zlib's output @@ -1249,14 +1247,14 @@ static void test_34(QPDF& pdf, char const* arg2) { // Look at Extensions dictionary - std::cout << "version: " << pdf.getPDFVersion() << std::endl - << "extension level: " << pdf.getExtensionLevel() << std::endl - << pdf.getRoot().getKey("/Extensions").unparse() << std::endl; + std::cout << "version: " << pdf.getPDFVersion() << '\n' + << "extension level: " << pdf.getExtensionLevel() << '\n' + << pdf.getRoot().getKey("/Extensions").unparse() << '\n'; auto v = pdf.getVersionAsPDFVersion(); std::string v_string; int extension_level; v.getVersion(v_string, extension_level); - std::cout << "As PDFVersion: " << v_string << "/" << extension_level << std::endl; + std::cout << "As PDFVersion: " << v_string << "/" << extension_level << '\n'; } static void @@ -1350,7 +1348,7 @@ test_38(QPDF& pdf, char const* arg2) // Designed for override-compressed-object.pdf QPDFObjectHandle qtest = pdf.getRoot().getKey("/QTest"); for (int i = 0; i < qtest.getArrayNItems(); ++i) { - std::cout << qtest.getArrayItem(i).unparseResolved() << std::endl; + std::cout << qtest.getArrayItem(i).unparseResolved() << '\n'; } } @@ -1360,13 +1358,13 @@ test_39(QPDF& pdf, char const* arg2) // Display image filter and color set for each image on each page int pageno = 0; for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { - std::cout << "page " << ++pageno << std::endl; + std::cout << "page " << ++pageno << '\n'; std::map images = page.getImages(); for (auto& i_iter: images) { QPDFObjectHandle image_dict = i_iter.second.getDict(); std::cout << "filter: " << image_dict.getKey("/Filter").unparseResolved() << ", color space: " << image_dict.getKey("/ColorSpace").unparseResolved() - << std::endl; + << '\n'; } } } @@ -1578,51 +1576,51 @@ test_43(QPDF& pdf, char const* arg2) } std::cout << "iterating over form fields\n"; for (auto& ffh: afdh.getFormFields()) { - std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl; + std::cout << "Field: " << ffh.getObjectHandle().unparse() << '\n'; QPDFFormFieldObjectHelper node = ffh; while (!node.isNull()) { QPDFFormFieldObjectHelper parent(node.getParent()); std::cout << " Parent: " << (parent.isNull() ? std::string("none") : parent.getObjectHandle().unparse()) - << std::endl; + << '\n'; node = parent; } - std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() << std::endl; - std::cout << " Partial name: " << ffh.getPartialName() << std::endl; - std::cout << " Alternative name: " << ffh.getAlternativeName() << std::endl; - std::cout << " Mapping name: " << ffh.getMappingName() << std::endl; - std::cout << " Field type: " << ffh.getFieldType() << std::endl; - std::cout << " Value: " << ffh.getValue().unparse() << std::endl; - std::cout << " Value as string: " << ffh.getValueAsString() << std::endl; - std::cout << " Default value: " << ffh.getDefaultValue().unparse() << std::endl; - std::cout << " Default value as string: " << ffh.getDefaultValueAsString() << std::endl; - std::cout << " Default appearance: " << ffh.getDefaultAppearance() << std::endl; - std::cout << " Quadding: " << ffh.getQuadding() << std::endl; + std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() << '\n'; + std::cout << " Partial name: " << ffh.getPartialName() << '\n'; + std::cout << " Alternative name: " << ffh.getAlternativeName() << '\n'; + std::cout << " Mapping name: " << ffh.getMappingName() << '\n'; + std::cout << " Field type: " << ffh.getFieldType() << '\n'; + std::cout << " Value: " << ffh.getValue().unparse() << '\n'; + std::cout << " Value as string: " << ffh.getValueAsString() << '\n'; + std::cout << " Default value: " << ffh.getDefaultValue().unparse() << '\n'; + std::cout << " Default value as string: " << ffh.getDefaultValueAsString() << '\n'; + std::cout << " Default appearance: " << ffh.getDefaultAppearance() << '\n'; + std::cout << " Quadding: " << ffh.getQuadding() << '\n'; std::vector annotations = afdh.getAnnotationsForField(ffh); for (auto& aoh: annotations) { - std::cout << " Annotation: " << aoh.getObjectHandle().unparse() << std::endl; + std::cout << " Annotation: " << aoh.getObjectHandle().unparse() << '\n'; } } std::cout << "iterating over annotations per page\n"; for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { - std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl; + std::cout << "Page: " << page.getObjectHandle().unparse() << '\n'; for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) { - std::cout << " Annotation: " << ah.getObjectHandle().unparse() << std::endl; + std::cout << " Annotation: " << ah.getObjectHandle().unparse() << '\n'; std::cout << " Field: " - << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) << std::endl; - std::cout << " Subtype: " << ah.getSubtype() << std::endl; + << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) << '\n'; + std::cout << " Subtype: " << ah.getSubtype() << '\n'; std::cout << " Rect: "; print_rect(std::cout, ah.getRect()); - std::cout << std::endl; + std::cout << '\n'; std::string state = ah.getAppearanceState(); if (!state.empty()) { - std::cout << " Appearance state: " << state << std::endl; + std::cout << " Appearance state: " << state << '\n'; } std::cout << " Appearance stream (/N): " << ah.getAppearanceStream("/N").unparse() - << std::endl; + << '\n'; std::cout << " Appearance stream (/N, /3): " - << ah.getAppearanceStream("/N", "/3").unparse() << std::endl; + << ah.getAppearanceStream("/N", "/3").unparse() << '\n'; } } } @@ -1637,7 +1635,7 @@ test_44(QPDF& pdf, char const* arg2) // \xc3\xb7 is utf-8 for U+00F7 (divided by) field.setV("3.14 \xc3\xb7 0"); std::cout << "Set field value: " << field.getFullyQualifiedName() << " -> " - << field.getValueAsString() << std::endl; + << field.getValueAsString() << '\n'; } } QPDFWriter w(pdf, "a.pdf"); @@ -1669,11 +1667,11 @@ test_46(QPDF& pdf, char const* arg2) QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); QPDFNumberTreeObjectHelper ntoh(qtest, pdf); for (auto& iter: ntoh) { - std::cout << iter.first << " " << iter.second.getStringValue() << std::endl; + std::cout << iter.first << " " << iter.second.getStringValue() << '\n'; } QPDFNumberTreeObjectHelper::idx_map ntoh_map = ntoh.getAsMap(); for (auto& iter: ntoh_map) { - std::cout << iter.first << " " << iter.second.getStringValue() << std::endl; + std::cout << iter.first << " " << iter.second.getStringValue() << '\n'; } assert(1 == ntoh.getMin()); assert(29 == ntoh.getMax()); @@ -1719,7 +1717,7 @@ test_46(QPDF& pdf, char const* arg2) --iter1; assert(iter1->first == 2); - std::cout << "insertAfter" << std::endl; + std::cout << "insertAfter" << '\n'; auto new2 = QPDFNumberTreeObjectHelper::newEmpty(pdf); auto iter2 = new2.begin(); assert(iter2 == new2.end()); @@ -1728,23 +1726,23 @@ test_46(QPDF& pdf, char const* arg2) iter2.insertAfter(4, QPDFObjectHandle::newString("4!")); assert(iter2->first == 4); for (auto& i: new2) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } - std::cout << "/Bad1" << std::endl; + std::cout << "/Bad1" << '\n'; auto bad1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf); assert(bad1.begin() == bad1.end()); assert(bad1.last() == bad1.end()); - std::cout << "/Bad2" << std::endl; + std::cout << "/Bad2" << '\n'; auto bad2 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf); for (auto& i: bad2) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } std::vector empties = {"/Empty1", "/Empty2"}; for (auto const& k: empties) { - std::cout << k << std::endl; + std::cout << k << '\n'; auto empty = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey(k), pdf); assert(empty.begin() == empty.end()); assert(empty.last() == empty.end()); @@ -1765,37 +1763,37 @@ test_46(QPDF& pdf, char const* arg2) assert(empty.last()->first == 6); assert(empty.last()->second.getStringValue() == "6"); } - std::cout << "Insert into invalid" << std::endl; + std::cout << "Insert into invalid" << '\n'; auto invalid1 = QPDFNumberTreeObjectHelper(QPDFObjectHandle::newDictionary(), pdf); try { invalid1.insert(1, QPDFObjectHandle::newNull()); } catch (QPDFExc& e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; } - std::cout << "/Bad3, no repair" << std::endl; + std::cout << "/Bad3, no repair" << '\n'; auto bad3_oh = pdf.getTrailer().getKey("/Bad3"); auto bad3 = QPDFNumberTreeObjectHelper(bad3_oh, pdf, false); for (auto& i: bad3) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } assert(!bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect()); - std::cout << "/Bad3, repair" << std::endl; + std::cout << "/Bad3, repair" << '\n'; bad3 = QPDFNumberTreeObjectHelper(bad3_oh, pdf, true); for (auto& i: bad3) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } assert(bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect()); - std::cout << "/Bad4 -- missing limits" << std::endl; + std::cout << "/Bad4 -- missing limits" << '\n'; auto bad4 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf); bad4.insert(5, QPDFObjectHandle::newString("5")); for (auto& i: bad4) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } - std::cout << "/Bad5 -- limit errors" << std::endl; + std::cout << "/Bad5 -- limit errors" << '\n'; auto bad5 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf); assert(bad5.find(10) == bad5.end()); } @@ -1810,7 +1808,7 @@ test_47(QPDF& pdf, char const* arg2) pldh.getLabelsForPageRange(0, npages - 1, 1, labels); assert(labels.size() % 2 == 0); for (size_t i = 0; i < labels.size(); i += 2) { - std::cout << labels.at(i).getIntValue() << " " << labels.at(i + 1).unparse() << std::endl; + std::cout << labels.at(i).getIntValue() << " " << labels.at(i + 1).unparse() << '\n'; } } @@ -1822,11 +1820,11 @@ test_48(QPDF& pdf, char const* arg2) QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); QPDFNameTreeObjectHelper ntoh(qtest, pdf); for (auto& iter: ntoh) { - std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl; + std::cout << iter.first << " -> " << iter.second.getStringValue() << '\n'; } std::map ntoh_map = ntoh.getAsMap(); for (auto& iter: ntoh_map) { - std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl; + std::cout << iter.first << " -> " << iter.second.getStringValue() << '\n'; } assert(ntoh.hasName("11 elephant")); assert(ntoh.hasName("07 sev\xe2\x80\xa2n")); @@ -1869,7 +1867,7 @@ test_48(QPDF& pdf, char const* arg2) --iter1; assert(iter1->first == "2"); - std::cout << "insertAfter" << std::endl; + std::cout << "insertAfter" << '\n'; auto new2 = QPDFNameTreeObjectHelper::newEmpty(pdf); auto iter2 = new2.begin(); assert(iter2 == new2.end()); @@ -1878,12 +1876,12 @@ test_48(QPDF& pdf, char const* arg2) iter2.insertAfter("4", QPDFObjectHandle::newString("4!")); assert(iter2->first == "4"); for (auto& i: new2) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } std::vector empties = {"/Empty1", "/Empty2"}; for (auto const& k: empties) { - std::cout << k << std::endl; + std::cout << k << '\n'; auto empty = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey(k), pdf); assert(empty.begin() == empty.end()); assert(empty.last() == empty.end()); @@ -1905,36 +1903,36 @@ test_48(QPDF& pdf, char const* arg2) assert(empty.last()->second.getStringValue() == "6"); } - std::cout << "/Bad1 -- wrong key type" << std::endl; + std::cout << "/Bad1 -- wrong key type" << '\n'; auto bad1 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf); assert(bad1.find("G", true)->first == "A"); for (auto const& i: bad1) { - std::cout << i.first << std::endl; + std::cout << i.first << '\n'; } - std::cout << "/Bad2 -- invalid kid" << std::endl; + std::cout << "/Bad2 -- invalid kid" << '\n'; auto bad2 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf); assert(bad2.find("G", true)->first == "B"); for (auto const& i: bad2) { - std::cout << i.first << std::endl; + std::cout << i.first << '\n'; } - std::cout << "/Bad3 -- invalid kid" << std::endl; + std::cout << "/Bad3 -- invalid kid" << '\n'; auto bad3 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad3"), pdf); assert(bad3.find("G", true) == bad3.end()); - std::cout << "/Bad4 -- invalid kid" << std::endl; + std::cout << "/Bad4 -- invalid kid" << '\n'; auto bad4 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf); assert(bad4.find("F", true)->first == "C"); for (auto const& i: bad4) { - std::cout << i.first << std::endl; + std::cout << i.first << '\n'; } - std::cout << "/Bad5 -- loop in find" << std::endl; + std::cout << "/Bad5 -- loop in find" << '\n'; auto bad5 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf); assert(bad5.find("F", true)->first == "D"); - std::cout << "/Bad6 -- bad limits" << std::endl; + std::cout << "/Bad6 -- bad limits" << '\n'; auto bad6 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Bad6"), pdf); assert(bad6.insert("H", QPDFObjectHandle::newNull())->first == "H"); } @@ -1949,7 +1947,7 @@ test_49(QPDF& pdf, char const* arg2) auto outlines = odh.getOutlinesForPage(page.getObjectHandle().getObjGen()); for (auto& ol: outlines) { std::cout << "page " << pageno << ": " << ol.getTitle() << " -> " - << ol.getDest().unparseResolved() << std::endl; + << ol.getDest().unparseResolved() << '\n'; } ++pageno; } @@ -1963,11 +1961,11 @@ test_50(QPDF& pdf, char const* arg2) QPDFObjectHandle d1 = pdf.getTrailer().getKey("/Dict1"); QPDFObjectHandle d2 = pdf.getTrailer().getKey("/Dict2"); d1.mergeResources(d2); - std::cout << d1.getJSON(JSON::LATEST).unparse() << std::endl; + std::cout << d1.getJSON(JSON::LATEST).unparse() << '\n'; // Top-level type mismatch d1.mergeResources(d2.getKey("/k1")); for (auto const& name: d1.getResourceNames()) { - std::cout << name << std::endl; + std::cout << name << '\n'; } } @@ -2047,10 +2045,10 @@ test_53(QPDF& pdf, char const* arg2) QPDFObjectHandle root = pdf.getRoot(); auto new_obj = pdf.makeIndirectObject(QPDFObjectHandle::newString("potato")); root.replaceKey("/Q1", new_obj); - std::cout << "new object: " << new_obj.unparse() << std::endl; - std::cout << "all objects" << std::endl; + std::cout << "new object: " << new_obj.unparse() << '\n'; + std::cout << "all objects" << '\n'; for (auto& obj: pdf.getAllObjects()) { - std::cout << obj.unparse() << std::endl; + std::cout << obj.unparse() << '\n'; } QPDFWriter w(pdf, "a.pdf"); @@ -2068,7 +2066,7 @@ test_54(QPDF& pdf, char const* arg2) assert(pdf.getPDFVersion() != "1.5"); w.setObjectStreamMode(qpdf_o_generate); if (w.getFinalVersion() != "1.5") { - std::cout << "oops: " << w.getFinalVersion() << std::endl; + std::cout << "oops: " << w.getFinalVersion() << '\n'; } } @@ -2193,11 +2191,11 @@ test_60(QPDF& pdf, char const* arg2) std::map> conflicts; auto show_conflicts = [&](std::string const& msg) { - std::cout << msg << std::endl; + std::cout << msg << '\n'; for (auto const& i1: conflicts) { - std::cout << i1.first << ":" << std::endl; + std::cout << i1.first << ":" << '\n'; for (auto const& i2: i1.second) { - std::cout << " " << i2.first << " -> " << i2.second << std::endl; + std::cout << " " << i2.first << " -> " << i2.second << '\n'; } } }; @@ -2242,22 +2240,22 @@ test_61(QPDF& pdf, char const* arg2) try { pdf.processMemoryFile("empty", "", 0); } catch (QPDFExc const&) { - std::cout << "Caught QPDFExc as expected" << std::endl; + std::cout << "Caught QPDFExc as expected" << '\n'; } try { QUtil::safe_fopen("/does/not/exist", "r"); } catch (QPDFSystemError const&) { - std::cout << "Caught QPDFSystemError as expected" << std::endl; + std::cout << "Caught QPDFSystemError as expected" << '\n'; } try { QUtil::int_to_string_base(0, 12); } catch (std::logic_error const&) { - std::cout << "Caught logic_error as expected" << std::endl; + std::cout << "Caught logic_error as expected" << '\n'; } try { QUtil::toUTF8(0xffffffff); } catch (std::runtime_error const&) { - std::cout << "Caught runtime_error as expected" << std::endl; + std::cout << "Caught runtime_error as expected" << '\n'; } // Spot check RTTI for dynamic cast. We intend to have pipelines @@ -2389,18 +2387,18 @@ test_68(QPDF& pdf, char const* arg2) QPDFObjectHandle qstream = root.getKey("/QStream"); try { qstream.getStreamData(); - std::cout << "oops -- didn't throw" << std::endl; + std::cout << "oops -- didn't throw" << '\n'; } catch (std::exception& e) { - std::cout << "get unfilterable stream: " << e.what() << std::endl; + std::cout << "get unfilterable stream: " << e.what() << '\n'; } std::shared_ptr b1 = qstream.getStreamData(qpdf_dl_all); if ((b1->getSize() > 10) && (memcmp(b1->getBuffer(), "wwwwwwwww", 9) == 0)) { - std::cout << "filtered stream data okay" << std::endl; + std::cout << "filtered stream data okay" << '\n'; } std::shared_ptr b2 = qstream.getRawStreamData(); if ((b2->getSize() > 10) && (memcmp(b2->getBuffer(), "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) == 0)) { - std::cout << "raw stream data okay" << std::endl; + std::cout << "raw stream data okay" << '\n'; } } @@ -2436,42 +2434,42 @@ static void test_71(QPDF& pdf, char const* arg2) { auto show = [](QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key) { - std::cout << xobj_dict.unparse() << " -> " << key << " -> " << obj.unparse() << std::endl; + std::cout << xobj_dict.unparse() << " -> " << key << " -> " << obj.unparse() << '\n'; }; auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0); - std::cout << "--- recursive, all ---" << std::endl; + std::cout << "--- recursive, all ---" << '\n'; page.forEachXObject(true, show); - std::cout << "--- non-recursive, all ---" << std::endl; + std::cout << "--- non-recursive, all ---" << '\n'; page.forEachXObject(false, show); - std::cout << "--- recursive, images ---" << std::endl; + std::cout << "--- recursive, images ---" << '\n'; page.forEachImage(true, show); - std::cout << "--- non-recursive, images ---" << std::endl; + std::cout << "--- non-recursive, images ---" << '\n'; page.forEachImage(false, show); - std::cout << "--- recursive, form XObjects ---" << std::endl; + std::cout << "--- recursive, form XObjects ---" << '\n'; page.forEachFormXObject(true, show); - std::cout << "--- non-recursive, form XObjects ---" << std::endl; + std::cout << "--- non-recursive, form XObjects ---" << '\n'; page.forEachFormXObject(false, show); auto fx1 = QPDFPageObjectHelper( page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1")); - std::cout << "--- recursive, all, from fx1 ---" << std::endl; + std::cout << "--- recursive, all, from fx1 ---" << '\n'; fx1.forEachXObject(true, show); - std::cout << "--- non-recursive, all, from fx1 ---" << std::endl; + std::cout << "--- non-recursive, all, from fx1 ---" << '\n'; fx1.forEachXObject(false, show); - std::cout << "--- get images, page ---" << std::endl; + std::cout << "--- get images, page ---" << '\n'; for (auto& i: page.getImages()) { - std::cout << i.first << " -> " << i.second.unparse() << std::endl; + std::cout << i.first << " -> " << i.second.unparse() << '\n'; } - std::cout << "--- get images, fx ---" << std::endl; + std::cout << "--- get images, fx ---" << '\n'; for (auto& i: fx1.getImages()) { - std::cout << i.first << " -> " << i.second.unparse() << std::endl; + std::cout << i.first << " -> " << i.second.unparse() << '\n'; } - std::cout << "--- get form XObjects, page ---" << std::endl; + std::cout << "--- get form XObjects, page ---" << '\n'; for (auto& i: page.getFormXObjects()) { - std::cout << i.first << " -> " << i.second.unparse() << std::endl; + std::cout << i.first << " -> " << i.second.unparse() << '\n'; } - std::cout << "--- get form XObjects, fx ---" << std::endl; + std::cout << "--- get form XObjects, fx ---" << '\n'; for (auto& i: fx1.getFormXObjects()) { - std::cout << i.first << " -> " << i.second.unparse() << std::endl; + std::cout << i.first << " -> " << i.second.unparse() << '\n'; } } @@ -2482,7 +2480,7 @@ test_72(QPDF& pdf, char const* arg2) auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0); auto fx1 = QPDFPageObjectHelper( page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1")); - std::cout << "--- parseContents ---" << std::endl; + std::cout << "--- parseContents ---" << '\n'; ParserCallbacks cb; fx1.parseContents(&cb); // Do this once with addContentTokenFilter and once with @@ -2511,7 +2509,7 @@ test_73(QPDF& pdf, char const* arg2) QPDF pdf2; pdf2.getRoot(); } catch (std::exception& e) { - std::cerr << "getRoot: " << e.what() << std::endl; + std::cerr << "getRoot: " << e.what() << '\n'; } pdf.closeInputSource(); @@ -2522,7 +2520,7 @@ static void test_74(QPDF& pdf, char const* arg2) { // This test is crafted to work with split-nntree.pdf - std::cout << "/Split1" << std::endl; + std::cout << "/Split1" << '\n'; auto split1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Split1"), pdf); split1.setSplitThreshold(4); auto check_split1 = [&split1](int k) { @@ -2533,10 +2531,10 @@ test_74(QPDF& pdf, char const* arg2) check_split1(35); check_split1(125); for (auto const& i: split1) { - std::cout << i.first << std::endl; + std::cout << i.first << '\n'; } - std::cout << "/Split2" << std::endl; + std::cout << "/Split2" << '\n'; auto split2 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split2"), pdf); split2.setSplitThreshold(4); auto check_split2 = [](QPDFNameTreeObjectHelper& noh, std::string const& k) { @@ -2545,16 +2543,16 @@ test_74(QPDF& pdf, char const* arg2) }; check_split2(split2, "C"); for (auto const& i: split2) { - std::cout << i.first << std::endl; + std::cout << i.first << '\n'; } - std::cout << "/Split3" << std::endl; + std::cout << "/Split3" << '\n'; auto split3 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split3"), pdf); split3.setSplitThreshold(4); check_split2(split3, "P"); check_split2(split3, "\xcf\x80"); for (auto& i: split3) { - std::cout << i.first << " " << i.second.unparse() << std::endl; + std::cout << i.first << " " << i.second.unparse() << '\n'; } QPDFWriter w(pdf, "a.pdf"); @@ -2655,7 +2653,7 @@ test_76(QPDF& pdf, char const* arg2) assert(QUtil::hex_encode(efs2.getChecksum()) == "2fce9c8228e360ba9b04a1bd1bf63d6b"); for (auto const& iter: efdh.getEmbeddedFiles()) { - std::cout << iter.first << " -> " << iter.second->getFilename() << std::endl; + std::cout << iter.first << " -> " << iter.second->getFilename() << '\n'; } assert(efdh.getEmbeddedFile("att1")->getFilename() == "att1.txt"); assert(!efdh.getEmbeddedFile("potato")); @@ -2689,17 +2687,17 @@ test_78(QPDF& pdf, char const* arg2) p->finish(); }; auto f2 = [](Pipeline* p, bool suppress_warnings, bool will_retry) { - std::cerr << "f2" << std::endl; + std::cerr << "f2" << '\n'; if (will_retry) { - std::cerr << "failing" << std::endl; + std::cerr << "failing" << '\n'; return false; } if (!suppress_warnings) { - std::cerr << "warning" << std::endl; + std::cerr << "warning" << '\n'; } p->writeCStr("salad"); p->finish(); - std::cerr << "f2 done" << std::endl; + std::cerr << "f2 done" << '\n'; return true; }; @@ -2709,11 +2707,11 @@ test_78(QPDF& pdf, char const* arg2) auto s2 = QPDFObjectHandle::newStream(&pdf); s2.replaceStreamData(f2, null, null); pdf.getTrailer().replaceKey("/Streams", QPDFObjectHandle::newArray({s1, s2})); - std::cout << "piping with warning suppression" << std::endl; + std::cout << "piping with warning suppression" << '\n'; Pl_Discard d; s2.pipeStreamData(&d, nullptr, 0, qpdf_dl_all, true, false); - std::cout << "writing" << std::endl; + std::cout << "writing" << '\n'; QPDFWriter w(pdf, "a.pdf"); w.setStaticID(true); w.setQDFMode(true); @@ -2890,13 +2888,13 @@ test_83(QPDF& pdf, char const* arg2) size_t size; QUtil::read_file_into_memory(arg2, file_buf, size); try { - std::cout << "calling initializeFromJson" << std::endl; + std::cout << "calling initializeFromJson" << '\n'; j.initializeFromJson(std::string(file_buf.get(), size)); - std::cout << "called initializeFromJson" << std::endl; + std::cout << "called initializeFromJson" << '\n'; } catch (QPDFUsage& e) { - std::cerr << "usage: " << e.what() << std::endl; + std::cerr << "usage: " << e.what() << '\n'; } catch (std::exception& e) { - std::cerr << "exception: " << e.what() << std::endl; + std::cerr << "exception: " << e.what() << '\n'; } } @@ -2905,7 +2903,7 @@ test_84(QPDF& pdf, char const* arg2) { // Test QPDFJob API - std::cout << "normal" << std::endl; + std::cout << "normal" << '\n'; { QPDFJob j; j.config() @@ -2922,11 +2920,11 @@ test_84(QPDF& pdf, char const* arg2) assert(j.getEncryptionStatus() == 0); } - std::cout << "custom progress reporter" << std::endl; + std::cout << "custom progress reporter" << '\n'; { QPDFJob j; j.registerProgressReporter( - [](int p) { std::cout << "custom write progress: " << p << "%" << std::endl; }); + [](int p) { std::cout << "custom write progress: " << p << "%" << '\n'; }); j.config() ->inputFile("minimal.pdf") ->outputFile("a.pdf") @@ -2941,29 +2939,29 @@ test_84(QPDF& pdf, char const* arg2) assert(j.getEncryptionStatus() == 0); } - std::cout << "error caught by check" << std::endl; + std::cout << "error caught by check" << '\n'; try { QPDFJob j; j.config()->outputFile("a.pdf")->qdf(); - std::cout << "finished config" << std::endl; + std::cout << "finished config" << '\n'; j.checkConfiguration(); assert(false); } catch (QPDFUsage& e) { - std::cout << "usage: " << e.what() << std::endl; + std::cout << "usage: " << e.what() << '\n'; } - std::cout << "error caught by run" << std::endl; + std::cout << "error caught by run" << '\n'; try { QPDFJob j; j.config()->outputFile("a.pdf")->qdf(); - std::cout << "finished config" << std::endl; + std::cout << "finished config" << '\n'; j.run(); assert(false); } catch (QPDFUsage& e) { - std::cout << "usage: " << e.what() << std::endl; + std::cout << "usage: " << e.what() << '\n'; } - std::cout << "output capture" << std::endl; + std::cout << "output capture" << '\n'; std::ostringstream cout; std::ostringstream cerr; { @@ -2980,11 +2978,11 @@ test_84(QPDF& pdf, char const* arg2) # pragma GCC diagnostic pop #endif j.config()->inputFile("bad2.pdf")->showObject("4,0")->checkConfiguration(); - std::cout << "calling run" << std::endl; + std::cout << "calling run" << '\n'; j.run(); - std::cout << "captured stdout" << std::endl; + std::cout << "captured stdout" << '\n'; std::cout << cout.str(); - std::cout << "captured stderr" << std::endl; + std::cout << "captured stderr" << '\n'; std::cout << cerr.str(); } } @@ -3478,7 +3476,7 @@ test_99(QPDF& pdf, char const* arg2) // Designed for no-space-compressed-object.pdf QPDFObjectHandle qtest = pdf.getRoot().getKey("/QTest"); for (int i = 0; i < qtest.getArrayNItems(); ++i) { - std::cout << qtest.getArrayItem(i).unparseResolved() << std::endl; + std::cout << qtest.getArrayItem(i).unparseResolved() << '\n'; } } @@ -3669,7 +3667,7 @@ runtest(int n, char const* filename1, char const* arg2) if (filep) { fclose(filep); } - std::cout << "test " << n << " done" << std::endl; + std::cout << "test " << n << " done" << '\n'; } int @@ -3692,7 +3690,7 @@ main(int argc, char* argv[]) char const* arg2 = argv[3]; runtest(n, filename1, arg2); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/qpdf/test_large_file.cc b/qpdf/test_large_file.cc index f273c78..cffd526 100644 --- a/qpdf/test_large_file.cc +++ b/qpdf/test_large_file.cc @@ -94,7 +94,7 @@ void ImageChecker::finish() { if (!okay) { - std::cout << "errors found checking image data for page " << n << std::endl; + std::cout << "errors found checking image data for page " << n << '\n'; } } @@ -120,7 +120,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) if (buf == nullptr) { buf = new unsigned char[width * stripesize]; } - std::cout << "page " << n << " of " << npages << std::endl; + std::cout << "page " << n << " of " << npages << '\n'; for (size_t y = 0; y < nstripes; ++y) { unsigned char color = get_pixel_color(n, y); memset(buf, color, width * stripesize); @@ -132,7 +132,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) void usage() { - std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" << std::endl; + std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" << '\n'; exit(2); } @@ -247,7 +247,7 @@ check_page_contents(size_t pageno, QPDFObjectHandle page) std::string(reinterpret_cast(buf->getBuffer()), buf->getSize()); std::string expected_contents = generate_page_contents(pageno); if (expected_contents != actual_contents) { - std::cout << "page contents wrong for page " << pageno << std::endl + std::cout << "page contents wrong for page " << pageno << '\n' << "ACTUAL: " << actual_contents << "EXPECTED: " << expected_contents << "----\n"; } } @@ -269,7 +269,7 @@ check_pdf(char const* filename) assert(pages.size() == QIntC::to_size(npages)); for (size_t i = 0; i < npages; ++i) { size_t pageno = i + 1; - std::cout << "page " << pageno << " of " << npages << std::endl; + std::cout << "page " << pageno << " of " << npages << '\n'; check_page_contents(pageno, pages.at(i)); check_image(pageno, pages.at(i)); } @@ -316,7 +316,7 @@ main(int argc, char* argv[]) check_pdf(filename); } } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; exit(2); } diff --git a/qpdf/test_many_nulls.cc b/qpdf/test_many_nulls.cc index 07e81af..84677d1 100644 --- a/qpdf/test_many_nulls.cc +++ b/qpdf/test_many_nulls.cc @@ -10,7 +10,7 @@ main(int argc, char* argv[]) { auto whoami = QUtil::getWhoami(argv[0]); if (argc != 2) { - std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl; + std::cerr << "Usage: " << whoami << " outfile.pdf" << '\n'; exit(2); } char const* outfile = argv[1]; diff --git a/qpdf/test_parsedoffset.cc b/qpdf/test_parsedoffset.cc index 4721e12..8f1924e 100644 --- a/qpdf/test_parsedoffset.cc +++ b/qpdf/test_parsedoffset.cc @@ -13,7 +13,7 @@ void usage() { - std::cerr << "Usage: test_parsedoffset INPUT.pdf" << std::endl; + std::cerr << "Usage: test_parsedoffset INPUT.pdf" << '\n'; } std::string @@ -79,7 +79,7 @@ process(std::string fn, std::vector(xref.getObjStreamNumber()); break; default: - std::cerr << "unknown xref entry type" << std::endl; + std::cerr << "unknown xref entry type" << '\n'; std::exit(2); } @@ -126,19 +126,19 @@ main(int argc, char* argv[]) std::sort(table[i].begin(), table[i].end()); if (i == 0) { - std::cout << "--- objects not in streams ---" << std::endl; + std::cout << "--- objects not in streams ---" << '\n'; } else { - std::cout << "--- objects in stream " << i << " ---" << std::endl; + std::cout << "--- objects in stream " << i << " ---" << '\n'; } for (auto const& iter: table[i]) { - std::cout << iter.second << std::endl; + std::cout << iter.second << '\n'; } } - std::cout << "succeeded" << std::endl; + std::cout << "succeeded" << '\n'; } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; std::exit(2); } diff --git a/qpdf/test_pdf_doc_encoding.cc b/qpdf/test_pdf_doc_encoding.cc index 6a16f16..ef0bac1 100644 --- a/qpdf/test_pdf_doc_encoding.cc +++ b/qpdf/test_pdf_doc_encoding.cc @@ -9,7 +9,7 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile" << std::endl; + std::cerr << "Usage: " << whoami << " infile" << '\n'; exit(2); } @@ -28,7 +28,7 @@ main(int argc, char* argv[]) char const* infilename = argv[1]; for (auto const& line: QUtil::read_lines_from_file(infilename)) { QPDFObjectHandle str = QPDFObjectHandle::newString(line); - std::cout << str.getUTF8Value() << std::endl; + std::cout << str.getUTF8Value() << '\n'; } return 0; } diff --git a/qpdf/test_pdf_unicode.cc b/qpdf/test_pdf_unicode.cc index a459369..e213046 100644 --- a/qpdf/test_pdf_unicode.cc +++ b/qpdf/test_pdf_unicode.cc @@ -9,7 +9,7 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " infile" << std::endl; + std::cerr << "Usage: " << whoami << " infile" << '\n'; exit(2); } @@ -28,7 +28,7 @@ main(int argc, char* argv[]) char const* infilename = argv[1]; for (auto const& line: QUtil::read_lines_from_file(infilename)) { QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line); - std::cout << str.getUTF8Value() << " // " << str.unparseBinary() << std::endl; + std::cout << str.getUTF8Value() << " // " << str.unparseBinary() << '\n'; } return 0; } diff --git a/qpdf/test_renumber.cc b/qpdf/test_renumber.cc index 33127f1..b3499a8 100644 --- a/qpdf/test_renumber.cc +++ b/qpdf/test_renumber.cc @@ -14,11 +14,11 @@ void usage() { - std::cerr << "Usage: test_renumber [OPTION] INPUT.pdf" << std::endl - << "Option:" << std::endl - << " --object-streams=preserve|disable|generate" << std::endl - << " --linearize" << std::endl - << " --preserve-unreferenced" << std::endl; + std::cerr << "Usage: test_renumber [OPTION] INPUT.pdf" << '\n' + << "Option:" << '\n' + << " --object-streams=preserve|disable|generate" << '\n' + << " --linearize" << '\n' + << " --preserve-unreferenced" << '\n'; } bool @@ -33,38 +33,38 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) } if (a.getTypeCode() != b.getTypeCode()) { - std::cerr << "different type code" << std::endl; + std::cerr << "different type code" << '\n'; return false; } switch (a.getTypeCode()) { case ::ot_boolean: if (a.getBoolValue() != b.getBoolValue()) { - std::cerr << "different boolean" << std::endl; + std::cerr << "different boolean" << '\n'; return false; } break; case ::ot_integer: if (a.getIntValue() != b.getIntValue()) { - std::cerr << "different integer" << std::endl; + std::cerr << "different integer" << '\n'; return false; } break; case ::ot_real: if (a.getRealValue() != b.getRealValue()) { - std::cerr << "different real" << std::endl; + std::cerr << "different real" << '\n'; return false; } break; case ::ot_string: if (a.getStringValue() != b.getStringValue()) { - std::cerr << "different string" << std::endl; + std::cerr << "different string" << '\n'; return false; } break; case ::ot_name: if (a.getName() != b.getName()) { - std::cerr << "different name" << std::endl; + std::cerr << "different name" << '\n'; return false; } break; @@ -74,13 +74,13 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) std::vector objs_b = b.getArrayAsVector(); size_t items = objs_a.size(); if (items != objs_b.size()) { - std::cerr << "different array size" << std::endl; + std::cerr << "different array size" << '\n'; return false; } for (size_t i = 0; i < items; ++i) { if (!compare(objs_a[i], objs_b[i])) { - std::cerr << "different array item" << std::endl; + std::cerr << "different array item" << '\n'; return false; } } @@ -91,13 +91,13 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) std::set keys_a = a.getKeys(); std::set keys_b = b.getKeys(); if (keys_a != keys_b) { - std::cerr << "different dictionary keys" << std::endl; + std::cerr << "different dictionary keys" << '\n'; return false; } for (auto const& key: keys_a) { if (!compare(a.getKey(key), b.getKey(key))) { - std::cerr << "different dictionary item" << std::endl; + std::cerr << "different dictionary item" << '\n'; return false; } } @@ -106,10 +106,10 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) case ::ot_null: break; case ::ot_stream: - std::cout << "stream objects are not compared" << std::endl; + std::cout << "stream objects are not compared" << '\n'; break; default: - std::cerr << "unknown object type" << std::endl; + std::cerr << "unknown object type" << '\n'; std::exit(2); } @@ -120,23 +120,22 @@ bool compare_xref_table(std::map a, std::map b) { if (a.size() != b.size()) { - std::cerr << "different size" << std::endl; + std::cerr << "different size" << '\n'; return false; } for (auto const& iter: a) { - std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen() - << std::endl; + std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen() << '\n'; if (!b.contains(iter.first)) { - std::cerr << "not found" << std::endl; + std::cerr << "not found" << '\n'; return false; } QPDFXRefEntry xref_a = iter.second; QPDFXRefEntry xref_b = b[iter.first]; if (xref_a.getType() != xref_b.getType()) { - std::cerr << "different xref entry type" << std::endl; + std::cerr << "different xref entry type" << '\n'; return false; } @@ -145,19 +144,19 @@ compare_xref_table(std::map a, std::map(buf->getBuffer()), buf->getSize()); std::map xrefs_ren = qpdf_ren.getXRefTable(); - std::cout << "--- compare between input and renumbered objects ---" << std::endl; + std::cout << "--- compare between input and renumbered objects ---" << '\n'; for (auto const& iter: objs_in) { QPDFObjGen og_in = iter.getObjGen(); QPDFObjGen og_ren = w.getRenumberedObjGen(og_in); std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() << " -> renumbered " - << og_ren.getObj() << "/" << og_ren.getGen() << std::endl; + << og_ren.getObj() << "/" << og_ren.getGen() << '\n'; if (og_ren.getObj() == 0) { - std::cout << "deleted" << std::endl; + std::cout << "deleted" << '\n'; continue; } if (!compare(iter, qpdf_ren.getObjectByObjGen(og_ren))) { - std::cerr << "different" << std::endl; + std::cerr << "different" << '\n'; std::exit(2); } } - std::cout << "complete" << std::endl; + std::cout << "complete" << '\n'; - std::cout << "--- compare between written and reloaded xref tables ---" << std::endl; + std::cout << "--- compare between written and reloaded xref tables ---" << '\n'; if (!compare_xref_table(xrefs_w, xrefs_ren)) { - std::cerr << "different" << std::endl; + std::cerr << "different" << '\n'; std::exit(2); } - std::cout << "complete" << std::endl; + std::cout << "complete" << '\n'; - std::cout << "succeeded" << std::endl; + std::cout << "succeeded" << '\n'; } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; std::exit(2); } diff --git a/qpdf/test_shell_glob.cc b/qpdf/test_shell_glob.cc index b916e3d..6df9782 100644 --- a/qpdf/test_shell_glob.cc +++ b/qpdf/test_shell_glob.cc @@ -32,11 +32,11 @@ realmain(int argc, char* argv[]) bool passed = (found_star && (argc == 2)); #endif if (passed) { - std::cout << "PASSED" << std::endl; + std::cout << "PASSED" << '\n'; } else { - std::cout << "FAILED" << std::endl; + std::cout << "FAILED" << '\n'; for (int i = 1; i < argc; ++i) { - std::cout << argv[i] << std::endl; + std::cout << argv[i] << '\n'; } } return 0; diff --git a/qpdf/test_tokenizer.cc b/qpdf/test_tokenizer.cc index 28aa306..773b586 100644 --- a/qpdf/test_tokenizer.cc +++ b/qpdf/test_tokenizer.cc @@ -16,7 +16,7 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " [-maxlen len | -no-ignorable] filename" << std::endl; + std::cerr << "Usage: " << whoami << " [-maxlen len | -no-ignorable] filename" << '\n'; exit(2); } @@ -115,10 +115,10 @@ try_skipping( char const* what, Finder& f) { - std::cout << "skipping to " << what << std::endl; + std::cout << "skipping to " << what << '\n'; qpdf_offset_t offset = is->tell(); if (!is->findFirst(what, offset, 0, f)) { - std::cout << what << " not found" << std::endl; + std::cout << what << " not found" << '\n'; is->seek(offset, SEEK_SET); } } @@ -133,7 +133,7 @@ dump_tokens( bool skip_inline_images) { Finder f1(is, "endstream"); - std::cout << "--- BEGIN " << label << " ---" << std::endl; + std::cout << "--- BEGIN " << label << " ---" << '\n'; bool done = false; QPDFTokenizer tokenizer; tokenizer.allowEOF(); @@ -145,7 +145,7 @@ dump_tokens( QPDFTokenizer::Token token = tokenizer.readToken(is, "test", true, inline_image_offset ? 0 : max_len); if (inline_image_offset && (token.getType() == QPDFTokenizer::tt_bad)) { - std::cout << "EI not found; resuming normal scanning" << std::endl; + std::cout << "EI not found; resuming normal scanning" << '\n'; is->seek(inline_image_offset, SEEK_SET); inline_image_offset = 0; continue; @@ -163,7 +163,7 @@ dump_tokens( if (!token.getErrorMessage().empty()) { std::cout << " (" << token.getErrorMessage() << ")"; } - std::cout << std::endl; + std::cout << '\n'; if (skip_streams && (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))) { try_skipping(tokenizer, is, max_len, "endstream", f1); } else if ( @@ -176,7 +176,7 @@ dump_tokens( done = true; } } - std::cout << "--- END " << label << " ---" << std::endl; + std::cout << "--- END " << label << " ---" << '\n'; } static void diff --git a/qpdf/test_unicode_filenames.cc b/qpdf/test_unicode_filenames.cc index 35ad7c7..17b1d1c 100644 --- a/qpdf/test_unicode_filenames.cc +++ b/qpdf/test_unicode_filenames.cc @@ -13,7 +13,7 @@ static void do_copy(FILE* in, FILE* out) { if ((in == nullptr) || (out == nullptr)) { - std::cerr << "errors opening files" << std::endl; + std::cerr << "errors opening files" << '\n'; exit(2); } char buf[10240]; @@ -22,7 +22,7 @@ do_copy(FILE* in, FILE* out) fwrite(buf, 1, len, out); } if (len != 0) { - std::cerr << "errors reading or writing" << std::endl; + std::cerr << "errors reading or writing" << '\n'; exit(2); } fclose(in); @@ -76,7 +76,7 @@ main(int argc, char* argv[]) char const* f2 = "auto-\xc3\xb6\xcf\x80.pdf"; copy(f1); copy(f2); - std::cout << "created Unicode filenames" << std::endl; + std::cout << "created Unicode filenames" << '\n'; return 0; } diff --git a/qpdf/test_xref.cc b/qpdf/test_xref.cc index bc733de..81e7d07 100644 --- a/qpdf/test_xref.cc +++ b/qpdf/test_xref.cc @@ -8,7 +8,7 @@ int main(int argc, char* argv[]) { if (argc != 2) { - std::cerr << "usage: test_xref INPUT.pdf" << std::endl; + std::cerr << "usage: test_xref INPUT.pdf" << '\n'; std::exit(2); } @@ -20,23 +20,23 @@ main(int argc, char* argv[]) std::cout << iter.first.getObj() << "/" << iter.first.getGen() << ", "; switch (iter.second.getType()) { case 0: - std::cout << "free entry" << std::endl; + std::cout << "free entry" << '\n'; break; case 1: std::cout << "uncompressed, offset = " << iter.second.getOffset() << " (0x" - << std::hex << iter.second.getOffset() << std::dec << ")" << std::endl; + << std::hex << iter.second.getOffset() << std::dec << ")" << '\n'; break; case 2: std::cout << "compressed, stream number = " << iter.second.getObjStreamNumber() - << ", stream index = " << iter.second.getObjStreamIndex() << std::endl; + << ", stream index = " << iter.second.getObjStreamIndex() << '\n'; break; default: - std::cerr << "unknown" << std::endl; + std::cerr << "unknown" << '\n'; std::exit(2); } } } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; std::exit(2); } diff --git a/zlib-flate/zlib-flate.cc b/zlib-flate/zlib-flate.cc index 02a748e..9822ff5 100644 --- a/zlib-flate/zlib-flate.cc +++ b/zlib-flate/zlib-flate.cc @@ -13,11 +13,10 @@ static char const* whoami = nullptr; void usage() { - std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" << std::endl - << "If n is specified with -compress, it is a zlib compression level from" - << std::endl - << "1 to 9 where lower numbers are faster and less compressed and higher" << std::endl - << "numbers are slower and more compressed" << std::endl; + std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" << '\n' + << "If n is specified with -compress, it is a zlib compression level from" << '\n' + << "1 to 9 where lower numbers are faster and less compressed and higher" << '\n' + << "numbers are slower and more compressed" << '\n'; exit(2); } @@ -31,7 +30,7 @@ main(int argc, char* argv[]) } if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) { - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl; + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << '\n'; exit(0); } @@ -53,7 +52,7 @@ main(int argc, char* argv[]) // Undocumented option, but that doesn't mean someone doesn't use it... // This is primarily here to support the test suite. std::cout << (Pl_Flate::zopfli_supported() ? "1" : "0") - << (Pl_Flate::zopfli_enabled() ? "1" : "0") << std::endl; + << (Pl_Flate::zopfli_enabled() ? "1" : "0") << '\n'; return 0; } else { usage(); @@ -68,8 +67,7 @@ main(int argc, char* argv[]) auto flate = std::make_shared("flate", out.get(), action); flate->setWarnCallback([&warn](char const* msg, int code) { warn = true; - std::cerr << whoami << ": WARNING: zlib code " << code << ", msg = " << msg - << std::endl; + std::cerr << whoami << ": WARNING: zlib code " << code << ", msg = " << msg << '\n'; }); unsigned char buf[10000]; @@ -84,7 +82,7 @@ main(int argc, char* argv[]) } flate->finish(); } catch (std::exception& e) { - std::cerr << whoami << ": " << e.what() << std::endl; + std::cerr << whoami << ": " << e.what() << '\n'; exit(2); }