aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pdf-count-strings.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-02 23:14:10 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-04 14:10:40 +0200
commit12f1eb15ca3fed6310402847559a7c99d3c77847 (patch)
tree8935675b623c6f3b4914b8b44f7fa5f2816a9241 /examples/pdf-count-strings.cc
parentf20fa61eb4c323eb1642c69c236b3d9a1f8b2cdb (diff)
downloadqpdf-12f1eb15ca3fed6310402847559a7c99d3c77847.tar.zst
Programmatically apply new formatting to code
Run this: for i in **/*.cc **/*.c **/*.h **/*.hh; do clang-format < $i >| $i.new && mv $i.new $i done
Diffstat (limited to 'examples/pdf-count-strings.cc')
-rw-r--r--examples/pdf-count-strings.cc38
1 files changed, 15 insertions, 23 deletions
diff --git a/examples/pdf-count-strings.cc b/examples/pdf-count-strings.cc
index 4a1a8e4e..a52b7a37 100644
--- a/examples/pdf-count-strings.cc
+++ b/examples/pdf-count-strings.cc
@@ -5,23 +5,23 @@
//
#include <iostream>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
+#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QPDF.hh>
+#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDFPageDocumentHelper.hh>
#include <qpdf/QPDFPageObjectHelper.hh>
#include <qpdf/QUtil.hh>
-#include <qpdf/QPDFObjectHandle.hh>
-#include <qpdf/Pl_StdioFile.hh>
static char const* whoami = 0;
-void usage()
+void
+usage()
{
std::cerr << "Usage: " << whoami << " infile" << std::endl
- << "Applies token filters to infile"
- << std::endl;
+ << "Applies token filters to infile" << std::endl;
exit(2);
}
@@ -47,8 +47,7 @@ void
StringCounter::handleToken(QPDFTokenizer::Token const& token)
{
// Count string tokens
- if (token.getType() == QPDFTokenizer::tt_string)
- {
+ if (token.getType() == QPDFTokenizer::tt_string) {
++this->count;
}
// Preserve input verbatim by passing each token to any specified
@@ -71,36 +70,31 @@ StringCounter::getCount() const
return this->count;
}
-int main(int argc, char* argv[])
+int
+main(int argc, char* argv[])
{
whoami = QUtil::getWhoami(argv[0]);
- if (argc != 2)
- {
+ if (argc != 2) {
usage();
}
char const* infilename = argv[1];
- try
- {
+ try {
QPDF pdf;
pdf.processFile(infilename);
int pageno = 0;
- for (auto& page : QPDFPageDocumentHelper(pdf).getAllPages())
- {
+ for (auto& page : QPDFPageDocumentHelper(pdf).getAllPages()) {
++pageno;
// Pass the contents of a page through our string counter.
// If it's an even page, capture the output. This
// illustrates that you may capture any output generated
// by the filter, or you may ignore it.
StringCounter counter;
- if (pageno % 2)
- {
+ if (pageno % 2) {
// Ignore output for odd pages.
page.filterContents(&counter);
- }
- else
- {
+ } else {
// Write output to stdout for even pages.
Pl_StdioFile out("stdout", stdout);
std::cout << "% Contents of page " << pageno << std::endl;
@@ -110,9 +104,7 @@ int main(int argc, char* argv[])
std::cout << "Page " << pageno
<< ": strings = " << counter.getCount() << std::endl;
}
- }
- catch (std::exception& e)
- {
+ } catch (std::exception& e) {
std::cerr << whoami << ": " << e.what() << std::endl;
exit(2);
}