Commit 12f1eb15ca3fed6310402847559a7c99d3c77847

Authored by Jay Berkenbilt
1 parent f20fa61e

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
Showing 244 changed files with 15225 additions and 18966 deletions

Too many changes.

To preserve performance only 100 of 244 files are displayed.

examples/pdf-attach-file.cc
1 #include <qpdf/QPDF.hh> 1 #include <qpdf/QPDF.hh>
2 -#include <qpdf/QUtil.hh>  
3 -#include <qpdf/QPDFWriter.hh>  
4 #include <qpdf/QPDFEmbeddedFileDocumentHelper.hh> 2 #include <qpdf/QPDFEmbeddedFileDocumentHelper.hh>
5 #include <qpdf/QPDFFileSpecObjectHelper.hh> 3 #include <qpdf/QPDFFileSpecObjectHelper.hh>
  4 +#include <qpdf/QPDFWriter.hh>
  5 +#include <qpdf/QUtil.hh>
6 6
7 -#include <iostream>  
8 #include <cstring> 7 #include <cstring>
  8 +#include <iostream>
9 9
10 // 10 //
11 // This example attaches a file to an input file, adds a page to the 11 // This example attaches a file to an input file, adds a page to the
@@ -17,9 +17,11 @@ @@ -17,9 +17,11 @@
17 17
18 static char const* whoami = 0; 18 static char const* whoami = 0;
19 19
20 -static void usage(std::string const& msg) 20 +static void
  21 +usage(std::string const& msg)
21 { 22 {
22 - std::cerr << msg << std::endl << std::endl 23 + std::cerr << msg << std::endl
  24 + << std::endl
23 << "Usage: " << whoami << " options" << std::endl 25 << "Usage: " << whoami << " options" << std::endl
24 << "Options:" << std::endl 26 << "Options:" << std::endl
25 << " --infile infile.pdf" << std::endl 27 << " --infile infile.pdf" << std::endl
@@ -30,33 +32,36 @@ static void usage(std::string const&amp; msg) @@ -30,33 +32,36 @@ static void usage(std::string const&amp; msg)
30 exit(2); 32 exit(2);
31 } 33 }
32 34
33 -static void process(char const* infilename, char const* password,  
34 - char const* attachment, char const* mimetype,  
35 - char const* outfilename) 35 +static void
  36 +process(
  37 + char const* infilename,
  38 + char const* password,
  39 + char const* attachment,
  40 + char const* mimetype,
  41 + char const* outfilename)
36 { 42 {
37 QPDF q; 43 QPDF q;
38 q.processFile(infilename, password); 44 q.processFile(infilename, password);
39 45
40 // Create an indirect object for the built-in Helvetica font. This 46 // Create an indirect object for the built-in Helvetica font. This
41 // uses the qpdf literal syntax introduced in qpdf 10.6. 47 // uses the qpdf literal syntax introduced in qpdf 10.6.
42 - auto f1 = q.makeIndirectObject(  
43 - "<<"  
44 - " /Type /Font"  
45 - " /Subtype /Type1"  
46 - " /Name /F1"  
47 - " /BaseFont /Helvetica"  
48 - " /Encoding /WinAnsiEncoding"  
49 - ">>"_qpdf); 48 + auto f1 = q.makeIndirectObject("<<"
  49 + " /Type /Font"
  50 + " /Subtype /Type1"
  51 + " /Name /F1"
  52 + " /BaseFont /Helvetica"
  53 + " /Encoding /WinAnsiEncoding"
  54 + ">>"_qpdf);
50 55
51 // Create a resources dictionary with fonts. This uses the new 56 // Create a resources dictionary with fonts. This uses the new
52 // parse introduced in qpdf 10.2 that takes a QPDF* and allows 57 // parse introduced in qpdf 10.2 that takes a QPDF* and allows
53 // indirect object references. 58 // indirect object references.
54 - auto resources = q.makeIndirectObject(  
55 - QPDFObjectHandle::parse(  
56 - &q,  
57 - "<<"  
58 - " /Font <<"  
59 - " /F1 " + f1.unparse() + 59 + auto resources = q.makeIndirectObject(QPDFObjectHandle::parse(
  60 + &q,
  61 + "<<"
  62 + " /Font <<"
  63 + " /F1 " +
  64 + f1.unparse() +
60 " >>" 65 " >>"
61 ">>")); 66 ">>"));
62 67
@@ -66,8 +71,7 @@ static void process(char const* infilename, char const* password, @@ -66,8 +71,7 @@ static void process(char const* infilename, char const* password,
66 << std::endl; 71 << std::endl;
67 auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment); 72 auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment);
68 73
69 - if (mimetype)  
70 - { 74 + if (mimetype) {
71 // Get an embedded file stream and set mimetype 75 // Get an embedded file stream and set mimetype
72 auto ef = QPDFEFStreamObjectHelper(fs.getEmbeddedFileStream()); 76 auto ef = QPDFEFStreamObjectHelper(fs.getEmbeddedFileStream());
73 ef.setSubtype(mimetype); 77 ef.setSubtype(mimetype);
@@ -102,17 +106,16 @@ static void process(char const* infilename, char const* password, @@ -102,17 +106,16 @@ static void process(char const* infilename, char const* password,
102 apdict.replaceKey("/Type", "/XObject"_qpdf); 106 apdict.replaceKey("/Type", "/XObject"_qpdf);
103 apdict.replaceKey("/Subtype", "/Form"_qpdf); 107 apdict.replaceKey("/Subtype", "/Form"_qpdf);
104 apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf); 108 apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf);
105 - auto annot = q.makeIndirectObject(  
106 - QPDFObjectHandle::parse(  
107 - &q,  
108 - "<<"  
109 - " /AP <<"  
110 - " /N " + ap.unparse() + 109 + auto annot = q.makeIndirectObject(QPDFObjectHandle::parse(
  110 + &q,
  111 + "<<"
  112 + " /AP <<"
  113 + " /N " +
  114 + ap.unparse() +
111 " >>" 115 " >>"
112 - " /Contents "  
113 - + QPDFObjectHandle::newUnicodeString(attachment).unparse() +  
114 - " /FS " + fs.getObjectHandle().unparse() +  
115 - " /NM " + 116 + " /Contents " +
  117 + QPDFObjectHandle::newUnicodeString(attachment).unparse() +
  118 + " /FS " + fs.getObjectHandle().unparse() + " /NM " +
116 QPDFObjectHandle::newUnicodeString(attachment).unparse() + 119 QPDFObjectHandle::newUnicodeString(attachment).unparse() +
117 " /Rect [ 72 700 92 720 ]" 120 " /Rect [ 72 700 92 720 ]"
118 " /Subtype /FileAttachment" 121 " /Subtype /FileAttachment"
@@ -134,12 +137,16 @@ static void process(char const* infilename, char const* password, @@ -134,12 +137,16 @@ static void process(char const* infilename, char const* password,
134 auto page = QPDFObjectHandle::parse( 137 auto page = QPDFObjectHandle::parse(
135 &q, 138 &q,
136 "<<" 139 "<<"
137 - " /Annots [ " + annot.unparse() + " ]"  
138 - " /Contents " + contents.unparse() +  
139 - " /MediaBox [0 0 612 792]"  
140 - " /Resources " + resources.unparse() +  
141 - " /Type /Page"  
142 - ">>"); 140 + " /Annots [ " +
  141 + annot.unparse() +
  142 + " ]"
  143 + " /Contents " +
  144 + contents.unparse() +
  145 + " /MediaBox [0 0 612 792]"
  146 + " /Resources " +
  147 + resources.unparse() +
  148 + " /Type /Page"
  149 + ">>");
143 150
144 // Add the page. 151 // Add the page.
145 q.addPage(page, true); 152 q.addPage(page, true);
@@ -151,7 +158,8 @@ static void process(char const* infilename, char const* password, @@ -151,7 +158,8 @@ static void process(char const* infilename, char const* password,
151 w.write(); 158 w.write();
152 } 159 }
153 160
154 -int main(int argc, char* argv[]) 161 +int
  162 +main(int argc, char* argv[])
155 { 163 {
156 whoami = QUtil::getWhoami(argv[0]); 164 whoami = QUtil::getWhoami(argv[0]);
157 165
@@ -162,64 +170,46 @@ int main(int argc, char* argv[]) @@ -162,64 +170,46 @@ int main(int argc, char* argv[])
162 char const* mimetype = 0; 170 char const* mimetype = 0;
163 171
164 auto check_arg = [](char const* arg, std::string const& msg) { 172 auto check_arg = [](char const* arg, std::string const& msg) {
165 - if (arg == nullptr)  
166 - { 173 + if (arg == nullptr) {
167 usage(msg); 174 usage(msg);
168 } 175 }
169 }; 176 };
170 177
171 - for (int i = 1; i < argc; ++i)  
172 - { 178 + for (int i = 1; i < argc; ++i) {
173 char* arg = argv[i]; 179 char* arg = argv[i];
174 - char* next = argv[i+1];  
175 - if (strcmp(arg, "--infile") == 0)  
176 - { 180 + char* next = argv[i + 1];
  181 + if (strcmp(arg, "--infile") == 0) {
177 check_arg(next, "--infile takes an argument"); 182 check_arg(next, "--infile takes an argument");
178 infilename = next; 183 infilename = next;
179 ++i; 184 ++i;
180 - }  
181 - else if (strcmp(arg, "--password") == 0)  
182 - { 185 + } else if (strcmp(arg, "--password") == 0) {
183 check_arg(next, "--password takes an argument"); 186 check_arg(next, "--password takes an argument");
184 password = next; 187 password = next;
185 ++i; 188 ++i;
186 - }  
187 - else if (strcmp(arg, "--attachment") == 0)  
188 - { 189 + } else if (strcmp(arg, "--attachment") == 0) {
189 check_arg(next, "--attachment takes an argument"); 190 check_arg(next, "--attachment takes an argument");
190 attachment = next; 191 attachment = next;
191 ++i; 192 ++i;
192 - }  
193 - else if (strcmp(arg, "--outfile") == 0)  
194 - { 193 + } else if (strcmp(arg, "--outfile") == 0) {
195 check_arg(next, "--outfile takes an argument"); 194 check_arg(next, "--outfile takes an argument");
196 outfilename = next; 195 outfilename = next;
197 ++i; 196 ++i;
198 - }  
199 - else if (strcmp(arg, "--mimetype") == 0)  
200 - { 197 + } else if (strcmp(arg, "--mimetype") == 0) {
201 check_arg(next, "--mimetype takes an argument"); 198 check_arg(next, "--mimetype takes an argument");
202 mimetype = next; 199 mimetype = next;
203 ++i; 200 ++i;
204 - }  
205 - else  
206 - { 201 + } else {
207 usage("unknown argument " + std::string(arg)); 202 usage("unknown argument " + std::string(arg));
208 } 203 }
209 } 204 }
210 - if (! (infilename && attachment && outfilename))  
211 - { 205 + if (!(infilename && attachment && outfilename)) {
212 usage("required arguments were not provided"); 206 usage("required arguments were not provided");
213 } 207 }
214 208
215 - try  
216 - { 209 + try {
217 process(infilename, password, attachment, mimetype, outfilename); 210 process(infilename, password, attachment, mimetype, outfilename);
218 - }  
219 - catch (std::exception &e)  
220 - {  
221 - std::cerr << whoami << " exception: "  
222 - << e.what() << std::endl; 211 + } catch (std::exception& e) {
  212 + std::cerr << whoami << " exception: " << e.what() << std::endl;
223 exit(2); 213 exit(2);
224 } 214 }
225 215
examples/pdf-bookmarks.cc
1 -#include <iostream>  
2 -#include <string.h>  
3 -#include <stdlib.h> 1 +#include <qpdf/QIntC.hh>
4 #include <qpdf/QPDF.hh> 2 #include <qpdf/QPDF.hh>
5 -#include <qpdf/QPDFPageDocumentHelper.hh>  
6 #include <qpdf/QPDFOutlineDocumentHelper.hh> 3 #include <qpdf/QPDFOutlineDocumentHelper.hh>
7 -#include <qpdf/QUtil.hh>  
8 -#include <qpdf/QIntC.hh> 4 +#include <qpdf/QPDFPageDocumentHelper.hh>
9 #include <qpdf/QTC.hh> 5 #include <qpdf/QTC.hh>
  6 +#include <qpdf/QUtil.hh>
  7 +#include <iostream>
  8 +#include <stdlib.h>
  9 +#include <string.h>
10 10
11 // This program demonstrates extraction of bookmarks using the qpdf 11 // This program demonstrates extraction of bookmarks using the qpdf
12 // outlines API. Note that all the information shown by this program 12 // outlines API. Note that all the information shown by this program
@@ -20,67 +20,62 @@ static bool show_open = false; @@ -20,67 +20,62 @@ static bool show_open = false;
20 static bool show_targets = false; 20 static bool show_targets = false;
21 static std::map<QPDFObjGen, int> page_map; 21 static std::map<QPDFObjGen, int> page_map;
22 22
23 -void usage() 23 +void
  24 +usage()
24 { 25 {
25 - std::cerr << "Usage: " << whoami << " [options] file.pdf [password]"  
26 - << std::endl  
27 - << "Options:" << std::endl  
28 - << " --numbers give bookmarks outline-style numbers"  
29 - << std::endl  
30 - << " --lines draw lines to show bookmark hierarchy"  
31 - << std::endl  
32 - << " --show-open indicate whether a bookmark is initially open"  
33 - << std::endl  
34 - << " --show-targets show target if possible"  
35 - << std::endl; 26 + std::cerr
  27 + << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl
  28 + << "Options:" << std::endl
  29 + << " --numbers give bookmarks outline-style numbers"
  30 + << std::endl
  31 + << " --lines draw lines to show bookmark hierarchy"
  32 + << std::endl
  33 + << " --show-open indicate whether a bookmark is initially open"
  34 + << std::endl
  35 + << " --show-targets show target if possible" << std::endl;
36 exit(2); 36 exit(2);
37 } 37 }
38 38
39 -void print_lines(std::vector<int>& numbers) 39 +void
  40 +print_lines(std::vector<int>& numbers)
40 { 41 {
41 - for (unsigned int i = 0; i < numbers.size() - 1; ++i)  
42 - {  
43 - if (numbers.at(i))  
44 - { 42 + for (unsigned int i = 0; i < numbers.size() - 1; ++i) {
  43 + if (numbers.at(i)) {
45 std::cout << "| "; 44 std::cout << "| ";
46 - }  
47 - else  
48 - { 45 + } else {
49 std::cout << " "; 46 std::cout << " ";
50 } 47 }
51 } 48 }
52 } 49 }
53 50
54 -void generate_page_map(QPDF& qpdf) 51 +void
  52 +generate_page_map(QPDF& qpdf)
55 { 53 {
56 QPDFPageDocumentHelper dh(qpdf); 54 QPDFPageDocumentHelper dh(qpdf);
57 int n = 0; 55 int n = 0;
58 - for (auto const& page : dh.getAllPages())  
59 - { 56 + for (auto const& page : dh.getAllPages()) {
60 page_map[page.getObjectHandle().getObjGen()] = ++n; 57 page_map[page.getObjectHandle().getObjGen()] = ++n;
61 } 58 }
62 } 59 }
63 60
64 -void show_bookmark_details(QPDFOutlineObjectHelper outline,  
65 - std::vector<int> numbers) 61 +void
  62 +show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers)
66 { 63 {
67 // No default so gcc will warn on missing tag 64 // No default so gcc will warn on missing tag
68 - switch (style)  
69 - {  
70 - case st_none: 65 + switch (style) {
  66 + case st_none:
71 QTC::TC("examples", "pdf-bookmarks none"); 67 QTC::TC("examples", "pdf-bookmarks none");
72 break; 68 break;
73 69
74 - case st_numbers: 70 + case st_numbers:
75 QTC::TC("examples", "pdf-bookmarks numbers"); 71 QTC::TC("examples", "pdf-bookmarks numbers");
76 - for (auto const& number : numbers)  
77 - { 72 + for (auto const& number : numbers) {
78 std::cout << number << "."; 73 std::cout << number << ".";
79 } 74 }
80 std::cout << " "; 75 std::cout << " ";
81 break; 76 break;
82 77
83 - case st_lines: 78 + case st_lines:
84 QTC::TC("examples", "pdf-bookmarks lines"); 79 QTC::TC("examples", "pdf-bookmarks lines");
85 print_lines(numbers); 80 print_lines(numbers);
86 std::cout << "|" << std::endl; 81 std::cout << "|" << std::endl;
@@ -89,42 +84,32 @@ void show_bookmark_details(QPDFOutlineObjectHelper outline, @@ -89,42 +84,32 @@ void show_bookmark_details(QPDFOutlineObjectHelper outline,
89 break; 84 break;
90 } 85 }
91 86
92 - if (show_open)  
93 - { 87 + if (show_open) {
94 int count = outline.getCount(); 88 int count = outline.getCount();
95 - if (count)  
96 - { 89 + if (count) {
97 QTC::TC("examples", "pdf-bookmarks has count"); 90 QTC::TC("examples", "pdf-bookmarks has count");
98 - if (count > 0)  
99 - { 91 + if (count > 0) {
100 // hierarchy is open at this point 92 // hierarchy is open at this point
101 QTC::TC("examples", "pdf-bookmarks open"); 93 QTC::TC("examples", "pdf-bookmarks open");
102 std::cout << "(v) "; 94 std::cout << "(v) ";
103 - }  
104 - else  
105 - { 95 + } else {
106 QTC::TC("examples", "pdf-bookmarks closed"); 96 QTC::TC("examples", "pdf-bookmarks closed");
107 std::cout << "(>) "; 97 std::cout << "(>) ";
108 } 98 }
109 - }  
110 - else  
111 - { 99 + } else {
112 QTC::TC("examples", "pdf-bookmarks no count"); 100 QTC::TC("examples", "pdf-bookmarks no count");
113 std::cout << "( ) "; 101 std::cout << "( ) ";
114 } 102 }
115 } 103 }
116 104
117 - if (show_targets)  
118 - { 105 + if (show_targets) {
119 QTC::TC("examples", "pdf-bookmarks targets"); 106 QTC::TC("examples", "pdf-bookmarks targets");
120 std::string target = "unknown"; 107 std::string target = "unknown";
121 QPDFObjectHandle dest_page = outline.getDestPage(); 108 QPDFObjectHandle dest_page = outline.getDestPage();
122 - if (! dest_page.isNull())  
123 - { 109 + if (!dest_page.isNull()) {
124 QTC::TC("examples", "pdf-bookmarks dest"); 110 QTC::TC("examples", "pdf-bookmarks dest");
125 QPDFObjGen og = dest_page.getObjGen(); 111 QPDFObjGen og = dest_page.getObjGen();
126 - if (page_map.count(og))  
127 - { 112 + if (page_map.count(og)) {
128 target = QUtil::int_to_string(page_map[og]); 113 target = QUtil::int_to_string(page_map[og]);
129 } 114 }
130 } 115 }
@@ -134,8 +119,9 @@ void show_bookmark_details(QPDFOutlineObjectHelper outline, @@ -134,8 +119,9 @@ void show_bookmark_details(QPDFOutlineObjectHelper outline,
134 std::cout << outline.getTitle() << std::endl; 119 std::cout << outline.getTitle() << std::endl;
135 } 120 }
136 121
137 -void extract_bookmarks(std::vector<QPDFOutlineObjectHelper> outlines,  
138 - std::vector<int>& numbers) 122 +void
  123 +extract_bookmarks(
  124 + std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers)
139 { 125 {
140 // For style == st_numbers, numbers.at(n) contains the numerical 126 // For style == st_numbers, numbers.at(n) contains the numerical
141 // label for the outline, so we count up from 1. 127 // label for the outline, so we count up from 1.
@@ -144,8 +130,7 @@ void extract_bookmarks(std::vector&lt;QPDFOutlineObjectHelper&gt; outlines, @@ -144,8 +130,7 @@ void extract_bookmarks(std::vector&lt;QPDFOutlineObjectHelper&gt; outlines,
144 // is, so we count up to zero. 130 // is, so we count up to zero.
145 numbers.push_back( 131 numbers.push_back(
146 (style == st_lines) ? -QIntC::to_int(outlines.size()) : 0); 132 (style == st_lines) ? -QIntC::to_int(outlines.size()) : 0);
147 - for (auto& outline : outlines)  
148 - { 133 + for (auto& outline : outlines) {
149 ++(numbers.back()); 134 ++(numbers.back());
150 show_bookmark_details(outline, numbers); 135 show_bookmark_details(outline, numbers);
151 extract_bookmarks(outline.getKids(), numbers); 136 extract_bookmarks(outline.getKids(), numbers);
@@ -153,87 +138,64 @@ void extract_bookmarks(std::vector&lt;QPDFOutlineObjectHelper&gt; outlines, @@ -153,87 +138,64 @@ void extract_bookmarks(std::vector&lt;QPDFOutlineObjectHelper&gt; outlines,
153 numbers.pop_back(); 138 numbers.pop_back();
154 } 139 }
155 140
156 -int main(int argc, char* argv[]) 141 +int
  142 +main(int argc, char* argv[])
157 { 143 {
158 whoami = QUtil::getWhoami(argv[0]); 144 whoami = QUtil::getWhoami(argv[0]);
159 145
160 - if ((argc == 2) && (strcmp(argv[1], "--version") == 0))  
161 - { 146 + if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
162 std::cout << whoami << " version 1.5" << std::endl; 147 std::cout << whoami << " version 1.5" << std::endl;
163 exit(0); 148 exit(0);
164 } 149 }
165 150
166 int arg; 151 int arg;
167 - for (arg = 1; arg < argc; ++arg)  
168 - {  
169 - if (argv[arg][0] == '-')  
170 - {  
171 - if (strcmp(argv[arg], "--numbers") == 0)  
172 - { 152 + for (arg = 1; arg < argc; ++arg) {
  153 + if (argv[arg][0] == '-') {
  154 + if (strcmp(argv[arg], "--numbers") == 0) {
173 style = st_numbers; 155 style = st_numbers;
174 - }  
175 - else if (strcmp(argv[arg], "--lines") == 0)  
176 - { 156 + } else if (strcmp(argv[arg], "--lines") == 0) {
177 style = st_lines; 157 style = st_lines;
178 - }  
179 - else if (strcmp(argv[arg], "--show-open") == 0)  
180 - { 158 + } else if (strcmp(argv[arg], "--show-open") == 0) {
181 show_open = true; 159 show_open = true;
182 - }  
183 - else if (strcmp(argv[arg], "--show-targets") == 0)  
184 - { 160 + } else if (strcmp(argv[arg], "--show-targets") == 0) {
185 show_targets = true; 161 show_targets = true;
186 - }  
187 - else  
188 - { 162 + } else {
189 usage(); 163 usage();
190 } 164 }
191 - }  
192 - else  
193 - { 165 + } else {
194 break; 166 break;
195 } 167 }
196 } 168 }
197 169
198 - if (arg >= argc)  
199 - { 170 + if (arg >= argc) {
200 usage(); 171 usage();
201 } 172 }
202 173
203 char const* filename = argv[arg++]; 174 char const* filename = argv[arg++];
204 char const* password = ""; 175 char const* password = "";
205 176
206 - if (arg < argc)  
207 - { 177 + if (arg < argc) {
208 password = argv[arg++]; 178 password = argv[arg++];
209 } 179 }
210 - if (arg != argc)  
211 - { 180 + if (arg != argc) {
212 usage(); 181 usage();
213 } 182 }
214 183
215 - try  
216 - { 184 + try {
217 QPDF qpdf; 185 QPDF qpdf;
218 qpdf.processFile(filename, password); 186 qpdf.processFile(filename, password);
219 187
220 QPDFOutlineDocumentHelper odh(qpdf); 188 QPDFOutlineDocumentHelper odh(qpdf);
221 - if (odh.hasOutlines())  
222 - { 189 + if (odh.hasOutlines()) {
223 std::vector<int> numbers; 190 std::vector<int> numbers;
224 - if (show_targets)  
225 - { 191 + if (show_targets) {
226 generate_page_map(qpdf); 192 generate_page_map(qpdf);
227 } 193 }
228 extract_bookmarks(odh.getTopLevelOutlines(), numbers); 194 extract_bookmarks(odh.getTopLevelOutlines(), numbers);
229 - }  
230 - else  
231 - { 195 + } else {
232 std::cout << filename << " has no bookmarks" << std::endl; 196 std::cout << filename << " has no bookmarks" << std::endl;
233 } 197 }
234 - }  
235 - catch (std::exception &e)  
236 - { 198 + } catch (std::exception& e) {
237 std::cerr << whoami << " processing file " << filename << ": " 199 std::cerr << whoami << " processing file " << filename << ": "
238 << e.what() << std::endl; 200 << e.what() << std::endl;
239 exit(2); 201 exit(2);
examples/pdf-c-objects.c
@@ -10,7 +10,8 @@ @@ -10,7 +10,8 @@
10 10
11 static char const* whoami = 0; 11 static char const* whoami = 0;
12 12
13 -static void usage() 13 +static void
  14 +usage()
14 { 15 {
15 fprintf(stderr, "Usage: %s infile infile-password outfile\n", whoami); 16 fprintf(stderr, "Usage: %s infile infile-password outfile\n", whoami);
16 exit(2); 17 exit(2);
@@ -33,12 +34,9 @@ modify_file(qpdf_data qpdf) @@ -33,12 +34,9 @@ modify_file(qpdf_data qpdf)
33 /* 0 is never a valid qpdf_oh */ 34 /* 0 is never a valid qpdf_oh */
34 qpdf_oh pagemode = 0; 35 qpdf_oh pagemode = 0;
35 if (qpdf_oh_is_dictionary( 36 if (qpdf_oh_is_dictionary(
36 - qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels")))  
37 - { 37 + qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) {
38 pagemode = qpdf_oh_new_name(qpdf, "/UseOutlines"); 38 pagemode = qpdf_oh_new_name(qpdf, "/UseOutlines");
39 - }  
40 - else  
41 - { 39 + } else {
42 pagemode = qpdf_oh_new_null(qpdf); 40 pagemode = qpdf_oh_new_null(qpdf);
43 } 41 }
44 qpdf_oh_replace_or_remove_key(qpdf, root, "/PageMode", pagemode); 42 qpdf_oh_replace_or_remove_key(qpdf, root, "/PageMode", pagemode);
@@ -46,7 +44,8 @@ modify_file(qpdf_data qpdf) @@ -46,7 +44,8 @@ modify_file(qpdf_data qpdf)
46 return QPDF_TRUE; 44 return QPDF_TRUE;
47 } 45 }
48 46
49 -int main(int argc, char* argv[]) 47 +int
  48 +main(int argc, char* argv[])
50 { 49 {
51 char* infile = NULL; 50 char* infile = NULL;
52 char* password = NULL; 51 char* password = NULL;
@@ -56,21 +55,15 @@ int main(int argc, char* argv[]) @@ -56,21 +55,15 @@ int main(int argc, char* argv[])
56 int errors = 0; 55 int errors = 0;
57 char* p = 0; 56 char* p = 0;
58 57
59 - if ((p = strrchr(argv[0], '/')) != NULL)  
60 - { 58 + if ((p = strrchr(argv[0], '/')) != NULL) {
61 whoami = p + 1; 59 whoami = p + 1;
62 - }  
63 - else if ((p = strrchr(argv[0], '\\')) != NULL)  
64 - { 60 + } else if ((p = strrchr(argv[0], '\\')) != NULL) {
65 whoami = p + 1; 61 whoami = p + 1;
66 - }  
67 - else  
68 - { 62 + } else {
69 whoami = argv[0]; 63 whoami = argv[0];
70 } 64 }
71 65
72 - if (argc != 4)  
73 - { 66 + if (argc != 4) {
74 usage(); 67 usage();
75 } 68 }
76 69
@@ -80,33 +73,29 @@ int main(int argc, char* argv[]) @@ -80,33 +73,29 @@ int main(int argc, char* argv[])
80 73
81 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && 74 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
82 modify_file(qpdf) && 75 modify_file(qpdf) &&
83 - ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0))  
84 - { 76 + ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) {
85 /* Use static ID for testing only. For production, a 77 /* Use static ID for testing only. For production, a
86 * non-static ID is used. See also 78 * non-static ID is used. See also
87 * qpdf_set_deterministic_ID. */ 79 * qpdf_set_deterministic_ID. */
88 qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */ 80 qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */
89 qpdf_write(qpdf); 81 qpdf_write(qpdf);
90 } 82 }
91 - while (qpdf_more_warnings(qpdf))  
92 - { 83 + while (qpdf_more_warnings(qpdf)) {
93 warnings = 1; 84 warnings = 1;
94 - printf("warning: %s\n",  
95 - qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); 85 + printf(
  86 + "warning: %s\n",
  87 + qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
96 } 88 }
97 - if (qpdf_has_error(qpdf))  
98 - { 89 + if (qpdf_has_error(qpdf)) {
99 errors = 1; 90 errors = 1;
100 - printf("error: %s\n",  
101 - qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); 91 + printf(
  92 + "error: %s\n",
  93 + qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
102 } 94 }
103 qpdf_cleanup(&qpdf); 95 qpdf_cleanup(&qpdf);
104 - if (errors)  
105 - { 96 + if (errors) {
106 return 2; 97 return 2;
107 - }  
108 - else if (warnings)  
109 - { 98 + } else if (warnings) {
110 return 3; 99 return 3;
111 } 100 }
112 101
examples/pdf-count-strings.cc
@@ -5,23 +5,23 @@ @@ -5,23 +5,23 @@
5 // 5 //
6 6
7 #include <iostream> 7 #include <iostream>
8 -#include <string.h>  
9 #include <stdlib.h> 8 #include <stdlib.h>
  9 +#include <string.h>
10 10
  11 +#include <qpdf/Pl_StdioFile.hh>
11 #include <qpdf/QPDF.hh> 12 #include <qpdf/QPDF.hh>
  13 +#include <qpdf/QPDFObjectHandle.hh>
12 #include <qpdf/QPDFPageDocumentHelper.hh> 14 #include <qpdf/QPDFPageDocumentHelper.hh>
13 #include <qpdf/QPDFPageObjectHelper.hh> 15 #include <qpdf/QPDFPageObjectHelper.hh>
14 #include <qpdf/QUtil.hh> 16 #include <qpdf/QUtil.hh>
15 -#include <qpdf/QPDFObjectHandle.hh>  
16 -#include <qpdf/Pl_StdioFile.hh>  
17 17
18 static char const* whoami = 0; 18 static char const* whoami = 0;
19 19
20 -void usage() 20 +void
  21 +usage()
21 { 22 {
22 std::cerr << "Usage: " << whoami << " infile" << std::endl 23 std::cerr << "Usage: " << whoami << " infile" << std::endl
23 - << "Applies token filters to infile"  
24 - << std::endl; 24 + << "Applies token filters to infile" << std::endl;
25 exit(2); 25 exit(2);
26 } 26 }
27 27
@@ -47,8 +47,7 @@ void @@ -47,8 +47,7 @@ void
47 StringCounter::handleToken(QPDFTokenizer::Token const& token) 47 StringCounter::handleToken(QPDFTokenizer::Token const& token)
48 { 48 {
49 // Count string tokens 49 // Count string tokens
50 - if (token.getType() == QPDFTokenizer::tt_string)  
51 - { 50 + if (token.getType() == QPDFTokenizer::tt_string) {
52 ++this->count; 51 ++this->count;
53 } 52 }
54 // Preserve input verbatim by passing each token to any specified 53 // Preserve input verbatim by passing each token to any specified
@@ -71,36 +70,31 @@ StringCounter::getCount() const @@ -71,36 +70,31 @@ StringCounter::getCount() const
71 return this->count; 70 return this->count;
72 } 71 }
73 72
74 -int main(int argc, char* argv[]) 73 +int
  74 +main(int argc, char* argv[])
75 { 75 {
76 whoami = QUtil::getWhoami(argv[0]); 76 whoami = QUtil::getWhoami(argv[0]);
77 77
78 - if (argc != 2)  
79 - { 78 + if (argc != 2) {
80 usage(); 79 usage();
81 } 80 }
82 char const* infilename = argv[1]; 81 char const* infilename = argv[1];
83 82
84 - try  
85 - { 83 + try {
86 QPDF pdf; 84 QPDF pdf;
87 pdf.processFile(infilename); 85 pdf.processFile(infilename);
88 int pageno = 0; 86 int pageno = 0;
89 - for (auto& page : QPDFPageDocumentHelper(pdf).getAllPages())  
90 - { 87 + for (auto& page : QPDFPageDocumentHelper(pdf).getAllPages()) {
91 ++pageno; 88 ++pageno;
92 // Pass the contents of a page through our string counter. 89 // Pass the contents of a page through our string counter.
93 // If it's an even page, capture the output. This 90 // If it's an even page, capture the output. This
94 // illustrates that you may capture any output generated 91 // illustrates that you may capture any output generated
95 // by the filter, or you may ignore it. 92 // by the filter, or you may ignore it.
96 StringCounter counter; 93 StringCounter counter;
97 - if (pageno % 2)  
98 - { 94 + if (pageno % 2) {
99 // Ignore output for odd pages. 95 // Ignore output for odd pages.
100 page.filterContents(&counter); 96 page.filterContents(&counter);
101 - }  
102 - else  
103 - { 97 + } else {
104 // Write output to stdout for even pages. 98 // Write output to stdout for even pages.
105 Pl_StdioFile out("stdout", stdout); 99 Pl_StdioFile out("stdout", stdout);
106 std::cout << "% Contents of page " << pageno << std::endl; 100 std::cout << "% Contents of page " << pageno << std::endl;
@@ -110,9 +104,7 @@ int main(int argc, char* argv[]) @@ -110,9 +104,7 @@ int main(int argc, char* argv[])
110 std::cout << "Page " << pageno 104 std::cout << "Page " << pageno
111 << ": strings = " << counter.getCount() << std::endl; 105 << ": strings = " << counter.getCount() << std::endl;
112 } 106 }
113 - }  
114 - catch (std::exception& e)  
115 - { 107 + } catch (std::exception& e) {
116 std::cerr << whoami << ": " << e.what() << std::endl; 108 std::cerr << whoami << ": " << e.what() << std::endl;
117 exit(2); 109 exit(2);
118 } 110 }
examples/pdf-create.cc
@@ -5,20 +5,20 @@ @@ -5,20 +5,20 @@
5 // StreamDataProvider with different types of filters. 5 // StreamDataProvider with different types of filters.
6 // 6 //
7 7
  8 +#include <qpdf/Pl_Buffer.hh>
  9 +#include <qpdf/Pl_DCT.hh>
  10 +#include <qpdf/Pl_RunLength.hh>
  11 +#include <qpdf/QIntC.hh>
8 #include <qpdf/QPDF.hh> 12 #include <qpdf/QPDF.hh>
  13 +#include <qpdf/QPDFObjectHandle.hh>
9 #include <qpdf/QPDFPageDocumentHelper.hh> 14 #include <qpdf/QPDFPageDocumentHelper.hh>
10 #include <qpdf/QPDFPageObjectHelper.hh> 15 #include <qpdf/QPDFPageObjectHelper.hh>
11 #include <qpdf/QPDFWriter.hh> 16 #include <qpdf/QPDFWriter.hh>
12 -#include <qpdf/QPDFObjectHandle.hh>  
13 #include <qpdf/QUtil.hh> 17 #include <qpdf/QUtil.hh>
14 -#include <qpdf/Pl_Buffer.hh>  
15 -#include <qpdf/Pl_RunLength.hh>  
16 -#include <qpdf/Pl_DCT.hh>  
17 -#include <qpdf/QIntC.hh>  
18 #include <iostream> 18 #include <iostream>
19 #include <memory> 19 #include <memory>
20 -#include <string.h>  
21 #include <stdlib.h> 20 #include <stdlib.h>
  21 +#include <string.h>
22 22
23 static char const* whoami = 0; 23 static char const* whoami = 0;
24 24
@@ -27,11 +27,10 @@ static char const* whoami = 0; @@ -27,11 +27,10 @@ static char const* whoami = 0;
27 class ImageProvider: public QPDFObjectHandle::StreamDataProvider 27 class ImageProvider: public QPDFObjectHandle::StreamDataProvider
28 { 28 {
29 public: 29 public:
30 - ImageProvider(std::string const& color_space,  
31 - std::string const& filter); 30 + ImageProvider(std::string const& color_space, std::string const& filter);
32 virtual ~ImageProvider(); 31 virtual ~ImageProvider();
33 - virtual void provideStreamData(int objid, int generation,  
34 - Pipeline* pipeline); 32 + virtual void
  33 + provideStreamData(int objid, int generation, Pipeline* pipeline);
35 size_t getWidth() const; 34 size_t getWidth() const;
36 size_t getHeight() const; 35 size_t getHeight() const;
37 36
@@ -45,8 +44,8 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider @@ -45,8 +44,8 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
45 J_COLOR_SPACE j_color_space; 44 J_COLOR_SPACE j_color_space;
46 }; 45 };
47 46
48 -ImageProvider::ImageProvider(std::string const& color_space,  
49 - std::string const& filter) : 47 +ImageProvider::ImageProvider(
  48 + std::string const& color_space, std::string const& filter) :
50 width(400), 49 width(400),
51 stripe_height(80), 50 stripe_height(80),
52 color_space(color_space), 51 color_space(color_space),
@@ -54,8 +53,7 @@ ImageProvider::ImageProvider(std::string const&amp; color_space, @@ -54,8 +53,7 @@ ImageProvider::ImageProvider(std::string const&amp; color_space,
54 n_stripes(6), 53 n_stripes(6),
55 j_color_space(JCS_UNKNOWN) 54 j_color_space(JCS_UNKNOWN)
56 { 55 {
57 - if (color_space == "/DeviceCMYK")  
58 - { 56 + if (color_space == "/DeviceCMYK") {
59 j_color_space = JCS_CMYK; 57 j_color_space = JCS_CMYK;
60 stripes.push_back(std::string("\xff\x00\x00\x00", 4)); 58 stripes.push_back(std::string("\xff\x00\x00\x00", 4));
61 stripes.push_back(std::string("\x00\xff\x00\x00", 4)); 59 stripes.push_back(std::string("\x00\xff\x00\x00", 4));
@@ -63,9 +61,7 @@ ImageProvider::ImageProvider(std::string const&amp; color_space, @@ -63,9 +61,7 @@ ImageProvider::ImageProvider(std::string const&amp; color_space,
63 stripes.push_back(std::string("\xff\x00\xff\x00", 4)); 61 stripes.push_back(std::string("\xff\x00\xff\x00", 4));
64 stripes.push_back(std::string("\xff\xff\x00\x00", 4)); 62 stripes.push_back(std::string("\xff\xff\x00\x00", 4));
65 stripes.push_back(std::string("\x00\x00\x00\xff", 4)); 63 stripes.push_back(std::string("\x00\x00\x00\xff", 4));
66 - }  
67 - else if (color_space == "/DeviceRGB")  
68 - { 64 + } else if (color_space == "/DeviceRGB") {
69 j_color_space = JCS_RGB; 65 j_color_space = JCS_RGB;
70 stripes.push_back(std::string("\xff\x00\x00", 3)); 66 stripes.push_back(std::string("\xff\x00\x00", 3));
71 stripes.push_back(std::string("\x00\xff\x00", 3)); 67 stripes.push_back(std::string("\x00\xff\x00", 3));
@@ -73,9 +69,7 @@ ImageProvider::ImageProvider(std::string const&amp; color_space, @@ -73,9 +69,7 @@ ImageProvider::ImageProvider(std::string const&amp; color_space,
73 stripes.push_back(std::string("\xff\x00\xff", 3)); 69 stripes.push_back(std::string("\xff\x00\xff", 3));
74 stripes.push_back(std::string("\xff\xff\x00", 3)); 70 stripes.push_back(std::string("\xff\xff\x00", 3));
75 stripes.push_back(std::string("\x00\x00\x00", 3)); 71 stripes.push_back(std::string("\x00\x00\x00", 3));
76 - }  
77 - else if (color_space == "/DeviceGray")  
78 - { 72 + } else if (color_space == "/DeviceGray") {
79 j_color_space = JCS_GRAYSCALE; 73 j_color_space = JCS_GRAYSCALE;
80 stripes.push_back(std::string("\xee", 1)); 74 stripes.push_back(std::string("\xee", 1));
81 stripes.push_back(std::string("\xcc", 1)); 75 stripes.push_back(std::string("\xcc", 1));
@@ -103,34 +97,31 @@ ImageProvider::getHeight() const @@ -103,34 +97,31 @@ ImageProvider::getHeight() const
103 } 97 }
104 98
105 void 99 void
106 -ImageProvider::provideStreamData(int objid, int generation,  
107 - Pipeline* pipeline) 100 +ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline)
108 { 101 {
109 std::vector<std::shared_ptr<Pipeline>> to_delete; 102 std::vector<std::shared_ptr<Pipeline>> to_delete;
110 Pipeline* p = pipeline; 103 Pipeline* p = pipeline;
111 std::shared_ptr<Pipeline> p_new; 104 std::shared_ptr<Pipeline> p_new;
112 105
113 - if (filter == "/DCTDecode")  
114 - { 106 + if (filter == "/DCTDecode") {
115 p_new = std::make_shared<Pl_DCT>( 107 p_new = std::make_shared<Pl_DCT>(
116 - "image encoder", pipeline,  
117 - QIntC::to_uint(width), QIntC::to_uint(getHeight()),  
118 - QIntC::to_int(stripes[0].length()), j_color_space); 108 + "image encoder",
  109 + pipeline,
  110 + QIntC::to_uint(width),
  111 + QIntC::to_uint(getHeight()),
  112 + QIntC::to_int(stripes[0].length()),
  113 + j_color_space);
119 to_delete.push_back(p_new); 114 to_delete.push_back(p_new);
120 p = p_new.get(); 115 p = p_new.get();
121 - }  
122 - else if (filter == "/RunLengthDecode")  
123 - { 116 + } else if (filter == "/RunLengthDecode") {
124 p_new = std::make_shared<Pl_RunLength>( 117 p_new = std::make_shared<Pl_RunLength>(
125 "image encoder", pipeline, Pl_RunLength::a_encode); 118 "image encoder", pipeline, Pl_RunLength::a_encode);
126 to_delete.push_back(p_new); 119 to_delete.push_back(p_new);
127 p = p_new.get(); 120 p = p_new.get();
128 } 121 }
129 122
130 - for (size_t i = 0; i < n_stripes; ++i)  
131 - {  
132 - for (size_t j = 0; j < width * stripe_height; ++j)  
133 - { 123 + for (size_t i = 0; i < n_stripes; ++i) {
  124 + for (size_t j = 0; j < width * stripe_height; ++j) {
134 p->write( 125 p->write(
135 QUtil::unsigned_char_pointer(stripes[i].c_str()), 126 QUtil::unsigned_char_pointer(stripes[i].c_str()),
136 stripes[i].length()); 127 stripes[i].length());
@@ -139,36 +130,43 @@ ImageProvider::provideStreamData(int objid, int generation, @@ -139,36 +130,43 @@ ImageProvider::provideStreamData(int objid, int generation,
139 p->finish(); 130 p->finish();
140 } 131 }
141 132
142 -void usage() 133 +void
  134 +usage()
143 { 135 {
144 std::cerr << "Usage: " << whoami << " filename" << std::endl 136 std::cerr << "Usage: " << whoami << " filename" << std::endl
145 << "Creates a simple PDF and writes it to filename" << std::endl; 137 << "Creates a simple PDF and writes it to filename" << std::endl;
146 exit(2); 138 exit(2);
147 } 139 }
148 140
149 -static QPDFObjectHandle createPageContents(QPDF& pdf, std::string const& text) 141 +static QPDFObjectHandle
  142 +createPageContents(QPDF& pdf, std::string const& text)
150 { 143 {
151 // Create a stream that displays our image and the given text in 144 // Create a stream that displays our image and the given text in
152 // our font. 145 // our font.
153 - std::string contents =  
154 - "BT /F1 24 Tf 72 320 Td (" + text + ") Tj ET\n" 146 + std::string contents = "BT /F1 24 Tf 72 320 Td (" + text +
  147 + ") Tj ET\n"
155 "q 244 0 0 144 184 100 cm /Im1 Do Q\n"; 148 "q 244 0 0 144 184 100 cm /Im1 Do Q\n";
156 return QPDFObjectHandle::newStream(&pdf, contents); 149 return QPDFObjectHandle::newStream(&pdf, contents);
157 } 150 }
158 151
159 -QPDFObjectHandle newName(std::string const& name) 152 +QPDFObjectHandle
  153 +newName(std::string const& name)
160 { 154 {
161 return QPDFObjectHandle::newName(name); 155 return QPDFObjectHandle::newName(name);
162 } 156 }
163 157
164 -QPDFObjectHandle newInteger(size_t val) 158 +QPDFObjectHandle
  159 +newInteger(size_t val)
165 { 160 {
166 return QPDFObjectHandle::newInteger(QIntC::to_int(val)); 161 return QPDFObjectHandle::newInteger(QIntC::to_int(val));
167 } 162 }
168 163
169 -void add_page(QPDFPageDocumentHelper& dh, QPDFObjectHandle font,  
170 - std::string const& color_space,  
171 - std::string const& filter) 164 +void
  165 +add_page(
  166 + QPDFPageDocumentHelper& dh,
  167 + QPDFObjectHandle font,
  168 + std::string const& color_space,
  169 + std::string const& filter)
172 { 170 {
173 QPDF& pdf(dh.getQPDF()); 171 QPDF& pdf(dh.getQPDF());
174 172
@@ -193,9 +191,8 @@ void add_page(QPDFPageDocumentHelper&amp; dh, QPDFObjectHandle font, @@ -193,9 +191,8 @@ void add_page(QPDFPageDocumentHelper&amp; dh, QPDFObjectHandle font,
193 image.replaceDict(image_dict); 191 image.replaceDict(image_dict);
194 192
195 // Provide the stream data. 193 // Provide the stream data.
196 - image.replaceStreamData(provider,  
197 - QPDFObjectHandle::parse(filter),  
198 - QPDFObjectHandle::newNull()); 194 + image.replaceStreamData(
  195 + provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull());
199 196
200 // Create direct objects as needed by the page dictionary. 197 // Create direct objects as needed by the page dictionary.
201 QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf; 198 QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf;
@@ -212,15 +209,14 @@ void add_page(QPDFPageDocumentHelper&amp; dh, QPDFObjectHandle font, @@ -212,15 +209,14 @@ void add_page(QPDFPageDocumentHelper&amp; dh, QPDFObjectHandle font,
212 resources.replaceKey("/XObject", xobject); 209 resources.replaceKey("/XObject", xobject);
213 210
214 // Create the page content stream 211 // Create the page content stream
215 - QPDFObjectHandle contents = createPageContents(  
216 - pdf, color_space + " with filter " + filter); 212 + QPDFObjectHandle contents =
  213 + createPageContents(pdf, color_space + " with filter " + filter);
217 214
218 // Create the page dictionary 215 // Create the page dictionary
219 - QPDFObjectHandle page = pdf.makeIndirectObject(  
220 - "<<"  
221 - " /Type /Page"  
222 - " /MediaBox [0 0 612 392]"  
223 - ">>"_qpdf); 216 + QPDFObjectHandle page = pdf.makeIndirectObject("<<"
  217 + " /Type /Page"
  218 + " /MediaBox [0 0 612 392]"
  219 + ">>"_qpdf);
224 page.replaceKey("/Contents", contents); 220 page.replaceKey("/Contents", contents);
225 page.replaceKey("/Resources", resources); 221 page.replaceKey("/Resources", resources);
226 222
@@ -228,9 +224,11 @@ void add_page(QPDFPageDocumentHelper&amp; dh, QPDFObjectHandle font, @@ -228,9 +224,11 @@ void add_page(QPDFPageDocumentHelper&amp; dh, QPDFObjectHandle font,
228 dh.addPage(page, false); 224 dh.addPage(page, false);
229 } 225 }
230 226
231 -static void check(char const* filename,  
232 - std::vector<std::string> const& color_spaces,  
233 - std::vector<std::string> const& filters) 227 +static void
  228 +check(
  229 + char const* filename,
  230 + std::vector<std::string> const& color_spaces,
  231 + std::vector<std::string> const& filters)
234 { 232 {
235 // Each stream is compressed the way it is supposed to be. We will 233 // Each stream is compressed the way it is supposed to be. We will
236 // add additional tests in qpdf.test to exercise QPDFWriter more 234 // add additional tests in qpdf.test to exercise QPDFWriter more
@@ -253,17 +251,14 @@ static void check(char const* filename, @@ -253,17 +251,14 @@ static void check(char const* filename,
253 QPDF pdf; 251 QPDF pdf;
254 pdf.processFile(filename); 252 pdf.processFile(filename);
255 auto pages = QPDFPageDocumentHelper(pdf).getAllPages(); 253 auto pages = QPDFPageDocumentHelper(pdf).getAllPages();
256 - if (n_color_spaces * n_filters != pages.size())  
257 - { 254 + if (n_color_spaces * n_filters != pages.size()) {
258 throw std::logic_error("incorrect number of pages"); 255 throw std::logic_error("incorrect number of pages");
259 } 256 }
260 size_t pageno = 1; 257 size_t pageno = 1;
261 bool errors = false; 258 bool errors = false;
262 - for (auto& page : pages)  
263 - { 259 + for (auto& page : pages) {
264 auto images = page.getImages(); 260 auto images = page.getImages();
265 - if (images.size() != 1)  
266 - { 261 + if (images.size() != 1) {
267 throw std::logic_error("incorrect number of images on page"); 262 throw std::logic_error("incorrect number of images on page");
268 } 263 }
269 264
@@ -273,8 +268,7 @@ static void check(char const* filename, @@ -273,8 +268,7 @@ static void check(char const* filename,
273 std::string desired_filter = filters[(pageno - 1) % n_filters]; 268 std::string desired_filter = filters[(pageno - 1) % n_filters];
274 // In the default mode, QPDFWriter will compress with 269 // In the default mode, QPDFWriter will compress with
275 // /FlateDecode if no filters are provided. 270 // /FlateDecode if no filters are provided.
276 - if (desired_filter == "null")  
277 - { 271 + if (desired_filter == "null") {
278 desired_filter = "/FlateDecode"; 272 desired_filter = "/FlateDecode";
279 } 273 }
280 QPDFObjectHandle image = images.begin()->second; 274 QPDFObjectHandle image = images.begin()->second;
@@ -282,40 +276,34 @@ static void check(char const* filename, @@ -282,40 +276,34 @@ static void check(char const* filename,
282 QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); 276 QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
283 QPDFObjectHandle filter = image_dict.getKey("/Filter"); 277 QPDFObjectHandle filter = image_dict.getKey("/Filter");
284 bool this_errors = false; 278 bool this_errors = false;
285 - if (! filter.isNameAndEquals(desired_filter))  
286 - { 279 + if (!filter.isNameAndEquals(desired_filter)) {
287 this_errors = errors = true; 280 this_errors = errors = true;
288 std::cout << "page " << pageno << ": expected filter " 281 std::cout << "page " << pageno << ": expected filter "
289 - << desired_filter << "; actual filter = "  
290 - << filter.unparse() << std::endl; 282 + << desired_filter
  283 + << "; actual filter = " << filter.unparse() << std::endl;
291 } 284 }
292 - if (! color_space.isNameAndEquals(desired_color_space))  
293 - { 285 + if (!color_space.isNameAndEquals(desired_color_space)) {
294 this_errors = errors = true; 286 this_errors = errors = true;
295 std::cout << "page " << pageno << ": expected color space " 287 std::cout << "page " << pageno << ": expected color space "
296 - << desired_color_space << "; actual color space = "  
297 - << color_space.unparse() << std::endl; 288 + << desired_color_space
  289 + << "; actual color space = " << color_space.unparse()
  290 + << std::endl;
298 } 291 }
299 292
300 - if (! this_errors)  
301 - { 293 + if (!this_errors) {
302 // Check image data 294 // Check image data
303 - auto actual_data =  
304 - image.getStreamData(qpdf_dl_all); 295 + auto actual_data = image.getStreamData(qpdf_dl_all);
305 ImageProvider* p = new ImageProvider(desired_color_space, "null"); 296 ImageProvider* p = new ImageProvider(desired_color_space, "null");
306 PointerHolder<QPDFObjectHandle::StreamDataProvider> provider(p); 297 PointerHolder<QPDFObjectHandle::StreamDataProvider> provider(p);
307 Pl_Buffer b_p("get image data"); 298 Pl_Buffer b_p("get image data");
308 provider->provideStreamData(0, 0, &b_p); 299 provider->provideStreamData(0, 0, &b_p);
309 PointerHolder<Buffer> desired_data(b_p.getBuffer()); 300 PointerHolder<Buffer> desired_data(b_p.getBuffer());
310 301
311 - if (desired_data->getSize() != actual_data->getSize())  
312 - {  
313 - std::cout << "page " << pageno  
314 - << ": image data length mismatch" << std::endl; 302 + if (desired_data->getSize() != actual_data->getSize()) {
  303 + std::cout << "page " << pageno << ": image data length mismatch"
  304 + << std::endl;
315 this_errors = errors = true; 305 this_errors = errors = true;
316 - }  
317 - else  
318 - { 306 + } else {
319 // Compare bytes. For JPEG, allow a certain number of 307 // Compare bytes. For JPEG, allow a certain number of
320 // the bytes to be off desired by more than a given 308 // the bytes to be off desired by more than a given
321 // tolerance. Any of the samples may be a little off 309 // tolerance. Any of the samples may be a little off
@@ -326,25 +314,20 @@ static void check(char const* filename, @@ -326,25 +314,20 @@ static void check(char const* filename,
326 unsigned char const* desired_bytes = desired_data->getBuffer(); 314 unsigned char const* desired_bytes = desired_data->getBuffer();
327 size_t len = actual_data->getSize(); 315 size_t len = actual_data->getSize();
328 unsigned int mismatches = 0; 316 unsigned int mismatches = 0;
329 - int tolerance = (  
330 - desired_filter == "/DCTDecode" ? 10 : 0);  
331 - size_t threshold = (  
332 - desired_filter == "/DCTDecode" ? len / 40U : 0);  
333 - for (size_t i = 0; i < len; ++i)  
334 - { 317 + int tolerance = (desired_filter == "/DCTDecode" ? 10 : 0);
  318 + size_t threshold =
  319 + (desired_filter == "/DCTDecode" ? len / 40U : 0);
  320 + for (size_t i = 0; i < len; ++i) {
335 int delta = actual_bytes[i] - desired_bytes[i]; 321 int delta = actual_bytes[i] - desired_bytes[i];
336 - if ((delta > tolerance) || (delta < -tolerance))  
337 - { 322 + if ((delta > tolerance) || (delta < -tolerance)) {
338 ++mismatches; 323 ++mismatches;
339 } 324 }
340 } 325 }
341 - if (mismatches > threshold)  
342 - {  
343 - std::cout << "page " << pageno  
344 - << ": " << desired_color_space << ", "  
345 - << desired_filter  
346 - << ": mismatches: " << mismatches  
347 - << " of " << len << std::endl; 326 + if (mismatches > threshold) {
  327 + std::cout << "page " << pageno << ": "
  328 + << desired_color_space << ", " << desired_filter
  329 + << ": mismatches: " << mismatches << " of " << len
  330 + << std::endl;
348 this_errors = errors = true; 331 this_errors = errors = true;
349 } 332 }
350 } 333 }
@@ -352,17 +335,15 @@ static void check(char const* filename, @@ -352,17 +335,15 @@ static void check(char const* filename,
352 335
353 ++pageno; 336 ++pageno;
354 } 337 }
355 - if (errors)  
356 - { 338 + if (errors) {
357 throw std::logic_error("errors found"); 339 throw std::logic_error("errors found");
358 - }  
359 - else  
360 - { 340 + } else {
361 std::cout << "all checks passed" << std::endl; 341 std::cout << "all checks passed" << std::endl;
362 } 342 }
363 } 343 }
364 344
365 -static void create_pdf(char const* filename) 345 +static void
  346 +create_pdf(char const* filename)
366 { 347 {
367 QPDF pdf; 348 QPDF pdf;
368 349
@@ -371,14 +352,13 @@ static void create_pdf(char const* filename) @@ -371,14 +352,13 @@ static void create_pdf(char const* filename)
371 352
372 // Add an indirect object to contain a font descriptor for the 353 // Add an indirect object to contain a font descriptor for the
373 // built-in Helvetica font. 354 // built-in Helvetica font.
374 - QPDFObjectHandle font = pdf.makeIndirectObject(  
375 - "<<"  
376 - " /Type /Font"  
377 - " /Subtype /Type1"  
378 - " /Name /F1"  
379 - " /BaseFont /Helvetica"  
380 - " /Encoding /WinAnsiEncoding"  
381 - ">>"_qpdf); 355 + QPDFObjectHandle font = pdf.makeIndirectObject("<<"
  356 + " /Type /Font"
  357 + " /Subtype /Type1"
  358 + " /Name /F1"
  359 + " /BaseFont /Helvetica"
  360 + " /Encoding /WinAnsiEncoding"
  361 + ">>"_qpdf);
382 362
383 std::vector<std::string> color_spaces; 363 std::vector<std::string> color_spaces;
384 color_spaces.push_back("/DeviceCMYK"); 364 color_spaces.push_back("/DeviceCMYK");
@@ -389,10 +369,8 @@ static void create_pdf(char const* filename) @@ -389,10 +369,8 @@ static void create_pdf(char const* filename)
389 filters.push_back("/DCTDecode"); 369 filters.push_back("/DCTDecode");
390 filters.push_back("/RunLengthDecode"); 370 filters.push_back("/RunLengthDecode");
391 QPDFPageDocumentHelper dh(pdf); 371 QPDFPageDocumentHelper dh(pdf);
392 - for (auto const& color_space : color_spaces)  
393 - {  
394 - for (auto const& filter : filters)  
395 - { 372 + for (auto const& color_space : color_spaces) {
  373 + for (auto const& filter : filters) {
396 add_page(dh, font, color_space, filter); 374 add_page(dh, font, color_space, filter);
397 } 375 }
398 } 376 }
@@ -405,22 +383,19 @@ static void create_pdf(char const* filename) @@ -405,22 +383,19 @@ static void create_pdf(char const* filename)
405 check(filename, color_spaces, filters); 383 check(filename, color_spaces, filters);
406 } 384 }
407 385
408 -int main(int argc, char* argv[]) 386 +int
  387 +main(int argc, char* argv[])
409 { 388 {
410 whoami = QUtil::getWhoami(argv[0]); 389 whoami = QUtil::getWhoami(argv[0]);
411 390
412 - if (argc != 2)  
413 - { 391 + if (argc != 2) {
414 usage(); 392 usage();
415 } 393 }
416 char const* filename = argv[1]; 394 char const* filename = argv[1];
417 395
418 - try  
419 - { 396 + try {
420 create_pdf(filename); 397 create_pdf(filename);
421 - }  
422 - catch (std::exception& e)  
423 - { 398 + } catch (std::exception& e) {
424 std::cerr << e.what() << std::endl; 399 std::cerr << e.what() << std::endl;
425 exit(2); 400 exit(2);
426 } 401 }
examples/pdf-custom-filter.cc
1 #include <qpdf/QPDF.hh> 1 #include <qpdf/QPDF.hh>
2 -#include <qpdf/QUtil.hh>  
3 -#include <qpdf/QPDFWriter.hh>  
4 #include <qpdf/QPDFStreamFilter.hh> 2 #include <qpdf/QPDFStreamFilter.hh>
  3 +#include <qpdf/QPDFWriter.hh>
  4 +#include <qpdf/QUtil.hh>
5 5
6 #include <cstring> 6 #include <cstring>
7 #include <exception> 7 #include <exception>
@@ -39,7 +39,6 @@ @@ -39,7 +39,6 @@
39 39
40 static char const* whoami = 0; 40 static char const* whoami = 0;
41 41
42 -  
43 class Pl_XOR: public Pipeline 42 class Pl_XOR: public Pipeline
44 { 43 {
45 // This class implements a Pipeline for the made-up XOR decoder. 44 // This class implements a Pipeline for the made-up XOR decoder.
@@ -66,8 +65,7 @@ Pl_XOR::Pl_XOR(char const* identifier, Pipeline* next, unsigned char key) : @@ -66,8 +65,7 @@ Pl_XOR::Pl_XOR(char const* identifier, Pipeline* next, unsigned char key) :
66 void 65 void
67 Pl_XOR::write(unsigned char* data, size_t len) 66 Pl_XOR::write(unsigned char* data, size_t len)
68 { 67 {
69 - for (size_t i = 0; i < len; ++i)  
70 - { 68 + for (size_t i = 0; i < len; ++i) {
71 unsigned char p = data[i] ^ this->key; 69 unsigned char p = data[i] ^ this->key;
72 getNext()->write(&p, 1); 70 getNext()->write(&p, 1);
73 } 71 }
@@ -118,8 +116,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) @@ -118,8 +116,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms)
118 // to handle the /JBIG2Globals key, which points to a stream. See 116 // to handle the /JBIG2Globals key, which points to a stream. See
119 // comments in SF_XORDecode::registerStream for additional notes 117 // comments in SF_XORDecode::registerStream for additional notes
120 // on this. 118 // on this.
121 - try  
122 - { 119 + try {
123 // Expect /DecodeParms to be a dictionary with a /KeyStream 120 // Expect /DecodeParms to be a dictionary with a /KeyStream
124 // key that points to a one-byte stream whose single byte is 121 // key that points to a one-byte stream whose single byte is
125 // the key. If we are successful at retrieving the key, return 122 // the key. If we are successful at retrieving the key, return
@@ -129,17 +126,14 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) @@ -129,17 +126,14 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms)
129 // implementations, look at the classes whose names start with 126 // implementations, look at the classes whose names start with
130 // SF_ in the qpdf library implementation. 127 // SF_ in the qpdf library implementation.
131 auto buf = decode_parms.getKey("/KeyStream").getStreamData(); 128 auto buf = decode_parms.getKey("/KeyStream").getStreamData();
132 - if (buf->getSize() != 1)  
133 - { 129 + if (buf->getSize() != 1) {
134 return false; 130 return false;
135 } 131 }
136 this->key = buf->getBuffer()[0]; 132 this->key = buf->getBuffer()[0];
137 return true; 133 return true;
138 - }  
139 - catch (std::exception& e)  
140 - {  
141 - std::cerr << "Error extracting key for /XORDecode: "  
142 - << e.what() << std::endl; 134 + } catch (std::exception& e) {
  135 + std::cerr << "Error extracting key for /XORDecode: " << e.what()
  136 + << std::endl;
143 } 137 }
144 return false; 138 return false;
145 } 139 }
@@ -206,17 +200,19 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider @@ -206,17 +200,19 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
206 public: 200 public:
207 StreamReplacer(QPDF* pdf); 201 StreamReplacer(QPDF* pdf);
208 virtual ~StreamReplacer() = default; 202 virtual ~StreamReplacer() = default;
209 - virtual void provideStreamData(int objid, int generation,  
210 - Pipeline* pipeline) override; 203 + virtual void
  204 + provideStreamData(int objid, int generation, Pipeline* pipeline) override;
211 205
212 void registerStream( 206 void registerStream(
213 QPDFObjectHandle stream, 207 QPDFObjectHandle stream,
214 PointerHolder<QPDFObjectHandle::StreamDataProvider> self); 208 PointerHolder<QPDFObjectHandle::StreamDataProvider> self);
215 209
216 private: 210 private:
217 - bool maybeReplace(QPDFObjGen const& og,  
218 - QPDFObjectHandle& stream, Pipeline* pipeline,  
219 - QPDFObjectHandle* dict_updates); 211 + bool maybeReplace(
  212 + QPDFObjGen const& og,
  213 + QPDFObjectHandle& stream,
  214 + Pipeline* pipeline,
  215 + QPDFObjectHandle* dict_updates);
220 216
221 // Hang onto a reference to the QPDF object containing the streams 217 // Hang onto a reference to the QPDF object containing the streams
222 // we are replacing. We need this to create a new stream. 218 // we are replacing. We need this to create a new stream.
@@ -238,10 +234,11 @@ StreamReplacer::StreamReplacer(QPDF* pdf) : @@ -238,10 +234,11 @@ StreamReplacer::StreamReplacer(QPDF* pdf) :
238 } 234 }
239 235
240 bool 236 bool
241 -StreamReplacer::maybeReplace(QPDFObjGen const& og,  
242 - QPDFObjectHandle& stream,  
243 - Pipeline* pipeline,  
244 - QPDFObjectHandle* dict_updates) 237 +StreamReplacer::maybeReplace(
  238 + QPDFObjGen const& og,
  239 + QPDFObjectHandle& stream,
  240 + Pipeline* pipeline,
  241 + QPDFObjectHandle* dict_updates)
245 { 242 {
246 // As described in the class comments, this method is called 243 // As described in the class comments, this method is called
247 // twice. Before writing has started pipeline is nullptr, and 244 // twice. Before writing has started pipeline is nullptr, and
@@ -276,8 +273,7 @@ StreamReplacer::maybeReplace(QPDFObjGen const&amp; og, @@ -276,8 +273,7 @@ StreamReplacer::maybeReplace(QPDFObjGen const&amp; og,
276 // density. 273 // density.
277 auto dict = stream.getDict(); 274 auto dict = stream.getDict();
278 auto mark = dict.getKey("/DoXOR"); 275 auto mark = dict.getKey("/DoXOR");
279 - if (! (mark.isBool() && mark.getBoolValue()))  
280 - { 276 + if (!(mark.isBool() && mark.getBoolValue())) {
281 return false; 277 return false;
282 } 278 }
283 279
@@ -288,17 +284,13 @@ StreamReplacer::maybeReplace(QPDFObjGen const&amp; og, @@ -288,17 +284,13 @@ StreamReplacer::maybeReplace(QPDFObjGen const&amp; og,
288 // it's a good idea to make sure we can retrieve the filtered data 284 // it's a good idea to make sure we can retrieve the filtered data
289 // if we are going to need it later. 285 // if we are going to need it later.
290 PointerHolder<Buffer> out; 286 PointerHolder<Buffer> out;
291 - try  
292 - { 287 + try {
293 out = stream.getStreamData(); 288 out = stream.getStreamData();
294 - }  
295 - catch (...)  
296 - { 289 + } catch (...) {
297 return false; 290 return false;
298 } 291 }
299 292
300 - if (dict_updates)  
301 - { 293 + if (dict_updates) {
302 // It's not safe to make any modifications to any objects 294 // It's not safe to make any modifications to any objects
303 // during the writing process since the updated objects may 295 // during the writing process since the updated objects may
304 // have already been written. In this mode, when dict_updates 296 // have already been written. In this mode, when dict_updates
@@ -309,16 +301,15 @@ StreamReplacer::maybeReplace(QPDFObjGen const&amp; og, @@ -309,16 +301,15 @@ StreamReplacer::maybeReplace(QPDFObjGen const&amp; og,
309 // changes. For example, an image resampler might change the 301 // changes. For example, an image resampler might change the
310 // dimensions or other properties of the image. 302 // dimensions or other properties of the image.
311 dict_updates->replaceKey( 303 dict_updates->replaceKey(
312 - "/OrigLength", QPDFObjectHandle::newInteger(  
313 - QIntC::to_longlong(out->getSize()))); 304 + "/OrigLength",
  305 + QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize())));
314 // We are also storing the "key" that we will access when 306 // We are also storing the "key" that we will access when
315 // writing the data. 307 // writing the data.
316 this->keys[og] = QIntC::to_uchar( 308 this->keys[og] = QIntC::to_uchar(
317 (og.getObj() * QIntC::to_int(out->getSize())) & 0xff); 309 (og.getObj() * QIntC::to_int(out->getSize())) & 0xff);
318 } 310 }
319 311
320 - if (pipeline)  
321 - { 312 + if (pipeline) {
322 unsigned char key = this->keys[og]; 313 unsigned char key = this->keys[og];
323 Pl_XOR p("xor", pipeline, key); 314 Pl_XOR p("xor", pipeline, key);
324 p.write(out->getBuffer(), out->getSize()); 315 p.write(out->getBuffer(), out->getSize());
@@ -338,8 +329,7 @@ StreamReplacer::registerStream( @@ -338,8 +329,7 @@ StreamReplacer::registerStream(
338 // example, we are just iterating through objects, but if we were 329 // example, we are just iterating through objects, but if we were
339 // doing something like iterating through images on pages, we 330 // doing something like iterating through images on pages, we
340 // might realistically encounter the same stream more than once. 331 // might realistically encounter the same stream more than once.
341 - if (this->copied_streams.count(og) > 0)  
342 - { 332 + if (this->copied_streams.count(og) > 0) {
343 return; 333 return;
344 } 334 }
345 // Store something in copied_streams so that we don't 335 // Store something in copied_streams so that we don't
@@ -352,19 +342,14 @@ StreamReplacer::registerStream( @@ -352,19 +342,14 @@ StreamReplacer::registerStream(
352 // so, supplies dictionary updates we should make. 342 // so, supplies dictionary updates we should make.
353 bool should_replace = false; 343 bool should_replace = false;
354 QPDFObjectHandle dict_updates = QPDFObjectHandle::newDictionary(); 344 QPDFObjectHandle dict_updates = QPDFObjectHandle::newDictionary();
355 - try  
356 - { 345 + try {
357 should_replace = maybeReplace(og, stream, nullptr, &dict_updates); 346 should_replace = maybeReplace(og, stream, nullptr, &dict_updates);
358 - }  
359 - catch (std::exception& e)  
360 - { 347 + } catch (std::exception& e) {
361 stream.warnIfPossible( 348 stream.warnIfPossible(
362 - std::string("exception while attempting to replace: ") +  
363 - e.what()); 349 + std::string("exception while attempting to replace: ") + e.what());
364 } 350 }
365 351
366 - if (should_replace)  
367 - { 352 + if (should_replace) {
368 // Copy the stream so we can get to the original data from the 353 // Copy the stream so we can get to the original data from the
369 // stream data provider. This doesn't actually copy any data, 354 // stream data provider. This doesn't actually copy any data,
370 // but the copy retains the original stream data after the 355 // but the copy retains the original stream data after the
@@ -372,14 +357,13 @@ StreamReplacer::registerStream( @@ -372,14 +357,13 @@ StreamReplacer::registerStream(
372 this->copied_streams[og] = stream.copyStream(); 357 this->copied_streams[og] = stream.copyStream();
373 // Update the stream dictionary with any changes. 358 // Update the stream dictionary with any changes.
374 auto dict = stream.getDict(); 359 auto dict = stream.getDict();
375 - for (auto const& k: dict_updates.getKeys())  
376 - { 360 + for (auto const& k : dict_updates.getKeys()) {
377 dict.replaceKey(k, dict_updates.getKey(k)); 361 dict.replaceKey(k, dict_updates.getKey(k));
378 } 362 }
379 // Create the key stream that will be referenced from 363 // Create the key stream that will be referenced from
380 // /DecodeParms. We have to do this now since you can't modify 364 // /DecodeParms. We have to do this now since you can't modify
381 // or create objects during write. 365 // or create objects during write.
382 - char p[1] = { static_cast<char>(this->keys[og]) }; 366 + char p[1] = {static_cast<char>(this->keys[og])};
383 std::string p_str(p, 1); 367 std::string p_str(p, 1);
384 QPDFObjectHandle dp_stream = 368 QPDFObjectHandle dp_stream =
385 QPDFObjectHandle::newStream(this->pdf, p_str); 369 QPDFObjectHandle::newStream(this->pdf, p_str);
@@ -388,23 +372,19 @@ StreamReplacer::registerStream( @@ -388,23 +372,19 @@ StreamReplacer::registerStream(
388 QPDFObjectHandle decode_parms = 372 QPDFObjectHandle decode_parms =
389 QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}}); 373 QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}});
390 stream.replaceStreamData( 374 stream.replaceStreamData(
391 - self,  
392 - QPDFObjectHandle::newName("/XORDecode"),  
393 - decode_parms); 375 + self, QPDFObjectHandle::newName("/XORDecode"), decode_parms);
394 // Further, if /ProtectXOR = true, we disable filtering on write 376 // Further, if /ProtectXOR = true, we disable filtering on write
395 // so that QPDFWriter will not decode the stream even though we 377 // so that QPDFWriter will not decode the stream even though we
396 // have registered a stream filter for /XORDecode. 378 // have registered a stream filter for /XORDecode.
397 auto protect = dict.getKey("/ProtectXOR"); 379 auto protect = dict.getKey("/ProtectXOR");
398 - if (protect.isBool() && protect.getBoolValue())  
399 - { 380 + if (protect.isBool() && protect.getBoolValue()) {
400 stream.setFilterOnWrite(false); 381 stream.setFilterOnWrite(false);
401 } 382 }
402 } 383 }
403 } 384 }
404 385
405 void 386 void
406 -StreamReplacer::provideStreamData(int objid, int generation,  
407 - Pipeline* pipeline) 387 +StreamReplacer::provideStreamData(int objid, int generation, Pipeline* pipeline)
408 { 388 {
409 QPDFObjGen og(objid, generation); 389 QPDFObjGen og(objid, generation);
410 QPDFObjectHandle orig = this->copied_streams[og]; 390 QPDFObjectHandle orig = this->copied_streams[og];
@@ -412,8 +392,7 @@ StreamReplacer::provideStreamData(int objid, int generation, @@ -412,8 +392,7 @@ StreamReplacer::provideStreamData(int objid, int generation,
412 // dict_updates. In this mode, maybeReplace doesn't make any 392 // dict_updates. In this mode, maybeReplace doesn't make any
413 // changes. We have to hand it the original stream data, which we 393 // changes. We have to hand it the original stream data, which we
414 // get from copied_streams. 394 // get from copied_streams.
415 - if (! maybeReplace(og, orig, pipeline, nullptr))  
416 - { 395 + if (!maybeReplace(og, orig, pipeline, nullptr)) {
417 // Since this only gets called for streams we already 396 // Since this only gets called for streams we already
418 // determined we are replacing, a false return would indicate 397 // determined we are replacing, a false return would indicate
419 // a logic error. 398 // a logic error.
@@ -422,8 +401,9 @@ StreamReplacer::provideStreamData(int objid, int generation, @@ -422,8 +401,9 @@ StreamReplacer::provideStreamData(int objid, int generation,
422 } 401 }
423 } 402 }
424 403
425 -static void process(char const* infilename, char const* outfilename,  
426 - bool decode_specialized) 404 +static void
  405 +process(
  406 + char const* infilename, char const* outfilename, bool decode_specialized)
427 { 407 {
428 QPDF qpdf; 408 QPDF qpdf;
429 qpdf.processFile(infilename); 409 qpdf.processFile(infilename);
@@ -434,10 +414,8 @@ static void process(char const* infilename, char const* outfilename, @@ -434,10 +414,8 @@ static void process(char const* infilename, char const* outfilename,
434 StreamReplacer* replacer = new StreamReplacer(&qpdf); 414 StreamReplacer* replacer = new StreamReplacer(&qpdf);
435 PointerHolder<QPDFObjectHandle::StreamDataProvider> p(replacer); 415 PointerHolder<QPDFObjectHandle::StreamDataProvider> p(replacer);
436 416
437 - for (auto& o: qpdf.getAllObjects())  
438 - {  
439 - if (o.isStream())  
440 - { 417 + for (auto& o : qpdf.getAllObjects()) {
  418 + if (o.isStream()) {
441 // Call registerStream for every stream. Only ones that 419 // Call registerStream for every stream. Only ones that
442 // registerStream decides to replace will actually be 420 // registerStream decides to replace will actually be
443 // replaced. 421 // replaced.
@@ -446,70 +424,58 @@ static void process(char const* infilename, char const* outfilename, @@ -446,70 +424,58 @@ static void process(char const* infilename, char const* outfilename,
446 } 424 }
447 425
448 QPDFWriter w(qpdf, outfilename); 426 QPDFWriter w(qpdf, outfilename);
449 - if (decode_specialized)  
450 - { 427 + if (decode_specialized) {
451 w.setDecodeLevel(qpdf_dl_specialized); 428 w.setDecodeLevel(qpdf_dl_specialized);
452 } 429 }
453 // For the test suite, use static IDs. 430 // For the test suite, use static IDs.
454 w.setStaticID(true); // for testing only 431 w.setStaticID(true); // for testing only
455 w.write(); 432 w.write();
456 - std::cout << whoami << ": new file written to " << outfilename  
457 - << std::endl; 433 + std::cout << whoami << ": new file written to " << outfilename << std::endl;
458 } 434 }
459 435
460 -static void usage() 436 +static void
  437 +usage()
461 { 438 {
462 - std::cerr  
463 - << "\n"  
464 - << "Usage: " << whoami << " [--decode-specialized] infile outfile\n"  
465 - << std::endl; 439 + std::cerr << "\n"
  440 + << "Usage: " << whoami
  441 + << " [--decode-specialized] infile outfile\n"
  442 + << std::endl;
466 exit(2); 443 exit(2);
467 } 444 }
468 445
469 -int main(int argc, char* argv[]) 446 +int
  447 +main(int argc, char* argv[])
470 { 448 {
471 whoami = QUtil::getWhoami(argv[0]); 449 whoami = QUtil::getWhoami(argv[0]);
472 450
473 char const* infilename = 0; 451 char const* infilename = 0;
474 char const* outfilename = 0; 452 char const* outfilename = 0;
475 bool decode_specialized = false; 453 bool decode_specialized = false;
476 - for (int i = 1; i < argc; ++i)  
477 - {  
478 - if (strcmp(argv[i], "--decode-specialized") == 0)  
479 - { 454 + for (int i = 1; i < argc; ++i) {
  455 + if (strcmp(argv[i], "--decode-specialized") == 0) {
480 decode_specialized = true; 456 decode_specialized = true;
481 - }  
482 - else if (! infilename)  
483 - { 457 + } else if (!infilename) {
484 infilename = argv[i]; 458 infilename = argv[i];
485 - }  
486 - else if (! outfilename)  
487 - { 459 + } else if (!outfilename) {
488 outfilename = argv[i]; 460 outfilename = argv[i];
489 - }  
490 - else  
491 - { 461 + } else {
492 usage(); 462 usage();
493 } 463 }
494 } 464 }
495 - if (! (infilename && outfilename))  
496 - { 465 + if (!(infilename && outfilename)) {
497 usage(); 466 usage();
498 } 467 }
499 468
500 - try  
501 - { 469 + try {
502 // Register our fictitious filter. This enables QPDFWriter to 470 // Register our fictitious filter. This enables QPDFWriter to
503 // decode our streams. This is not a real filter, so no real 471 // decode our streams. This is not a real filter, so no real
504 // PDF reading application would be able to interpret it. This 472 // PDF reading application would be able to interpret it. This
505 // is just for illustrative purposes. 473 // is just for illustrative purposes.
506 QPDF::registerStreamFilter( 474 QPDF::registerStreamFilter(
507 - "/XORDecode", []{ return std::make_shared<SF_XORDecode>(); }); 475 + "/XORDecode", [] { return std::make_shared<SF_XORDecode>(); });
508 // Do the actual processing. 476 // Do the actual processing.
509 process(infilename, outfilename, decode_specialized); 477 process(infilename, outfilename, decode_specialized);
510 - }  
511 - catch (std::exception &e)  
512 - { 478 + } catch (std::exception& e) {
513 std::cerr << whoami << ": exception: " << e.what() << std::endl; 479 std::cerr << whoami << ": exception: " << e.what() << std::endl;
514 exit(2); 480 exit(2);
515 } 481 }
examples/pdf-double-page-size.cc
1 -#include <iostream>  
2 -#include <string.h>  
3 -#include <stdlib.h> 1 +#include <qpdf/Buffer.hh>
4 #include <qpdf/QPDF.hh> 2 #include <qpdf/QPDF.hh>
5 #include <qpdf/QPDFPageDocumentHelper.hh> 3 #include <qpdf/QPDFPageDocumentHelper.hh>
6 #include <qpdf/QPDFPageObjectHelper.hh> 4 #include <qpdf/QPDFPageObjectHelper.hh>
7 -#include <qpdf/QUtil.hh>  
8 -#include <qpdf/Buffer.hh>  
9 #include <qpdf/QPDFWriter.hh> 5 #include <qpdf/QPDFWriter.hh>
  6 +#include <qpdf/QUtil.hh>
  7 +#include <iostream>
  8 +#include <stdlib.h>
  9 +#include <string.h>
10 10
11 static char const* whoami = 0; 11 static char const* whoami = 0;
12 12
13 -void usage() 13 +void
  14 +usage()
14 { 15 {
15 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" 16 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
16 << std::endl 17 << std::endl
@@ -21,45 +22,43 @@ void usage() @@ -21,45 +22,43 @@ void usage()
21 22
22 // If there is a box of name box_name, replace it with a new box whose 23 // If there is a box of name box_name, replace it with a new box whose
23 // elements are double the values of the original box. 24 // elements are double the values of the original box.
24 -static void doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name) 25 +static void
  26 +doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name)
25 { 27 {
26 // We need to use getAttribute rather than getKey as some boxes could 28 // We need to use getAttribute rather than getKey as some boxes could
27 // be inherited. 29 // be inherited.
28 auto box = page.getAttribute(box_name, true); 30 auto box = page.getAttribute(box_name, true);
29 - if (box.isNull())  
30 - { 31 + if (box.isNull()) {
31 return; 32 return;
32 } 33 }
33 - if (! box.isRectangle())  
34 - {  
35 - throw std::runtime_error(std::string("box ") + box_name +  
36 - " is not an array of four elements"); 34 + if (!box.isRectangle()) {
  35 + throw std::runtime_error(
  36 + std::string("box ") + box_name +
  37 + " is not an array of four elements");
37 } 38 }
38 std::vector<QPDFObjectHandle> doubled; 39 std::vector<QPDFObjectHandle> doubled;
39 - for (auto& item : box.aitems())  
40 - { 40 + for (auto& item : box.aitems()) {
41 doubled.push_back( 41 doubled.push_back(
42 QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2)); 42 QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2));
43 } 43 }
44 - page.getObjectHandle()  
45 - .replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); 44 + page.getObjectHandle().replaceKey(
  45 + box_name, QPDFObjectHandle::newArray(doubled));
46 } 46 }
47 47
48 -int main(int argc, char* argv[]) 48 +int
  49 +main(int argc, char* argv[])
49 { 50 {
50 whoami = QUtil::getWhoami(argv[0]); 51 whoami = QUtil::getWhoami(argv[0]);
51 52
52 // For test suite 53 // For test suite
53 bool static_id = false; 54 bool static_id = false;
54 - if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0))  
55 - { 55 + if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) {
56 static_id = true; 56 static_id = true;
57 --argc; 57 --argc;
58 ++argv; 58 ++argv;
59 } 59 }
60 60
61 - if (! ((argc == 3) || (argc == 4)))  
62 - { 61 + if (!((argc == 3) || (argc == 4))) {
63 usage(); 62 usage();
64 } 63 }
65 64
@@ -70,13 +69,11 @@ int main(int argc, char* argv[]) @@ -70,13 +69,11 @@ int main(int argc, char* argv[])
70 // Text to prepend to each page's contents 69 // Text to prepend to each page's contents
71 std::string content = "2 0 0 2 0 0 cm\n"; 70 std::string content = "2 0 0 2 0 0 cm\n";
72 71
73 - try  
74 - { 72 + try {
75 QPDF qpdf; 73 QPDF qpdf;
76 qpdf.processFile(infilename, password); 74 qpdf.processFile(infilename, password);
77 75
78 - for (auto& page : QPDFPageDocumentHelper(qpdf).getAllPages())  
79 - { 76 + for (auto& page : QPDFPageDocumentHelper(qpdf).getAllPages()) {
80 // Prepend the buffer to the page's contents 77 // Prepend the buffer to the page's contents
81 page.addPageContents( 78 page.addPageContents(
82 QPDFObjectHandle::newStream(&qpdf, content), true); 79 QPDFObjectHandle::newStream(&qpdf, content), true);
@@ -91,8 +88,7 @@ int main(int argc, char* argv[]) @@ -91,8 +88,7 @@ int main(int argc, char* argv[])
91 88
92 // Write out a new file 89 // Write out a new file
93 QPDFWriter w(qpdf, outfilename); 90 QPDFWriter w(qpdf, outfilename);
94 - if (static_id)  
95 - { 91 + if (static_id) {
96 // For the test suite, uncompress streams and use static IDs. 92 // For the test suite, uncompress streams and use static IDs.
97 w.setStaticID(true); // for testing only 93 w.setStaticID(true); // for testing only
98 w.setStreamDataMode(qpdf_s_uncompress); 94 w.setStreamDataMode(qpdf_s_uncompress);
@@ -100,9 +96,7 @@ int main(int argc, char* argv[]) @@ -100,9 +96,7 @@ int main(int argc, char* argv[])
100 w.write(); 96 w.write();
101 std::cout << whoami << ": new file written to " << outfilename 97 std::cout << whoami << ": new file written to " << outfilename
102 << std::endl; 98 << std::endl;
103 - }  
104 - catch (std::exception &e)  
105 - { 99 + } catch (std::exception& e) {
106 std::cerr << whoami << " processing file " << infilename << ": " 100 std::cerr << whoami << " processing file " << infilename << ": "
107 << e.what() << std::endl; 101 << e.what() << std::endl;
108 exit(2); 102 exit(2);
examples/pdf-filter-tokens.cc
@@ -5,22 +5,23 @@ @@ -5,22 +5,23 @@
5 // QPDFObjectHandle::TokenFilter with filterContents. 5 // QPDFObjectHandle::TokenFilter with filterContents.
6 // 6 //
7 7
8 -#include <iostream>  
9 -#include <string.h>  
10 -#include <stdlib.h>  
11 #include <algorithm> 8 #include <algorithm>
12 #include <deque> 9 #include <deque>
  10 +#include <iostream>
  11 +#include <stdlib.h>
  12 +#include <string.h>
13 13
14 #include <qpdf/QPDF.hh> 14 #include <qpdf/QPDF.hh>
  15 +#include <qpdf/QPDFObjectHandle.hh>
15 #include <qpdf/QPDFPageDocumentHelper.hh> 16 #include <qpdf/QPDFPageDocumentHelper.hh>
16 #include <qpdf/QPDFPageObjectHelper.hh> 17 #include <qpdf/QPDFPageObjectHelper.hh>
17 -#include <qpdf/QUtil.hh>  
18 #include <qpdf/QPDFWriter.hh> 18 #include <qpdf/QPDFWriter.hh>
19 -#include <qpdf/QPDFObjectHandle.hh> 19 +#include <qpdf/QUtil.hh>
20 20
21 static char const* whoami = 0; 21 static char const* whoami = 0;
22 22
23 -void usage() 23 +void
  24 +usage()
24 { 25 {
25 std::cerr << "Usage: " << whoami << " infile outfile" << std::endl 26 std::cerr << "Usage: " << whoami << " infile outfile" << std::endl
26 << "Applies token filters to infile and writes outfile" 27 << "Applies token filters to infile and writes outfile"
@@ -52,14 +53,11 @@ StringReverser::handleToken(QPDFTokenizer::Token const&amp; token) @@ -52,14 +53,11 @@ StringReverser::handleToken(QPDFTokenizer::Token const&amp; token)
52 // strings. It's just intended to give a simple example of a 53 // strings. It's just intended to give a simple example of a
53 // pretty minimal filter and to show an example of writing a 54 // pretty minimal filter and to show an example of writing a
54 // constructed token. 55 // constructed token.
55 - if (token.getType() == QPDFTokenizer::tt_string)  
56 - { 56 + if (token.getType() == QPDFTokenizer::tt_string) {
57 std::string value = token.getValue(); 57 std::string value = token.getValue();
58 std::reverse(value.begin(), value.end()); 58 std::reverse(value.begin(), value.end());
59 writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_string, value)); 59 writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_string, value));
60 - }  
61 - else  
62 - { 60 + } else {
63 writeToken(token); 61 writeToken(token);
64 } 62 }
65 } 63 }
@@ -90,15 +88,17 @@ class ColorToGray: public QPDFObjectHandle::TokenFilter @@ -90,15 +88,17 @@ class ColorToGray: public QPDFObjectHandle::TokenFilter
90 bool 88 bool
91 ColorToGray::isNumeric(QPDFTokenizer::token_type_e token_type) 89 ColorToGray::isNumeric(QPDFTokenizer::token_type_e token_type)
92 { 90 {
93 - return ((token_type == QPDFTokenizer::tt_integer) ||  
94 - (token_type == QPDFTokenizer::tt_real)); 91 + return (
  92 + (token_type == QPDFTokenizer::tt_integer) ||
  93 + (token_type == QPDFTokenizer::tt_real));
95 } 94 }
96 95
97 bool 96 bool
98 ColorToGray::isIgnorable(QPDFTokenizer::token_type_e token_type) 97 ColorToGray::isIgnorable(QPDFTokenizer::token_type_e token_type)
99 { 98 {
100 - return ((token_type == QPDFTokenizer::tt_space) ||  
101 - (token_type == QPDFTokenizer::tt_comment)); 99 + return (
  100 + (token_type == QPDFTokenizer::tt_space) ||
  101 + (token_type == QPDFTokenizer::tt_comment));
102 } 102 }
103 103
104 double 104 double
@@ -134,33 +134,28 @@ ColorToGray::handleToken(QPDFTokenizer::Token const&amp; token) @@ -134,33 +134,28 @@ ColorToGray::handleToken(QPDFTokenizer::Token const&amp; token)
134 // kinds of operands, replace the command. Flush any additional 134 // kinds of operands, replace the command. Flush any additional
135 // accumulated tokens to keep the stack only four tokens deep. 135 // accumulated tokens to keep the stack only four tokens deep.
136 136
137 - while ((! this->all_stack.empty()) &&  
138 - isIgnorable(this->all_stack.at(0).getType()))  
139 - { 137 + while ((!this->all_stack.empty()) &&
  138 + isIgnorable(this->all_stack.at(0).getType())) {
140 writeToken(this->all_stack.at(0)); 139 writeToken(this->all_stack.at(0));
141 this->all_stack.pop_front(); 140 this->all_stack.pop_front();
142 } 141 }
143 this->all_stack.push_back(token); 142 this->all_stack.push_back(token);
144 QPDFTokenizer::token_type_e token_type = token.getType(); 143 QPDFTokenizer::token_type_e token_type = token.getType();
145 - if (! isIgnorable(token_type))  
146 - { 144 + if (!isIgnorable(token_type)) {
147 this->stack.push_back(token); 145 this->stack.push_back(token);
148 if ((this->stack.size() == 4) && 146 if ((this->stack.size() == 4) &&
149 (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "rg")) && 147 (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "rg")) &&
150 (isNumeric(this->stack.at(0).getType())) && 148 (isNumeric(this->stack.at(0).getType())) &&
151 (isNumeric(this->stack.at(1).getType())) && 149 (isNumeric(this->stack.at(1).getType())) &&
152 - (isNumeric(this->stack.at(2).getType())))  
153 - { 150 + (isNumeric(this->stack.at(2).getType()))) {
154 double r = numericValue(this->stack.at(0)); 151 double r = numericValue(this->stack.at(0));
155 double g = numericValue(this->stack.at(1)); 152 double g = numericValue(this->stack.at(1));
156 double b = numericValue(this->stack.at(2)); 153 double b = numericValue(this->stack.at(2));
157 double gray = ((0.3 * r) + (0.59 * b) + (0.11 * g)); 154 double gray = ((0.3 * r) + (0.59 * b) + (0.11 * g));
158 - if (gray > 1.0)  
159 - { 155 + if (gray > 1.0) {
160 gray = 1.0; 156 gray = 1.0;
161 } 157 }
162 - if (gray < 0.0)  
163 - { 158 + if (gray < 0.0) {
164 gray = 0.0; 159 gray = 0.0;
165 } 160 }
166 write(QUtil::double_to_string(gray, 3)); 161 write(QUtil::double_to_string(gray, 3));
@@ -169,8 +164,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const&amp; token) @@ -169,8 +164,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const&amp; token)
169 this->all_stack.clear(); 164 this->all_stack.clear();
170 } 165 }
171 } 166 }
172 - if (this->stack.size() == 4)  
173 - { 167 + if (this->stack.size() == 4) {
174 writeToken(this->all_stack.at(0)); 168 writeToken(this->all_stack.at(0));
175 this->all_stack.pop_front(); 169 this->all_stack.pop_front();
176 this->stack.pop_front(); 170 this->stack.pop_front();
@@ -181,33 +175,31 @@ void @@ -181,33 +175,31 @@ void
181 ColorToGray::handleEOF() 175 ColorToGray::handleEOF()
182 { 176 {
183 // Flush out any remaining accumulated tokens. 177 // Flush out any remaining accumulated tokens.
184 - while (! this->all_stack.empty())  
185 - { 178 + while (!this->all_stack.empty()) {
186 writeToken(this->all_stack.at(0)); 179 writeToken(this->all_stack.at(0));
187 this->all_stack.pop_front(); 180 this->all_stack.pop_front();
188 } 181 }
189 } 182 }
190 183
191 -int main(int argc, char* argv[]) 184 +int
  185 +main(int argc, char* argv[])
192 { 186 {
193 whoami = QUtil::getWhoami(argv[0]); 187 whoami = QUtil::getWhoami(argv[0]);
194 188
195 - if (argc != 3)  
196 - { 189 + if (argc != 3) {
197 usage(); 190 usage();
198 } 191 }
199 char const* infilename = argv[1]; 192 char const* infilename = argv[1];
200 char const* outfilename = argv[2]; 193 char const* outfilename = argv[2];
201 194
202 - try  
203 - { 195 + try {
204 QPDF pdf; 196 QPDF pdf;
205 pdf.processFile(infilename); 197 pdf.processFile(infilename);
206 std::vector<QPDFPageObjectHelper> pages = 198 std::vector<QPDFPageObjectHelper> pages =
207 QPDFPageDocumentHelper(pdf).getAllPages(); 199 QPDFPageDocumentHelper(pdf).getAllPages();
208 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); 200 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
209 - iter != pages.end(); ++iter)  
210 - { 201 + iter != pages.end();
  202 + ++iter) {
211 // Attach two token filters to each page of this file. 203 // Attach two token filters to each page of this file.
212 // When the file is written, or when the pages' contents 204 // When the file is written, or when the pages' contents
213 // are retrieved in any other way, the filters will be 205 // are retrieved in any other way, the filters will be
@@ -222,11 +214,9 @@ int main(int argc, char* argv[]) @@ -222,11 +214,9 @@ int main(int argc, char* argv[])
222 } 214 }
223 215
224 QPDFWriter w(pdf, outfilename); 216 QPDFWriter w(pdf, outfilename);
225 - w.setStaticID(true); // for testing only 217 + w.setStaticID(true); // for testing only
226 w.write(); 218 w.write();
227 - }  
228 - catch (std::exception& e)  
229 - { 219 + } catch (std::exception& e) {
230 std::cerr << whoami << ": " << e.what() << std::endl; 220 std::cerr << whoami << ": " << e.what() << std::endl;
231 exit(2); 221 exit(2);
232 } 222 }
examples/pdf-invert-images.cc
1 -#include <iostream>  
2 -#include <string.h>  
3 -#include <stdlib.h> 1 +#include <qpdf/Buffer.hh>
  2 +#include <qpdf/QIntC.hh>
4 #include <qpdf/QPDF.hh> 3 #include <qpdf/QPDF.hh>
5 #include <qpdf/QPDFPageDocumentHelper.hh> 4 #include <qpdf/QPDFPageDocumentHelper.hh>
6 #include <qpdf/QPDFPageObjectHelper.hh> 5 #include <qpdf/QPDFPageObjectHelper.hh>
7 -#include <qpdf/QUtil.hh>  
8 -#include <qpdf/Buffer.hh>  
9 #include <qpdf/QPDFWriter.hh> 6 #include <qpdf/QPDFWriter.hh>
10 -#include <qpdf/QIntC.hh> 7 +#include <qpdf/QUtil.hh>
  8 +#include <iostream>
  9 +#include <stdlib.h>
  10 +#include <string.h>
11 11
12 static char const* whoami = 0; 12 static char const* whoami = 0;
13 13
14 -void usage() 14 +void
  15 +usage()
15 { 16 {
16 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" 17 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
17 << std::endl 18 << std::endl
@@ -35,8 +36,8 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider @@ -35,8 +36,8 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider
35 virtual ~ImageInverter() 36 virtual ~ImageInverter()
36 { 37 {
37 } 38 }
38 - virtual void provideStreamData(int objid, int generation,  
39 - Pipeline* pipeline) override; 39 + virtual void
  40 + provideStreamData(int objid, int generation, Pipeline* pipeline) override;
40 41
41 void registerImage( 42 void registerImage(
42 QPDFObjectHandle image, 43 QPDFObjectHandle image,
@@ -64,8 +65,7 @@ ImageInverter::registerImage( @@ -64,8 +65,7 @@ ImageInverter::registerImage(
64 // generation number. Recall that a single image object may be 65 // generation number. Recall that a single image object may be
65 // used more than once, so no need to update the same stream 66 // used more than once, so no need to update the same stream
66 // multiple times. 67 // multiple times.
67 - if (this->copied_images.count(og) > 0)  
68 - { 68 + if (this->copied_images.count(og) > 0) {
69 return; 69 return;
70 } 70 }
71 this->copied_images[og] = image.copyStream(); 71 this->copied_images[og] = image.copyStream();
@@ -79,14 +79,12 @@ ImageInverter::registerImage( @@ -79,14 +79,12 @@ ImageInverter::registerImage(
79 // filterable in the input QPDF object, so we don't have to deal 79 // filterable in the input QPDF object, so we don't have to deal
80 // with it explicitly here. We could explicitly use /DCTDecode and 80 // with it explicitly here. We could explicitly use /DCTDecode and
81 // write through a DCT filter if we wanted. 81 // write through a DCT filter if we wanted.
82 - image.replaceStreamData(self,  
83 - QPDFObjectHandle::newNull(),  
84 - QPDFObjectHandle::newNull()); 82 + image.replaceStreamData(
  83 + self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
85 } 84 }
86 85
87 void 86 void
88 -ImageInverter::provideStreamData(int objid, int generation,  
89 - Pipeline* pipeline) 87 +ImageInverter::provideStreamData(int objid, int generation, Pipeline* pipeline)
90 { 88 {
91 // Use the object and generation number supplied to look up the 89 // Use the object and generation number supplied to look up the
92 // image data. Then invert the image data and write the inverted 90 // image data. Then invert the image data and write the inverted
@@ -97,29 +95,27 @@ ImageInverter::provideStreamData(int objid, int generation, @@ -97,29 +95,27 @@ ImageInverter::provideStreamData(int objid, int generation,
97 size_t size = data->getSize(); 95 size_t size = data->getSize();
98 unsigned char* buf = data->getBuffer(); 96 unsigned char* buf = data->getBuffer();
99 unsigned char ch; 97 unsigned char ch;
100 - for (size_t i = 0; i < size; ++i)  
101 - { 98 + for (size_t i = 0; i < size; ++i) {
102 ch = QIntC::to_uchar(0xff - buf[i]); 99 ch = QIntC::to_uchar(0xff - buf[i]);
103 pipeline->write(&ch, 1); 100 pipeline->write(&ch, 1);
104 } 101 }
105 pipeline->finish(); 102 pipeline->finish();
106 } 103 }
107 104
108 -int main(int argc, char* argv[]) 105 +int
  106 +main(int argc, char* argv[])
109 { 107 {
110 whoami = QUtil::getWhoami(argv[0]); 108 whoami = QUtil::getWhoami(argv[0]);
111 109
112 // For test suite 110 // For test suite
113 bool static_id = false; 111 bool static_id = false;
114 - if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0))  
115 - { 112 + if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) {
116 static_id = true; 113 static_id = true;
117 --argc; 114 --argc;
118 ++argv; 115 ++argv;
119 } 116 }
120 117
121 - if (! ((argc == 3) || (argc == 4)))  
122 - { 118 + if (!((argc == 3) || (argc == 4))) {
123 usage(); 119 usage();
124 } 120 }
125 121
@@ -127,8 +123,7 @@ int main(int argc, char* argv[]) @@ -127,8 +123,7 @@ int main(int argc, char* argv[])
127 char const* outfilename = argv[2]; 123 char const* outfilename = argv[2];
128 char const* password = (argc == 4) ? argv[3] : ""; 124 char const* password = (argc == 4) ? argv[3] : "";
129 125
130 - try  
131 - { 126 + try {
132 QPDF qpdf; 127 QPDF qpdf;
133 qpdf.processFile(infilename, password); 128 qpdf.processFile(infilename, password);
134 129
@@ -139,18 +134,15 @@ int main(int argc, char* argv[]) @@ -139,18 +134,15 @@ int main(int argc, char* argv[])
139 std::vector<QPDFPageObjectHelper> pages = 134 std::vector<QPDFPageObjectHelper> pages =
140 QPDFPageDocumentHelper(qpdf).getAllPages(); 135 QPDFPageDocumentHelper(qpdf).getAllPages();
141 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); 136 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
142 - iter != pages.end(); ++iter)  
143 - { 137 + iter != pages.end();
  138 + ++iter) {
144 QPDFPageObjectHelper& page(*iter); 139 QPDFPageObjectHelper& page(*iter);
145 // Get all images on the page. 140 // Get all images on the page.
146 - std::map<std::string, QPDFObjectHandle> images =  
147 - page.getImages();  
148 - for (auto& iter2: images)  
149 - { 141 + std::map<std::string, QPDFObjectHandle> images = page.getImages();
  142 + for (auto& iter2 : images) {
150 QPDFObjectHandle& image = iter2.second; 143 QPDFObjectHandle& image = iter2.second;
151 QPDFObjectHandle image_dict = image.getDict(); 144 QPDFObjectHandle image_dict = image.getDict();
152 - QPDFObjectHandle color_space =  
153 - image_dict.getKey("/ColorSpace"); 145 + QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
154 QPDFObjectHandle bits_per_component = 146 QPDFObjectHandle bits_per_component =
155 image_dict.getKey("/BitsPerComponent"); 147 image_dict.getKey("/BitsPerComponent");
156 148
@@ -159,12 +151,10 @@ int main(int argc, char* argv[]) @@ -159,12 +151,10 @@ int main(int argc, char* argv[])
159 // pipeStreamData with a null pipeline to determine 151 // pipeStreamData with a null pipeline to determine
160 // whether the image is filterable. Directly inspect 152 // whether the image is filterable. Directly inspect
161 // keys to determine the image type. 153 // keys to determine the image type.
162 - if (image.pipeStreamData(0, qpdf_ef_compress,  
163 - qpdf_dl_all) && 154 + if (image.pipeStreamData(0, qpdf_ef_compress, qpdf_dl_all) &&
164 color_space.isNameAndEquals("/DeviceGray") && 155 color_space.isNameAndEquals("/DeviceGray") &&
165 bits_per_component.isInteger() && 156 bits_per_component.isInteger() &&
166 - (bits_per_component.getIntValue() == 8))  
167 - { 157 + (bits_per_component.getIntValue() == 8)) {
168 inv->registerImage(image, p); 158 inv->registerImage(image, p);
169 } 159 }
170 } 160 }
@@ -172,8 +162,7 @@ int main(int argc, char* argv[]) @@ -172,8 +162,7 @@ int main(int argc, char* argv[])
172 162
173 // Write out a new file 163 // Write out a new file
174 QPDFWriter w(qpdf, outfilename); 164 QPDFWriter w(qpdf, outfilename);
175 - if (static_id)  
176 - { 165 + if (static_id) {
177 // For the test suite, uncompress streams and use static 166 // For the test suite, uncompress streams and use static
178 // IDs. 167 // IDs.
179 w.setStaticID(true); // for testing only 168 w.setStaticID(true); // for testing only
@@ -181,9 +170,7 @@ int main(int argc, char* argv[]) @@ -181,9 +170,7 @@ int main(int argc, char* argv[])
181 w.write(); 170 w.write();
182 std::cout << whoami << ": new file written to " << outfilename 171 std::cout << whoami << ": new file written to " << outfilename
183 << std::endl; 172 << std::endl;
184 - }  
185 - catch (std::exception &e)  
186 - { 173 + } catch (std::exception& e) {
187 std::cerr << whoami << " processing file " << infilename << ": " 174 std::cerr << whoami << " processing file " << infilename << ": "
188 << e.what() << std::endl; 175 << e.what() << std::endl;
189 exit(2); 176 exit(2);
examples/pdf-linearize.c
@@ -9,18 +9,21 @@ @@ -9,18 +9,21 @@
9 9
10 static char const* whoami = 0; 10 static char const* whoami = 0;
11 11
12 -static void usage() 12 +static void
  13 +usage()
13 { 14 {
14 fprintf(stderr, "Usage: %s infile infile-password outfile\n", whoami); 15 fprintf(stderr, "Usage: %s infile infile-password outfile\n", whoami);
15 exit(2); 16 exit(2);
16 } 17 }
17 18
18 -static void write_progress(int percent, void* data) 19 +static void
  20 +write_progress(int percent, void* data)
19 { 21 {
20 printf("%s progress: %d%%\n", (char const*)(data), percent); 22 printf("%s progress: %d%%\n", (char const*)(data), percent);
21 } 23 }
22 24
23 -int main(int argc, char* argv[]) 25 +int
  26 +main(int argc, char* argv[])
24 { 27 {
25 char* infile = NULL; 28 char* infile = NULL;
26 char* password = NULL; 29 char* password = NULL;
@@ -30,21 +33,15 @@ int main(int argc, char* argv[]) @@ -30,21 +33,15 @@ int main(int argc, char* argv[])
30 int errors = 0; 33 int errors = 0;
31 char* p = 0; 34 char* p = 0;
32 35
33 - if ((p = strrchr(argv[0], '/')) != NULL)  
34 - { 36 + if ((p = strrchr(argv[0], '/')) != NULL) {
35 whoami = p + 1; 37 whoami = p + 1;
36 - }  
37 - else if ((p = strrchr(argv[0], '\\')) != NULL)  
38 - { 38 + } else if ((p = strrchr(argv[0], '\\')) != NULL) {
39 whoami = p + 1; 39 whoami = p + 1;
40 - }  
41 - else  
42 - { 40 + } else {
43 whoami = argv[0]; 41 whoami = argv[0];
44 } 42 }
45 43
46 - if (argc != 4)  
47 - { 44 + if (argc != 4) {
48 usage(); 45 usage();
49 } 46 }
50 47
@@ -53,8 +50,7 @@ int main(int argc, char* argv[]) @@ -53,8 +50,7 @@ int main(int argc, char* argv[])
53 outfile = argv[3]; 50 outfile = argv[3];
54 51
55 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && 52 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
56 - ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0))  
57 - { 53 + ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) {
58 /* Use static ID for testing only. For production, a 54 /* Use static ID for testing only. For production, a
59 * non-static ID is used. See also 55 * non-static ID is used. See also
60 * qpdf_set_deterministic_ID. */ 56 * qpdf_set_deterministic_ID. */
@@ -63,25 +59,22 @@ int main(int argc, char* argv[]) @@ -63,25 +59,22 @@ int main(int argc, char* argv[])
63 qpdf_register_progress_reporter(qpdf, write_progress, infile); 59 qpdf_register_progress_reporter(qpdf, write_progress, infile);
64 qpdf_write(qpdf); 60 qpdf_write(qpdf);
65 } 61 }
66 - while (qpdf_more_warnings(qpdf))  
67 - { 62 + while (qpdf_more_warnings(qpdf)) {
68 warnings = 1; 63 warnings = 1;
69 - printf("warning: %s\n",  
70 - qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); 64 + printf(
  65 + "warning: %s\n",
  66 + qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
71 } 67 }
72 - if (qpdf_has_error(qpdf))  
73 - { 68 + if (qpdf_has_error(qpdf)) {
74 errors = 1; 69 errors = 1;
75 - printf("error: %s\n",  
76 - qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); 70 + printf(
  71 + "error: %s\n",
  72 + qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
77 } 73 }
78 qpdf_cleanup(&qpdf); 74 qpdf_cleanup(&qpdf);
79 - if (errors)  
80 - { 75 + if (errors) {
81 return 2; 76 return 2;
82 - }  
83 - else if (warnings)  
84 - { 77 + } else if (warnings) {
85 return 3; 78 return 3;
86 } 79 }
87 80
examples/pdf-mod-info.cc
1 // Author: Vitaliy Pavlyuk 1 // Author: Vitaliy Pavlyuk
2 2
3 #include <qpdf/QPDF.hh> 3 #include <qpdf/QPDF.hh>
4 -#include <qpdf/QPDFWriter.hh>  
5 #include <qpdf/QPDFObjectHandle.hh> 4 #include <qpdf/QPDFObjectHandle.hh>
6 -#include <qpdf/QUtil.hh> 5 +#include <qpdf/QPDFWriter.hh>
7 #include <qpdf/QTC.hh> 6 #include <qpdf/QTC.hh>
  7 +#include <qpdf/QUtil.hh>
8 #include <iostream> 8 #include <iostream>
9 -#include <string.h>  
10 -#include <stdlib.h>  
11 #include <stdio.h> 9 #include <stdio.h>
  10 +#include <stdlib.h>
  11 +#include <string.h>
12 12
13 static char const* version = "1.1"; 13 static char const* version = "1.1";
14 static char const* whoami = 0; 14 static char const* whoami = 0;
15 15
16 -void usage() 16 +void
  17 +usage()
17 { 18 {
18 - std::cerr  
19 - << "Usage: " << whoami  
20 - << " --in in_file [--out out_file] [--key key [--val val]?]+\n"  
21 - << "Modifies/Adds/Removes PDF /Info entries in the in_file\n"  
22 - << "and stores the result in out_file\n"  
23 - << "Special mode: " << whoami << " --dump file\n"  
24 - << "dumps all /Info entries to stdout\n"; 19 + std::cerr << "Usage: " << whoami
  20 + << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
  21 + << "Modifies/Adds/Removes PDF /Info entries in the in_file\n"
  22 + << "and stores the result in out_file\n"
  23 + << "Special mode: " << whoami << " --dump file\n"
  24 + << "dumps all /Info entries to stdout\n";
25 exit(2); 25 exit(2);
26 } 26 }
27 27
28 -void dumpInfoDict(QPDF& pdf,  
29 - std::ostream& os = std::cout,  
30 - std::string const& sep = ":\t") 28 +void
  29 +dumpInfoDict(
  30 + QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t")
31 { 31 {
32 QPDFObjectHandle trailer = pdf.getTrailer(); 32 QPDFObjectHandle trailer = pdf.getTrailer();
33 - if (trailer.hasKey("/Info"))  
34 - {  
35 - for (auto& it: trailer.getKey("/Info").ditems())  
36 - { 33 + if (trailer.hasKey("/Info")) {
  34 + for (auto& it : trailer.getKey("/Info").ditems()) {
37 std::string val; 35 std::string val;
38 - if (it.second.isString())  
39 - { 36 + if (it.second.isString()) {
40 val = it.second.getStringValue(); 37 val = it.second.getStringValue();
41 - }  
42 - else if (it.second.isName())  
43 - { 38 + } else if (it.second.isName()) {
44 val = it.second.getName(); 39 val = it.second.getName();
45 - }  
46 - else // according to PDF Spec 1.5, shouldn't happen 40 + } else // according to PDF Spec 1.5, shouldn't happen
47 { 41 {
48 val = it.second.unparseResolved(); 42 val = it.second.unparseResolved();
49 } 43 }
@@ -52,36 +46,32 @@ void dumpInfoDict(QPDF&amp; pdf, @@ -52,36 +46,32 @@ void dumpInfoDict(QPDF&amp; pdf,
52 } 46 }
53 } 47 }
54 48
55 -void pdfDumpInfoDict(char const* fname) 49 +void
  50 +pdfDumpInfoDict(char const* fname)
56 { 51 {
57 - try  
58 - { 52 + try {
59 QPDF pdf; 53 QPDF pdf;
60 pdf.processFile(fname); 54 pdf.processFile(fname);
61 dumpInfoDict(pdf); 55 dumpInfoDict(pdf);
62 - }  
63 - catch (std::exception& e)  
64 - { 56 + } catch (std::exception& e) {
65 std::cerr << e.what() << std::endl; 57 std::cerr << e.what() << std::endl;
66 exit(2); 58 exit(2);
67 } 59 }
68 } 60 }
69 61
70 -int main(int argc, char* argv[]) 62 +int
  63 +main(int argc, char* argv[])
71 { 64 {
72 -  
73 bool static_id = false; 65 bool static_id = false;
74 std::map<std::string, std::string> Keys; 66 std::map<std::string, std::string> Keys;
75 67
76 whoami = QUtil::getWhoami(argv[0]); 68 whoami = QUtil::getWhoami(argv[0]);
77 69
78 - if ((argc == 2) && (! strcmp(argv[1], "--version")) )  
79 - { 70 + if ((argc == 2) && (!strcmp(argv[1], "--version"))) {
80 std::cout << whoami << " version " << version << std::endl; 71 std::cout << whoami << " version " << version << std::endl;
81 exit(0); 72 exit(0);
82 } 73 }
83 - if ((argc == 3) && (! strcmp(argv[1], "--dump")))  
84 - { 74 + if ((argc == 3) && (!strcmp(argv[1], "--dump"))) {
85 QTC::TC("examples", "pdf-mod-info --dump"); 75 QTC::TC("examples", "pdf-mod-info --dump");
86 pdfDumpInfoDict(argv[2]); 76 pdfDumpInfoDict(argv[2]);
87 exit(0); 77 exit(0);
@@ -91,59 +81,43 @@ int main(int argc, char* argv[]) @@ -91,59 +81,43 @@ int main(int argc, char* argv[])
91 char* fl_out = 0; 81 char* fl_out = 0;
92 std::string cur_key; 82 std::string cur_key;
93 83
94 - for (int i = 1; i < argc; ++i)  
95 - {  
96 - if ((! strcmp(argv[i], "--in")) && (++i < argc))  
97 - { 84 + for (int i = 1; i < argc; ++i) {
  85 + if ((!strcmp(argv[i], "--in")) && (++i < argc)) {
98 fl_in = argv[i]; 86 fl_in = argv[i];
99 - }  
100 - else if ((! strcmp(argv[i], "--out")) && (++i < argc))  
101 - { 87 + } else if ((!strcmp(argv[i], "--out")) && (++i < argc)) {
102 fl_out = argv[i]; 88 fl_out = argv[i];
103 - }  
104 - else if (! strcmp(argv[i], "--static-id")) // don't document 89 + } else if (!strcmp(argv[i], "--static-id")) // don't document
105 { 90 {
106 static_id = true; // this should be used in test suites only 91 static_id = true; // this should be used in test suites only
107 - }  
108 - else if ((! strcmp(argv[i], "--key")) && (++i < argc))  
109 - { 92 + } else if ((!strcmp(argv[i], "--key")) && (++i < argc)) {
110 QTC::TC("examples", "pdf-mod-info -key"); 93 QTC::TC("examples", "pdf-mod-info -key");
111 cur_key = argv[i]; 94 cur_key = argv[i];
112 - if (! ((cur_key.length() > 0) && (cur_key.at(0) == '/')))  
113 - { 95 + if (!((cur_key.length() > 0) && (cur_key.at(0) == '/'))) {
114 cur_key = "/" + cur_key; 96 cur_key = "/" + cur_key;
115 } 97 }
116 Keys[cur_key] = ""; 98 Keys[cur_key] = "";
117 - }  
118 - else if ((! strcmp(argv[i], "--val")) && (++i < argc))  
119 - {  
120 - if (cur_key.empty())  
121 - { 99 + } else if ((!strcmp(argv[i], "--val")) && (++i < argc)) {
  100 + if (cur_key.empty()) {
122 QTC::TC("examples", "pdf-mod-info usage wrong val"); 101 QTC::TC("examples", "pdf-mod-info usage wrong val");
123 usage(); 102 usage();
124 } 103 }
125 QTC::TC("examples", "pdf-mod-info -val"); 104 QTC::TC("examples", "pdf-mod-info -val");
126 Keys[cur_key] = argv[i]; 105 Keys[cur_key] = argv[i];
127 cur_key.clear(); 106 cur_key.clear();
128 - }  
129 - else  
130 - { 107 + } else {
131 QTC::TC("examples", "pdf-mod-info usage junk"); 108 QTC::TC("examples", "pdf-mod-info usage junk");
132 usage(); 109 usage();
133 } 110 }
134 } 111 }
135 - if (! fl_in)  
136 - { 112 + if (!fl_in) {
137 QTC::TC("examples", "pdf-mod-info no in file"); 113 QTC::TC("examples", "pdf-mod-info no in file");
138 usage(); 114 usage();
139 } 115 }
140 - if (! fl_out)  
141 - { 116 + if (!fl_out) {
142 QTC::TC("examples", "pdf-mod-info in-place"); 117 QTC::TC("examples", "pdf-mod-info in-place");
143 fl_out = fl_in; 118 fl_out = fl_in;
144 } 119 }
145 - if (Keys.size() == 0)  
146 - { 120 + if (Keys.size() == 0) {
147 QTC::TC("examples", "pdf-mod-info no keys"); 121 QTC::TC("examples", "pdf-mod-info no keys");
148 usage(); 122 usage();
149 } 123 }
@@ -151,8 +125,7 @@ int main(int argc, char* argv[]) @@ -151,8 +125,7 @@ int main(int argc, char* argv[])
151 std::string fl_tmp = fl_out; 125 std::string fl_tmp = fl_out;
152 fl_tmp += ".tmp"; 126 fl_tmp += ".tmp";
153 127
154 - try  
155 - { 128 + try {
156 QPDF file; 129 QPDF file;
157 file.processFile(fl_in); 130 file.processFile(fl_in);
158 131
@@ -160,28 +133,22 @@ int main(int argc, char* argv[]) @@ -160,28 +133,22 @@ int main(int argc, char* argv[])
160 QPDFObjectHandle fileinfo; 133 QPDFObjectHandle fileinfo;
161 134
162 for (std::map<std::string, std::string>::const_iterator it = 135 for (std::map<std::string, std::string>::const_iterator it =
163 - Keys.begin(); Keys.end() != it; ++it)  
164 - {  
165 - if (! fileinfo.isInitialized())  
166 - {  
167 - if (filetrailer.hasKey("/Info"))  
168 - { 136 + Keys.begin();
  137 + Keys.end() != it;
  138 + ++it) {
  139 + if (!fileinfo.isInitialized()) {
  140 + if (filetrailer.hasKey("/Info")) {
169 QTC::TC("examples", "pdf-mod-info has info"); 141 QTC::TC("examples", "pdf-mod-info has info");
170 fileinfo = filetrailer.getKey("/Info"); 142 fileinfo = filetrailer.getKey("/Info");
171 - }  
172 - else  
173 - { 143 + } else {
174 QTC::TC("examples", "pdf-mod-info file no info"); 144 QTC::TC("examples", "pdf-mod-info file no info");
175 fileinfo = QPDFObjectHandle::newDictionary(); 145 fileinfo = QPDFObjectHandle::newDictionary();
176 filetrailer.replaceKey("/Info", fileinfo); 146 filetrailer.replaceKey("/Info", fileinfo);
177 } 147 }
178 } 148 }
179 - if (it->second == "")  
180 - { 149 + if (it->second == "") {
181 fileinfo.removeKey(it->first); 150 fileinfo.removeKey(it->first);
182 - }  
183 - else  
184 - { 151 + } else {
185 QPDFObjectHandle elt = fileinfo.newString(it->second); 152 QPDFObjectHandle elt = fileinfo.newString(it->second);
186 elt.makeDirect(); 153 elt.makeDirect();
187 fileinfo.replaceKey(it->first, elt); 154 fileinfo.replaceKey(it->first, elt);
@@ -192,21 +159,17 @@ int main(int argc, char* argv[]) @@ -192,21 +159,17 @@ int main(int argc, char* argv[])
192 w.setLinearization(true); 159 w.setLinearization(true);
193 w.setStaticID(static_id); // for testing only 160 w.setStaticID(static_id); // for testing only
194 w.write(); 161 w.write();
195 - }  
196 - catch (std::exception& e)  
197 - { 162 + } catch (std::exception& e) {
198 std::cerr << e.what() << std::endl; 163 std::cerr << e.what() << std::endl;
199 exit(2); 164 exit(2);
200 } 165 }
201 166
202 - try  
203 - {  
204 - (void) remove(fl_out);  
205 - QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out),  
206 - rename(fl_tmp.c_str(), fl_out));  
207 - }  
208 - catch (std::exception& e)  
209 - { 167 + try {
  168 + (void)remove(fl_out);
  169 + QUtil::os_wrapper(
  170 + "rename " + fl_tmp + " " + std::string(fl_out),
  171 + rename(fl_tmp.c_str(), fl_out));
  172 + } catch (std::exception& e) {
210 std::cerr << e.what() << std::endl; 173 std::cerr << e.what() << std::endl;
211 exit(2); 174 exit(2);
212 } 175 }
examples/pdf-name-number-tree.cc
@@ -3,26 +3,26 @@ @@ -3,26 +3,26 @@
3 #include <qpdf/QPDFNumberTreeObjectHelper.hh> 3 #include <qpdf/QPDFNumberTreeObjectHelper.hh>
4 #include <qpdf/QPDFWriter.hh> 4 #include <qpdf/QPDFWriter.hh>
5 #include <qpdf/QUtil.hh> 5 #include <qpdf/QUtil.hh>
6 -#include <iostream>  
7 #include <cstring> 6 #include <cstring>
  7 +#include <iostream>
8 8
9 static char const* whoami = 0; 9 static char const* whoami = 0;
10 10
11 -void usage() 11 +void
  12 +usage()
12 { 13 {
13 - std::cerr << "Usage: " << whoami << " outfile.pdf"  
14 - << std::endl 14 + std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl
15 << "Create some name/number trees and write to a file" 15 << "Create some name/number trees and write to a file"
16 << std::endl; 16 << std::endl;
17 exit(2); 17 exit(2);
18 } 18 }
19 19
20 -int main(int argc, char* argv[]) 20 +int
  21 +main(int argc, char* argv[])
21 { 22 {
22 whoami = QUtil::getWhoami(argv[0]); 23 whoami = QUtil::getWhoami(argv[0]);
23 24
24 - if (argc != 2)  
25 - { 25 + if (argc != 2) {
26 usage(); 26 usage();
27 } 27 }
28 28
@@ -62,8 +62,8 @@ int main(int argc, char* argv[]) @@ -62,8 +62,8 @@ int main(int argc, char* argv[])
62 name_tree.insert("R", QPDFObjectHandle::newUnicodeString("rook")); 62 name_tree.insert("R", QPDFObjectHandle::newUnicodeString("rook"));
63 name_tree.insert("B", QPDFObjectHandle::newUnicodeString("bishop")); 63 name_tree.insert("B", QPDFObjectHandle::newUnicodeString("bishop"));
64 name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight")); 64 name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight"));
65 - auto iter = name_tree.insert(  
66 - "P", QPDFObjectHandle::newUnicodeString("pawn")); 65 + auto iter =
  66 + name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn"));
67 // Look at the iterator 67 // Look at the iterator
68 std::cout << "just inserted " << iter->first << " -> " 68 std::cout << "just inserted " << iter->first << " -> "
69 << iter->second.unparse() << std::endl; 69 << iter->second.unparse() << std::endl;
@@ -77,28 +77,24 @@ int main(int argc, char* argv[]) @@ -77,28 +77,24 @@ int main(int argc, char* argv[])
77 77
78 // Use range-for iteration 78 // Use range-for iteration
79 std::cout << "Name tree items:" << std::endl; 79 std::cout << "Name tree items:" << std::endl;
80 - for (auto i: name_tree)  
81 - {  
82 - std::cout << " " << i.first << " -> "  
83 - << i.second.unparse() << std::endl; 80 + for (auto i : name_tree) {
  81 + std::cout << " " << i.first << " -> " << i.second.unparse()
  82 + << std::endl;
84 } 83 }
85 84
86 // This is a small tree, so everything will be at the root. We can 85 // This is a small tree, so everything will be at the root. We can
87 // look at it using dictionary and array iterators. 86 // look at it using dictionary and array iterators.
88 std::cout << "Keys in name tree object:" << std::endl; 87 std::cout << "Keys in name tree object:" << std::endl;
89 QPDFObjectHandle names; 88 QPDFObjectHandle names;
90 - for (auto const& i: name_tree_oh.ditems())  
91 - { 89 + for (auto const& i : name_tree_oh.ditems()) {
92 std::cout << i.first << std::endl; 90 std::cout << i.first << std::endl;
93 - if (i.first == "/Names")  
94 - { 91 + if (i.first == "/Names") {
95 names = i.second; 92 names = i.second;
96 } 93 }
97 } 94 }
98 // Values in names array: 95 // Values in names array:
99 std::cout << "Values in names:" << std::endl; 96 std::cout << "Values in names:" << std::endl;
100 - for (auto& i: names.aitems())  
101 - { 97 + for (auto& i : names.aitems()) {
102 std::cout << " " << i.unparse() << std::endl; 98 std::cout << " " << i.unparse() << std::endl;
103 } 99 }
104 100
@@ -112,8 +108,8 @@ int main(int argc, char* argv[]) @@ -112,8 +108,8 @@ int main(int argc, char* argv[])
112 108
113 // 10.2 API 109 // 10.2 API
114 iter = name_tree.find("Q"); 110 iter = name_tree.find("Q");
115 - std::cout << "Q: " << iter->first << " -> "  
116 - << iter->second.unparse() << std::endl; 111 + std::cout << "Q: " << iter->first << " -> " << iter->second.unparse()
  112 + << std::endl;
117 iter = name_tree.find("W"); 113 iter = name_tree.find("W");
118 std::cout << "W found: " << (iter != name_tree.end()) << std::endl; 114 std::cout << "W found: " << (iter != name_tree.end()) << std::endl;
119 // Allow find to return predecessor 115 // Allow find to return predecessor
@@ -146,22 +142,18 @@ int main(int argc, char* argv[]) @@ -146,22 +142,18 @@ int main(int argc, char* argv[])
146 auto number_tree_oh = number_tree.getObjectHandle(); 142 auto number_tree_oh = number_tree.getObjectHandle();
147 example.replaceKey("/NumberTree", number_tree_oh); 143 example.replaceKey("/NumberTree", number_tree_oh);
148 auto iter2 = number_tree.begin(); 144 auto iter2 = number_tree.begin();
149 - for (int i = 7; i <= 350; i += 7)  
150 - {  
151 - iter2.insertAfter(i, QPDFObjectHandle::newString(  
152 - "-" + QUtil::int_to_string(i) + "-")); 145 + for (int i = 7; i <= 350; i += 7) {
  146 + iter2.insertAfter(
  147 + i,
  148 + QPDFObjectHandle::newString("-" + QUtil::int_to_string(i) + "-"));
153 } 149 }
154 std::cout << "Numbers:" << std::endl; 150 std::cout << "Numbers:" << std::endl;
155 int n = 1; 151 int n = 1;
156 - for (auto& i: number_tree)  
157 - { 152 + for (auto& i : number_tree) {
158 std::cout << i.first << " -> " << i.second.getUTF8Value(); 153 std::cout << i.first << " -> " << i.second.getUTF8Value();
159 - if (n % 5)  
160 - { 154 + if (n % 5) {
161 std::cout << ", "; 155 std::cout << ", ";
162 - }  
163 - else  
164 - { 156 + } else {
165 std::cout << std::endl; 157 std::cout << std::endl;
166 } 158 }
167 ++n; 159 ++n;
@@ -171,28 +163,20 @@ int main(int argc, char* argv[]) @@ -171,28 +163,20 @@ int main(int argc, char* argv[])
171 // advances. This makes it possible to filter while iterating. 163 // advances. This makes it possible to filter while iterating.
172 // Remove all items that are multiples of 5. 164 // Remove all items that are multiples of 5.
173 iter2 = number_tree.begin(); 165 iter2 = number_tree.begin();
174 - while (iter2 != number_tree.end())  
175 - {  
176 - if (iter2->first % 5 == 0)  
177 - {  
178 - iter2.remove(); // also advances  
179 - }  
180 - else  
181 - { 166 + while (iter2 != number_tree.end()) {
  167 + if (iter2->first % 5 == 0) {
  168 + iter2.remove(); // also advances
  169 + } else {
182 ++iter2; 170 ++iter2;
183 } 171 }
184 } 172 }
185 std::cout << "Numbers after filtering:" << std::endl; 173 std::cout << "Numbers after filtering:" << std::endl;
186 n = 1; 174 n = 1;
187 - for (auto& i: number_tree)  
188 - { 175 + for (auto& i : number_tree) {
189 std::cout << i.first << " -> " << i.second.getUTF8Value(); 176 std::cout << i.first << " -> " << i.second.getUTF8Value();
190 - if (n % 5)  
191 - { 177 + if (n % 5) {
192 std::cout << ", "; 178 std::cout << ", ";
193 - }  
194 - else  
195 - { 179 + } else {
196 std::cout << std::endl; 180 std::cout << std::endl;
197 } 181 }
198 ++n; 182 ++n;
examples/pdf-npages.cc
1 #include <iostream> 1 #include <iostream>
2 -#include <string.h>  
3 #include <stdlib.h> 2 #include <stdlib.h>
  3 +#include <string.h>
4 4
5 #include <qpdf/QPDF.hh> 5 #include <qpdf/QPDF.hh>
6 #include <qpdf/QUtil.hh> 6 #include <qpdf/QUtil.hh>
7 7
8 static char const* whoami = 0; 8 static char const* whoami = 0;
9 9
10 -void usage() 10 +void
  11 +usage()
11 { 12 {
12 std::cerr << "Usage: " << whoami << " filename" << std::endl 13 std::cerr << "Usage: " << whoami << " filename" << std::endl
13 << "Prints the number of pages in filename" << std::endl; 14 << "Prints the number of pages in filename" << std::endl;
14 exit(2); 15 exit(2);
15 } 16 }
16 17
17 -int main(int argc, char* argv[]) 18 +int
  19 +main(int argc, char* argv[])
18 { 20 {
19 whoami = QUtil::getWhoami(argv[0]); 21 whoami = QUtil::getWhoami(argv[0]);
20 22
21 - if ((argc == 2) && (strcmp(argv[1], "--version") == 0))  
22 - { 23 + if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
23 std::cout << whoami << " version 1.3" << std::endl; 24 std::cout << whoami << " version 1.3" << std::endl;
24 exit(0); 25 exit(0);
25 } 26 }
26 27
27 - if (argc != 2)  
28 - { 28 + if (argc != 2) {
29 usage(); 29 usage();
30 } 30 }
31 char const* filename = argv[1]; 31 char const* filename = argv[1];
32 32
33 - try  
34 - { 33 + try {
35 QPDF pdf; 34 QPDF pdf;
36 pdf.processFile(filename); 35 pdf.processFile(filename);
37 QPDFObjectHandle root = pdf.getRoot(); 36 QPDFObjectHandle root = pdf.getRoot();
38 QPDFObjectHandle pages = root.getKey("/Pages"); 37 QPDFObjectHandle pages = root.getKey("/Pages");
39 QPDFObjectHandle count = pages.getKey("/Count"); 38 QPDFObjectHandle count = pages.getKey("/Count");
40 std::cout << count.getIntValue() << std::endl; 39 std::cout << count.getIntValue() << std::endl;
41 - }  
42 - catch (std::exception& e)  
43 - { 40 + } catch (std::exception& e) {
44 std::cerr << whoami << ": " << e.what() << std::endl; 41 std::cerr << whoami << ": " << e.what() << std::endl;
45 exit(2); 42 exit(2);
46 } 43 }
examples/pdf-overlay-page.cc
1 -#include <iostream>  
2 -#include <string.h>  
3 -#include <stdlib.h>  
4 #include <qpdf/QPDF.hh> 1 #include <qpdf/QPDF.hh>
5 #include <qpdf/QPDFPageDocumentHelper.hh> 2 #include <qpdf/QPDFPageDocumentHelper.hh>
6 #include <qpdf/QPDFPageObjectHelper.hh> 3 #include <qpdf/QPDFPageObjectHelper.hh>
7 #include <qpdf/QPDFWriter.hh> 4 #include <qpdf/QPDFWriter.hh>
8 #include <qpdf/QUtil.hh> 5 #include <qpdf/QUtil.hh>
  6 +#include <iostream>
  7 +#include <stdlib.h>
  8 +#include <string.h>
9 9
10 // This program demonstrates use of form XObjects to overlay a page 10 // This program demonstrates use of form XObjects to overlay a page
11 // from one file onto all pages of another file. The qpdf program's 11 // from one file onto all pages of another file. The qpdf program's
@@ -14,19 +14,17 @@ @@ -14,19 +14,17 @@
14 14
15 static char const* whoami = 0; 15 static char const* whoami = 0;
16 16
17 -void usage() 17 +void
  18 +usage()
18 { 19 {
19 - std::cerr << "Usage: " << whoami << " infile pagefile outfile"  
20 - << std::endl 20 + std::cerr << "Usage: " << whoami << " infile pagefile outfile" << std::endl
21 << "Stamp page 1 of pagefile on every page of infile," 21 << "Stamp page 1 of pagefile on every page of infile,"
22 - << " writing to outfile"  
23 - << std::endl; 22 + << " writing to outfile" << std::endl;
24 exit(2); 23 exit(2);
25 } 24 }
26 25
27 -static void stamp_page(char const* infile,  
28 - char const* stampfile,  
29 - char const* outfile) 26 +static void
  27 +stamp_page(char const* infile, char const* stampfile, char const* outfile)
30 { 28 {
31 QPDF inpdf; 29 QPDF inpdf;
32 inpdf.processFile(infile); 30 inpdf.processFile(infile);
@@ -45,8 +43,8 @@ static void stamp_page(char const* infile, @@ -45,8 +43,8 @@ static void stamp_page(char const* infile,
45 std::vector<QPDFPageObjectHelper> pages = 43 std::vector<QPDFPageObjectHelper> pages =
46 QPDFPageDocumentHelper(inpdf).getAllPages(); 44 QPDFPageDocumentHelper(inpdf).getAllPages();
47 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); 45 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
48 - iter != pages.end(); ++iter)  
49 - { 46 + iter != pages.end();
  47 + ++iter) {
50 QPDFPageObjectHelper& ph = *iter; 48 QPDFPageObjectHelper& ph = *iter;
51 49
52 // Find a unique resource name for the new form XObject 50 // Find a unique resource name for the new form XObject
@@ -57,11 +55,9 @@ static void stamp_page(char const* infile, @@ -57,11 +55,9 @@ static void stamp_page(char const* infile,
57 // Generate content to place the form XObject centered within 55 // Generate content to place the form XObject centered within
58 // destination page's trim box. 56 // destination page's trim box.
59 QPDFMatrix m; 57 QPDFMatrix m;
60 - std::string content =  
61 - ph.placeFormXObject(  
62 - stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);  
63 - if (! content.empty())  
64 - { 58 + std::string content = ph.placeFormXObject(
  59 + stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);
  60 + if (!content.empty()) {
65 // Append the content to the page's content. Surround the 61 // Append the content to the page's content. Surround the
66 // original content with q...Q to the new content from the 62 // original content with q...Q to the new content from the
67 // page's original content. 63 // page's original content.
@@ -80,28 +76,25 @@ static void stamp_page(char const* infile, @@ -80,28 +76,25 @@ static void stamp_page(char const* infile,
80 } 76 }
81 77
82 QPDFWriter w(inpdf, outfile); 78 QPDFWriter w(inpdf, outfile);
83 - w.setStaticID(true); // for testing only 79 + w.setStaticID(true); // for testing only
84 w.write(); 80 w.write();
85 } 81 }
86 82
87 -int main(int argc, char* argv[]) 83 +int
  84 +main(int argc, char* argv[])
88 { 85 {
89 whoami = QUtil::getWhoami(argv[0]); 86 whoami = QUtil::getWhoami(argv[0]);
90 87
91 - if (argc != 4)  
92 - { 88 + if (argc != 4) {
93 usage(); 89 usage();
94 } 90 }
95 char const* infile = argv[1]; 91 char const* infile = argv[1];
96 char const* stampfile = argv[2]; 92 char const* stampfile = argv[2];
97 char const* outfile = argv[3]; 93 char const* outfile = argv[3];
98 94
99 - try  
100 - { 95 + try {
101 stamp_page(infile, stampfile, outfile); 96 stamp_page(infile, stampfile, outfile);
102 - }  
103 - catch (std::exception &e)  
104 - { 97 + } catch (std::exception& e) {
105 std::cerr << whoami << ": " << e.what() << std::endl; 98 std::cerr << whoami << ": " << e.what() << std::endl;
106 exit(2); 99 exit(2);
107 } 100 }
examples/pdf-parse-content.cc
1 #include <iostream> 1 #include <iostream>
2 -#include <string.h>  
3 #include <stdlib.h> 2 #include <stdlib.h>
  3 +#include <string.h>
4 4
  5 +#include <qpdf/QIntC.hh>
5 #include <qpdf/QPDF.hh> 6 #include <qpdf/QPDF.hh>
6 #include <qpdf/QPDFPageDocumentHelper.hh> 7 #include <qpdf/QPDFPageDocumentHelper.hh>
7 #include <qpdf/QPDFPageObjectHelper.hh> 8 #include <qpdf/QPDFPageObjectHelper.hh>
8 #include <qpdf/QUtil.hh> 9 #include <qpdf/QUtil.hh>
9 -#include <qpdf/QIntC.hh>  
10 10
11 static char const* whoami = 0; 11 static char const* whoami = 0;
12 12
13 -void usage() 13 +void
  14 +usage()
14 { 15 {
15 std::cerr << "Usage: " << whoami << " filename page-number" << std::endl 16 std::cerr << "Usage: " << whoami << " filename page-number" << std::endl
16 << "Prints a dump of the objects in the content streams" 17 << "Prints a dump of the objects in the content streams"
@@ -38,17 +39,14 @@ ParserCallbacks::contentSize(size_t size) @@ -38,17 +39,14 @@ ParserCallbacks::contentSize(size_t size)
38 } 39 }
39 40
40 void 41 void
41 -ParserCallbacks::handleObject(QPDFObjectHandle obj,  
42 - size_t offset, size_t length) 42 +ParserCallbacks::handleObject(
  43 + QPDFObjectHandle obj, size_t offset, size_t length)
43 { 44 {
44 std::cout << obj.getTypeName() << ", offset=" << offset 45 std::cout << obj.getTypeName() << ", offset=" << offset
45 << ", length=" << length << ": "; 46 << ", length=" << length << ": ";
46 - if (obj.isInlineImage())  
47 - { 47 + if (obj.isInlineImage()) {
48 std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl; 48 std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
49 - }  
50 - else  
51 - { 49 + } else {
52 std::cout << obj.unparse() << std::endl; 50 std::cout << obj.unparse() << std::endl;
53 } 51 }
54 } 52 }
@@ -59,34 +57,30 @@ ParserCallbacks::handleEOF() @@ -59,34 +57,30 @@ ParserCallbacks::handleEOF()
59 std::cout << "-EOF-" << std::endl; 57 std::cout << "-EOF-" << std::endl;
60 } 58 }
61 59
62 -int main(int argc, char* argv[]) 60 +int
  61 +main(int argc, char* argv[])
63 { 62 {
64 whoami = QUtil::getWhoami(argv[0]); 63 whoami = QUtil::getWhoami(argv[0]);
65 64
66 - if (argc != 3)  
67 - { 65 + if (argc != 3) {
68 usage(); 66 usage();
69 } 67 }
70 char const* filename = argv[1]; 68 char const* filename = argv[1];
71 int pageno = QUtil::string_to_int(argv[2]); 69 int pageno = QUtil::string_to_int(argv[2]);
72 70
73 - try  
74 - { 71 + try {
75 QPDF pdf; 72 QPDF pdf;
76 pdf.processFile(filename); 73 pdf.processFile(filename);
77 std::vector<QPDFPageObjectHelper> pages = 74 std::vector<QPDFPageObjectHelper> pages =
78 QPDFPageDocumentHelper(pdf).getAllPages(); 75 QPDFPageDocumentHelper(pdf).getAllPages();
79 - if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size()))  
80 - { 76 + if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) {
81 usage(); 77 usage();
82 } 78 }
83 79
84 - QPDFPageObjectHelper& page = pages.at(QIntC::to_size(pageno-1)); 80 + QPDFPageObjectHelper& page = pages.at(QIntC::to_size(pageno - 1));
85 ParserCallbacks cb; 81 ParserCallbacks cb;
86 page.parseContents(&cb); 82 page.parseContents(&cb);
87 - }  
88 - catch (std::exception& e)  
89 - { 83 + } catch (std::exception& e) {
90 std::cerr << whoami << ": " << e.what() << std::endl; 84 std::cerr << whoami << ": " << e.what() << std::endl;
91 exit(2); 85 exit(2);
92 } 86 }
examples/pdf-set-form-values.cc
1 -#include <stdio.h>  
2 -#include <string.h>  
3 -#include <iostream>  
4 -#include <stdlib.h>  
5 #include <qpdf/QPDF.hh> 1 #include <qpdf/QPDF.hh>
6 -#include <qpdf/QPDFPageDocumentHelper.hh>  
7 #include <qpdf/QPDFAcroFormDocumentHelper.hh> 2 #include <qpdf/QPDFAcroFormDocumentHelper.hh>
  3 +#include <qpdf/QPDFPageDocumentHelper.hh>
8 #include <qpdf/QPDFWriter.hh> 4 #include <qpdf/QPDFWriter.hh>
9 #include <qpdf/QUtil.hh> 5 #include <qpdf/QUtil.hh>
  6 +#include <iostream>
  7 +#include <stdio.h>
  8 +#include <stdlib.h>
  9 +#include <string.h>
10 10
11 static char const* whoami = 0; 11 static char const* whoami = 0;
12 12
13 -void usage() 13 +void
  14 +usage()
14 { 15 {
15 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" 16 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value"
16 << std::endl 17 << std::endl
@@ -19,13 +20,12 @@ void usage() @@ -19,13 +20,12 @@ void usage()
19 exit(2); 20 exit(2);
20 } 21 }
21 22
22 -  
23 -int main(int argc, char* argv[]) 23 +int
  24 +main(int argc, char* argv[])
24 { 25 {
25 whoami = QUtil::getWhoami(argv[0]); 26 whoami = QUtil::getWhoami(argv[0]);
26 27
27 - if (argc != 4)  
28 - { 28 + if (argc != 4) {
29 usage(); 29 usage();
30 } 30 }
31 31
@@ -39,8 +39,7 @@ int main(int argc, char* argv[]) @@ -39,8 +39,7 @@ int main(int argc, char* argv[])
39 // to illustrate use of the helper classes around interactive 39 // to illustrate use of the helper classes around interactive
40 // forms. 40 // forms.
41 41
42 - try  
43 - { 42 + try {
44 QPDF qpdf; 43 QPDF qpdf;
45 qpdf.processFile(infilename); 44 qpdf.processFile(infilename);
46 45
@@ -55,8 +54,8 @@ int main(int argc, char* argv[]) @@ -55,8 +54,8 @@ int main(int argc, char* argv[])
55 std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); 54 std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
56 for (std::vector<QPDFPageObjectHelper>::iterator page_iter = 55 for (std::vector<QPDFPageObjectHelper>::iterator page_iter =
57 pages.begin(); 56 pages.begin();
58 - page_iter != pages.end(); ++page_iter)  
59 - { 57 + page_iter != pages.end();
  58 + ++page_iter) {
60 // Get all widget annotations for each page. Widget 59 // Get all widget annotations for each page. Widget
61 // annotations are the ones that contain the details of 60 // annotations are the ones that contain the details of
62 // what's in a form field. 61 // what's in a form field.
@@ -64,14 +63,13 @@ int main(int argc, char* argv[]) @@ -64,14 +63,13 @@ int main(int argc, char* argv[])
64 afdh.getWidgetAnnotationsForPage(*page_iter); 63 afdh.getWidgetAnnotationsForPage(*page_iter);
65 for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter = 64 for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
66 annotations.begin(); 65 annotations.begin();
67 - annot_iter != annotations.end(); ++annot_iter)  
68 - { 66 + annot_iter != annotations.end();
  67 + ++annot_iter) {
69 // For each annotation, find its associated field. If 68 // For each annotation, find its associated field. If
70 // it's a text field, set its value. 69 // it's a text field, set its value.
71 QPDFFormFieldObjectHelper ffh = 70 QPDFFormFieldObjectHelper ffh =
72 afdh.getFieldForAnnotation(*annot_iter); 71 afdh.getFieldForAnnotation(*annot_iter);
73 - if (ffh.getFieldType() == "/Tx")  
74 - { 72 + if (ffh.getFieldType() == "/Tx") {
75 // Set the value. Passing false as the second 73 // Set the value. Passing false as the second
76 // value prevents qpdf from setting 74 // value prevents qpdf from setting
77 // /NeedAppearances to true (but will not turn it 75 // /NeedAppearances to true (but will not turn it
@@ -92,9 +90,7 @@ int main(int argc, char* argv[]) @@ -92,9 +90,7 @@ int main(int argc, char* argv[])
92 QPDFWriter w(qpdf, outfilename); 90 QPDFWriter w(qpdf, outfilename);
93 w.setStaticID(true); // for testing only 91 w.setStaticID(true); // for testing only
94 w.write(); 92 w.write();
95 - }  
96 - catch (std::exception &e)  
97 - { 93 + } catch (std::exception& e) {
98 std::cerr << whoami << " processing file " << infilename << ": " 94 std::cerr << whoami << " processing file " << infilename << ": "
99 << e.what() << std::endl; 95 << e.what() << std::endl;
100 exit(2); 96 exit(2);
examples/pdf-split-pages.cc
@@ -4,22 +4,21 @@ @@ -4,22 +4,21 @@
4 // does. 4 // does.
5 // 5 //
6 6
  7 +#include <qpdf/QIntC.hh>
7 #include <qpdf/QPDF.hh> 8 #include <qpdf/QPDF.hh>
8 #include <qpdf/QPDFPageDocumentHelper.hh> 9 #include <qpdf/QPDFPageDocumentHelper.hh>
9 #include <qpdf/QPDFWriter.hh> 10 #include <qpdf/QPDFWriter.hh>
10 #include <qpdf/QUtil.hh> 11 #include <qpdf/QUtil.hh>
11 -#include <qpdf/QIntC.hh>  
12 12
  13 +#include <cstring>
13 #include <iostream> 14 #include <iostream>
14 #include <stdlib.h> 15 #include <stdlib.h>
15 #include <string> 16 #include <string>
16 -#include <cstring>  
17 17
18 static bool static_id = false; 18 static bool static_id = false;
19 19
20 -static void process(char const* whoami,  
21 - char const* infile,  
22 - std::string outprefix) 20 +static void
  21 +process(char const* whoami, char const* infile, std::string outprefix)
23 { 22 {
24 QPDF inpdf; 23 QPDF inpdf;
25 inpdf.processFile(infile); 24 inpdf.processFile(infile);
@@ -29,8 +28,8 @@ static void process(char const* whoami, @@ -29,8 +28,8 @@ static void process(char const* whoami,
29 QIntC::to_int(QUtil::uint_to_string(pages.size()).length()); 28 QIntC::to_int(QUtil::uint_to_string(pages.size()).length());
30 int pageno = 0; 29 int pageno = 0;
31 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); 30 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
32 - iter != pages.end(); ++iter)  
33 - { 31 + iter != pages.end();
  32 + ++iter) {
34 QPDFPageObjectHelper& page(*iter); 33 QPDFPageObjectHelper& page(*iter);
35 std::string outfile = 34 std::string outfile =
36 outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf"; 35 outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
@@ -38,8 +37,7 @@ static void process(char const* whoami, @@ -38,8 +37,7 @@ static void process(char const* whoami,
38 outpdf.emptyPDF(); 37 outpdf.emptyPDF();
39 QPDFPageDocumentHelper(outpdf).addPage(page, false); 38 QPDFPageDocumentHelper(outpdf).addPage(page, false);
40 QPDFWriter outpdfw(outpdf, outfile.c_str()); 39 QPDFWriter outpdfw(outpdf, outfile.c_str());
41 - if (static_id)  
42 - { 40 + if (static_id) {
43 // For the test suite, uncompress streams and use static 41 // For the test suite, uncompress streams and use static
44 // IDs. 42 // IDs.
45 outpdfw.setStaticID(true); // for testing only 43 outpdfw.setStaticID(true); // for testing only
@@ -49,34 +47,31 @@ static void process(char const* whoami, @@ -49,34 +47,31 @@ static void process(char const* whoami,
49 } 47 }
50 } 48 }
51 49
52 -void usage(char const* whoami) 50 +void
  51 +usage(char const* whoami)
53 { 52 {
54 std::cerr << "Usage: " << whoami << " infile outprefix" << std::endl; 53 std::cerr << "Usage: " << whoami << " infile outprefix" << std::endl;
55 exit(2); 54 exit(2);
56 } 55 }
57 56
58 -int main(int argc, char* argv[]) 57 +int
  58 +main(int argc, char* argv[])
59 { 59 {
60 char const* whoami = QUtil::getWhoami(argv[0]); 60 char const* whoami = QUtil::getWhoami(argv[0]);
61 61
62 // For test suite 62 // For test suite
63 - if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0))  
64 - { 63 + if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) {
65 static_id = true; 64 static_id = true;
66 --argc; 65 --argc;
67 ++argv; 66 ++argv;
68 } 67 }
69 68
70 - if (argc != 3)  
71 - { 69 + if (argc != 3) {
72 usage(whoami); 70 usage(whoami);
73 } 71 }
74 - try  
75 - { 72 + try {
76 process(whoami, argv[1], argv[2]); 73 process(whoami, argv[1], argv[2]);
77 - }  
78 - catch (std::exception const& e)  
79 - { 74 + } catch (std::exception const& e) {
80 std::cerr << whoami << ": exception: " << e.what() << std::endl; 75 std::cerr << whoami << ": exception: " << e.what() << std::endl;
81 return 2; 76 return 2;
82 } 77 }
examples/qpdf-job.cc
  1 +#include <qpdf/QIntC.hh>
1 #include <qpdf/QPDFJob.hh> 2 #include <qpdf/QPDFJob.hh>
2 #include <qpdf/QUtil.hh> 3 #include <qpdf/QUtil.hh>
3 -#include <qpdf/QIntC.hh>  
4 4
5 -#include <iostream>  
6 #include <cstring> 5 #include <cstring>
  6 +#include <iostream>
7 7
8 // This program is a simple demonstration of different ways to use the 8 // This program is a simple demonstration of different ways to use the
9 // QPDFJob API. 9 // QPDFJob API.
10 10
11 static char const* whoami = 0; 11 static char const* whoami = 0;
12 12
13 -static void usage() 13 +static void
  14 +usage()
14 { 15 {
15 - std::cerr  
16 - << "Usage: " << whoami << std::endl  
17 - << "This program linearizes the first page of in.pdf to out1.pdf,"  
18 - << " out2.pdf, and"  
19 - << std::endl  
20 - << " out3.pdf, each demonstrating a different way to use the"  
21 - << " QPDFJob API"  
22 - << std::endl; 16 + std::cerr << "Usage: " << whoami << std::endl
  17 + << "This program linearizes the first page of in.pdf to out1.pdf,"
  18 + << " out2.pdf, and" << std::endl
  19 + << " out3.pdf, each demonstrating a different way to use the"
  20 + << " QPDFJob API" << std::endl;
23 exit(2); 21 exit(2);
24 } 22 }
25 23
26 -int main(int argc, char* argv[]) 24 +int
  25 +main(int argc, char* argv[])
27 { 26 {
28 whoami = QUtil::getWhoami(argv[0]); 27 whoami = QUtil::getWhoami(argv[0]);
29 28
30 - if (argc != 1)  
31 - { 29 + if (argc != 1) {
32 usage(); 30 usage();
33 } 31 }
34 32
@@ -39,8 +37,7 @@ int main(int argc, char* argv[]) @@ -39,8 +37,7 @@ int main(int argc, char* argv[])
39 37
40 // Note that staticId is used for testing only. 38 // Note that staticId is used for testing only.
41 39
42 - try  
43 - { 40 + try {
44 // Use the config API 41 // Use the config API
45 QPDFJob j; 42 QPDFJob j;
46 j.config() 43 j.config()
@@ -54,15 +51,12 @@ int main(int argc, char* argv[]) @@ -54,15 +51,12 @@ int main(int argc, char* argv[])
54 ->checkConfiguration(); 51 ->checkConfiguration();
55 j.run(); 52 j.run();
56 std::cout << "out1 status: " << j.getExitCode() << std::endl; 53 std::cout << "out1 status: " << j.getExitCode() << std::endl;
57 - }  
58 - catch (std::exception& e)  
59 - { 54 + } catch (std::exception& e) {
60 std::cerr << "exception: " << e.what() << std::endl; 55 std::cerr << "exception: " << e.what() << std::endl;
61 return 2; 56 return 2;
62 } 57 }
63 58
64 - try  
65 - { 59 + try {
66 char const* new_argv[] = { 60 char const* new_argv[] = {
67 whoami, 61 whoami,
68 "in.pdf", 62 "in.pdf",
@@ -73,21 +67,17 @@ int main(int argc, char* argv[]) @@ -73,21 +67,17 @@ int main(int argc, char* argv[])
73 "1", 67 "1",
74 "--", 68 "--",
75 "--static-id", 69 "--static-id",
76 - nullptr  
77 - }; 70 + nullptr};
78 QPDFJob j; 71 QPDFJob j;
79 j.initializeFromArgv(new_argv); 72 j.initializeFromArgv(new_argv);
80 j.run(); 73 j.run();
81 std::cout << "out2 status: " << j.getExitCode() << std::endl; 74 std::cout << "out2 status: " << j.getExitCode() << std::endl;
82 - }  
83 - catch (std::exception& e)  
84 - { 75 + } catch (std::exception& e) {
85 std::cerr << "exception: " << e.what() << std::endl; 76 std::cerr << "exception: " << e.what() << std::endl;
86 return 2; 77 return 2;
87 } 78 }
88 79
89 - try  
90 - { 80 + try {
91 // Use the JSON API 81 // Use the JSON API
92 QPDFJob j; 82 QPDFJob j;
93 j.initializeFromJson(R"({ 83 j.initializeFromJson(R"({
@@ -105,9 +95,7 @@ int main(int argc, char* argv[]) @@ -105,9 +95,7 @@ int main(int argc, char* argv[])
105 )"); 95 )");
106 j.run(); 96 j.run();
107 std::cout << "out3 status: " << j.getExitCode() << std::endl; 97 std::cout << "out3 status: " << j.getExitCode() << std::endl;
108 - }  
109 - catch (std::exception& e)  
110 - { 98 + } catch (std::exception& e) {
111 std::cerr << "exception: " << e.what() << std::endl; 99 std::cerr << "exception: " << e.what() << std::endl;
112 return 2; 100 return 2;
113 } 101 }
examples/qpdfjob-c.c
@@ -10,13 +10,15 @@ @@ -10,13 +10,15 @@
10 10
11 static char const* whoami = 0; 11 static char const* whoami = 0;
12 12
13 -static void usage() 13 +static void
  14 +usage()
14 { 15 {
15 fprintf(stderr, "Usage: %s infile outfile\n", whoami); 16 fprintf(stderr, "Usage: %s infile outfile\n", whoami);
16 exit(2); 17 exit(2);
17 } 18 }
18 19
19 -int main(int argc, char* argv[]) 20 +int
  21 +main(int argc, char* argv[])
20 { 22 {
21 char* infile = NULL; 23 char* infile = NULL;
22 char* outfile = NULL; 24 char* outfile = NULL;
@@ -24,21 +26,15 @@ int main(int argc, char* argv[]) @@ -24,21 +26,15 @@ int main(int argc, char* argv[])
24 int r = 0; 26 int r = 0;
25 char* p = 0; 27 char* p = 0;
26 28
27 - if ((p = strrchr(argv[0], '/')) != NULL)  
28 - { 29 + if ((p = strrchr(argv[0], '/')) != NULL) {
29 whoami = p + 1; 30 whoami = p + 1;
30 - }  
31 - else if ((p = strrchr(argv[0], '\\')) != NULL)  
32 - { 31 + } else if ((p = strrchr(argv[0], '\\')) != NULL) {
33 whoami = p + 1; 32 whoami = p + 1;
34 - }  
35 - else  
36 - { 33 + } else {
37 whoami = argv[0]; 34 whoami = argv[0];
38 } 35 }
39 36
40 - if (argc != 3)  
41 - { 37 + if (argc != 3) {
42 usage(); 38 usage();
43 } 39 }
44 40
fuzz/ascii85_fuzzer.cc
1 -#include <qpdf/Pl_Discard.hh>  
2 #include <qpdf/Pl_ASCII85Decoder.hh> 1 #include <qpdf/Pl_ASCII85Decoder.hh>
  2 +#include <qpdf/Pl_Discard.hh>
3 #include <iostream> 3 #include <iostream>
4 #include <stdexcept> 4 #include <stdexcept>
5 5
@@ -34,17 +34,15 @@ FuzzHelper::doChecks() @@ -34,17 +34,15 @@ FuzzHelper::doChecks()
34 void 34 void
35 FuzzHelper::run() 35 FuzzHelper::run()
36 { 36 {
37 - try  
38 - { 37 + try {
39 doChecks(); 38 doChecks();
40 - }  
41 - catch (std::runtime_error const& e)  
42 - { 39 + } catch (std::runtime_error const& e) {
43 std::cerr << "runtime_error: " << e.what() << std::endl; 40 std::cerr << "runtime_error: " << e.what() << std::endl;
44 } 41 }
45 } 42 }
46 43
47 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 44 +extern "C" int
  45 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 { 46 {
49 FuzzHelper f(data, size); 47 FuzzHelper f(data, size);
50 f.run(); 48 f.run();
fuzz/dct_fuzzer.cc
1 -#include <qpdf/Pl_Discard.hh>  
2 #include <qpdf/Pl_DCT.hh> 1 #include <qpdf/Pl_DCT.hh>
  2 +#include <qpdf/Pl_Discard.hh>
  3 +#include <cstdlib>
3 #include <iostream> 4 #include <iostream>
4 #include <stdexcept> 5 #include <stdexcept>
5 -#include <cstdlib>  
6 6
7 class FuzzHelper 7 class FuzzHelper
8 { 8 {
@@ -35,17 +35,15 @@ FuzzHelper::doChecks() @@ -35,17 +35,15 @@ FuzzHelper::doChecks()
35 void 35 void
36 FuzzHelper::run() 36 FuzzHelper::run()
37 { 37 {
38 - try  
39 - { 38 + try {
40 doChecks(); 39 doChecks();
41 - }  
42 - catch (std::runtime_error const& e)  
43 - { 40 + } catch (std::runtime_error const& e) {
44 std::cerr << "runtime_error: " << e.what() << std::endl; 41 std::cerr << "runtime_error: " << e.what() << std::endl;
45 } 42 }
46 } 43 }
47 44
48 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 45 +extern "C" int
  46 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
49 { 47 {
50 #ifndef _WIN32 48 #ifndef _WIN32
51 // Used by jpeg library to work around false positives in memory 49 // Used by jpeg library to work around false positives in memory
fuzz/flate_fuzzer.cc
@@ -34,17 +34,15 @@ FuzzHelper::doChecks() @@ -34,17 +34,15 @@ FuzzHelper::doChecks()
34 void 34 void
35 FuzzHelper::run() 35 FuzzHelper::run()
36 { 36 {
37 - try  
38 - { 37 + try {
39 doChecks(); 38 doChecks();
40 - }  
41 - catch (std::runtime_error const& e)  
42 - { 39 + } catch (std::runtime_error const& e) {
43 std::cerr << "runtime_error: " << e.what() << std::endl; 40 std::cerr << "runtime_error: " << e.what() << std::endl;
44 } 41 }
45 } 42 }
46 43
47 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 44 +extern "C" int
  45 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 { 46 {
49 FuzzHelper f(data, size); 47 FuzzHelper f(data, size);
50 f.run(); 48 f.run();
fuzz/hex_fuzzer.cc
1 -#include <qpdf/Pl_Discard.hh>  
2 #include <qpdf/Pl_ASCIIHexDecoder.hh> 1 #include <qpdf/Pl_ASCIIHexDecoder.hh>
  2 +#include <qpdf/Pl_Discard.hh>
3 #include <iostream> 3 #include <iostream>
4 #include <stdexcept> 4 #include <stdexcept>
5 5
@@ -34,17 +34,15 @@ FuzzHelper::doChecks() @@ -34,17 +34,15 @@ FuzzHelper::doChecks()
34 void 34 void
35 FuzzHelper::run() 35 FuzzHelper::run()
36 { 36 {
37 - try  
38 - { 37 + try {
39 doChecks(); 38 doChecks();
40 - }  
41 - catch (std::runtime_error const& e)  
42 - { 39 + } catch (std::runtime_error const& e) {
43 std::cerr << "runtime_error: " << e.what() << std::endl; 40 std::cerr << "runtime_error: " << e.what() << std::endl;
44 } 41 }
45 } 42 }
46 43
47 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 44 +extern "C" int
  45 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 { 46 {
49 FuzzHelper f(data, size); 47 FuzzHelper f(data, size);
50 f.run(); 48 f.run();
fuzz/lzw_fuzzer.cc
@@ -34,17 +34,15 @@ FuzzHelper::doChecks() @@ -34,17 +34,15 @@ FuzzHelper::doChecks()
34 void 34 void
35 FuzzHelper::run() 35 FuzzHelper::run()
36 { 36 {
37 - try  
38 - { 37 + try {
39 doChecks(); 38 doChecks();
40 - }  
41 - catch (std::runtime_error const& e)  
42 - { 39 + } catch (std::runtime_error const& e) {
43 std::cerr << "runtime_error: " << e.what() << std::endl; 40 std::cerr << "runtime_error: " << e.what() << std::endl;
44 } 41 }
45 } 42 }
46 43
47 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 44 +extern "C" int
  45 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 { 46 {
49 FuzzHelper f(data, size); 47 FuzzHelper f(data, size);
50 f.run(); 48 f.run();
fuzz/pngpredictor_fuzzer.cc
@@ -34,17 +34,15 @@ FuzzHelper::doChecks() @@ -34,17 +34,15 @@ FuzzHelper::doChecks()
34 void 34 void
35 FuzzHelper::run() 35 FuzzHelper::run()
36 { 36 {
37 - try  
38 - { 37 + try {
39 doChecks(); 38 doChecks();
40 - }  
41 - catch (std::runtime_error const& e)  
42 - { 39 + } catch (std::runtime_error const& e) {
43 std::cerr << "runtime_error: " << e.what() << std::endl; 40 std::cerr << "runtime_error: " << e.what() << std::endl;
44 } 41 }
45 } 42 }
46 43
47 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 44 +extern "C" int
  45 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 { 46 {
49 FuzzHelper f(data, size); 47 FuzzHelper f(data, size);
50 f.run(); 48 f.run();
fuzz/qpdf_fuzzer.cc
1 -#include <qpdf/QPDF.hh>  
2 -#include <qpdf/QPDFWriter.hh>  
3 -#include <qpdf/QUtil.hh>  
4 -#include <qpdf/BufferInputSource.hh>  
5 #include <qpdf/Buffer.hh> 1 #include <qpdf/Buffer.hh>
  2 +#include <qpdf/BufferInputSource.hh>
6 #include <qpdf/Pl_Discard.hh> 3 #include <qpdf/Pl_Discard.hh>
  4 +#include <qpdf/QPDF.hh>
  5 +#include <qpdf/QPDFAcroFormDocumentHelper.hh>
  6 +#include <qpdf/QPDFOutlineDocumentHelper.hh>
7 #include <qpdf/QPDFPageDocumentHelper.hh> 7 #include <qpdf/QPDFPageDocumentHelper.hh>
8 -#include <qpdf/QPDFPageObjectHelper.hh>  
9 #include <qpdf/QPDFPageLabelDocumentHelper.hh> 8 #include <qpdf/QPDFPageLabelDocumentHelper.hh>
10 -#include <qpdf/QPDFOutlineDocumentHelper.hh>  
11 -#include <qpdf/QPDFAcroFormDocumentHelper.hh> 9 +#include <qpdf/QPDFPageObjectHelper.hh>
  10 +#include <qpdf/QPDFWriter.hh>
  11 +#include <qpdf/QUtil.hh>
12 #include <cstdlib> 12 #include <cstdlib>
13 13
14 class DiscardContents: public QPDFObjectHandle::ParserCallbacks 14 class DiscardContents: public QPDFObjectHandle::ParserCallbacks
15 { 15 {
16 public: 16 public:
17 - virtual ~DiscardContents() {}  
18 - virtual void handleObject(QPDFObjectHandle) {}  
19 - virtual void handleEOF() {} 17 + virtual ~DiscardContents()
  18 + {
  19 + }
  20 + virtual void
  21 + handleObject(QPDFObjectHandle)
  22 + {
  23 + }
  24 + virtual void
  25 + handleEOF()
  26 + {
  27 + }
20 }; 28 };
21 29
22 class FuzzHelper 30 class FuzzHelper
@@ -66,16 +74,11 @@ FuzzHelper::getWriter(PointerHolder&lt;QPDF&gt; qpdf) @@ -66,16 +74,11 @@ FuzzHelper::getWriter(PointerHolder&lt;QPDF&gt; qpdf)
66 void 74 void
67 FuzzHelper::doWrite(PointerHolder<QPDFWriter> w) 75 FuzzHelper::doWrite(PointerHolder<QPDFWriter> w)
68 { 76 {
69 - try  
70 - { 77 + try {
71 w->write(); 78 w->write();
72 - }  
73 - catch (QPDFExc const& e)  
74 - { 79 + } catch (QPDFExc const& e) {
75 std::cerr << e.what() << std::endl; 80 std::cerr << e.what() << std::endl;
76 - }  
77 - catch (std::runtime_error const& e)  
78 - { 81 + } catch (std::runtime_error const& e) {
79 std::cerr << e.what() << std::endl; 82 std::cerr << e.what() << std::endl;
80 } 83 }
81 } 84 }
@@ -133,14 +136,12 @@ FuzzHelper::testPages() @@ -133,14 +136,12 @@ FuzzHelper::testPages()
133 std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); 136 std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
134 DiscardContents discard_contents; 137 DiscardContents discard_contents;
135 int pageno = 0; 138 int pageno = 0;
136 - for (std::vector<QPDFPageObjectHelper>::iterator iter =  
137 - pages.begin();  
138 - iter != pages.end(); ++iter)  
139 - { 139 + for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
  140 + iter != pages.end();
  141 + ++iter) {
140 QPDFPageObjectHelper& page(*iter); 142 QPDFPageObjectHelper& page(*iter);
141 ++pageno; 143 ++pageno;
142 - try  
143 - { 144 + try {
144 page.coalesceContentStreams(); 145 page.coalesceContentStreams();
145 page.parseContents(&discard_contents); 146 page.parseContents(&discard_contents);
146 page.getImages(); 147 page.getImages();
@@ -153,16 +154,13 @@ FuzzHelper::testPages() @@ -153,16 +154,13 @@ FuzzHelper::testPages()
153 afdh.getWidgetAnnotationsForPage(page); 154 afdh.getWidgetAnnotationsForPage(page);
154 for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter = 155 for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
155 annotations.begin(); 156 annotations.begin();
156 - annot_iter != annotations.end(); ++annot_iter)  
157 - { 157 + annot_iter != annotations.end();
  158 + ++annot_iter) {
158 QPDFAnnotationObjectHelper& aoh = *annot_iter; 159 QPDFAnnotationObjectHelper& aoh = *annot_iter;
159 afdh.getFieldForAnnotation(aoh); 160 afdh.getFieldForAnnotation(aoh);
160 } 161 }
161 - }  
162 - catch (QPDFExc& e)  
163 - {  
164 - std::cerr << "page " << pageno << ": "  
165 - << e.what() << std::endl; 162 + } catch (QPDFExc& e) {
  163 + std::cerr << "page " << pageno << ": " << e.what() << std::endl;
166 } 164 }
167 } 165 }
168 } 166 }
@@ -171,16 +169,15 @@ void @@ -171,16 +169,15 @@ void
171 FuzzHelper::testOutlines() 169 FuzzHelper::testOutlines()
172 { 170 {
173 PointerHolder<QPDF> q = getQpdf(); 171 PointerHolder<QPDF> q = getQpdf();
174 - std::list<std::vector<QPDFOutlineObjectHelper> > queue; 172 + std::list<std::vector<QPDFOutlineObjectHelper>> queue;
175 QPDFOutlineDocumentHelper odh(*q); 173 QPDFOutlineDocumentHelper odh(*q);
176 queue.push_back(odh.getTopLevelOutlines()); 174 queue.push_back(odh.getTopLevelOutlines());
177 - while (! queue.empty())  
178 - { 175 + while (!queue.empty()) {
179 std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin()); 176 std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin());
180 for (std::vector<QPDFOutlineObjectHelper>::iterator iter = 177 for (std::vector<QPDFOutlineObjectHelper>::iterator iter =
181 outlines.begin(); 178 outlines.begin();
182 - iter != outlines.end(); ++iter)  
183 - { 179 + iter != outlines.end();
  180 + ++iter) {
184 QPDFOutlineObjectHelper& ol = *iter; 181 QPDFOutlineObjectHelper& ol = *iter;
185 ol.getDestPage(); 182 ol.getDestPage();
186 queue.push_back(ol.getKids()); 183 queue.push_back(ol.getKids());
@@ -208,21 +205,17 @@ FuzzHelper::run() @@ -208,21 +205,17 @@ FuzzHelper::run()
208 // std::runtime_error. Throwing any other kind of exception, 205 // std::runtime_error. Throwing any other kind of exception,
209 // segfaulting, or having a memory error (when built with 206 // segfaulting, or having a memory error (when built with
210 // appropriate sanitizers) will all cause abnormal exit. 207 // appropriate sanitizers) will all cause abnormal exit.
211 - try  
212 - { 208 + try {
213 doChecks(); 209 doChecks();
214 - }  
215 - catch (QPDFExc const& e)  
216 - { 210 + } catch (QPDFExc const& e) {
217 std::cerr << "QPDFExc: " << e.what() << std::endl; 211 std::cerr << "QPDFExc: " << e.what() << std::endl;
218 - }  
219 - catch (std::runtime_error const& e)  
220 - { 212 + } catch (std::runtime_error const& e) {
221 std::cerr << "runtime_error: " << e.what() << std::endl; 213 std::cerr << "runtime_error: " << e.what() << std::endl;
222 } 214 }
223 } 215 }
224 216
225 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 217 +extern "C" int
  218 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
226 { 219 {
227 #ifndef _WIN32 220 #ifndef _WIN32
228 // Used by jpeg library to work around false positives in memory 221 // Used by jpeg library to work around false positives in memory
fuzz/runlength_fuzzer.cc
@@ -34,17 +34,15 @@ FuzzHelper::doChecks() @@ -34,17 +34,15 @@ FuzzHelper::doChecks()
34 void 34 void
35 FuzzHelper::run() 35 FuzzHelper::run()
36 { 36 {
37 - try  
38 - { 37 + try {
39 doChecks(); 38 doChecks();
40 - }  
41 - catch (std::runtime_error const& e)  
42 - { 39 + } catch (std::runtime_error const& e) {
43 std::cerr << "runtime_error: " << e.what() << std::endl; 40 std::cerr << "runtime_error: " << e.what() << std::endl;
44 } 41 }
45 } 42 }
46 43
47 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 44 +extern "C" int
  45 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 { 46 {
49 FuzzHelper f(data, size); 47 FuzzHelper f(data, size);
50 f.run(); 48 f.run();
fuzz/standalone_fuzz_target_runner.cc
@@ -4,10 +4,10 @@ @@ -4,10 +4,10 @@
4 4
5 extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size); 5 extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size);
6 6
7 -int main(int argc, char **argv) 7 +int
  8 +main(int argc, char** argv)
8 { 9 {
9 - for (int i = 1; i < argc; i++)  
10 - { 10 + for (int i = 1; i < argc; i++) {
11 PointerHolder<char> file_buf; 11 PointerHolder<char> file_buf;
12 size_t size = 0; 12 size_t size = 0;
13 QUtil::read_file_into_memory(argv[i], file_buf, size); 13 QUtil::read_file_into_memory(argv[i], file_buf, size);
fuzz/tiffpredictor_fuzzer.cc
@@ -26,8 +26,8 @@ void @@ -26,8 +26,8 @@ void
26 FuzzHelper::doChecks() 26 FuzzHelper::doChecks()
27 { 27 {
28 Pl_Discard discard; 28 Pl_Discard discard;
29 - Pl_TIFFPredictor p("decoder", &discard,  
30 - Pl_TIFFPredictor::a_decode, 16, 1, 8); 29 + Pl_TIFFPredictor p(
  30 + "decoder", &discard, Pl_TIFFPredictor::a_decode, 16, 1, 8);
31 p.write(const_cast<unsigned char*>(data), size); 31 p.write(const_cast<unsigned char*>(data), size);
32 p.finish(); 32 p.finish();
33 } 33 }
@@ -35,17 +35,15 @@ FuzzHelper::doChecks() @@ -35,17 +35,15 @@ FuzzHelper::doChecks()
35 void 35 void
36 FuzzHelper::run() 36 FuzzHelper::run()
37 { 37 {
38 - try  
39 - { 38 + try {
40 doChecks(); 39 doChecks();
41 - }  
42 - catch (std::runtime_error const& e)  
43 - { 40 + } catch (std::runtime_error const& e) {
44 std::cerr << "runtime_error: " << e.what() << std::endl; 41 std::cerr << "runtime_error: " << e.what() << std::endl;
45 } 42 }
46 } 43 }
47 44
48 -extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) 45 +extern "C" int
  46 +LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
49 { 47 {
50 FuzzHelper f(data, size); 48 FuzzHelper f(data, size);
51 f.run(); 49 f.run();
include/qpdf/Buffer.hh
@@ -25,8 +25,8 @@ @@ -25,8 +25,8 @@
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 #include <qpdf/PointerHolder.hh> 26 #include <qpdf/PointerHolder.hh>
27 27
28 -#include <stddef.h>  
29 #include <memory> 28 #include <memory>
  29 +#include <stddef.h>
30 30
31 class Buffer 31 class Buffer
32 { 32 {
include/qpdf/BufferInputSource.hh
@@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
22 #ifndef QPDF_BUFFERINPUTSOURCE_HH 22 #ifndef QPDF_BUFFERINPUTSOURCE_HH
23 #define QPDF_BUFFERINPUTSOURCE_HH 23 #define QPDF_BUFFERINPUTSOURCE_HH
24 24
25 -#include <qpdf/InputSource.hh>  
26 #include <qpdf/Buffer.hh> 25 #include <qpdf/Buffer.hh>
  26 +#include <qpdf/InputSource.hh>
27 27
28 class BufferInputSource: public InputSource 28 class BufferInputSource: public InputSource
29 { 29 {
@@ -31,11 +31,11 @@ class BufferInputSource: public InputSource @@ -31,11 +31,11 @@ class BufferInputSource: public InputSource
31 // If own_memory is true, BufferInputSource will delete the buffer 31 // If own_memory is true, BufferInputSource will delete the buffer
32 // when finished with it. Otherwise, the caller owns the memory. 32 // when finished with it. Otherwise, the caller owns the memory.
33 QPDF_DLL 33 QPDF_DLL
34 - BufferInputSource(std::string const& description, Buffer* buf,  
35 - bool own_memory = false); 34 + BufferInputSource(
  35 + std::string const& description, Buffer* buf, bool own_memory = false);
36 QPDF_DLL 36 QPDF_DLL
37 - BufferInputSource(std::string const& description,  
38 - std::string const& contents); 37 + BufferInputSource(
  38 + std::string const& description, std::string const& contents);
39 QPDF_DLL 39 QPDF_DLL
40 virtual ~BufferInputSource(); 40 virtual ~BufferInputSource();
41 QPDF_DLL 41 QPDF_DLL
include/qpdf/Constants.h
@@ -29,16 +29,15 @@ @@ -29,16 +29,15 @@
29 29
30 /* Error Codes */ 30 /* Error Codes */
31 31
32 -enum qpdf_error_code_e  
33 -{ 32 +enum qpdf_error_code_e {
34 qpdf_e_success = 0, 33 qpdf_e_success = 0,
35 - qpdf_e_internal, /* logic/programming error -- indicates bug */  
36 - qpdf_e_system, /* I/O error, memory error, etc. */  
37 - qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */  
38 - qpdf_e_password, /* incorrect password for encrypted file */  
39 - qpdf_e_damaged_pdf, /* syntax errors or other damage in PDF */  
40 - qpdf_e_pages, /* erroneous or unsupported pages structure */  
41 - qpdf_e_object, /* type/bounds errors accessing objects */ 34 + qpdf_e_internal, /* logic/programming error -- indicates bug */
  35 + qpdf_e_system, /* I/O error, memory error, etc. */
  36 + qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */
  37 + qpdf_e_password, /* incorrect password for encrypted file */
  38 + qpdf_e_damaged_pdf, /* syntax errors or other damage in PDF */
  39 + qpdf_e_pages, /* erroneous or unsupported pages structure */
  40 + qpdf_e_object, /* type/bounds errors accessing objects */
42 }; 41 };
43 42
44 /* Object Types */ 43 /* Object Types */
@@ -75,62 +74,56 @@ enum qpdf_object_type_e { @@ -75,62 +74,56 @@ enum qpdf_object_type_e {
75 74
76 /* Write Parameters. See QPDFWriter.hh for details. */ 75 /* Write Parameters. See QPDFWriter.hh for details. */
77 76
78 -enum qpdf_object_stream_e  
79 -{  
80 - qpdf_o_disable = 0, /* disable object streams */  
81 - qpdf_o_preserve, /* preserve object streams */  
82 - qpdf_o_generate /* generate object streams */ 77 +enum qpdf_object_stream_e {
  78 + qpdf_o_disable = 0, /* disable object streams */
  79 + qpdf_o_preserve, /* preserve object streams */
  80 + qpdf_o_generate /* generate object streams */
83 }; 81 };
84 -enum qpdf_stream_data_e  
85 -{  
86 - qpdf_s_uncompress = 0, /* uncompress stream data */  
87 - qpdf_s_preserve, /* preserve stream data compression */  
88 - qpdf_s_compress /* compress stream data */ 82 +enum qpdf_stream_data_e {
  83 + qpdf_s_uncompress = 0, /* uncompress stream data */
  84 + qpdf_s_preserve, /* preserve stream data compression */
  85 + qpdf_s_compress /* compress stream data */
89 }; 86 };
90 87
91 /* Stream data flags */ 88 /* Stream data flags */
92 89
93 /* See pipeStreamData in QPDFObjectHandle.hh for details on these flags. */ 90 /* See pipeStreamData in QPDFObjectHandle.hh for details on these flags. */
94 -enum qpdf_stream_encode_flags_e  
95 -{  
96 - qpdf_ef_compress = 1 << 0, /* compress uncompressed streams */ 91 +enum qpdf_stream_encode_flags_e {
  92 + qpdf_ef_compress = 1 << 0, /* compress uncompressed streams */
97 qpdf_ef_normalize = 1 << 1, /* normalize content stream */ 93 qpdf_ef_normalize = 1 << 1, /* normalize content stream */
98 }; 94 };
99 -enum qpdf_stream_decode_level_e  
100 -{ 95 +enum qpdf_stream_decode_level_e {
101 /* These must be in order from less to more decoding. */ 96 /* These must be in order from less to more decoding. */
102 - qpdf_dl_none = 0, /* preserve all stream filters */  
103 - qpdf_dl_generalized, /* decode general-purpose filters */  
104 - qpdf_dl_specialized, /* also decode other non-lossy filters */  
105 - qpdf_dl_all /* also decode lossy filters */ 97 + qpdf_dl_none = 0, /* preserve all stream filters */
  98 + qpdf_dl_generalized, /* decode general-purpose filters */
  99 + qpdf_dl_specialized, /* also decode other non-lossy filters */
  100 + qpdf_dl_all /* also decode lossy filters */
106 }; 101 };
107 102
108 /* R3 Encryption Parameters */ 103 /* R3 Encryption Parameters */
109 104
110 -enum qpdf_r3_print_e  
111 -{  
112 - qpdf_r3p_full = 0, /* allow all printing */  
113 - qpdf_r3p_low, /* allow only low-resolution printing */  
114 - qpdf_r3p_none /* allow no printing */ 105 +enum qpdf_r3_print_e {
  106 + qpdf_r3p_full = 0, /* allow all printing */
  107 + qpdf_r3p_low, /* allow only low-resolution printing */
  108 + qpdf_r3p_none /* allow no printing */
115 }; 109 };
116 110
117 /* qpdf_r3_modify_e doesn't allow the full flexibility of the spec. It 111 /* qpdf_r3_modify_e doesn't allow the full flexibility of the spec. It
118 * corresponds to options in Acrobat 5's menus. The new interface in 112 * corresponds to options in Acrobat 5's menus. The new interface in
119 * QPDFWriter offers more granularity and no longer uses this type. 113 * QPDFWriter offers more granularity and no longer uses this type.
120 */ 114 */
121 -enum qpdf_r3_modify_e /* Allowed changes: */ 115 +enum qpdf_r3_modify_e /* Allowed changes: */
122 { 116 {
123 - qpdf_r3m_all = 0, /* All editing */  
124 - qpdf_r3m_annotate, /* Comments, fill forms, signing, assembly */  
125 - qpdf_r3m_form, /* Fill forms, signing, assembly */  
126 - qpdf_r3m_assembly, /* Only document assembly */  
127 - qpdf_r3m_none /* No modifications */ 117 + qpdf_r3m_all = 0, /* All editing */
  118 + qpdf_r3m_annotate, /* Comments, fill forms, signing, assembly */
  119 + qpdf_r3m_form, /* Fill forms, signing, assembly */
  120 + qpdf_r3m_assembly, /* Only document assembly */
  121 + qpdf_r3m_none /* No modifications */
128 }; 122 };
129 123
130 /* Form field flags from the PDF spec */ 124 /* Form field flags from the PDF spec */
131 125
132 -enum pdf_form_field_flag_e  
133 -{ 126 +enum pdf_form_field_flag_e {
134 /* flags that apply to all form fields */ 127 /* flags that apply to all form fields */
135 ff_all_read_only = 1 << 0, 128 ff_all_read_only = 1 << 0,
136 ff_all_required = 1 << 1, 129 ff_all_required = 1 << 1,
@@ -162,8 +155,7 @@ enum pdf_form_field_flag_e @@ -162,8 +155,7 @@ enum pdf_form_field_flag_e
162 155
163 /* Annotation flags from the PDF spec */ 156 /* Annotation flags from the PDF spec */
164 157
165 -enum pdf_annotation_flag_e  
166 -{ 158 +enum pdf_annotation_flag_e {
167 an_invisible = 1 << 0, 159 an_invisible = 1 << 0,
168 an_hidden = 1 << 1, 160 an_hidden = 1 << 1,
169 an_print = 1 << 2, 161 an_print = 1 << 2,
@@ -177,8 +169,7 @@ enum pdf_annotation_flag_e @@ -177,8 +169,7 @@ enum pdf_annotation_flag_e
177 }; 169 };
178 170
179 /* Encryption/password status for QPDFJob */ 171 /* Encryption/password status for QPDFJob */
180 -enum qpdf_encryption_status_e  
181 -{ 172 +enum qpdf_encryption_status_e {
182 qpdf_es_encrypted = 1 << 0, 173 qpdf_es_encrypted = 1 << 0,
183 qpdf_es_password_incorrect = 1 << 1 174 qpdf_es_password_incorrect = 1 << 1
184 }; 175 };
include/qpdf/DLL.h
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 #if (defined _WIN32 || defined __CYGWIN__) && defined(DLL_EXPORT) 32 #if (defined _WIN32 || defined __CYGWIN__) && defined(DLL_EXPORT)
33 # define QPDF_DLL __declspec(dllexport) 33 # define QPDF_DLL __declspec(dllexport)
34 #elif defined __GNUC__ 34 #elif defined __GNUC__
35 -# define QPDF_DLL __attribute__ ((visibility ("default"))) 35 +# define QPDF_DLL __attribute__((visibility("default")))
36 #else 36 #else
37 # define QPDF_DLL 37 # define QPDF_DLL
38 #endif 38 #endif
include/qpdf/InputSource.hh
@@ -23,12 +23,12 @@ @@ -23,12 +23,12 @@
23 #define QPDF_INPUTSOURCE_HH 23 #define QPDF_INPUTSOURCE_HH
24 24
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 -#include <qpdf/Types.h>  
27 #include <qpdf/PointerHolder.hh> 26 #include <qpdf/PointerHolder.hh>
  27 +#include <qpdf/Types.h>
28 28
  29 +#include <memory>
29 #include <stdio.h> 30 #include <stdio.h>
30 #include <string> 31 #include <string>
31 -#include <memory>  
32 32
33 class QPDF_DLL_CLASS InputSource 33 class QPDF_DLL_CLASS InputSource
34 { 34 {
@@ -71,13 +71,17 @@ class QPDF_DLL_CLASS InputSource @@ -71,13 +71,17 @@ class QPDF_DLL_CLASS InputSource
71 // methods return true and leave the input source positioned 71 // methods return true and leave the input source positioned
72 // wherever check() left it at the end of the matching pattern. 72 // wherever check() left it at the end of the matching pattern.
73 QPDF_DLL 73 QPDF_DLL
74 - bool findFirst(char const* start_chars,  
75 - qpdf_offset_t offset, size_t len,  
76 - Finder& finder); 74 + bool findFirst(
  75 + char const* start_chars,
  76 + qpdf_offset_t offset,
  77 + size_t len,
  78 + Finder& finder);
77 QPDF_DLL 79 QPDF_DLL
78 - bool findLast(char const* start_chars,  
79 - qpdf_offset_t offset, size_t len,  
80 - Finder& finder); 80 + bool findLast(
  81 + char const* start_chars,
  82 + qpdf_offset_t offset,
  83 + size_t len,
  84 + Finder& finder);
81 85
82 virtual qpdf_offset_t findAndSkipNextEOL() = 0; 86 virtual qpdf_offset_t findAndSkipNextEOL() = 0;
83 virtual std::string const& getName() const = 0; 87 virtual std::string const& getName() const = 0;
include/qpdf/JSON.hh
@@ -38,12 +38,12 @@ @@ -38,12 +38,12 @@
38 #include <qpdf/DLL.h> 38 #include <qpdf/DLL.h>
39 #include <qpdf/PointerHolder.hh> 39 #include <qpdf/PointerHolder.hh>
40 40
41 -#include <string>  
42 -#include <map>  
43 -#include <vector>  
44 -#include <list>  
45 #include <functional> 41 #include <functional>
  42 +#include <list>
  43 +#include <map>
46 #include <memory> 44 #include <memory>
  45 +#include <string>
  46 +#include <vector>
47 47
48 class JSON 48 class JSON
49 { 49 {
@@ -134,14 +134,13 @@ class JSON @@ -134,14 +134,13 @@ class JSON
134 f_optional = 1 << 0, 134 f_optional = 1 << 0,
135 }; 135 };
136 QPDF_DLL 136 QPDF_DLL
137 - bool checkSchema(JSON schema, unsigned long flags,  
138 - std::list<std::string>& errors); 137 + bool checkSchema(
  138 + JSON schema, unsigned long flags, std::list<std::string>& errors);
139 139
140 // Same as passing 0 for flags 140 // Same as passing 0 for flags
141 QPDF_DLL 141 QPDF_DLL
142 bool checkSchema(JSON schema, std::list<std::string>& errors); 142 bool checkSchema(JSON schema, std::list<std::string>& errors);
143 143
144 -  
145 // Create a JSON object from a string. 144 // Create a JSON object from a string.
146 QPDF_DLL 145 QPDF_DLL
147 static JSON parse(std::string const&); 146 static JSON parse(std::string const&);
@@ -198,11 +197,12 @@ class JSON @@ -198,11 +197,12 @@ class JSON
198 197
199 JSON(std::shared_ptr<JSON_value>); 198 JSON(std::shared_ptr<JSON_value>);
200 199
201 - static bool  
202 - checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,  
203 - unsigned long flags,  
204 - std::list<std::string>& errors,  
205 - std::string prefix); 200 + static bool checkSchemaInternal(
  201 + JSON_value* this_v,
  202 + JSON_value* sch_v,
  203 + unsigned long flags,
  204 + std::list<std::string>& errors,
  205 + std::string prefix);
206 206
207 class Members 207 class Members
208 { 208 {
@@ -222,5 +222,4 @@ class JSON @@ -222,5 +222,4 @@ class JSON
222 PointerHolder<Members> m; 222 PointerHolder<Members> m;
223 }; 223 };
224 224
225 -  
226 #endif // JSON_HH 225 #endif // JSON_HH
include/qpdf/Pipeline.hh
@@ -47,8 +47,8 @@ @@ -47,8 +47,8 @@
47 #include <qpdf/DLL.h> 47 #include <qpdf/DLL.h>
48 #include <qpdf/PointerHolder.hh> 48 #include <qpdf/PointerHolder.hh>
49 49
50 -#include <string>  
51 #include <memory> 50 #include <memory>
  51 +#include <string>
52 52
53 class QPDF_DLL_CLASS Pipeline 53 class QPDF_DLL_CLASS Pipeline
54 { 54 {
include/qpdf/Pl_Buffer.hh
@@ -33,9 +33,9 @@ @@ -33,9 +33,9 @@
33 // For this pipeline, "next" may be null. If a next pointer is 33 // For this pipeline, "next" may be null. If a next pointer is
34 // provided, this pipeline will also pass the data through to it. 34 // provided, this pipeline will also pass the data through to it.
35 35
  36 +#include <qpdf/Buffer.hh>
36 #include <qpdf/Pipeline.hh> 37 #include <qpdf/Pipeline.hh>
37 #include <qpdf/PointerHolder.hh> 38 #include <qpdf/PointerHolder.hh>
38 -#include <qpdf/Buffer.hh>  
39 39
40 #include <memory> 40 #include <memory>
41 41
@@ -68,7 +68,7 @@ class Pl_Buffer: public Pipeline @@ -68,7 +68,7 @@ class Pl_Buffer: public Pipeline
68 // a buffer of size *len allocated with malloc(). It is the 68 // a buffer of size *len allocated with malloc(). It is the
69 // caller's responsibility to call free() on the buffer. 69 // caller's responsibility to call free() on the buffer.
70 QPDF_DLL 70 QPDF_DLL
71 - void getMallocBuffer(unsigned char **buf, size_t* len); 71 + void getMallocBuffer(unsigned char** buf, size_t* len);
72 72
73 private: 73 private:
74 class Members 74 class Members
include/qpdf/Pl_Count.hh
@@ -25,8 +25,8 @@ @@ -25,8 +25,8 @@
25 // This pipeline is reusable; i.e., it is safe to call write() after 25 // This pipeline is reusable; i.e., it is safe to call write() after
26 // calling finish(). 26 // calling finish().
27 27
28 -#include <qpdf/Types.h>  
29 #include <qpdf/Pipeline.hh> 28 #include <qpdf/Pipeline.hh>
  29 +#include <qpdf/Types.h>
30 30
31 class Pl_Count: public Pipeline 31 class Pl_Count: public Pipeline
32 { 32 {
include/qpdf/Pl_DCT.hh
@@ -52,12 +52,14 @@ class Pl_DCT: public Pipeline @@ -52,12 +52,14 @@ class Pl_DCT: public Pipeline
52 52
53 // Constructor for compressing image data 53 // Constructor for compressing image data
54 QPDF_DLL 54 QPDF_DLL
55 - Pl_DCT(char const* identifier, Pipeline* next,  
56 - JDIMENSION image_width,  
57 - JDIMENSION image_height,  
58 - int components,  
59 - J_COLOR_SPACE color_space,  
60 - CompressConfig* config_callback = 0); 55 + Pl_DCT(
  56 + char const* identifier,
  57 + Pipeline* next,
  58 + JDIMENSION image_width,
  59 + JDIMENSION image_height,
  60 + int components,
  61 + J_COLOR_SPACE color_space,
  62 + CompressConfig* config_callback = 0);
61 63
62 QPDF_DLL 64 QPDF_DLL
63 virtual ~Pl_DCT(); 65 virtual ~Pl_DCT();
@@ -82,13 +84,14 @@ class Pl_DCT: public Pipeline @@ -82,13 +84,14 @@ class Pl_DCT: public Pipeline
82 ~Members(); 84 ~Members();
83 85
84 private: 86 private:
85 - Members(action_e action,  
86 - char const* buf_description,  
87 - JDIMENSION image_width = 0,  
88 - JDIMENSION image_height = 0,  
89 - int components = 1,  
90 - J_COLOR_SPACE color_space = JCS_GRAYSCALE,  
91 - CompressConfig* config_callback = 0); 87 + Members(
  88 + action_e action,
  89 + char const* buf_description,
  90 + JDIMENSION image_width = 0,
  91 + JDIMENSION image_height = 0,
  92 + int components = 1,
  93 + J_COLOR_SPACE color_space = JCS_GRAYSCALE,
  94 + CompressConfig* config_callback = 0);
92 Members(Members const&); 95 Members(Members const&);
93 96
94 action_e action; 97 action_e action;
include/qpdf/Pl_Flate.hh
@@ -35,8 +35,11 @@ class Pl_Flate: public Pipeline @@ -35,8 +35,11 @@ class Pl_Flate: public Pipeline
35 enum action_e { a_inflate, a_deflate }; 35 enum action_e { a_inflate, a_deflate };
36 36
37 QPDF_DLL 37 QPDF_DLL
38 - Pl_Flate(char const* identifier, Pipeline* next,  
39 - action_e action, unsigned int out_bufsize = def_bufsize); 38 + Pl_Flate(
  39 + char const* identifier,
  40 + Pipeline* next,
  41 + action_e action,
  42 + unsigned int out_bufsize = def_bufsize);
40 QPDF_DLL 43 QPDF_DLL
41 virtual ~Pl_Flate(); 44 virtual ~Pl_Flate();
42 45
include/qpdf/Pl_QPDFTokenizer.hh
@@ -24,10 +24,10 @@ @@ -24,10 +24,10 @@
24 24
25 #include <qpdf/Pipeline.hh> 25 #include <qpdf/Pipeline.hh>
26 26
27 -#include <qpdf/QPDFTokenizer.hh> 27 +#include <qpdf/Pl_Buffer.hh>
28 #include <qpdf/PointerHolder.hh> 28 #include <qpdf/PointerHolder.hh>
29 #include <qpdf/QPDFObjectHandle.hh> 29 #include <qpdf/QPDFObjectHandle.hh>
30 -#include <qpdf/Pl_Buffer.hh> 30 +#include <qpdf/QPDFTokenizer.hh>
31 31
32 #include <memory> 32 #include <memory>
33 33
@@ -48,9 +48,10 @@ class Pl_QPDFTokenizer: public Pipeline @@ -48,9 +48,10 @@ class Pl_QPDFTokenizer: public Pipeline
48 // pipeline that the token filter writes to. If next is not 48 // pipeline that the token filter writes to. If next is not
49 // provided, any output written by the filter will be discarded. 49 // provided, any output written by the filter will be discarded.
50 QPDF_DLL 50 QPDF_DLL
51 - Pl_QPDFTokenizer(char const* identifier,  
52 - QPDFObjectHandle::TokenFilter* filter,  
53 - Pipeline* next = 0); 51 + Pl_QPDFTokenizer(
  52 + char const* identifier,
  53 + QPDFObjectHandle::TokenFilter* filter,
  54 + Pipeline* next = 0);
54 QPDF_DLL 55 QPDF_DLL
55 virtual ~Pl_QPDFTokenizer(); 56 virtual ~Pl_QPDFTokenizer();
56 QPDF_DLL 57 QPDF_DLL
include/qpdf/Pl_RunLength.hh
@@ -30,8 +30,7 @@ class Pl_RunLength: public Pipeline @@ -30,8 +30,7 @@ class Pl_RunLength: public Pipeline
30 enum action_e { a_encode, a_decode }; 30 enum action_e { a_encode, a_decode };
31 31
32 QPDF_DLL 32 QPDF_DLL
33 - Pl_RunLength(char const* identifier, Pipeline* next,  
34 - action_e action); 33 + Pl_RunLength(char const* identifier, Pipeline* next, action_e action);
35 QPDF_DLL 34 QPDF_DLL
36 virtual ~Pl_RunLength(); 35 virtual ~Pl_RunLength();
37 36
include/qpdf/PointerHolder.hh
@@ -187,18 +187,16 @@ class PointerHolder @@ -187,18 +187,16 @@ class PointerHolder
187 } 187 }
188 ~Data() 188 ~Data()
189 { 189 {
190 - if (array)  
191 - {  
192 - delete [] this->pointer;  
193 - }  
194 - else  
195 - { 190 + if (array) {
  191 + delete[] this->pointer;
  192 + } else {
196 delete this->pointer; 193 delete this->pointer;
197 } 194 }
198 } 195 }
199 T* pointer; 196 T* pointer;
200 bool array; 197 bool array;
201 int refcount; 198 int refcount;
  199 +
202 private: 200 private:
203 Data(Data const&) = delete; 201 Data(Data const&) = delete;
204 Data& operator=(Data const&) = delete; 202 Data& operator=(Data const&) = delete;
@@ -208,7 +206,7 @@ class PointerHolder @@ -208,7 +206,7 @@ class PointerHolder
208 #if POINTERHOLDER_TRANSITION >= 1 206 #if POINTERHOLDER_TRANSITION >= 1
209 explicit 207 explicit
210 #endif // POINTERHOLDER_TRANSITION >= 1 208 #endif // POINTERHOLDER_TRANSITION >= 1
211 - PointerHolder(T* pointer = 0) 209 + PointerHolder(T* pointer = 0)
212 { 210 {
213 this->init(new Data(pointer, false)); 211 this->init(new Data(pointer, false));
214 } 212 }
@@ -222,16 +220,17 @@ class PointerHolder @@ -222,16 +220,17 @@ class PointerHolder
222 { 220 {
223 this->copy(rhs); 221 this->copy(rhs);
224 } 222 }
225 - PointerHolder& operator=(PointerHolder const& rhs) 223 + PointerHolder&
  224 + operator=(PointerHolder const& rhs)
226 { 225 {
227 - if (this != &rhs)  
228 - { 226 + if (this != &rhs) {
229 this->destroy(); 227 this->destroy();
230 this->copy(rhs); 228 this->copy(rhs);
231 } 229 }
232 return *this; 230 return *this;
233 } 231 }
234 - PointerHolder& operator=(decltype(nullptr)) 232 + PointerHolder&
  233 + operator=(decltype(nullptr))
235 { 234 {
236 this->operator=(PointerHolder<T>()); 235 this->operator=(PointerHolder<T>());
237 return *this; 236 return *this;
@@ -240,21 +239,25 @@ class PointerHolder @@ -240,21 +239,25 @@ class PointerHolder
240 { 239 {
241 this->destroy(); 240 this->destroy();
242 } 241 }
243 - bool operator==(PointerHolder const& rhs) const 242 + bool
  243 + operator==(PointerHolder const& rhs) const
244 { 244 {
245 return this->data->pointer == rhs.data->pointer; 245 return this->data->pointer == rhs.data->pointer;
246 } 246 }
247 - bool operator==(decltype(nullptr)) const 247 + bool
  248 + operator==(decltype(nullptr)) const
248 { 249 {
249 return this->data->pointer == nullptr; 250 return this->data->pointer == nullptr;
250 } 251 }
251 - bool operator<(PointerHolder const& rhs) const 252 + bool
  253 + operator<(PointerHolder const& rhs) const
252 { 254 {
253 return this->data->pointer < rhs.data->pointer; 255 return this->data->pointer < rhs.data->pointer;
254 } 256 }
255 257
256 // get() is for interface compatibility with std::shared_ptr 258 // get() is for interface compatibility with std::shared_ptr
257 - T* get() const 259 + T*
  260 + get() const
258 { 261 {
259 return this->data->pointer; 262 return this->data->pointer;
260 } 263 }
@@ -264,70 +267,79 @@ class PointerHolder @@ -264,70 +267,79 @@ class PointerHolder
264 #if POINTERHOLDER_TRANSITION >= 2 267 #if POINTERHOLDER_TRANSITION >= 2
265 [[deprecated("use PointerHolder<T>::get() instead of getPointer()")]] 268 [[deprecated("use PointerHolder<T>::get() instead of getPointer()")]]
266 #endif // POINTERHOLDER_TRANSITION >= 2 269 #endif // POINTERHOLDER_TRANSITION >= 2
267 - T* getPointer() 270 + T*
  271 + getPointer()
268 { 272 {
269 return this->data->pointer; 273 return this->data->pointer;
270 } 274 }
271 #if POINTERHOLDER_TRANSITION >= 2 275 #if POINTERHOLDER_TRANSITION >= 2
272 [[deprecated("use PointerHolder<T>::get() instead of getPointer()")]] 276 [[deprecated("use PointerHolder<T>::get() instead of getPointer()")]]
273 #endif // POINTERHOLDER_TRANSITION >= 2 277 #endif // POINTERHOLDER_TRANSITION >= 2
274 - T const* getPointer() const 278 + T const*
  279 + getPointer() const
275 { 280 {
276 return this->data->pointer; 281 return this->data->pointer;
277 } 282 }
278 #if POINTERHOLDER_TRANSITION >= 2 283 #if POINTERHOLDER_TRANSITION >= 2
279 [[deprecated("use use_count() instead of getRefcount()")]] 284 [[deprecated("use use_count() instead of getRefcount()")]]
280 #endif // POINTERHOLDER_TRANSITION >= 2 285 #endif // POINTERHOLDER_TRANSITION >= 2
281 - int getRefcount() const 286 + int
  287 + getRefcount() const
282 { 288 {
283 return this->data->refcount; 289 return this->data->refcount;
284 } 290 }
285 291
286 // use_count() is for compatibility with std::shared_ptr 292 // use_count() is for compatibility with std::shared_ptr
287 - long use_count() 293 + long
  294 + use_count()
288 { 295 {
289 return static_cast<long>(this->data->refcount); 296 return static_cast<long>(this->data->refcount);
290 } 297 }
291 298
292 - T const& operator*() const 299 + T const&
  300 + operator*() const
293 { 301 {
294 return *this->data->pointer; 302 return *this->data->pointer;
295 } 303 }
296 - T& operator*() 304 + T&
  305 + operator*()
297 { 306 {
298 return *this->data->pointer; 307 return *this->data->pointer;
299 } 308 }
300 309
301 - T const* operator->() const 310 + T const*
  311 + operator->() const
302 { 312 {
303 return this->data->pointer; 313 return this->data->pointer;
304 } 314 }
305 - T* operator->() 315 + T*
  316 + operator->()
306 { 317 {
307 return this->data->pointer; 318 return this->data->pointer;
308 } 319 }
309 320
310 private: 321 private:
311 - void init(Data* data) 322 + void
  323 + init(Data* data)
312 { 324 {
313 this->data = data; 325 this->data = data;
314 ++this->data->refcount; 326 ++this->data->refcount;
315 } 327 }
316 - void copy(PointerHolder const& rhs) 328 + void
  329 + copy(PointerHolder const& rhs)
317 { 330 {
318 this->init(rhs.data); 331 this->init(rhs.data);
319 } 332 }
320 - void destroy() 333 + void
  334 + destroy()
321 { 335 {
322 bool gone = false; 336 bool gone = false;
323 { 337 {
324 - if (--this->data->refcount == 0)  
325 - { 338 + if (--this->data->refcount == 0) {
326 gone = true; 339 gone = true;
327 } 340 }
328 } 341 }
329 - if (gone)  
330 - { 342 + if (gone) {
331 delete this->data; 343 delete this->data;
332 } 344 }
333 } 345 }
@@ -335,7 +347,7 @@ class PointerHolder @@ -335,7 +347,7 @@ class PointerHolder
335 Data* data; 347 Data* data;
336 }; 348 };
337 349
338 -template<typename T, typename... _Args> 350 +template <typename T, typename... _Args>
339 inline PointerHolder<T> 351 inline PointerHolder<T>
340 make_pointer_holder(_Args&&... __args) 352 make_pointer_holder(_Args&&... __args)
341 { 353 {
include/qpdf/QIntC.hh
@@ -24,12 +24,12 @@ @@ -24,12 +24,12 @@
24 24
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 #include <qpdf/Types.h> 26 #include <qpdf/Types.h>
27 -#include <stdexcept> 27 +#include <cassert>
28 #include <iostream> 28 #include <iostream>
29 #include <limits> 29 #include <limits>
30 -#include <sstream>  
31 -#include <cassert>  
32 #include <locale> 30 #include <locale>
  31 +#include <sstream>
  32 +#include <stdexcept>
33 #include <type_traits> 33 #include <type_traits>
34 34
35 // This namespace provides safe integer conversion that detects 35 // This namespace provides safe integer conversion that detects
@@ -51,9 +51,11 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -51,9 +51,11 @@ namespace QIntC // QIntC = qpdf Integer Conversion
51 // throws a range_error otherwise. This class is specialized for 51 // throws a range_error otherwise. This class is specialized for
52 // each permutation of signed/unsigned for the From and To 52 // each permutation of signed/unsigned for the From and To
53 // classes. 53 // classes.
54 - template <typename From, typename To,  
55 - bool From_signed = std::numeric_limits<From>::is_signed,  
56 - bool To_signed = std::numeric_limits<To>::is_signed> 54 + template <
  55 + typename From,
  56 + typename To,
  57 + bool From_signed = std::numeric_limits<From>::is_signed,
  58 + bool To_signed = std::numeric_limits<To>::is_signed>
57 class IntConverter 59 class IntConverter
58 { 60 {
59 }; 61 };
@@ -62,17 +64,16 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -62,17 +64,16 @@ namespace QIntC // QIntC = qpdf Integer Conversion
62 class IntConverter<From, To, false, false> 64 class IntConverter<From, To, false, false>
63 { 65 {
64 public: 66 public:
65 - static To convert(From const& i) 67 + static To
  68 + convert(From const& i)
66 { 69 {
67 // From and To are both unsigned. 70 // From and To are both unsigned.
68 - if (i > std::numeric_limits<To>::max())  
69 - { 71 + if (i > std::numeric_limits<To>::max()) {
70 std::ostringstream msg; 72 std::ostringstream msg;
71 msg.imbue(std::locale::classic()); 73 msg.imbue(std::locale::classic());
72 - msg << "integer out of range converting " << i  
73 - << " from a "  
74 - << sizeof(From) << "-byte unsigned type to a "  
75 - << sizeof(To) << "-byte unsigned type"; 74 + msg << "integer out of range converting " << i << " from a "
  75 + << sizeof(From) << "-byte unsigned type to a " << sizeof(To)
  76 + << "-byte unsigned type";
76 throw std::range_error(msg.str()); 77 throw std::range_error(msg.str());
77 } 78 }
78 return static_cast<To>(i); 79 return static_cast<To>(i);
@@ -83,18 +84,17 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -83,18 +84,17 @@ namespace QIntC // QIntC = qpdf Integer Conversion
83 class IntConverter<From, To, true, true> 84 class IntConverter<From, To, true, true>
84 { 85 {
85 public: 86 public:
86 - static To convert(From const& i) 87 + static To
  88 + convert(From const& i)
87 { 89 {
88 // From and To are both signed. 90 // From and To are both signed.
89 if ((i < std::numeric_limits<To>::min()) || 91 if ((i < std::numeric_limits<To>::min()) ||
90 - (i > std::numeric_limits<To>::max()))  
91 - { 92 + (i > std::numeric_limits<To>::max())) {
92 std::ostringstream msg; 93 std::ostringstream msg;
93 msg.imbue(std::locale::classic()); 94 msg.imbue(std::locale::classic());
94 - msg << "integer out of range converting " << i  
95 - << " from a "  
96 - << sizeof(From) << "-byte signed type to a "  
97 - << sizeof(To) << "-byte signed type"; 95 + msg << "integer out of range converting " << i << " from a "
  96 + << sizeof(From) << "-byte signed type to a " << sizeof(To)
  97 + << "-byte signed type";
98 throw std::range_error(msg.str()); 98 throw std::range_error(msg.str());
99 } 99 }
100 return static_cast<To>(i); 100 return static_cast<To>(i);
@@ -105,20 +105,19 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -105,20 +105,19 @@ namespace QIntC // QIntC = qpdf Integer Conversion
105 class IntConverter<From, To, true, false> 105 class IntConverter<From, To, true, false>
106 { 106 {
107 public: 107 public:
108 - static To convert(From const& i) 108 + static To
  109 + convert(From const& i)
109 { 110 {
110 // From is signed, and To is unsigned. If i > 0, it's safe to 111 // From is signed, and To is unsigned. If i > 0, it's safe to
111 // convert it to the corresponding unsigned type and to 112 // convert it to the corresponding unsigned type and to
112 // compare with To's max. 113 // compare with To's max.
113 auto ii = static_cast<typename to_u<From>::type>(i); 114 auto ii = static_cast<typename to_u<From>::type>(i);
114 - if ((i < 0) || (ii > std::numeric_limits<To>::max()))  
115 - { 115 + if ((i < 0) || (ii > std::numeric_limits<To>::max())) {
116 std::ostringstream msg; 116 std::ostringstream msg;
117 msg.imbue(std::locale::classic()); 117 msg.imbue(std::locale::classic());
118 - msg << "integer out of range converting " << i  
119 - << " from a "  
120 - << sizeof(From) << "-byte signed type to a "  
121 - << sizeof(To) << "-byte unsigned type"; 118 + msg << "integer out of range converting " << i << " from a "
  119 + << sizeof(From) << "-byte signed type to a " << sizeof(To)
  120 + << "-byte unsigned type";
122 throw std::range_error(msg.str()); 121 throw std::range_error(msg.str());
123 } 122 }
124 return static_cast<To>(i); 123 return static_cast<To>(i);
@@ -129,20 +128,19 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -129,20 +128,19 @@ namespace QIntC // QIntC = qpdf Integer Conversion
129 class IntConverter<From, To, false, true> 128 class IntConverter<From, To, false, true>
130 { 129 {
131 public: 130 public:
132 - static To convert(From const& i) 131 + static To
  132 + convert(From const& i)
133 { 133 {
134 // From is unsigned, and to is signed. Convert To's max to the 134 // From is unsigned, and to is signed. Convert To's max to the
135 // unsigned version of To and compare i against that. 135 // unsigned version of To and compare i against that.
136 auto maxval = static_cast<typename to_u<To>::type>( 136 auto maxval = static_cast<typename to_u<To>::type>(
137 std::numeric_limits<To>::max()); 137 std::numeric_limits<To>::max());
138 - if (i > maxval)  
139 - { 138 + if (i > maxval) {
140 std::ostringstream msg; 139 std::ostringstream msg;
141 msg.imbue(std::locale::classic()); 140 msg.imbue(std::locale::classic());
142 - msg << "integer out of range converting " << i  
143 - << " from a "  
144 - << sizeof(From) << "-byte unsigned type to a "  
145 - << sizeof(To) << "-byte signed type"; 141 + msg << "integer out of range converting " << i << " from a "
  142 + << sizeof(From) << "-byte unsigned type to a " << sizeof(To)
  143 + << "-byte signed type";
146 throw std::range_error(msg.str()); 144 throw std::range_error(msg.str());
147 } 145 }
148 return static_cast<To>(i); 146 return static_cast<To>(i);
@@ -152,97 +150,105 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -152,97 +150,105 @@ namespace QIntC // QIntC = qpdf Integer Conversion
152 // Specific converters. The return type of each function must match 150 // Specific converters. The return type of each function must match
153 // the second template parameter to IntConverter. 151 // the second template parameter to IntConverter.
154 template <typename T> 152 template <typename T>
155 - char to_char(T const& i) 153 + char
  154 + to_char(T const& i)
156 { 155 {
157 return IntConverter<T, char>::convert(i); 156 return IntConverter<T, char>::convert(i);
158 } 157 }
159 158
160 template <typename T> 159 template <typename T>
161 - unsigned char to_uchar(T const& i) 160 + unsigned char
  161 + to_uchar(T const& i)
162 { 162 {
163 return IntConverter<T, unsigned char>::convert(i); 163 return IntConverter<T, unsigned char>::convert(i);
164 } 164 }
165 165
166 template <typename T> 166 template <typename T>
167 - short to_short(T const& i) 167 + short
  168 + to_short(T const& i)
168 { 169 {
169 return IntConverter<T, short>::convert(i); 170 return IntConverter<T, short>::convert(i);
170 } 171 }
171 172
172 template <typename T> 173 template <typename T>
173 - unsigned short to_ushort(T const& i) 174 + unsigned short
  175 + to_ushort(T const& i)
174 { 176 {
175 return IntConverter<T, unsigned short>::convert(i); 177 return IntConverter<T, unsigned short>::convert(i);
176 } 178 }
177 179
178 template <typename T> 180 template <typename T>
179 - int to_int(T const& i) 181 + int
  182 + to_int(T const& i)
180 { 183 {
181 return IntConverter<T, int>::convert(i); 184 return IntConverter<T, int>::convert(i);
182 } 185 }
183 186
184 template <typename T> 187 template <typename T>
185 - unsigned int to_uint(T const& i) 188 + unsigned int
  189 + to_uint(T const& i)
186 { 190 {
187 return IntConverter<T, unsigned int>::convert(i); 191 return IntConverter<T, unsigned int>::convert(i);
188 } 192 }
189 193
190 template <typename T> 194 template <typename T>
191 - size_t to_size(T const& i) 195 + size_t
  196 + to_size(T const& i)
192 { 197 {
193 return IntConverter<T, size_t>::convert(i); 198 return IntConverter<T, size_t>::convert(i);
194 } 199 }
195 200
196 template <typename T> 201 template <typename T>
197 - qpdf_offset_t to_offset(T const& i) 202 + qpdf_offset_t
  203 + to_offset(T const& i)
198 { 204 {
199 return IntConverter<T, qpdf_offset_t>::convert(i); 205 return IntConverter<T, qpdf_offset_t>::convert(i);
200 } 206 }
201 207
202 template <typename T> 208 template <typename T>
203 - long to_long(T const& i) 209 + long
  210 + to_long(T const& i)
204 { 211 {
205 - return IntConverter<T, long >::convert(i); 212 + return IntConverter<T, long>::convert(i);
206 } 213 }
207 214
208 template <typename T> 215 template <typename T>
209 - unsigned long to_ulong(T const& i) 216 + unsigned long
  217 + to_ulong(T const& i)
210 { 218 {
211 - return IntConverter<T, unsigned long >::convert(i); 219 + return IntConverter<T, unsigned long>::convert(i);
212 } 220 }
213 221
214 template <typename T> 222 template <typename T>
215 - long long to_longlong(T const& i) 223 + long long
  224 + to_longlong(T const& i)
216 { 225 {
217 return IntConverter<T, long long>::convert(i); 226 return IntConverter<T, long long>::convert(i);
218 } 227 }
219 228
220 template <typename T> 229 template <typename T>
221 - unsigned long long to_ulonglong(T const& i) 230 + unsigned long long
  231 + to_ulonglong(T const& i)
222 { 232 {
223 return IntConverter<T, unsigned long long>::convert(i); 233 return IntConverter<T, unsigned long long>::convert(i);
224 } 234 }
225 235
226 template <typename T> 236 template <typename T>
227 - void range_check(T const& cur, T const& delta) 237 + void
  238 + range_check(T const& cur, T const& delta)
228 { 239 {
229 - if ((delta > 0) != (cur > 0))  
230 - { 240 + if ((delta > 0) != (cur > 0)) {
231 return; 241 return;
232 } 242 }
233 243
234 - if ((delta > 0) &&  
235 - ((std::numeric_limits<T>::max() - cur) < delta))  
236 - { 244 + if ((delta > 0) && ((std::numeric_limits<T>::max() - cur) < delta)) {
237 std::ostringstream msg; 245 std::ostringstream msg;
238 msg.imbue(std::locale::classic()); 246 msg.imbue(std::locale::classic());
239 msg << "adding " << delta << " to " << cur 247 msg << "adding " << delta << " to " << cur
240 << " would cause an integer overflow"; 248 << " would cause an integer overflow";
241 throw std::range_error(msg.str()); 249 throw std::range_error(msg.str());
242 - }  
243 - else if ((delta < 0) &&  
244 - ((std::numeric_limits<T>::min() - cur) > delta))  
245 - { 250 + } else if (
  251 + (delta < 0) && ((std::numeric_limits<T>::min() - cur) > delta)) {
246 std::ostringstream msg; 252 std::ostringstream msg;
247 msg.imbue(std::locale::classic()); 253 msg.imbue(std::locale::classic());
248 msg << "adding " << delta << " to " << cur 254 msg << "adding " << delta << " to " << cur
@@ -252,25 +258,21 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -252,25 +258,21 @@ namespace QIntC // QIntC = qpdf Integer Conversion
252 } 258 }
253 259
254 template <typename T> 260 template <typename T>
255 - void range_check_substract(T const& cur, T const& delta) 261 + void
  262 + range_check_substract(T const& cur, T const& delta)
256 { 263 {
257 - if ((delta >= 0) == (cur >= 0))  
258 - { 264 + if ((delta >= 0) == (cur >= 0)) {
259 return; 265 return;
260 } 266 }
261 267
262 - if ((delta > 0) &&  
263 - ((std::numeric_limits<T>::min() + delta) > cur))  
264 - { 268 + if ((delta > 0) && ((std::numeric_limits<T>::min() + delta) > cur)) {
265 std::ostringstream msg; 269 std::ostringstream msg;
266 msg.imbue(std::locale::classic()); 270 msg.imbue(std::locale::classic());
267 msg << "subtracting " << delta << " from " << cur 271 msg << "subtracting " << delta << " from " << cur
268 << " would cause an integer underflow"; 272 << " would cause an integer underflow";
269 throw std::range_error(msg.str()); 273 throw std::range_error(msg.str());
270 - }  
271 - else if ((delta < 0) &&  
272 - ((std::numeric_limits<T>::max() + delta) < cur))  
273 - { 274 + } else if (
  275 + (delta < 0) && ((std::numeric_limits<T>::max() + delta) < cur)) {
274 std::ostringstream msg; 276 std::ostringstream msg;
275 msg.imbue(std::locale::classic()); 277 msg.imbue(std::locale::classic());
276 msg << "subtracting " << delta << " from " << cur 278 msg << "subtracting " << delta << " from " << cur
@@ -278,6 +280,6 @@ namespace QIntC // QIntC = qpdf Integer Conversion @@ -278,6 +280,6 @@ namespace QIntC // QIntC = qpdf Integer Conversion
278 throw std::range_error(msg.str()); 280 throw std::range_error(msg.str());
279 } 281 }
280 } 282 }
281 -}; 283 +}; // namespace QIntC
282 284
283 #endif // QINTC_HH 285 #endif // QINTC_HH
include/qpdf/QPDF.hh
@@ -25,26 +25,25 @@ @@ -25,26 +25,25 @@
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 #include <qpdf/Types.h> 26 #include <qpdf/Types.h>
27 27
  28 +#include <functional>
  29 +#include <iostream>
  30 +#include <list>
  31 +#include <map>
  32 +#include <memory>
28 #include <stdio.h> 33 #include <stdio.h>
29 #include <string> 34 #include <string>
30 -#include <map>  
31 -#include <list>  
32 -#include <iostream>  
33 #include <vector> 35 #include <vector>
34 -#include <functional>  
35 -#include <memory>  
36 36
  37 +#include <qpdf/Buffer.hh>
  38 +#include <qpdf/InputSource.hh>
  39 +#include <qpdf/PDFVersion.hh>
37 #include <qpdf/QIntC.hh> 40 #include <qpdf/QIntC.hh>
38 #include <qpdf/QPDFExc.hh> 41 #include <qpdf/QPDFExc.hh>
39 -#include <qpdf/QPDFObjectHandle.hh>  
40 #include <qpdf/QPDFObjGen.hh> 42 #include <qpdf/QPDFObjGen.hh>
41 -#include <qpdf/QPDFXRefEntry.hh>  
42 #include <qpdf/QPDFObjectHandle.hh> 43 #include <qpdf/QPDFObjectHandle.hh>
43 -#include <qpdf/QPDFTokenizer.hh>  
44 #include <qpdf/QPDFStreamFilter.hh> 44 #include <qpdf/QPDFStreamFilter.hh>
45 -#include <qpdf/Buffer.hh>  
46 -#include <qpdf/InputSource.hh>  
47 -#include <qpdf/PDFVersion.hh> 45 +#include <qpdf/QPDFTokenizer.hh>
  46 +#include <qpdf/QPDFXRefEntry.hh>
48 47
49 class QPDF_Stream; 48 class QPDF_Stream;
50 class BitStream; 49 class BitStream;
@@ -87,24 +86,29 @@ class QPDF @@ -87,24 +86,29 @@ class QPDF
87 // file will be closed at the end. Otherwise, the caller is 86 // file will be closed at the end. Otherwise, the caller is
88 // responsible for closing the file. 87 // responsible for closing the file.
89 QPDF_DLL 88 QPDF_DLL
90 - void processFile(char const* description, FILE* file,  
91 - bool close_file, char const* password = 0); 89 + void processFile(
  90 + char const* description,
  91 + FILE* file,
  92 + bool close_file,
  93 + char const* password = 0);
92 94
93 // Parse a PDF file loaded into a memory buffer. This works 95 // Parse a PDF file loaded into a memory buffer. This works
94 // exactly like processFile except that the PDF file is in memory 96 // exactly like processFile except that the PDF file is in memory
95 // instead of on disk. The description appears in any warning or 97 // instead of on disk. The description appears in any warning or
96 // error message in place of the file name. 98 // error message in place of the file name.
97 QPDF_DLL 99 QPDF_DLL
98 - void processMemoryFile(char const* description,  
99 - char const* buf, size_t length,  
100 - char const* password = 0); 100 + void processMemoryFile(
  101 + char const* description,
  102 + char const* buf,
  103 + size_t length,
  104 + char const* password = 0);
101 105
102 // Parse a PDF file loaded from a custom InputSource. If you have 106 // Parse a PDF file loaded from a custom InputSource. If you have
103 // your own method of retrieving a PDF file, you can subclass 107 // your own method of retrieving a PDF file, you can subclass
104 // InputSource and use this method. 108 // InputSource and use this method.
105 QPDF_DLL 109 QPDF_DLL
106 - void processInputSource(PointerHolder<InputSource>,  
107 - char const* password = 0); 110 + void
  111 + processInputSource(PointerHolder<InputSource>, char const* password = 0);
108 112
109 // Close or otherwise release the input source. Once this has been 113 // Close or otherwise release the input source. Once this has been
110 // called, no other methods of qpdf can be called safely except 114 // called, no other methods of qpdf can be called safely except
@@ -149,7 +153,7 @@ class QPDF @@ -149,7 +153,7 @@ class QPDF
149 QPDF_DLL 153 QPDF_DLL
150 static void registerStreamFilter( 154 static void registerStreamFilter(
151 std::string const& filter_name, 155 std::string const& filter_name,
152 - std::function<std::shared_ptr<QPDFStreamFilter> ()> factory); 156 + std::function<std::shared_ptr<QPDFStreamFilter>()> factory);
153 157
154 // Parameter settings 158 // Parameter settings
155 159
@@ -312,8 +316,7 @@ class QPDF @@ -312,8 +316,7 @@ class QPDF
312 QPDF_DLL 316 QPDF_DLL
313 void swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2); 317 void swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2);
314 QPDF_DLL 318 QPDF_DLL
315 - void swapObjects(int objid1, int generation1,  
316 - int objid2, int generation2); 319 + void swapObjects(int objid1, int generation1, int objid2, int generation2);
317 320
318 // Replace a reserved object. This is a wrapper around 321 // Replace a reserved object. This is a wrapper around
319 // replaceObject but it guarantees that the underlying object is a 322 // replaceObject but it guarantees that the underlying object is a
@@ -321,8 +324,7 @@ class QPDF @@ -321,8 +324,7 @@ class QPDF
321 // to replacement. 324 // to replacement.
322 QPDF_DLL 325 QPDF_DLL
323 void 326 void
324 - replaceReserved(QPDFObjectHandle reserved,  
325 - QPDFObjectHandle replacement); 327 + replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement);
326 328
327 // Copy an object from another QPDF to this one. Starting with 329 // Copy an object from another QPDF to this one. Starting with
328 // qpdf version 8.3.0, it is no longer necessary to keep the 330 // qpdf version 8.3.0, it is no longer necessary to keep the
@@ -377,13 +379,19 @@ class QPDF @@ -377,13 +379,19 @@ class QPDF
377 class EncryptionData 379 class EncryptionData
378 { 380 {
379 public: 381 public:
380 -  
381 // This class holds data read from the encryption dictionary. 382 // This class holds data read from the encryption dictionary.
382 - EncryptionData(int V, int R, int Length_bytes, int P,  
383 - std::string const& O, std::string const& U,  
384 - std::string const& OE, std::string const& UE,  
385 - std::string const& Perms,  
386 - std::string const& id1, bool encrypt_metadata) : 383 + EncryptionData(
  384 + int V,
  385 + int R,
  386 + int Length_bytes,
  387 + int P,
  388 + std::string const& O,
  389 + std::string const& U,
  390 + std::string const& OE,
  391 + std::string const& UE,
  392 + std::string const& Perms,
  393 + std::string const& id1,
  394 + bool encrypt_metadata) :
387 V(V), 395 V(V),
388 R(R), 396 R(R),
389 Length_bytes(Length_bytes), 397 Length_bytes(Length_bytes),
@@ -412,11 +420,12 @@ class QPDF @@ -412,11 +420,12 @@ class QPDF
412 420
413 void setO(std::string const&); 421 void setO(std::string const&);
414 void setU(std::string const&); 422 void setU(std::string const&);
415 - void setV5EncryptionParameters(std::string const& O,  
416 - std::string const& OE,  
417 - std::string const& U,  
418 - std::string const& UE,  
419 - std::string const& Perms); 423 + void setV5EncryptionParameters(
  424 + std::string const& O,
  425 + std::string const& OE,
  426 + std::string const& U,
  427 + std::string const& UE,
  428 + std::string const& Perms);
420 429
421 private: 430 private:
422 EncryptionData(EncryptionData const&) = delete; 431 EncryptionData(EncryptionData const&) = delete;
@@ -442,10 +451,13 @@ class QPDF @@ -442,10 +451,13 @@ class QPDF
442 bool isEncrypted(int& R, int& P); 451 bool isEncrypted(int& R, int& P);
443 452
444 QPDF_DLL 453 QPDF_DLL
445 - bool isEncrypted(int& R, int& P, int& V,  
446 - encryption_method_e& stream_method,  
447 - encryption_method_e& string_method,  
448 - encryption_method_e& file_method); 454 + bool isEncrypted(
  455 + int& R,
  456 + int& P,
  457 + int& V,
  458 + encryption_method_e& stream_method,
  459 + encryption_method_e& string_method,
  460 + encryption_method_e& file_method);
449 461
450 QPDF_DLL 462 QPDF_DLL
451 bool ownerPasswordMatched() const; 463 bool ownerPasswordMatched() const;
@@ -480,26 +492,44 @@ class QPDF @@ -480,26 +492,44 @@ class QPDF
480 static void trim_user_password(std::string& user_password); 492 static void trim_user_password(std::string& user_password);
481 QPDF_DLL 493 QPDF_DLL
482 static std::string compute_data_key( 494 static std::string compute_data_key(
483 - std::string const& encryption_key, int objid, int generation,  
484 - bool use_aes, int encryption_V, int encryption_R); 495 + std::string const& encryption_key,
  496 + int objid,
  497 + int generation,
  498 + bool use_aes,
  499 + int encryption_V,
  500 + int encryption_R);
485 QPDF_DLL 501 QPDF_DLL
486 static std::string compute_encryption_key( 502 static std::string compute_encryption_key(
487 std::string const& password, EncryptionData const& data); 503 std::string const& password, EncryptionData const& data);
488 504
489 QPDF_DLL 505 QPDF_DLL
490 static void compute_encryption_O_U( 506 static void compute_encryption_O_U(
491 - char const* user_password, char const* owner_password,  
492 - int V, int R, int key_len, int P, bool encrypt_metadata, 507 + char const* user_password,
  508 + char const* owner_password,
  509 + int V,
  510 + int R,
  511 + int key_len,
  512 + int P,
  513 + bool encrypt_metadata,
493 std::string const& id1, 514 std::string const& id1,
494 - std::string& O, std::string& U); 515 + std::string& O,
  516 + std::string& U);
495 QPDF_DLL 517 QPDF_DLL
496 static void compute_encryption_parameters_V5( 518 static void compute_encryption_parameters_V5(
497 - char const* user_password, char const* owner_password,  
498 - int V, int R, int key_len, int P, bool encrypt_metadata, 519 + char const* user_password,
  520 + char const* owner_password,
  521 + int V,
  522 + int R,
  523 + int key_len,
  524 + int P,
  525 + bool encrypt_metadata,
499 std::string const& id1, 526 std::string const& id1,
500 std::string& encryption_key, 527 std::string& encryption_key,
501 - std::string& O, std::string& U,  
502 - std::string& OE, std::string& UE, std::string& Perms); 528 + std::string& O,
  529 + std::string& U,
  530 + std::string& OE,
  531 + std::string& UE,
  532 + std::string& Perms);
503 // Return the full user password as stored in the PDF file. For 533 // Return the full user password as stored in the PDF file. For
504 // files encrypted with 40-bit or 128-bit keys, the user password 534 // files encrypted with 40-bit or 128-bit keys, the user password
505 // can be recovered when the file is opened using the owner 535 // can be recovered when the file is opened using the owner
@@ -587,8 +617,9 @@ class QPDF @@ -587,8 +617,9 @@ class QPDF
587 // keys. This is used by QPDFWriter to avoid creation of dangling 617 // keys. This is used by QPDFWriter to avoid creation of dangling
588 // objects for stream dictionary keys it will be regenerating. 618 // objects for stream dictionary keys it will be regenerating.
589 QPDF_DLL 619 QPDF_DLL
590 - void optimize(std::map<int, int> const& object_stream_data,  
591 - bool allow_changes = true); 620 + void optimize(
  621 + std::map<int, int> const& object_stream_data,
  622 + bool allow_changes = true);
592 // ABI: make function optional and merge overloaded versions 623 // ABI: make function optional and merge overloaded versions
593 QPDF_DLL 624 QPDF_DLL
594 void optimize( 625 void optimize(
@@ -650,8 +681,8 @@ class QPDF @@ -650,8 +681,8 @@ class QPDF
650 QPDF_DLL 681 QPDF_DLL
651 void addPage(QPDFObjectHandle newpage, bool first); 682 void addPage(QPDFObjectHandle newpage, bool first);
652 QPDF_DLL 683 QPDF_DLL
653 - void addPageAt(QPDFObjectHandle newpage, bool before,  
654 - QPDFObjectHandle refpage); 684 + void
  685 + addPageAt(QPDFObjectHandle newpage, bool before, QPDFObjectHandle refpage);
655 QPDF_DLL 686 QPDF_DLL
656 void removePage(QPDFObjectHandle page); 687 void removePage(QPDFObjectHandle page);
657 // End legacy page helpers 688 // End legacy page helpers
@@ -661,9 +692,10 @@ class QPDF @@ -661,9 +692,10 @@ class QPDF
661 class Writer 692 class Writer
662 { 693 {
663 friend class QPDFWriter; 694 friend class QPDFWriter;
664 - private:  
665 695
666 - static void getLinearizedParts( 696 + private:
  697 + static void
  698 + getLinearizedParts(
667 QPDF& qpdf, 699 QPDF& qpdf,
668 std::map<int, int> const& object_stream_data, 700 std::map<int, int> const& object_stream_data,
669 std::vector<QPDFObjectHandle>& part4, 701 std::vector<QPDFObjectHandle>& part4,
@@ -672,28 +704,32 @@ class QPDF @@ -672,28 +704,32 @@ class QPDF
672 std::vector<QPDFObjectHandle>& part8, 704 std::vector<QPDFObjectHandle>& part8,
673 std::vector<QPDFObjectHandle>& part9) 705 std::vector<QPDFObjectHandle>& part9)
674 { 706 {
675 - qpdf.getLinearizedParts(object_stream_data,  
676 - part4, part6, part7, part8, part9); 707 + qpdf.getLinearizedParts(
  708 + object_stream_data, part4, part6, part7, part8, part9);
677 } 709 }
678 710
679 - static void generateHintStream( 711 + static void
  712 + generateHintStream(
680 QPDF& qpdf, 713 QPDF& qpdf,
681 std::map<int, QPDFXRefEntry> const& xref, 714 std::map<int, QPDFXRefEntry> const& xref,
682 std::map<int, qpdf_offset_t> const& lengths, 715 std::map<int, qpdf_offset_t> const& lengths,
683 std::map<int, int> const& obj_renumber, 716 std::map<int, int> const& obj_renumber,
684 PointerHolder<Buffer>& hint_stream, 717 PointerHolder<Buffer>& hint_stream,
685 - int& S, int& O) 718 + int& S,
  719 + int& O)
686 { 720 {
687 - return qpdf.generateHintStream(xref, lengths, obj_renumber,  
688 - hint_stream, S, O); 721 + return qpdf.generateHintStream(
  722 + xref, lengths, obj_renumber, hint_stream, S, O);
689 } 723 }
690 724
691 - static void getObjectStreamData(QPDF& qpdf, std::map<int, int>& omap) 725 + static void
  726 + getObjectStreamData(QPDF& qpdf, std::map<int, int>& omap)
692 { 727 {
693 qpdf.getObjectStreamData(omap); 728 qpdf.getObjectStreamData(omap);
694 } 729 }
695 730
696 - static std::vector<QPDFObjGen> getCompressibleObjGens(QPDF& qpdf) 731 + static std::vector<QPDFObjGen>
  732 + getCompressibleObjGens(QPDF& qpdf)
697 { 733 {
698 return qpdf.getCompressibleObjGens(); 734 return qpdf.getCompressibleObjGens();
699 } 735 }
@@ -704,13 +740,15 @@ class QPDF @@ -704,13 +740,15 @@ class QPDF
704 class Resolver 740 class Resolver
705 { 741 {
706 friend class QPDFObjectHandle; 742 friend class QPDFObjectHandle;
  743 +
707 private: 744 private:
708 - static PointerHolder<QPDFObject> resolve(  
709 - QPDF* qpdf, int objid, int generation) 745 + static PointerHolder<QPDFObject>
  746 + resolve(QPDF* qpdf, int objid, int generation)
710 { 747 {
711 return qpdf->resolve(objid, generation); 748 return qpdf->resolve(objid, generation);
712 } 749 }
713 - static bool objectChanged( 750 + static bool
  751 + objectChanged(
714 QPDF* qpdf, QPDFObjGen const& og, PointerHolder<QPDFObject>& oph) 752 QPDF* qpdf, QPDFObjGen const& og, PointerHolder<QPDFObject>& oph)
715 { 753 {
716 return qpdf->objectChanged(og, oph); 754 return qpdf->objectChanged(og, oph);
@@ -723,10 +761,13 @@ class QPDF @@ -723,10 +761,13 @@ class QPDF
723 class StreamCopier 761 class StreamCopier
724 { 762 {
725 friend class QPDFObjectHandle; 763 friend class QPDFObjectHandle;
  764 +
726 private: 765 private:
727 - static void copyStreamData(QPDF* qpdf,  
728 - QPDFObjectHandle const& dest,  
729 - QPDFObjectHandle const& src) 766 + static void
  767 + copyStreamData(
  768 + QPDF* qpdf,
  769 + QPDFObjectHandle const& dest,
  770 + QPDFObjectHandle const& src)
730 { 771 {
731 qpdf->copyStreamData(dest, src); 772 qpdf->copyStreamData(dest, src);
732 } 773 }
@@ -738,19 +779,18 @@ class QPDF @@ -738,19 +779,18 @@ class QPDF
738 class ParseGuard 779 class ParseGuard
739 { 780 {
740 friend class QPDFObjectHandle; 781 friend class QPDFObjectHandle;
  782 +
741 private: 783 private:
742 ParseGuard(QPDF* qpdf) : 784 ParseGuard(QPDF* qpdf) :
743 qpdf(qpdf) 785 qpdf(qpdf)
744 { 786 {
745 - if (qpdf)  
746 - { 787 + if (qpdf) {
747 qpdf->inParse(true); 788 qpdf->inParse(true);
748 } 789 }
749 } 790 }
750 ~ParseGuard() 791 ~ParseGuard()
751 { 792 {
752 - if (qpdf)  
753 - { 793 + if (qpdf) {
754 qpdf->inParse(false); 794 qpdf->inParse(false);
755 } 795 }
756 } 796 }
@@ -762,17 +802,29 @@ class QPDF @@ -762,17 +802,29 @@ class QPDF
762 class Pipe 802 class Pipe
763 { 803 {
764 friend class QPDF_Stream; 804 friend class QPDF_Stream;
  805 +
765 private: 806 private:
766 - static bool pipeStreamData(QPDF* qpdf, int objid, int generation,  
767 - qpdf_offset_t offset, size_t length,  
768 - QPDFObjectHandle dict,  
769 - Pipeline* pipeline,  
770 - bool suppress_warnings,  
771 - bool will_retry) 807 + static bool
  808 + pipeStreamData(
  809 + QPDF* qpdf,
  810 + int objid,
  811 + int generation,
  812 + qpdf_offset_t offset,
  813 + size_t length,
  814 + QPDFObjectHandle dict,
  815 + Pipeline* pipeline,
  816 + bool suppress_warnings,
  817 + bool will_retry)
772 { 818 {
773 return qpdf->pipeStreamData( 819 return qpdf->pipeStreamData(
774 - objid, generation, offset, length, dict, pipeline,  
775 - suppress_warnings, will_retry); 820 + objid,
  821 + generation,
  822 + offset,
  823 + length,
  824 + dict,
  825 + pipeline,
  826 + suppress_warnings,
  827 + will_retry);
776 } 828 }
777 }; 829 };
778 friend class Pipe; 830 friend class Pipe;
@@ -788,9 +840,10 @@ class QPDF @@ -788,9 +840,10 @@ class QPDF
788 end_after_space(0) 840 end_after_space(0)
789 { 841 {
790 } 842 }
791 - ObjCache(PointerHolder<QPDFObject> object,  
792 - qpdf_offset_t end_before_space,  
793 - qpdf_offset_t end_after_space) : 843 + ObjCache(
  844 + PointerHolder<QPDFObject> object,
  845 + qpdf_offset_t end_before_space,
  846 + qpdf_offset_t end_after_space) :
794 object(object), 847 object(object),
795 end_before_space(end_before_space), 848 end_before_space(end_before_space),
796 end_after_space(end_after_space) 849 end_after_space(end_after_space)
@@ -813,6 +866,7 @@ class QPDF @@ -813,6 +866,7 @@ class QPDF
813 class EncryptionParameters 866 class EncryptionParameters
814 { 867 {
815 friend class QPDF; 868 friend class QPDF;
  869 +
816 public: 870 public:
817 EncryptionParameters(); 871 EncryptionParameters();
818 872
@@ -839,6 +893,7 @@ class QPDF @@ -839,6 +893,7 @@ class QPDF
839 class ForeignStreamData 893 class ForeignStreamData
840 { 894 {
841 friend class QPDF; 895 friend class QPDF;
  896 +
842 public: 897 public:
843 ForeignStreamData( 898 ForeignStreamData(
844 PointerHolder<EncryptionParameters> encp, 899 PointerHolder<EncryptionParameters> encp,
@@ -867,18 +922,21 @@ class QPDF @@ -867,18 +922,21 @@ class QPDF
867 { 922 {
868 } 923 }
869 virtual bool provideStreamData( 924 virtual bool provideStreamData(
870 - int objid, int generation, Pipeline* pipeline,  
871 - bool suppress_warnings, bool will_retry) override;  
872 - void registerForeignStream(QPDFObjGen const& local_og,  
873 - QPDFObjectHandle foreign_stream);  
874 - void registerForeignStream(QPDFObjGen const& local_og,  
875 - PointerHolder<ForeignStreamData>); 925 + int objid,
  926 + int generation,
  927 + Pipeline* pipeline,
  928 + bool suppress_warnings,
  929 + bool will_retry) override;
  930 + void registerForeignStream(
  931 + QPDFObjGen const& local_og, QPDFObjectHandle foreign_stream);
  932 + void registerForeignStream(
  933 + QPDFObjGen const& local_og, PointerHolder<ForeignStreamData>);
876 934
877 private: 935 private:
878 QPDF& destination_qpdf; 936 QPDF& destination_qpdf;
879 std::map<QPDFObjGen, QPDFObjectHandle> foreign_streams; 937 std::map<QPDFObjGen, QPDFObjectHandle> foreign_streams;
880 - std::map<QPDFObjGen,  
881 - PointerHolder<ForeignStreamData> > foreign_stream_data; 938 + std::map<QPDFObjGen, PointerHolder<ForeignStreamData>>
  939 + foreign_stream_data;
882 }; 940 };
883 941
884 class StringDecrypter: public QPDFObjectHandle::StringDecrypter 942 class StringDecrypter: public QPDFObjectHandle::StringDecrypter
@@ -911,6 +969,7 @@ class QPDF @@ -911,6 +969,7 @@ class QPDF
911 { 969 {
912 this->qpdf->m->resolving.erase(og); 970 this->qpdf->m->resolving.erase(og);
913 } 971 }
  972 +
914 private: 973 private:
915 QPDF* qpdf; 974 QPDF* qpdf;
916 QPDFObjGen og; 975 QPDFObjGen og;
@@ -922,56 +981,72 @@ class QPDF @@ -922,56 +981,72 @@ class QPDF
922 void setTrailer(QPDFObjectHandle obj); 981 void setTrailer(QPDFObjectHandle obj);
923 void read_xref(qpdf_offset_t offset); 982 void read_xref(qpdf_offset_t offset);
924 void reconstruct_xref(QPDFExc& e); 983 void reconstruct_xref(QPDFExc& e);
925 - bool parse_xrefFirst(std::string const& line,  
926 - int& obj, int& num, int& bytes);  
927 - bool parse_xrefEntry(std::string const& line,  
928 - qpdf_offset_t& f1, int& f2, char& type); 984 + bool
  985 + parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes);
  986 + bool parse_xrefEntry(
  987 + std::string const& line, qpdf_offset_t& f1, int& f2, char& type);
929 qpdf_offset_t read_xrefTable(qpdf_offset_t offset); 988 qpdf_offset_t read_xrefTable(qpdf_offset_t offset);
930 qpdf_offset_t read_xrefStream(qpdf_offset_t offset); 989 qpdf_offset_t read_xrefStream(qpdf_offset_t offset);
931 - qpdf_offset_t processXRefStream(  
932 - qpdf_offset_t offset, QPDFObjectHandle& xref_stream);  
933 - void insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2,  
934 - bool overwrite = false);  
935 - void setLastObjectDescription(std::string const& description,  
936 - int objid, int generation); 990 + qpdf_offset_t
  991 + processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
  992 + void insertXrefEntry(
  993 + int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false);
  994 + void setLastObjectDescription(
  995 + std::string const& description, int objid, int generation);
937 QPDFObjectHandle readObject( 996 QPDFObjectHandle readObject(
938 - PointerHolder<InputSource>, std::string const& description,  
939 - int objid, int generation, bool in_object_stream); 997 + PointerHolder<InputSource>,
  998 + std::string const& description,
  999 + int objid,
  1000 + int generation,
  1001 + bool in_object_stream);
940 size_t recoverStreamLength( 1002 size_t recoverStreamLength(
941 - PointerHolder<InputSource> input, int objid, int generation, 1003 + PointerHolder<InputSource> input,
  1004 + int objid,
  1005 + int generation,
942 qpdf_offset_t stream_offset); 1006 qpdf_offset_t stream_offset);
943 - QPDFTokenizer::Token readToken(PointerHolder<InputSource>,  
944 - size_t max_len = 0); 1007 + QPDFTokenizer::Token
  1008 + readToken(PointerHolder<InputSource>, size_t max_len = 0);
945 1009
946 QPDFObjectHandle readObjectAtOffset( 1010 QPDFObjectHandle readObjectAtOffset(
947 bool attempt_recovery, 1011 bool attempt_recovery,
948 - qpdf_offset_t offset, std::string const& description,  
949 - int exp_objid, int exp_generation,  
950 - int& act_objid, int& act_generation); 1012 + qpdf_offset_t offset,
  1013 + std::string const& description,
  1014 + int exp_objid,
  1015 + int exp_generation,
  1016 + int& act_objid,
  1017 + int& act_generation);
951 bool objectChanged(QPDFObjGen const& og, PointerHolder<QPDFObject>& oph); 1018 bool objectChanged(QPDFObjGen const& og, PointerHolder<QPDFObject>& oph);
952 PointerHolder<QPDFObject> resolve(int objid, int generation); 1019 PointerHolder<QPDFObject> resolve(int objid, int generation);
953 void resolveObjectsInStream(int obj_stream_number); 1020 void resolveObjectsInStream(int obj_stream_number);
954 void stopOnError(std::string const& message); 1021 void stopOnError(std::string const& message);
955 1022
956 // Calls finish() on the pipeline when done but does not delete it 1023 // Calls finish() on the pipeline when done but does not delete it
957 - bool pipeStreamData(int objid, int generation,  
958 - qpdf_offset_t offset, size_t length,  
959 - QPDFObjectHandle dict,  
960 - Pipeline* pipeline,  
961 - bool suppress_warnings,  
962 - bool will_retry); 1024 + bool pipeStreamData(
  1025 + int objid,
  1026 + int generation,
  1027 + qpdf_offset_t offset,
  1028 + size_t length,
  1029 + QPDFObjectHandle dict,
  1030 + Pipeline* pipeline,
  1031 + bool suppress_warnings,
  1032 + bool will_retry);
963 bool pipeForeignStreamData( 1033 bool pipeForeignStreamData(
964 PointerHolder<ForeignStreamData>, 1034 PointerHolder<ForeignStreamData>,
965 - Pipeline*, bool suppress_warnings, bool will_retry);  
966 - static bool pipeStreamData(PointerHolder<QPDF::EncryptionParameters> encp,  
967 - PointerHolder<InputSource> file,  
968 - QPDF& qpdf_for_warning,  
969 - int objid, int generation,  
970 - qpdf_offset_t offset, size_t length,  
971 - QPDFObjectHandle dict,  
972 - Pipeline* pipeline,  
973 - bool suppress_warnings,  
974 - bool will_retry); 1035 + Pipeline*,
  1036 + bool suppress_warnings,
  1037 + bool will_retry);
  1038 + static bool pipeStreamData(
  1039 + PointerHolder<QPDF::EncryptionParameters> encp,
  1040 + PointerHolder<InputSource> file,
  1041 + QPDF& qpdf_for_warning,
  1042 + int objid,
  1043 + int generation,
  1044 + qpdf_offset_t offset,
  1045 + size_t length,
  1046 + QPDFObjectHandle dict,
  1047 + Pipeline* pipeline,
  1048 + bool suppress_warnings,
  1049 + bool will_retry);
975 1050
976 // For QPDFWriter: 1051 // For QPDFWriter:
977 1052
@@ -985,11 +1060,13 @@ class QPDF @@ -985,11 +1060,13 @@ class QPDF
985 std::vector<QPDFObjectHandle>& part8, 1060 std::vector<QPDFObjectHandle>& part8,
986 std::vector<QPDFObjectHandle>& part9); 1061 std::vector<QPDFObjectHandle>& part9);
987 1062
988 - void generateHintStream(std::map<int, QPDFXRefEntry> const& xref,  
989 - std::map<int, qpdf_offset_t> const& lengths,  
990 - std::map<int, int> const& obj_renumber,  
991 - PointerHolder<Buffer>& hint_stream,  
992 - int& S, int& O); 1063 + void generateHintStream(
  1064 + std::map<int, QPDFXRefEntry> const& xref,
  1065 + std::map<int, qpdf_offset_t> const& lengths,
  1066 + std::map<int, int> const& obj_renumber,
  1067 + PointerHolder<Buffer>& hint_stream,
  1068 + int& S,
  1069 + int& O);
993 1070
994 // Map object to object stream that contains it 1071 // Map object to object stream that contains it
995 void getObjectStreamData(std::map<int, int>&); 1072 void getObjectStreamData(std::map<int, int>&);
@@ -1000,45 +1077,51 @@ class QPDF @@ -1000,45 +1077,51 @@ class QPDF
1000 1077
1001 // methods to support page handling 1078 // methods to support page handling
1002 1079
1003 - void getAllPagesInternal(QPDFObjectHandle cur_pages,  
1004 - std::vector<QPDFObjectHandle>& result,  
1005 - std::set<QPDFObjGen>& visited,  
1006 - std::set<QPDFObjGen>& seen); 1080 + void getAllPagesInternal(
  1081 + QPDFObjectHandle cur_pages,
  1082 + std::vector<QPDFObjectHandle>& result,
  1083 + std::set<QPDFObjGen>& visited,
  1084 + std::set<QPDFObjGen>& seen);
1007 void insertPage(QPDFObjectHandle newpage, int pos); 1085 void insertPage(QPDFObjectHandle newpage, int pos);
1008 void flattenPagesTree(); 1086 void flattenPagesTree();
1009 - void insertPageobjToPage(QPDFObjectHandle const& obj, int pos,  
1010 - bool check_duplicate); 1087 + void insertPageobjToPage(
  1088 + QPDFObjectHandle const& obj, int pos, bool check_duplicate);
1011 1089
1012 // methods to support encryption -- implemented in QPDF_encryption.cc 1090 // methods to support encryption -- implemented in QPDF_encryption.cc
1013 - static encryption_method_e interpretCF(  
1014 - PointerHolder<EncryptionParameters> encp, QPDFObjectHandle); 1091 + static encryption_method_e
  1092 + interpretCF(PointerHolder<EncryptionParameters> encp, QPDFObjectHandle);
1015 void initializeEncryption(); 1093 void initializeEncryption();
1016 static std::string getKeyForObject( 1094 static std::string getKeyForObject(
1017 PointerHolder<EncryptionParameters> encp, 1095 PointerHolder<EncryptionParameters> encp,
1018 - int objid, int generation, bool use_aes); 1096 + int objid,
  1097 + int generation,
  1098 + bool use_aes);
1019 void decryptString(std::string&, int objid, int generation); 1099 void decryptString(std::string&, int objid, int generation);
1020 static std::string compute_encryption_key_from_password( 1100 static std::string compute_encryption_key_from_password(
1021 std::string const& password, EncryptionData const& data); 1101 std::string const& password, EncryptionData const& data);
1022 static std::string recover_encryption_key_with_password( 1102 static std::string recover_encryption_key_with_password(
1023 std::string const& password, EncryptionData const& data); 1103 std::string const& password, EncryptionData const& data);
1024 static std::string recover_encryption_key_with_password( 1104 static std::string recover_encryption_key_with_password(
1025 - std::string const& password, EncryptionData const& data, 1105 + std::string const& password,
  1106 + EncryptionData const& data,
1026 bool& perms_valid); 1107 bool& perms_valid);
1027 static void decryptStream( 1108 static void decryptStream(
1028 PointerHolder<EncryptionParameters> encp, 1109 PointerHolder<EncryptionParameters> encp,
1029 PointerHolder<InputSource> file, 1110 PointerHolder<InputSource> file,
1030 - QPDF& qpdf_for_warning, Pipeline*& pipeline,  
1031 - int objid, int generation, 1111 + QPDF& qpdf_for_warning,
  1112 + Pipeline*& pipeline,
  1113 + int objid,
  1114 + int generation,
1032 QPDFObjectHandle& stream_dict, 1115 QPDFObjectHandle& stream_dict,
1033 std::vector<std::shared_ptr<Pipeline>>& heap); 1116 std::vector<std::shared_ptr<Pipeline>>& heap);
1034 1117
1035 // Methods to support object copying 1118 // Methods to support object copying
1036 - void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier,  
1037 - bool top); 1119 + void
  1120 + reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);
1038 QPDFObjectHandle replaceForeignIndirectObjects( 1121 QPDFObjectHandle replaceForeignIndirectObjects(
1039 QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); 1122 QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);
1040 - void copyStreamData(  
1041 - QPDFObjectHandle dest_stream, QPDFObjectHandle src_stream); 1123 + void
  1124 + copyStreamData(QPDFObjectHandle dest_stream, QPDFObjectHandle src_stream);
1042 1125
1043 // Linearization Hint table structures. 1126 // Linearization Hint table structures.
1044 // Naming conventions: 1127 // Naming conventions:
@@ -1065,14 +1148,14 @@ class QPDF @@ -1065,14 +1148,14 @@ class QPDF
1065 { 1148 {
1066 } 1149 }
1067 1150
1068 - int delta_nobjects; // 1  
1069 - qpdf_offset_t delta_page_length; // 2  
1070 - int nshared_objects; // 3 1151 + int delta_nobjects; // 1
  1152 + qpdf_offset_t delta_page_length; // 2
  1153 + int nshared_objects; // 3
1071 // vectors' sizes = nshared_objects 1154 // vectors' sizes = nshared_objects
1072 - std::vector<int> shared_identifiers; // 4  
1073 - std::vector<int> shared_numerators; // 5  
1074 - qpdf_offset_t delta_content_offset; // 6  
1075 - qpdf_offset_t delta_content_length; // 7 1155 + std::vector<int> shared_identifiers; // 4
  1156 + std::vector<int> shared_numerators; // 5
  1157 + qpdf_offset_t delta_content_offset; // 6
  1158 + qpdf_offset_t delta_content_length; // 7
1076 }; 1159 };
1077 1160
1078 // PDF 1.4: Table F.3 1161 // PDF 1.4: Table F.3
@@ -1095,19 +1178,19 @@ class QPDF @@ -1095,19 +1178,19 @@ class QPDF
1095 { 1178 {
1096 } 1179 }
1097 1180
1098 - int min_nobjects; // 1  
1099 - qpdf_offset_t first_page_offset; // 2  
1100 - int nbits_delta_nobjects; // 3  
1101 - int min_page_length; // 4  
1102 - int nbits_delta_page_length; // 5  
1103 - int min_content_offset; // 6  
1104 - int nbits_delta_content_offset; // 7  
1105 - int min_content_length; // 8  
1106 - int nbits_delta_content_length; // 9  
1107 - int nbits_nshared_objects; // 10  
1108 - int nbits_shared_identifier; // 11  
1109 - int nbits_shared_numerator; // 12  
1110 - int shared_denominator; // 13 1181 + int min_nobjects; // 1
  1182 + qpdf_offset_t first_page_offset; // 2
  1183 + int nbits_delta_nobjects; // 3
  1184 + int min_page_length; // 4
  1185 + int nbits_delta_page_length; // 5
  1186 + int min_content_offset; // 6
  1187 + int nbits_delta_content_offset; // 7
  1188 + int min_content_length; // 8
  1189 + int nbits_delta_content_length; // 9
  1190 + int nbits_nshared_objects; // 10
  1191 + int nbits_shared_identifier; // 11
  1192 + int nbits_shared_numerator; // 12
  1193 + int shared_denominator; // 13
1111 // vector size is npages 1194 // vector size is npages
1112 std::vector<HPageOffsetEntry> entries; 1195 std::vector<HPageOffsetEntry> entries;
1113 }; 1196 };
@@ -1123,9 +1206,9 @@ class QPDF @@ -1123,9 +1206,9 @@ class QPDF
1123 } 1206 }
1124 1207
1125 // Item 3 is a 128-bit signature (unsupported by Acrobat) 1208 // Item 3 is a 128-bit signature (unsupported by Acrobat)
1126 - int delta_group_length; // 1  
1127 - int signature_present; // 2 -- always 0  
1128 - int nobjects_minus_one; // 4 -- always 0 1209 + int delta_group_length; // 1
  1210 + int signature_present; // 2 -- always 0
  1211 + int nobjects_minus_one; // 4 -- always 0
1129 }; 1212 };
1130 1213
1131 // PDF 1.4: Table F.5 1214 // PDF 1.4: Table F.5
@@ -1142,13 +1225,13 @@ class QPDF @@ -1142,13 +1225,13 @@ class QPDF
1142 { 1225 {
1143 } 1226 }
1144 1227
1145 - int first_shared_obj; // 1  
1146 - qpdf_offset_t first_shared_offset; // 2  
1147 - int nshared_first_page; // 3  
1148 - int nshared_total; // 4  
1149 - int nbits_nobjects; // 5  
1150 - int min_group_length; // 6  
1151 - int nbits_delta_group_length; // 7 1228 + int first_shared_obj; // 1
  1229 + qpdf_offset_t first_shared_offset; // 2
  1230 + int nshared_first_page; // 3
  1231 + int nshared_total; // 4
  1232 + int nbits_nobjects; // 5
  1233 + int min_group_length; // 6
  1234 + int nbits_delta_group_length; // 7
1152 // vector size is nshared_total 1235 // vector size is nshared_total
1153 std::vector<HSharedObjectEntry> entries; 1236 std::vector<HSharedObjectEntry> entries;
1154 }; 1237 };
@@ -1164,10 +1247,10 @@ class QPDF @@ -1164,10 +1247,10 @@ class QPDF
1164 { 1247 {
1165 } 1248 }
1166 1249
1167 - int first_object; // 1  
1168 - qpdf_offset_t first_object_offset; // 2  
1169 - int nobjects; // 3  
1170 - int group_length; // 4 1250 + int first_object; // 1
  1251 + qpdf_offset_t first_object_offset; // 2
  1252 + int nobjects; // 3
  1253 + int group_length; // 4
1171 }; 1254 };
1172 1255
1173 // Other linearization data structures 1256 // Other linearization data structures
@@ -1261,15 +1344,13 @@ class QPDF @@ -1261,15 +1344,13 @@ class QPDF
1261 1344
1262 // No need for CHGeneric -- HGeneric is fine as is. 1345 // No need for CHGeneric -- HGeneric is fine as is.
1263 1346
1264 -  
1265 // Data structures to support optimization -- implemented in 1347 // Data structures to support optimization -- implemented in
1266 // QPDF_optimization.cc 1348 // QPDF_optimization.cc
1267 1349
1268 class ObjUser 1350 class ObjUser
1269 { 1351 {
1270 public: 1352 public:
1271 - enum user_e  
1272 - { 1353 + enum user_e {
1273 ou_bad, 1354 ou_bad,
1274 ou_page, 1355 ou_page,
1275 ou_thumb, 1356 ou_thumb,
@@ -1293,8 +1374,8 @@ class QPDF @@ -1293,8 +1374,8 @@ class QPDF
1293 bool operator<(ObjUser const&) const; 1374 bool operator<(ObjUser const&) const;
1294 1375
1295 user_e ou_type; 1376 user_e ou_type;
1296 - int pageno; // if ou_page;  
1297 - std::string key; // if ou_trailer_key or ou_root_key 1377 + int pageno; // if ou_page;
  1378 + std::string key; // if ou_trailer_key or ou_root_key
1298 }; 1379 };
1299 1380
1300 class PatternFinder: public InputSource::Finder 1381 class PatternFinder: public InputSource::Finder
@@ -1308,7 +1389,8 @@ class QPDF @@ -1308,7 +1389,8 @@ class QPDF
1308 virtual ~PatternFinder() 1389 virtual ~PatternFinder()
1309 { 1390 {
1310 } 1391 }
1311 - virtual bool check() 1392 + virtual bool
  1393 + check()
1312 { 1394 {
1313 return (this->qpdf.*checker)(); 1395 return (this->qpdf.*checker)();
1314 } 1396 }
@@ -1328,8 +1410,8 @@ class QPDF @@ -1328,8 +1410,8 @@ class QPDF
1328 void readLinearizationData(); 1410 void readLinearizationData();
1329 bool checkLinearizationInternal(); 1411 bool checkLinearizationInternal();
1330 void dumpLinearizationDataInternal(); 1412 void dumpLinearizationDataInternal();
1331 - QPDFObjectHandle readHintStream(  
1332 - Pipeline&, qpdf_offset_t offset, size_t length); 1413 + QPDFObjectHandle
  1414 + readHintStream(Pipeline&, qpdf_offset_t offset, size_t length);
1333 void readHPageOffset(BitStream); 1415 void readHPageOffset(BitStream);
1334 void readHSharedObject(BitStream); 1416 void readHSharedObject(BitStream);
1335 void readHGeneric(BitStream, HGeneric&); 1417 void readHGeneric(BitStream, HGeneric&);
@@ -1337,30 +1419,32 @@ class QPDF @@ -1337,30 +1419,32 @@ class QPDF
1337 qpdf_offset_t getLinearizationOffset(QPDFObjGen const&); 1419 qpdf_offset_t getLinearizationOffset(QPDFObjGen const&);
1338 QPDFObjectHandle getUncompressedObject( 1420 QPDFObjectHandle getUncompressedObject(
1339 QPDFObjectHandle&, std::map<int, int> const& object_stream_data); 1421 QPDFObjectHandle&, std::map<int, int> const& object_stream_data);
1340 - int lengthNextN(int first_object, int n,  
1341 - std::list<std::string>& errors);  
1342 - void checkHPageOffset(std::list<std::string>& errors,  
1343 - std::list<std::string>& warnings,  
1344 - std::vector<QPDFObjectHandle> const& pages,  
1345 - std::map<int, int>& idx_to_obj);  
1346 - void checkHSharedObject(std::list<std::string>& warnings,  
1347 - std::list<std::string>& errors,  
1348 - std::vector<QPDFObjectHandle> const& pages,  
1349 - std::map<int, int>& idx_to_obj); 1422 + int lengthNextN(int first_object, int n, std::list<std::string>& errors);
  1423 + void checkHPageOffset(
  1424 + std::list<std::string>& errors,
  1425 + std::list<std::string>& warnings,
  1426 + std::vector<QPDFObjectHandle> const& pages,
  1427 + std::map<int, int>& idx_to_obj);
  1428 + void checkHSharedObject(
  1429 + std::list<std::string>& warnings,
  1430 + std::list<std::string>& errors,
  1431 + std::vector<QPDFObjectHandle> const& pages,
  1432 + std::map<int, int>& idx_to_obj);
1350 void checkHOutlines(std::list<std::string>& warnings); 1433 void checkHOutlines(std::list<std::string>& warnings);
1351 void dumpHPageOffset(); 1434 void dumpHPageOffset();
1352 void dumpHSharedObject(); 1435 void dumpHSharedObject();
1353 void dumpHGeneric(HGeneric&); 1436 void dumpHGeneric(HGeneric&);
1354 qpdf_offset_t adjusted_offset(qpdf_offset_t offset); 1437 qpdf_offset_t adjusted_offset(qpdf_offset_t offset);
1355 QPDFObjectHandle objGenToIndirect(QPDFObjGen const&); 1438 QPDFObjectHandle objGenToIndirect(QPDFObjGen const&);
1356 - void calculateLinearizationData(  
1357 - std::map<int, int> const& object_stream_data); 1439 + void
  1440 + calculateLinearizationData(std::map<int, int> const& object_stream_data);
1358 void pushOutlinesToPart( 1441 void pushOutlinesToPart(
1359 std::vector<QPDFObjectHandle>& part, 1442 std::vector<QPDFObjectHandle>& part,
1360 std::set<QPDFObjGen>& lc_outlines, 1443 std::set<QPDFObjGen>& lc_outlines,
1361 std::map<int, int> const& object_stream_data); 1444 std::map<int, int> const& object_stream_data);
1362 int outputLengthNextN( 1445 int outputLengthNextN(
1363 - int in_object, int n, 1446 + int in_object,
  1447 + int n,
1364 std::map<int, qpdf_offset_t> const& lengths, 1448 std::map<int, qpdf_offset_t> const& lengths,
1365 std::map<int, int> const& obj_renumber); 1449 std::map<int, int> const& obj_renumber);
1366 void calculateHPageOffset( 1450 void calculateHPageOffset(
@@ -1379,37 +1463,46 @@ class QPDF @@ -1379,37 +1463,46 @@ class QPDF
1379 void writeHSharedObject(BitWriter&); 1463 void writeHSharedObject(BitWriter&);
1380 void writeHGeneric(BitWriter&, HGeneric&); 1464 void writeHGeneric(BitWriter&, HGeneric&);
1381 1465
1382 -  
1383 // Methods to support optimization 1466 // Methods to support optimization
1384 1467
1385 - void pushInheritedAttributesToPage(bool allow_changes,  
1386 - bool warn_skipped_keys); 1468 + void
  1469 + pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys);
1387 void pushInheritedAttributesToPageInternal( 1470 void pushInheritedAttributesToPageInternal(
1388 QPDFObjectHandle, 1471 QPDFObjectHandle,
1389 - std::map<std::string, std::vector<QPDFObjectHandle> >&, 1472 + std::map<std::string, std::vector<QPDFObjectHandle>>&,
1390 std::vector<QPDFObjectHandle>& all_pages, 1473 std::vector<QPDFObjectHandle>& all_pages,
1391 - bool allow_changes, bool warn_skipped_keys, 1474 + bool allow_changes,
  1475 + bool warn_skipped_keys,
1392 std::set<QPDFObjGen>& visited); 1476 std::set<QPDFObjGen>& visited);
1393 void updateObjectMaps( 1477 void updateObjectMaps(
1394 - ObjUser const& ou, QPDFObjectHandle oh, 1478 + ObjUser const& ou,
  1479 + QPDFObjectHandle oh,
1395 std::function<int(QPDFObjectHandle&)> skip_stream_parameters); 1480 std::function<int(QPDFObjectHandle&)> skip_stream_parameters);
1396 void updateObjectMapsInternal( 1481 void updateObjectMapsInternal(
1397 - ObjUser const& ou, QPDFObjectHandle oh, 1482 + ObjUser const& ou,
  1483 + QPDFObjectHandle oh,
1398 std::function<int(QPDFObjectHandle&)> skip_stream_parameters, 1484 std::function<int(QPDFObjectHandle&)> skip_stream_parameters,
1399 - std::set<QPDFObjGen>& visited, bool top, 1485 + std::set<QPDFObjGen>& visited,
  1486 + bool top,
1400 int depth); 1487 int depth);
1401 void filterCompressedObjects(std::map<int, int> const& object_stream_data); 1488 void filterCompressedObjects(std::map<int, int> const& object_stream_data);
1402 1489
1403 // Type conversion helper methods 1490 // Type conversion helper methods
1404 - template<typename T> static qpdf_offset_t toO(T const& i) 1491 + template <typename T>
  1492 + static qpdf_offset_t
  1493 + toO(T const& i)
1405 { 1494 {
1406 return QIntC::to_offset(i); 1495 return QIntC::to_offset(i);
1407 } 1496 }
1408 - template<typename T> static size_t toS(T const& i) 1497 + template <typename T>
  1498 + static size_t
  1499 + toS(T const& i)
1409 { 1500 {
1410 return QIntC::to_size(i); 1501 return QIntC::to_size(i);
1411 } 1502 }
1412 - template<typename T> static int toI(T const& i) 1503 + template <typename T>
  1504 + static int
  1505 + toI(T const& i)
1413 { 1506 {
1414 return QIntC::to_int(i); 1507 return QIntC::to_int(i);
1415 } 1508 }
@@ -1490,8 +1583,8 @@ class QPDF @@ -1490,8 +1583,8 @@ class QPDF
1490 std::vector<QPDFObjectHandle> part9; 1583 std::vector<QPDFObjectHandle> part9;
1491 1584
1492 // Optimization data 1585 // Optimization data
1493 - std::map<ObjUser, std::set<QPDFObjGen> > obj_user_to_objects;  
1494 - std::map<QPDFObjGen, std::set<ObjUser> > object_to_obj_users; 1586 + std::map<ObjUser, std::set<QPDFObjGen>> obj_user_to_objects;
  1587 + std::map<QPDFObjGen, std::set<ObjUser>> object_to_obj_users;
1495 }; 1588 };
1496 1589
1497 // Keep all member variables inside the Members object, which we 1590 // Keep all member variables inside the Members object, which we
include/qpdf/QPDFAcroFormDocumentHelper.hh
@@ -67,7 +67,6 @@ @@ -67,7 +67,6 @@
67 // the "/AcroForm" field entry until you find the annotation 67 // the "/AcroForm" field entry until you find the annotation
68 // dictionary. 68 // dictionary.
69 69
70 -  
71 #include <qpdf/QPDFDocumentHelper.hh> 70 #include <qpdf/QPDFDocumentHelper.hh>
72 71
73 #include <qpdf/DLL.h> 72 #include <qpdf/DLL.h>
@@ -144,8 +143,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -144,8 +143,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
144 // information to be accurate, any changes to field names must be 143 // information to be accurate, any changes to field names must be
145 // done through setFormFieldName() above. 144 // done through setFormFieldName() above.
146 QPDF_DLL 145 QPDF_DLL
147 - std::set<QPDFObjGen>  
148 - getFieldsWithQualifiedName(std::string const& name); 146 + std::set<QPDFObjGen> getFieldsWithQualifiedName(std::string const& name);
149 147
150 // Return the annotations associated with a terminal field. Note 148 // Return the annotations associated with a terminal field. Note
151 // that in the case of a field having a single annotation, the 149 // that in the case of a field having a single annotation, the
@@ -153,17 +151,17 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -153,17 +151,17 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
153 // object for the field. 151 // object for the field.
154 QPDF_DLL 152 QPDF_DLL
155 std::vector<QPDFAnnotationObjectHelper> 153 std::vector<QPDFAnnotationObjectHelper>
156 - getAnnotationsForField(QPDFFormFieldObjectHelper); 154 + getAnnotationsForField(QPDFFormFieldObjectHelper);
157 155
158 // Return annotations of subtype /Widget for a page. 156 // Return annotations of subtype /Widget for a page.
159 QPDF_DLL 157 QPDF_DLL
160 std::vector<QPDFAnnotationObjectHelper> 158 std::vector<QPDFAnnotationObjectHelper>
161 - getWidgetAnnotationsForPage(QPDFPageObjectHelper); 159 + getWidgetAnnotationsForPage(QPDFPageObjectHelper);
162 160
163 // Return top-level form fields for a page. 161 // Return top-level form fields for a page.
164 QPDF_DLL 162 QPDF_DLL
165 std::vector<QPDFFormFieldObjectHelper> 163 std::vector<QPDFFormFieldObjectHelper>
166 - getFormFieldsForPage(QPDFPageObjectHelper); 164 + getFormFieldsForPage(QPDFPageObjectHelper);
167 165
168 // Return the terminal field that is associated with this 166 // Return the terminal field that is associated with this
169 // annotation. If the annotation dictionary is merged with the 167 // annotation. If the annotation dictionary is merged with the
@@ -173,8 +171,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -173,8 +171,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
173 // not be an associated field, and this method will return a 171 // not be an associated field, and this method will return a
174 // helper associated with a null object (isNull() == true). 172 // helper associated with a null object (isNull() == true).
175 QPDF_DLL 173 QPDF_DLL
176 - QPDFFormFieldObjectHelper  
177 - getFieldForAnnotation(QPDFAnnotationObjectHelper); 174 + QPDFFormFieldObjectHelper getFieldForAnnotation(QPDFAnnotationObjectHelper);
178 175
179 // Return the current value of /NeedAppearances. If 176 // Return the current value of /NeedAppearances. If
180 // /NeedAppearances is missing, return false as that is how PDF 177 // /NeedAppearances is missing, return false as that is how PDF
@@ -260,30 +257,33 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -260,30 +257,33 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
260 // happens with qpdf --split-pages. 257 // happens with qpdf --split-pages.
261 [[deprecated("Use fixCopiedAnnotations instead")]] 258 [[deprecated("Use fixCopiedAnnotations instead")]]
262 // ABI: delete this method 259 // ABI: delete this method
263 - QPDF_DLL  
264 - void copyFieldsFromForeignPage( 260 + QPDF_DLL void
  261 + copyFieldsFromForeignPage(
265 QPDFPageObjectHelper foreign_page, 262 QPDFPageObjectHelper foreign_page,
266 QPDFAcroFormDocumentHelper& foreign_afdh, 263 QPDFAcroFormDocumentHelper& foreign_afdh,
267 std::vector<QPDFObjectHandle>* copied_fields = nullptr); 264 std::vector<QPDFObjectHandle>* copied_fields = nullptr);
268 265
269 private: 266 private:
270 void analyze(); 267 void analyze();
271 - void traverseField(QPDFObjectHandle field,  
272 - QPDFObjectHandle parent,  
273 - int depth, std::set<QPDFObjGen>& visited); 268 + void traverseField(
  269 + QPDFObjectHandle field,
  270 + QPDFObjectHandle parent,
  271 + int depth,
  272 + std::set<QPDFObjGen>& visited);
274 QPDFObjectHandle getOrCreateAcroForm(); 273 QPDFObjectHandle getOrCreateAcroForm();
275 void adjustInheritedFields( 274 void adjustInheritedFields(
276 QPDFObjectHandle obj, 275 QPDFObjectHandle obj,
277 - bool override_da, std::string const& from_default_da,  
278 - bool override_q, int from_default_q); 276 + bool override_da,
  277 + std::string const& from_default_da,
  278 + bool override_q,
  279 + int from_default_q);
279 void adjustDefaultAppearances( 280 void adjustDefaultAppearances(
280 QPDFObjectHandle obj, 281 QPDFObjectHandle obj,
281 - std::map<std::string,  
282 - std::map<std::string, std::string>> const& dr_map); 282 + std::map<std::string, std::map<std::string, std::string>> const&
  283 + dr_map);
283 void adjustAppearanceStream( 284 void adjustAppearanceStream(
284 QPDFObjectHandle stream, 285 QPDFObjectHandle stream,
285 - std::map<std::string,  
286 - std::map<std::string, std::string>> dr_map); 286 + std::map<std::string, std::map<std::string, std::string>> dr_map);
287 287
288 class Members 288 class Members
289 { 289 {
@@ -298,9 +298,8 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper @@ -298,9 +298,8 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
298 Members(Members const&); 298 Members(Members const&);
299 299
300 bool cache_valid; 300 bool cache_valid;
301 - std::map<QPDFObjGen,  
302 - std::vector<QPDFAnnotationObjectHelper>  
303 - > field_to_annotations; 301 + std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>>
  302 + field_to_annotations;
304 std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field; 303 std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field;
305 std::map<QPDFObjGen, std::string> field_to_name; 304 std::map<QPDFObjGen, std::string> field_to_name;
306 std::map<std::string, std::set<QPDFObjGen>> name_to_fields; 305 std::map<std::string, std::set<QPDFObjGen>> name_to_fields;
include/qpdf/QPDFAnnotationObjectHelper.hh
@@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
22 #ifndef QPDFANNOTATIONOBJECTHELPER_HH 22 #ifndef QPDFANNOTATIONOBJECTHELPER_HH
23 #define QPDFANNOTATIONOBJECTHELPER_HH 23 #define QPDFANNOTATIONOBJECTHELPER_HH
24 24
25 -#include <qpdf/QPDFObjectHelper.hh>  
26 #include <qpdf/Constants.h> 25 #include <qpdf/Constants.h>
  26 +#include <qpdf/QPDFObjectHelper.hh>
27 27
28 #include <qpdf/DLL.h> 28 #include <qpdf/DLL.h>
29 29
@@ -78,8 +78,8 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper @@ -78,8 +78,8 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper
78 // which appearance stream is desired. If not specified, the 78 // which appearance stream is desired. If not specified, the
79 // appearance state in "/AS" will used. 79 // appearance state in "/AS" will used.
80 QPDF_DLL 80 QPDF_DLL
81 - QPDFObjectHandle getAppearanceStream(std::string const& which,  
82 - std::string const& state = ""); 81 + QPDFObjectHandle getAppearanceStream(
  82 + std::string const& which, std::string const& state = "");
83 83
84 // Generate text suitable for addition to the containing page's 84 // Generate text suitable for addition to the containing page's
85 // content stream that draws this annotation's appearance stream 85 // content stream that draws this annotation's appearance stream
@@ -96,7 +96,8 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper @@ -96,7 +96,8 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper
96 // preparing to print. 96 // preparing to print.
97 QPDF_DLL 97 QPDF_DLL
98 std::string getPageContentForAppearance( 98 std::string getPageContentForAppearance(
99 - std::string const& name, int rotate, 99 + std::string const& name,
  100 + int rotate,
100 int required_flags = 0, 101 int required_flags = 0,
101 int forbidden_flags = an_invisible | an_hidden); 102 int forbidden_flags = an_invisible | an_hidden);
102 103
include/qpdf/QPDFCryptoImpl.hh
@@ -77,19 +77,22 @@ class QPDF_DLL_CLASS QPDFCryptoImpl @@ -77,19 +77,22 @@ class QPDF_DLL_CLASS QPDFCryptoImpl
77 virtual void RC4_init(unsigned char const* key_data, int key_len = -1) = 0; 77 virtual void RC4_init(unsigned char const* key_data, int key_len = -1) = 0;
78 // out_data = 0 means to encrypt/decrypt in place 78 // out_data = 0 means to encrypt/decrypt in place
79 QPDF_DLL 79 QPDF_DLL
80 - virtual void RC4_process(unsigned char* in_data, size_t len,  
81 - unsigned char* out_data = 0) = 0; 80 + virtual void RC4_process(
  81 + unsigned char* in_data, size_t len, unsigned char* out_data = 0) = 0;
82 QPDF_DLL 82 QPDF_DLL
83 virtual void RC4_finalize() = 0; 83 virtual void RC4_finalize() = 0;
84 84
85 static size_t constexpr rijndael_buf_size = 16; 85 static size_t constexpr rijndael_buf_size = 16;
86 QPDF_DLL 86 QPDF_DLL
87 virtual void rijndael_init( 87 virtual void rijndael_init(
88 - bool encrypt, unsigned char const* key_data, size_t key_len,  
89 - bool cbc_mode, unsigned char* cbc_block) = 0;  
90 - QPDF_DLL  
91 - virtual void rijndael_process(  
92 - unsigned char* in_data, unsigned char* out_data) = 0; 88 + bool encrypt,
  89 + unsigned char const* key_data,
  90 + size_t key_len,
  91 + bool cbc_mode,
  92 + unsigned char* cbc_block) = 0;
  93 + QPDF_DLL
  94 + virtual void
  95 + rijndael_process(unsigned char* in_data, unsigned char* out_data) = 0;
93 QPDF_DLL 96 QPDF_DLL
94 virtual void rijndael_finalize() = 0; 97 virtual void rijndael_finalize() = 0;
95 }; 98 };
include/qpdf/QPDFCryptoProvider.hh
@@ -24,11 +24,11 @@ @@ -24,11 +24,11 @@
24 24
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 #include <qpdf/QPDFCryptoImpl.hh> 26 #include <qpdf/QPDFCryptoImpl.hh>
27 -#include <string> 27 +#include <functional>
28 #include <map> 28 #include <map>
29 -#include <set>  
30 #include <memory> 29 #include <memory>
31 -#include <functional> 30 +#include <set>
  31 +#include <string>
32 32
33 // This class is part of qpdf's pluggable crypto provider support. 33 // This class is part of qpdf's pluggable crypto provider support.
34 // Most users won't need to know or care about this class, but you can 34 // Most users won't need to know or care about this class, but you can
@@ -38,7 +38,6 @@ @@ -38,7 +38,6 @@
38 class QPDFCryptoProvider 38 class QPDFCryptoProvider
39 { 39 {
40 public: 40 public:
41 -  
42 // Methods for getting and registering crypto implementations. 41 // Methods for getting and registering crypto implementations.
43 // These methods are not thread-safe. 42 // These methods are not thread-safe.
44 43
@@ -50,15 +49,13 @@ class QPDFCryptoProvider @@ -50,15 +49,13 @@ class QPDFCryptoProvider
50 // Return an instance of the crypto provider registered using the 49 // Return an instance of the crypto provider registered using the
51 // given name. 50 // given name.
52 QPDF_DLL 51 QPDF_DLL
53 - static std::shared_ptr<QPDFCryptoImpl>  
54 - getImpl(std::string const& name); 52 + static std::shared_ptr<QPDFCryptoImpl> getImpl(std::string const& name);
55 53
56 // Register the given type (T) as a crypto implementation. T must 54 // Register the given type (T) as a crypto implementation. T must
57 // be derived from QPDFCryptoImpl and must have a constructor that 55 // be derived from QPDFCryptoImpl and must have a constructor that
58 // takes no arguments. 56 // takes no arguments.
59 - template<typename T>  
60 - QPDF_DLL  
61 - static void registerImpl(std::string const& name); 57 + template <typename T>
  58 + QPDF_DLL static void registerImpl(std::string const& name);
62 59
63 // Set the crypto provider registered with the given name as the 60 // Set the crypto provider registered with the given name as the
64 // default crypto implementation. 61 // default crypto implementation.
@@ -83,7 +80,7 @@ class QPDFCryptoProvider @@ -83,7 +80,7 @@ class QPDFCryptoProvider
83 80
84 std::shared_ptr<QPDFCryptoImpl> 81 std::shared_ptr<QPDFCryptoImpl>
85 getImpl_internal(std::string const& name) const; 82 getImpl_internal(std::string const& name) const;
86 - template<typename T> 83 + template <typename T>
87 void registerImpl_internal(std::string const& name); 84 void registerImpl_internal(std::string const& name);
88 void setDefaultProvider_internal(std::string const& name); 85 void setDefaultProvider_internal(std::string const& name);
89 86
@@ -100,7 +97,7 @@ class QPDFCryptoProvider @@ -100,7 +97,7 @@ class QPDFCryptoProvider
100 Members(Members const&) = delete; 97 Members(Members const&) = delete;
101 Members& operator=(Members const&) = delete; 98 Members& operator=(Members const&) = delete;
102 99
103 - typedef std::function<std::shared_ptr<QPDFCryptoImpl> ()> provider_fn; 100 + typedef std::function<std::shared_ptr<QPDFCryptoImpl>()> provider_fn;
104 std::string default_provider; 101 std::string default_provider;
105 std::map<std::string, provider_fn> providers; 102 std::map<std::string, provider_fn> providers;
106 }; 103 };
include/qpdf/QPDFDocumentHelper.hh
@@ -49,12 +49,14 @@ class QPDFDocumentHelper @@ -49,12 +49,14 @@ class QPDFDocumentHelper
49 { 49 {
50 } 50 }
51 QPDF_DLL 51 QPDF_DLL
52 - QPDF& getQPDF() 52 + QPDF&
  53 + getQPDF()
53 { 54 {
54 return this->qpdf; 55 return this->qpdf;
55 } 56 }
56 QPDF_DLL 57 QPDF_DLL
57 - QPDF const& getQPDF() const 58 + QPDF const&
  59 + getQPDF() const
58 { 60 {
59 return this->qpdf; 61 return this->qpdf;
60 } 62 }
include/qpdf/QPDFEmbeddedFileDocumentHelper.hh
@@ -24,13 +24,13 @@ @@ -24,13 +24,13 @@
24 24
25 #include <qpdf/QPDFDocumentHelper.hh> 25 #include <qpdf/QPDFDocumentHelper.hh>
26 26
  27 +#include <qpdf/DLL.h>
27 #include <qpdf/QPDF.hh> 28 #include <qpdf/QPDF.hh>
28 -#include <qpdf/QPDFNameTreeObjectHelper.hh>  
29 #include <qpdf/QPDFFileSpecObjectHelper.hh> 29 #include <qpdf/QPDFFileSpecObjectHelper.hh>
30 -#include <qpdf/DLL.h> 30 +#include <qpdf/QPDFNameTreeObjectHelper.hh>
31 31
32 -#include <memory>  
33 #include <map> 32 #include <map>
  33 +#include <memory>
34 34
35 // This class provides a higher level interface around document-level 35 // This class provides a higher level interface around document-level
36 // file attachments, also known as embedded files. These are discussed 36 // file attachments, also known as embedded files. These are discussed
@@ -48,8 +48,8 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper @@ -48,8 +48,8 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper
48 bool hasEmbeddedFiles() const; 48 bool hasEmbeddedFiles() const;
49 49
50 QPDF_DLL 50 QPDF_DLL
51 - std::map<std::string,  
52 - std::shared_ptr<QPDFFileSpecObjectHelper>> getEmbeddedFiles(); 51 + std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>>
  52 + getEmbeddedFiles();
53 53
54 // If an embedded file with the given name exists, return a 54 // If an embedded file with the given name exists, return a
55 // (shared) pointer to it. Otherwise, return nullptr. 55 // (shared) pointer to it. Otherwise, return nullptr.
include/qpdf/QPDFExc.hh
@@ -22,22 +22,23 @@ @@ -22,22 +22,23 @@
22 #ifndef QPDFEXC_HH 22 #ifndef QPDFEXC_HH
23 #define QPDFEXC_HH 23 #define QPDFEXC_HH
24 24
  25 +#include <qpdf/Constants.h>
25 #include <qpdf/DLL.h> 26 #include <qpdf/DLL.h>
26 #include <qpdf/Types.h> 27 #include <qpdf/Types.h>
27 -#include <qpdf/Constants.h>  
28 28
29 -#include <string>  
30 #include <stdexcept> 29 #include <stdexcept>
  30 +#include <string>
31 31
32 class QPDF_DLL_CLASS QPDFExc: public std::runtime_error 32 class QPDF_DLL_CLASS QPDFExc: public std::runtime_error
33 { 33 {
34 public: 34 public:
35 QPDF_DLL 35 QPDF_DLL
36 - QPDFExc(qpdf_error_code_e error_code,  
37 - std::string const& filename,  
38 - std::string const& object,  
39 - qpdf_offset_t offset,  
40 - std::string const& message); 36 + QPDFExc(
  37 + qpdf_error_code_e error_code,
  38 + std::string const& filename,
  39 + std::string const& object,
  40 + qpdf_offset_t offset,
  41 + std::string const& message);
41 QPDF_DLL 42 QPDF_DLL
42 virtual ~QPDFExc() noexcept 43 virtual ~QPDFExc() noexcept
43 { 44 {
@@ -65,10 +66,11 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error @@ -65,10 +66,11 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error
65 std::string const& getMessageDetail() const; 66 std::string const& getMessageDetail() const;
66 67
67 private: 68 private:
68 - static std::string createWhat(std::string const& filename,  
69 - std::string const& object,  
70 - qpdf_offset_t offset,  
71 - std::string const& message); 69 + static std::string createWhat(
  70 + std::string const& filename,
  71 + std::string const& object,
  72 + qpdf_offset_t offset,
  73 + std::string const& message);
72 74
73 // This class does not use the Members pattern to avoid needless 75 // This class does not use the Members pattern to avoid needless
74 // memory allocations during exception handling. 76 // memory allocations during exception handling.
include/qpdf/QPDFFileSpecObjectHelper.hh
@@ -26,8 +26,8 @@ @@ -26,8 +26,8 @@
26 26
27 #include <qpdf/DLL.h> 27 #include <qpdf/DLL.h>
28 28
29 -#include <qpdf/QPDFObjectHandle.hh>  
30 #include <qpdf/QPDFEFStreamObjectHelper.hh> 29 #include <qpdf/QPDFEFStreamObjectHelper.hh>
  30 +#include <qpdf/QPDFObjectHandle.hh>
31 31
32 // This class provides a higher level interface around File 32 // This class provides a higher level interface around File
33 // Specification dictionaries, which are discussed in section 7.11 of 33 // Specification dictionaries, which are discussed in section 7.11 of
@@ -77,22 +77,16 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper @@ -77,22 +77,16 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper
77 // filename, and attach the contents of the specified file as data 77 // filename, and attach the contents of the specified file as data
78 // in an embedded file stream. 78 // in an embedded file stream.
79 QPDF_DLL 79 QPDF_DLL
80 - static  
81 - QPDFFileSpecObjectHelper createFileSpec(  
82 - QPDF& qpdf,  
83 - std::string const& filename,  
84 - std::string const& fullpath); 80 + static QPDFFileSpecObjectHelper createFileSpec(
  81 + QPDF& qpdf, std::string const& filename, std::string const& fullpath);
85 82
86 // Create a new filespec as an indirect object with the given 83 // Create a new filespec as an indirect object with the given
87 // unicode filename and embedded file stream. The file name will 84 // unicode filename and embedded file stream. The file name will
88 // be used as both /UF and /F. If you need to override, call 85 // be used as both /UF and /F. If you need to override, call
89 // setFilename. 86 // setFilename.
90 QPDF_DLL 87 QPDF_DLL
91 - static  
92 - QPDFFileSpecObjectHelper createFileSpec(  
93 - QPDF& qpdf,  
94 - std::string const& filename,  
95 - QPDFEFStreamObjectHelper); 88 + static QPDFFileSpecObjectHelper createFileSpec(
  89 + QPDF& qpdf, std::string const& filename, QPDFEFStreamObjectHelper);
96 90
97 QPDF_DLL 91 QPDF_DLL
98 QPDFFileSpecObjectHelper& setDescription(std::string const&); 92 QPDFFileSpecObjectHelper& setDescription(std::string const&);
@@ -103,8 +97,7 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper @@ -103,8 +97,7 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper
103 // might happen to have. 97 // might happen to have.
104 QPDF_DLL 98 QPDF_DLL
105 QPDFFileSpecObjectHelper& setFilename( 99 QPDFFileSpecObjectHelper& setFilename(
106 - std::string const& unicode_name,  
107 - std::string const& compat_name = ""); 100 + std::string const& unicode_name, std::string const& compat_name = "");
108 101
109 private: 102 private:
110 class Members 103 class Members
include/qpdf/QPDFFormFieldObjectHelper.hh
@@ -185,8 +185,8 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper @@ -185,8 +185,8 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper
185 // of a field, use QPDFAcroFormDocumentHelper::setFormFieldName 185 // of a field, use QPDFAcroFormDocumentHelper::setFormFieldName
186 // instead. 186 // instead.
187 QPDF_DLL 187 QPDF_DLL
188 - void setFieldAttribute(std::string const& key,  
189 - std::string const& utf8_value); 188 + void
  189 + setFieldAttribute(std::string const& key, std::string const& utf8_value);
190 190
191 // Set /V (field value) to the given value. If need_appearances is 191 // Set /V (field value) to the given value. If need_appearances is
192 // true and the field type is either /Tx (text) or /Ch (choice), 192 // true and the field type is either /Tx (text) or /Ch (choice),
include/qpdf/QPDFJob.hh
@@ -22,22 +22,21 @@ @@ -22,22 +22,21 @@
22 #ifndef QPDFJOB_HH 22 #ifndef QPDFJOB_HH
23 #define QPDFJOB_HH 23 #define QPDFJOB_HH
24 24
25 -#include <qpdf/DLL.h>  
26 #include <qpdf/Constants.h> 25 #include <qpdf/Constants.h>
  26 +#include <qpdf/DLL.h>
  27 +#include <qpdf/PDFVersion.hh>
27 #include <qpdf/QPDF.hh> 28 #include <qpdf/QPDF.hh>
28 #include <qpdf/QPDFPageObjectHelper.hh> 29 #include <qpdf/QPDFPageObjectHelper.hh>
29 -#include <qpdf/PDFVersion.hh>  
30 30
31 -#include <memory>  
32 -#include <string> 31 +#include <functional>
  32 +#include <iostream>
33 #include <list> 33 #include <list>
34 -#include <vector>  
35 -#include <set>  
36 #include <map> 34 #include <map>
37 -#include <iostream>  
38 -#include <functional>  
39 #include <memory> 35 #include <memory>
  36 +#include <set>
40 #include <stdexcept> 37 #include <stdexcept>
  38 +#include <string>
  39 +#include <vector>
41 40
42 class QPDFWriter; 41 class QPDFWriter;
43 42
@@ -79,8 +78,8 @@ class QPDFJob @@ -79,8 +78,8 @@ class QPDFJob
79 // about converting arguments to UTF-8. This method will mutate 78 // about converting arguments to UTF-8. This method will mutate
80 // arguments that are passed to it. 79 // arguments that are passed to it.
81 QPDF_DLL 80 QPDF_DLL
82 - void initializeFromArgv(char const* const argv[],  
83 - char const* progname_env = nullptr); 81 + void initializeFromArgv(
  82 + char const* const argv[], char const* progname_env = nullptr);
84 83
85 // Initialize a QPDFJob from json. Passing partial = true prevents 84 // Initialize a QPDFJob from json. Passing partial = true prevents
86 // this method from doing the final checks (calling 85 // this method from doing the final checks (calling
@@ -155,9 +154,10 @@ class QPDFJob @@ -155,9 +154,10 @@ class QPDFJob
155 154
156 struct PageSpec 155 struct PageSpec
157 { 156 {
158 - PageSpec(std::string const& filename,  
159 - char const* password,  
160 - std::string const& range); 157 + PageSpec(
  158 + std::string const& filename,
  159 + char const* password,
  160 + std::string const& range);
161 161
162 std::string filename; 162 std::string filename;
163 std::shared_ptr<char> password; 163 std::shared_ptr<char> password;
@@ -203,13 +203,14 @@ class QPDFJob @@ -203,13 +203,14 @@ class QPDFJob
203 { 203 {
204 friend class QPDFJob; 204 friend class QPDFJob;
205 friend class Config; 205 friend class Config;
  206 +
206 public: 207 public:
207 QPDF_DLL 208 QPDF_DLL
208 Config* endAddAttachment(); 209 Config* endAddAttachment();
209 QPDF_DLL 210 QPDF_DLL
210 AttConfig* file(std::string const& parameter); 211 AttConfig* file(std::string const& parameter);
211 212
212 -# include <qpdf/auto_job_c_att.hh> 213 +#include <qpdf/auto_job_c_att.hh>
213 214
214 private: 215 private:
215 AttConfig(Config*); 216 AttConfig(Config*);
@@ -223,13 +224,14 @@ class QPDFJob @@ -223,13 +224,14 @@ class QPDFJob
223 { 224 {
224 friend class QPDFJob; 225 friend class QPDFJob;
225 friend class Config; 226 friend class Config;
  227 +
226 public: 228 public:
227 QPDF_DLL 229 QPDF_DLL
228 Config* endCopyAttachmentsFrom(); 230 Config* endCopyAttachmentsFrom();
229 QPDF_DLL 231 QPDF_DLL
230 CopyAttConfig* file(std::string const& parameter); 232 CopyAttConfig* file(std::string const& parameter);
231 233
232 -# include <qpdf/auto_job_c_copy_att.hh> 234 +#include <qpdf/auto_job_c_copy_att.hh>
233 235
234 private: 236 private:
235 CopyAttConfig(Config*); 237 CopyAttConfig(Config*);
@@ -243,15 +245,17 @@ class QPDFJob @@ -243,15 +245,17 @@ class QPDFJob
243 { 245 {
244 friend class QPDFJob; 246 friend class QPDFJob;
245 friend class Config; 247 friend class Config;
  248 +
246 public: 249 public:
247 QPDF_DLL 250 QPDF_DLL
248 Config* endPages(); 251 Config* endPages();
249 QPDF_DLL 252 QPDF_DLL
250 - PagesConfig* pageSpec(std::string const& filename,  
251 - std::string const& range,  
252 - char const* password = nullptr); 253 + PagesConfig* pageSpec(
  254 + std::string const& filename,
  255 + std::string const& range,
  256 + char const* password = nullptr);
253 257
254 -# include <qpdf/auto_job_c_pages.hh> 258 +#include <qpdf/auto_job_c_pages.hh>
255 259
256 private: 260 private:
257 PagesConfig(Config*); 261 PagesConfig(Config*);
@@ -264,13 +268,14 @@ class QPDFJob @@ -264,13 +268,14 @@ class QPDFJob
264 { 268 {
265 friend class QPDFJob; 269 friend class QPDFJob;
266 friend class Config; 270 friend class Config;
  271 +
267 public: 272 public:
268 QPDF_DLL 273 QPDF_DLL
269 Config* endUnderlayOverlay(); 274 Config* endUnderlayOverlay();
270 QPDF_DLL 275 QPDF_DLL
271 UOConfig* file(std::string const& parameter); 276 UOConfig* file(std::string const& parameter);
272 277
273 -# include <qpdf/auto_job_c_uo.hh> 278 +#include <qpdf/auto_job_c_uo.hh>
274 279
275 private: 280 private:
276 UOConfig(Config*); 281 UOConfig(Config*);
@@ -283,13 +288,14 @@ class QPDFJob @@ -283,13 +288,14 @@ class QPDFJob
283 { 288 {
284 friend class QPDFJob; 289 friend class QPDFJob;
285 friend class Config; 290 friend class Config;
  291 +
286 public: 292 public:
287 QPDF_DLL 293 QPDF_DLL
288 Config* endEncrypt(); 294 Config* endEncrypt();
289 QPDF_DLL 295 QPDF_DLL
290 EncConfig* file(std::string const& parameter); 296 EncConfig* file(std::string const& parameter);
291 297
292 -# include <qpdf/auto_job_c_enc.hh> 298 +#include <qpdf/auto_job_c_enc.hh>
293 299
294 private: 300 private:
295 EncConfig(Config*); 301 EncConfig(Config*);
@@ -301,6 +307,7 @@ class QPDFJob @@ -301,6 +307,7 @@ class QPDFJob
301 class Config 307 class Config
302 { 308 {
303 friend class QPDFJob; 309 friend class QPDFJob;
  310 +
304 public: 311 public:
305 // Proxy to QPDFJob::checkConfiguration() 312 // Proxy to QPDFJob::checkConfiguration()
306 QPDF_DLL 313 QPDF_DLL
@@ -331,7 +338,7 @@ class QPDFJob @@ -331,7 +338,7 @@ class QPDFJob
331 std::string const& user_password, 338 std::string const& user_password,
332 std::string const& owner_password); 339 std::string const& owner_password);
333 340
334 -# include <qpdf/auto_job_c_main.hh> 341 +#include <qpdf/auto_job_c_main.hh>
335 342
336 private: 343 private:
337 Config() = delete; 344 Config() = delete;
@@ -444,32 +451,37 @@ class QPDFJob @@ -444,32 +451,37 @@ class QPDFJob
444 451
445 // Basic file processing 452 // Basic file processing
446 std::shared_ptr<QPDF> processFile( 453 std::shared_ptr<QPDF> processFile(
447 - char const* filename, char const* password,  
448 - bool used_for_input); 454 + char const* filename, char const* password, bool used_for_input);
449 std::shared_ptr<QPDF> processInputSource( 455 std::shared_ptr<QPDF> processInputSource(
450 - PointerHolder<InputSource> is, char const* password, 456 + PointerHolder<InputSource> is,
  457 + char const* password,
451 bool used_for_input); 458 bool used_for_input);
452 std::shared_ptr<QPDF> doProcess( 459 std::shared_ptr<QPDF> doProcess(
453 std::function<void(QPDF*, char const*)> fn, 460 std::function<void(QPDF*, char const*)> fn,
454 - char const* password, bool empty, bool used_for_input); 461 + char const* password,
  462 + bool empty,
  463 + bool used_for_input);
455 std::shared_ptr<QPDF> doProcessOnce( 464 std::shared_ptr<QPDF> doProcessOnce(
456 std::function<void(QPDF*, char const*)> fn, 465 std::function<void(QPDF*, char const*)> fn,
457 - char const* password, bool empty, bool used_for_input); 466 + char const* password,
  467 + bool empty,
  468 + bool used_for_input);
458 469
459 // Transformations 470 // Transformations
460 void setQPDFOptions(QPDF& pdf); 471 void setQPDFOptions(QPDF& pdf);
461 void handlePageSpecs( 472 void handlePageSpecs(
462 - QPDF& pdf, bool& warnings, 473 + QPDF& pdf,
  474 + bool& warnings,
463 std::vector<std::shared_ptr<QPDF>>& page_heap); 475 std::vector<std::shared_ptr<QPDF>>& page_heap);
464 bool shouldRemoveUnreferencedResources(QPDF& pdf); 476 bool shouldRemoveUnreferencedResources(QPDF& pdf);
465 void handleRotations(QPDF& pdf); 477 void handleRotations(QPDF& pdf);
466 - void getUOPagenos(UnderOverlay& uo,  
467 - std::map<int, std::vector<int> >& pagenos); 478 + void
  479 + getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos);
468 void handleUnderOverlay(QPDF& pdf); 480 void handleUnderOverlay(QPDF& pdf);
469 void doUnderOverlayForPage( 481 void doUnderOverlayForPage(
470 QPDF& pdf, 482 QPDF& pdf,
471 UnderOverlay& uo, 483 UnderOverlay& uo,
472 - std::map<int, std::vector<int> >& pagenos, 484 + std::map<int, std::vector<int>>& pagenos,
473 size_t page_idx, 485 size_t page_idx,
474 std::map<int, QPDFObjectHandle>& fo, 486 std::map<int, QPDFObjectHandle>& fo,
475 std::vector<QPDFPageObjectHelper>& pages, 487 std::vector<QPDFPageObjectHelper>& pages,
include/qpdf/QPDFMatrix.hh
@@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
22 #ifndef QPDFMATRIX_HH 22 #ifndef QPDFMATRIX_HH
23 #define QPDFMATRIX_HH 23 #define QPDFMATRIX_HH
24 24
25 -#include <qpdf/QPDFObjectHandle.hh>  
26 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
  26 +#include <qpdf/QPDFObjectHandle.hh>
27 #include <string> 27 #include <string>
28 28
29 // This class represents a PDF transformation matrix using a tuple 29 // This class represents a PDF transformation matrix using a tuple
@@ -41,8 +41,7 @@ class QPDFMatrix @@ -41,8 +41,7 @@ class QPDFMatrix
41 QPDF_DLL 41 QPDF_DLL
42 QPDFMatrix(); 42 QPDFMatrix();
43 QPDF_DLL 43 QPDF_DLL
44 - QPDFMatrix(double a, double b, double c,  
45 - double d, double e, double f); 44 + QPDFMatrix(double a, double b, double c, double d, double e, double f);
46 QPDF_DLL 45 QPDF_DLL
47 QPDFMatrix(QPDFObjectHandle::Matrix const&); 46 QPDFMatrix(QPDFObjectHandle::Matrix const&);
48 47
@@ -83,21 +82,22 @@ class QPDFMatrix @@ -83,21 +82,22 @@ class QPDFMatrix
83 // bounds the polygon resulting from transforming the four 82 // bounds the polygon resulting from transforming the four
84 // corners. 83 // corners.
85 QPDF_DLL 84 QPDF_DLL
86 - QPDFObjectHandle::Rectangle transformRectangle(  
87 - QPDFObjectHandle::Rectangle r) const; 85 + QPDFObjectHandle::Rectangle
  86 + transformRectangle(QPDFObjectHandle::Rectangle r) const;
88 // ABI: delete non-const version 87 // ABI: delete non-const version
89 QPDF_DLL 88 QPDF_DLL
90 - QPDFObjectHandle::Rectangle transformRectangle(  
91 - QPDFObjectHandle::Rectangle r); 89 + QPDFObjectHandle::Rectangle
  90 + transformRectangle(QPDFObjectHandle::Rectangle r);
92 91
93 // operator== tests for exact equality, not considering deltas for 92 // operator== tests for exact equality, not considering deltas for
94 // floating point. 93 // floating point.
95 QPDF_DLL 94 QPDF_DLL
96 bool operator==(QPDFMatrix const& rhs) const; 95 bool operator==(QPDFMatrix const& rhs) const;
97 QPDF_DLL 96 QPDF_DLL
98 - bool operator!=(QPDFMatrix const& rhs) const 97 + bool
  98 + operator!=(QPDFMatrix const& rhs) const
99 { 99 {
100 - return ! operator==(rhs); 100 + return !operator==(rhs);
101 } 101 }
102 102
103 double a; 103 double a;
include/qpdf/QPDFNameTreeObjectHelper.hh
@@ -22,11 +22,11 @@ @@ -22,11 +22,11 @@
22 #ifndef QPDFNAMETREEOBJECTHELPER_HH 22 #ifndef QPDFNAMETREEOBJECTHELPER_HH
23 #define QPDFNAMETREEOBJECTHELPER_HH 23 #define QPDFNAMETREEOBJECTHELPER_HH
24 24
25 -#include <qpdf/QPDFObjectHelper.hh>  
26 #include <qpdf/QPDFObjGen.hh> 25 #include <qpdf/QPDFObjGen.hh>
  26 +#include <qpdf/QPDFObjectHelper.hh>
  27 +#include <iterator>
27 #include <map> 28 #include <map>
28 #include <memory> 29 #include <memory>
29 -#include <iterator>  
30 30
31 #include <qpdf/DLL.h> 31 #include <qpdf/DLL.h>
32 32
@@ -48,16 +48,14 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper @@ -48,16 +48,14 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
48 // The qpdf object is required so that this class can issue 48 // The qpdf object is required so that this class can issue
49 // warnings, attempt repairs, and add indirect objects. 49 // warnings, attempt repairs, and add indirect objects.
50 QPDF_DLL 50 QPDF_DLL
51 - QPDFNameTreeObjectHelper(QPDFObjectHandle, QPDF&,  
52 - bool auto_repair = true); 51 + QPDFNameTreeObjectHelper(QPDFObjectHandle, QPDF&, bool auto_repair = true);
53 52
54 // ABI: Legacy Constructor will be removed in QPDF 11. A 53 // ABI: Legacy Constructor will be removed in QPDF 11. A
55 // QPDFNameTreeObjectHelper constructed in this way can't be 54 // QPDFNameTreeObjectHelper constructed in this way can't be
56 // modified or repaired and will silently ignore problems in the 55 // modified or repaired and will silently ignore problems in the
57 // structure. 56 // structure.
58 - [[deprecated("use constructor that takes QPDF&")]]  
59 - QPDF_DLL  
60 - QPDFNameTreeObjectHelper(QPDFObjectHandle); 57 + [[deprecated("use constructor that takes QPDF&")]] QPDF_DLL
  58 + QPDFNameTreeObjectHelper(QPDFObjectHandle);
61 59
62 // Create an empty name tree 60 // Create an empty name tree
63 QPDF_DLL 61 QPDF_DLL
@@ -80,6 +78,7 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper @@ -80,6 +78,7 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
80 class iterator 78 class iterator
81 { 79 {
82 friend class QPDFNameTreeObjectHelper; 80 friend class QPDFNameTreeObjectHelper;
  81 +
83 public: 82 public:
84 typedef std::pair<std::string, QPDFObjectHandle> T; 83 typedef std::pair<std::string, QPDFObjectHandle> T;
85 using iterator_category = std::bidirectional_iterator_tag; 84 using iterator_category = std::bidirectional_iterator_tag;
@@ -94,7 +93,8 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper @@ -94,7 +93,8 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
94 QPDF_DLL 93 QPDF_DLL
95 iterator& operator++(); 94 iterator& operator++();
96 QPDF_DLL 95 QPDF_DLL
97 - iterator operator++(int) 96 + iterator
  97 + operator++(int)
98 { 98 {
99 iterator t = *this; 99 iterator t = *this;
100 ++(*this); 100 ++(*this);
@@ -103,7 +103,8 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper @@ -103,7 +103,8 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
103 QPDF_DLL 103 QPDF_DLL
104 iterator& operator--(); 104 iterator& operator--();
105 QPDF_DLL 105 QPDF_DLL
106 - iterator operator--(int) 106 + iterator
  107 + operator--(int)
107 { 108 {
108 iterator t = *this; 109 iterator t = *this;
109 --(*this); 110 --(*this);
@@ -116,9 +117,10 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper @@ -116,9 +117,10 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
116 QPDF_DLL 117 QPDF_DLL
117 bool operator==(iterator const& other) const; 118 bool operator==(iterator const& other) const;
118 QPDF_DLL 119 QPDF_DLL
119 - bool operator!=(iterator const& other) const 120 + bool
  121 + operator!=(iterator const& other) const
120 { 122 {
121 - return ! operator==(other); 123 + return !operator==(other);
122 } 124 }
123 125
124 // DANGER: this method can create inconsistent trees if not 126 // DANGER: this method can create inconsistent trees if not
@@ -162,8 +164,8 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper @@ -162,8 +164,8 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
162 // Find the entry with the given key. If return_prev_if_not_found 164 // Find the entry with the given key. If return_prev_if_not_found
163 // is true and the item is not found, return the next lower item. 165 // is true and the item is not found, return the next lower item.
164 QPDF_DLL 166 QPDF_DLL
165 - iterator find(std::string const& key,  
166 - bool return_prev_if_not_found = false); 167 + iterator
  168 + find(std::string const& key, bool return_prev_if_not_found = false);
167 169
168 // Insert a new item. If the key already exists, it is replaced. 170 // Insert a new item. If the key already exists, it is replaced.
169 QPDF_DLL 171 QPDF_DLL
include/qpdf/QPDFNumberTreeObjectHelper.hh
@@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
22 #ifndef QPDFNUMBERTREEOBJECTHELPER_HH 22 #ifndef QPDFNUMBERTREEOBJECTHELPER_HH
23 #define QPDFNUMBERTREEOBJECTHELPER_HH 23 #define QPDFNUMBERTREEOBJECTHELPER_HH
24 24
25 -#include <qpdf/QPDFObjectHelper.hh>  
26 #include <qpdf/QPDFObjGen.hh> 25 #include <qpdf/QPDFObjGen.hh>
  26 +#include <qpdf/QPDFObjectHelper.hh>
27 #include <map> 27 #include <map>
28 #include <memory> 28 #include <memory>
29 29
@@ -45,16 +45,15 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper @@ -45,16 +45,15 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
45 // The qpdf object is required so that this class can issue 45 // The qpdf object is required so that this class can issue
46 // warnings, attempt repairs, and add indirect objects. 46 // warnings, attempt repairs, and add indirect objects.
47 QPDF_DLL 47 QPDF_DLL
48 - QPDFNumberTreeObjectHelper(QPDFObjectHandle, QPDF&,  
49 - bool auto_repair = true); 48 + QPDFNumberTreeObjectHelper(
  49 + QPDFObjectHandle, QPDF&, bool auto_repair = true);
50 50
51 // ABI: Legacy Constructor will be removed in QPDF 11. A 51 // ABI: Legacy Constructor will be removed in QPDF 11. A
52 // QPDFNumberTreeObjectHelper constructed in this way can't be 52 // QPDFNumberTreeObjectHelper constructed in this way can't be
53 // modified or repaired and will silently ignore problems in the 53 // modified or repaired and will silently ignore problems in the
54 // structure. 54 // structure.
55 - [[deprecated("use constructor that takes QPDF&")]]  
56 - QPDF_DLL  
57 - QPDFNumberTreeObjectHelper(QPDFObjectHandle); 55 + [[deprecated("use constructor that takes QPDF&")]] QPDF_DLL
  56 + QPDFNumberTreeObjectHelper(QPDFObjectHandle);
58 57
59 // ABI: = default 58 // ABI: = default
60 QPDF_DLL 59 QPDF_DLL
@@ -93,12 +92,13 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper @@ -93,12 +92,13 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
93 // oh to the value with index 3, and set offset to 2 (5 - 3). See 92 // oh to the value with index 3, and set offset to 2 (5 - 3). See
94 // also find(). 93 // also find().
95 QPDF_DLL 94 QPDF_DLL
96 - bool findObjectAtOrBelow(numtree_number idx, QPDFObjectHandle& oh,  
97 - numtree_number& offset); 95 + bool findObjectAtOrBelow(
  96 + numtree_number idx, QPDFObjectHandle& oh, numtree_number& offset);
98 97
99 class iterator 98 class iterator
100 { 99 {
101 friend class QPDFNumberTreeObjectHelper; 100 friend class QPDFNumberTreeObjectHelper;
  101 +
102 public: 102 public:
103 typedef std::pair<numtree_number, QPDFObjectHandle> T; 103 typedef std::pair<numtree_number, QPDFObjectHandle> T;
104 using iterator_category = std::bidirectional_iterator_tag; 104 using iterator_category = std::bidirectional_iterator_tag;
@@ -113,7 +113,8 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper @@ -113,7 +113,8 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
113 QPDF_DLL 113 QPDF_DLL
114 iterator& operator++(); 114 iterator& operator++();
115 QPDF_DLL 115 QPDF_DLL
116 - iterator operator++(int) 116 + iterator
  117 + operator++(int)
117 { 118 {
118 iterator t = *this; 119 iterator t = *this;
119 ++(*this); 120 ++(*this);
@@ -122,7 +123,8 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper @@ -122,7 +123,8 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
122 QPDF_DLL 123 QPDF_DLL
123 iterator& operator--(); 124 iterator& operator--();
124 QPDF_DLL 125 QPDF_DLL
125 - iterator operator--(int) 126 + iterator
  127 + operator--(int)
126 { 128 {
127 iterator t = *this; 129 iterator t = *this;
128 --(*this); 130 --(*this);
@@ -135,9 +137,10 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper @@ -135,9 +137,10 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
135 QPDF_DLL 137 QPDF_DLL
136 bool operator==(iterator const& other) const; 138 bool operator==(iterator const& other) const;
137 QPDF_DLL 139 QPDF_DLL
138 - bool operator!=(iterator const& other) const 140 + bool
  141 + operator!=(iterator const& other) const
139 { 142 {
140 - return ! operator==(other); 143 + return !operator==(other);
141 } 144 }
142 145
143 // DANGER: this method can create inconsistent trees if not 146 // DANGER: this method can create inconsistent trees if not
include/qpdf/QPDFObject.hh
@@ -22,10 +22,10 @@ @@ -22,10 +22,10 @@
22 #ifndef QPDFOBJECT_HH 22 #ifndef QPDFOBJECT_HH
23 #define QPDFOBJECT_HH 23 #define QPDFOBJECT_HH
24 24
  25 +#include <qpdf/Constants.h>
25 #include <qpdf/DLL.h> 26 #include <qpdf/DLL.h>
26 -#include <qpdf/Types.h>  
27 #include <qpdf/JSON.hh> 27 #include <qpdf/JSON.hh>
28 -#include <qpdf/Constants.h> 28 +#include <qpdf/Types.h>
29 29
30 #include <string> 30 #include <string>
31 31
@@ -62,7 +62,9 @@ class QPDF_DLL_CLASS QPDFObject @@ -62,7 +62,9 @@ class QPDF_DLL_CLASS QPDFObject
62 static constexpr object_type_e ot_operator = ::ot_operator; 62 static constexpr object_type_e ot_operator = ::ot_operator;
63 static constexpr object_type_e ot_inlineimage = ::ot_inlineimage; 63 static constexpr object_type_e ot_inlineimage = ::ot_inlineimage;
64 64
65 - virtual ~QPDFObject() {} 65 + virtual ~QPDFObject()
  66 + {
  67 + }
66 virtual std::string unparse() = 0; 68 virtual std::string unparse() = 0;
67 virtual JSON getJSON() = 0; 69 virtual JSON getJSON() = 0;
68 70
@@ -78,11 +80,12 @@ class QPDF_DLL_CLASS QPDFObject @@ -78,11 +80,12 @@ class QPDF_DLL_CLASS QPDFObject
78 { 80 {
79 friend class QPDF; 81 friend class QPDF;
80 friend class QPDFObjectHandle; 82 friend class QPDFObjectHandle;
  83 +
81 private: 84 private:
82 - static void releaseResolved(QPDFObject* o) 85 + static void
  86 + releaseResolved(QPDFObject* o)
83 { 87 {
84 - if (o)  
85 - { 88 + if (o) {
86 o->releaseResolved(); 89 o->releaseResolved();
87 } 90 }
88 } 91 }
@@ -97,7 +100,10 @@ class QPDF_DLL_CLASS QPDFObject @@ -97,7 +100,10 @@ class QPDF_DLL_CLASS QPDFObject
97 qpdf_offset_t getParsedOffset(); 100 qpdf_offset_t getParsedOffset();
98 101
99 protected: 102 protected:
100 - virtual void releaseResolved() {} 103 + virtual void
  104 + releaseResolved()
  105 + {
  106 + }
101 107
102 private: 108 private:
103 QPDFObject(QPDFObject const&) = delete; 109 QPDFObject(QPDFObject const&) = delete;
include/qpdf/QPDFObjectHandle.hh
@@ -22,21 +22,21 @@ @@ -22,21 +22,21 @@
22 #ifndef QPDFOBJECTHANDLE_HH 22 #ifndef QPDFOBJECTHANDLE_HH
23 #define QPDFOBJECTHANDLE_HH 23 #define QPDFOBJECTHANDLE_HH
24 24
  25 +#include <qpdf/Constants.h>
25 #include <qpdf/DLL.h> 26 #include <qpdf/DLL.h>
26 #include <qpdf/Types.h> 27 #include <qpdf/Types.h>
27 -#include <qpdf/Constants.h>  
28 28
29 -#include <string>  
30 -#include <vector>  
31 -#include <set>  
32 -#include <map>  
33 #include <functional> 29 #include <functional>
  30 +#include <map>
34 #include <memory> 31 #include <memory>
  32 +#include <set>
  33 +#include <string>
  34 +#include <vector>
35 35
36 -#include <qpdf/QPDFObjGen.hh>  
37 -#include <qpdf/PointerHolder.hh>  
38 #include <qpdf/Buffer.hh> 36 #include <qpdf/Buffer.hh>
39 #include <qpdf/InputSource.hh> 37 #include <qpdf/InputSource.hh>
  38 +#include <qpdf/PointerHolder.hh>
  39 +#include <qpdf/QPDFObjGen.hh>
40 #include <qpdf/QPDFTokenizer.hh> 40 #include <qpdf/QPDFTokenizer.hh>
41 41
42 #include <qpdf/QPDFObject.hh> 42 #include <qpdf/QPDFObject.hh>
@@ -117,12 +117,15 @@ class QPDFObjectHandle @@ -117,12 +117,15 @@ class QPDFObjectHandle
117 // version of the method, which should also return a boolean 117 // version of the method, which should also return a boolean
118 // indicating whether it ran without errors. 118 // indicating whether it ran without errors.
119 QPDF_DLL 119 QPDF_DLL
120 - virtual void provideStreamData(int objid, int generation,  
121 - Pipeline* pipeline); 120 + virtual void
  121 + provideStreamData(int objid, int generation, Pipeline* pipeline);
122 QPDF_DLL 122 QPDF_DLL
123 virtual bool provideStreamData( 123 virtual bool provideStreamData(
124 - int objid, int generation, Pipeline* pipeline,  
125 - bool suppress_warnings, bool will_retry); 124 + int objid,
  125 + int generation,
  126 + Pipeline* pipeline,
  127 + bool suppress_warnings,
  128 + bool will_retry);
126 QPDF_DLL 129 QPDF_DLL
127 bool supportsRetry(); 130 bool supportsRetry();
128 131
@@ -183,8 +186,10 @@ class QPDFObjectHandle @@ -183,8 +186,10 @@ class QPDFObjectHandle
183 class PipelineAccessor 186 class PipelineAccessor
184 { 187 {
185 friend class Pl_QPDFTokenizer; 188 friend class Pl_QPDFTokenizer;
  189 +
186 private: 190 private:
187 - static void setPipeline(TokenFilter* f, Pipeline* p) 191 + static void
  192 + setPipeline(TokenFilter* f, Pipeline* p)
188 { 193 {
189 f->setPipeline(p); 194 f->setPipeline(p);
190 } 195 }
@@ -230,8 +235,8 @@ class QPDFObjectHandle @@ -230,8 +235,8 @@ class QPDFObjectHandle
230 QPDF_DLL 235 QPDF_DLL
231 virtual void handleObject(QPDFObjectHandle); 236 virtual void handleObject(QPDFObjectHandle);
232 QPDF_DLL 237 QPDF_DLL
233 - virtual void handleObject(  
234 - QPDFObjectHandle, size_t offset, size_t length); 238 + virtual void
  239 + handleObject(QPDFObjectHandle, size_t offset, size_t length);
235 240
236 virtual void handleEOF() = 0; 241 virtual void handleEOF() = 0;
237 242
@@ -261,8 +266,7 @@ class QPDFObjectHandle @@ -261,8 +266,7 @@ class QPDFObjectHandle
261 ury(0.0) 266 ury(0.0)
262 { 267 {
263 } 268 }
264 - Rectangle(double llx, double lly,  
265 - double urx, double ury) : 269 + Rectangle(double llx, double lly, double urx, double ury) :
266 llx(llx), 270 llx(llx),
267 lly(lly), 271 lly(lly),
268 urx(urx), 272 urx(urx),
@@ -292,8 +296,7 @@ class QPDFObjectHandle @@ -292,8 +296,7 @@ class QPDFObjectHandle
292 f(0.0) 296 f(0.0)
293 { 297 {
294 } 298 }
295 - Matrix(double a, double b, double c,  
296 - double d, double e, double f) : 299 + Matrix(double a, double b, double c, double d, double e, double f) :
297 a(a), 300 a(a),
298 b(b), 301 b(b),
299 c(c), 302 c(c),
@@ -316,8 +319,7 @@ class QPDFObjectHandle @@ -316,8 +319,7 @@ class QPDFObjectHandle
316 QPDF_DLL 319 QPDF_DLL
317 QPDFObjectHandle(QPDFObjectHandle const&) = default; 320 QPDFObjectHandle(QPDFObjectHandle const&) = default;
318 QPDF_DLL 321 QPDF_DLL
319 - QPDFObjectHandle&  
320 - operator=(QPDFObjectHandle const&) = default; 322 + QPDFObjectHandle& operator=(QPDFObjectHandle const&) = default;
321 QPDF_DLL 323 QPDF_DLL
322 bool isInitialized() const; 324 bool isInitialized() const;
323 325
@@ -381,14 +383,14 @@ class QPDFObjectHandle @@ -381,14 +383,14 @@ class QPDFObjectHandle
381 // True if the object is a dictionary of the specified type and 383 // True if the object is a dictionary of the specified type and
382 // subtype, if any. 384 // subtype, if any.
383 QPDF_DLL 385 QPDF_DLL
384 - bool isDictionaryOfType(std::string const& type,  
385 - std::string const& subtype = ""); 386 + bool isDictionaryOfType(
  387 + std::string const& type, std::string const& subtype = "");
386 388
387 // True if the object is a stream of the specified type and 389 // True if the object is a stream of the specified type and
388 // subtype, if any. 390 // subtype, if any.
389 QPDF_DLL 391 QPDF_DLL
390 - bool isStreamOfType(std::string const& type,  
391 - std::string const& subtype = ""); 392 + bool
  393 + isStreamOfType(std::string const& type, std::string const& subtype = "");
392 394
393 // Public factory methods 395 // Public factory methods
394 396
@@ -406,8 +408,9 @@ class QPDFObjectHandle @@ -406,8 +408,9 @@ class QPDFObjectHandle
406 // in the message of any QPDFExc exception thrown for invalid 408 // in the message of any QPDFExc exception thrown for invalid
407 // syntax. See also the global `operator ""_qpdf` defined below. 409 // syntax. See also the global `operator ""_qpdf` defined below.
408 QPDF_DLL 410 QPDF_DLL
409 - static QPDFObjectHandle parse(std::string const& object_str,  
410 - std::string const& object_description = ""); 411 + static QPDFObjectHandle parse(
  412 + std::string const& object_str,
  413 + std::string const& object_description = "");
411 414
412 // Construct an object of any type from a string representation of 415 // Construct an object of any type from a string representation of
413 // the object. Indirect object syntax (obj gen R) is allowed and 416 // the object. Indirect object syntax (obj gen R) is allowed and
@@ -419,9 +422,10 @@ class QPDFObjectHandle @@ -419,9 +422,10 @@ class QPDFObjectHandle
419 // object, which will just be the first number and will report 422 // object, which will just be the first number and will report
420 // that there is trailing data at the end of the string. 423 // that there is trailing data at the end of the string.
421 QPDF_DLL 424 QPDF_DLL
422 - static QPDFObjectHandle parse(QPDF* context,  
423 - std::string const& object_str,  
424 - std::string const& object_description = ""); 425 + static QPDFObjectHandle parse(
  426 + QPDF* context,
  427 + std::string const& object_str,
  428 + std::string const& object_description = "");
425 429
426 // Construct an object as above by reading from the given 430 // Construct an object as above by reading from the given
427 // InputSource at its current position and using the tokenizer you 431 // InputSource at its current position and using the tokenizer you
@@ -429,11 +433,13 @@ class QPDFObjectHandle @@ -429,11 +433,13 @@ class QPDFObjectHandle
429 // This method is intended to be called by QPDF for parsing 433 // This method is intended to be called by QPDF for parsing
430 // objects that are ready from the object's input stream. 434 // objects that are ready from the object's input stream.
431 QPDF_DLL 435 QPDF_DLL
432 - static QPDFObjectHandle parse(PointerHolder<InputSource> input,  
433 - std::string const& object_description,  
434 - QPDFTokenizer&, bool& empty,  
435 - StringDecrypter* decrypter,  
436 - QPDF* context); 436 + static QPDFObjectHandle parse(
  437 + PointerHolder<InputSource> input,
  438 + std::string const& object_description,
  439 + QPDFTokenizer&,
  440 + bool& empty,
  441 + StringDecrypter* decrypter,
  442 + QPDF* context);
437 443
438 // Return the offset where the object was found when parsed. A 444 // Return the offset where the object was found when parsed. A
439 // negative value means that the object was created without 445 // negative value means that the object was created without
@@ -449,8 +455,8 @@ class QPDFObjectHandle @@ -449,8 +455,8 @@ class QPDFObjectHandle
449 // error messages will also be more useful because the page object 455 // error messages will also be more useful because the page object
450 // information will be known. 456 // information will be known.
451 QPDF_DLL 457 QPDF_DLL
452 - static void parseContentStream(QPDFObjectHandle stream_or_array,  
453 - ParserCallbacks* callbacks); 458 + static void parseContentStream(
  459 + QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks);
454 460
455 // When called on a stream or stream array that is some page's 461 // When called on a stream or stream array that is some page's
456 // content streams, do the same as pipePageContents. This method 462 // content streams, do the same as pipePageContents. This method
@@ -469,8 +475,10 @@ class QPDFObjectHandle @@ -469,8 +475,10 @@ class QPDFObjectHandle
469 // Pl_Concatenate and then call manualFinish() on the 475 // Pl_Concatenate and then call manualFinish() on the
470 // Pl_Concatenate pipeline at the end. 476 // Pl_Concatenate pipeline at the end.
471 QPDF_DLL 477 QPDF_DLL
472 - void pipeContentStreams(Pipeline* p, std::string const& description,  
473 - std::string& all_description); 478 + void pipeContentStreams(
  479 + Pipeline* p,
  480 + std::string const& description,
  481 + std::string& all_description);
474 482
475 // As of qpdf 8, it is possible to add custom token filters to a 483 // As of qpdf 8, it is possible to add custom token filters to a
476 // stream. The tokenized stream data is passed through the token 484 // stream. The tokenized stream data is passed through the token
@@ -525,8 +533,8 @@ class QPDFObjectHandle @@ -525,8 +533,8 @@ class QPDFObjectHandle
525 // ABI: combine with other newReal by adding trim_trailing_zeroes 533 // ABI: combine with other newReal by adding trim_trailing_zeroes
526 // above as an optional parameter with a default of true. 534 // above as an optional parameter with a default of true.
527 QPDF_DLL 535 QPDF_DLL
528 - static QPDFObjectHandle newReal(double value, int decimal_places,  
529 - bool trim_trailing_zeroes); 536 + static QPDFObjectHandle
  537 + newReal(double value, int decimal_places, bool trim_trailing_zeroes);
530 // Note about name objects: qpdf's internal representation of a 538 // Note about name objects: qpdf's internal representation of a
531 // PDF name is a sequence of bytes, excluding the NUL character, 539 // PDF name is a sequence of bytes, excluding the NUL character,
532 // and starting with a slash. Name objects as represented in the 540 // and starting with a slash. Name objects as represented in the
@@ -562,8 +570,8 @@ class QPDFObjectHandle @@ -562,8 +570,8 @@ class QPDFObjectHandle
562 QPDF_DLL 570 QPDF_DLL
563 static QPDFObjectHandle newArray(); 571 static QPDFObjectHandle newArray();
564 QPDF_DLL 572 QPDF_DLL
565 - static QPDFObjectHandle newArray(  
566 - std::vector<QPDFObjectHandle> const& items); 573 + static QPDFObjectHandle
  574 + newArray(std::vector<QPDFObjectHandle> const& items);
567 QPDF_DLL 575 QPDF_DLL
568 static QPDFObjectHandle newArray(Rectangle const&); 576 static QPDFObjectHandle newArray(Rectangle const&);
569 QPDF_DLL 577 QPDF_DLL
@@ -573,8 +581,8 @@ class QPDFObjectHandle @@ -573,8 +581,8 @@ class QPDFObjectHandle
573 QPDF_DLL 581 QPDF_DLL
574 static QPDFObjectHandle newDictionary(); 582 static QPDFObjectHandle newDictionary();
575 QPDF_DLL 583 QPDF_DLL
576 - static QPDFObjectHandle newDictionary(  
577 - std::map<std::string, QPDFObjectHandle> const& items); 584 + static QPDFObjectHandle
  585 + newDictionary(std::map<std::string, QPDFObjectHandle> const& items);
578 586
579 // Create an array from a rectangle. Equivalent to the rectangle 587 // Create an array from a rectangle. Equivalent to the rectangle
580 // form of newArray. 588 // form of newArray.
@@ -646,8 +654,8 @@ class QPDFObjectHandle @@ -646,8 +654,8 @@ class QPDFObjectHandle
646 // with proper context in some cases where it would otherwise 654 // with proper context in some cases where it would otherwise
647 // raise exceptions. 655 // raise exceptions.
648 QPDF_DLL 656 QPDF_DLL
649 - void setObjectDescription(QPDF* owning_qpdf,  
650 - std::string const& object_description); 657 + void setObjectDescription(
  658 + QPDF* owning_qpdf, std::string const& object_description);
651 QPDF_DLL 659 QPDF_DLL
652 bool hasObjectDescription(); 660 bool hasObjectDescription();
653 661
@@ -959,8 +967,8 @@ class QPDFObjectHandle @@ -959,8 +967,8 @@ class QPDFObjectHandle
959 // ABI: remove this version and make resource_names default to 967 // ABI: remove this version and make resource_names default to
960 // nullptr. 968 // nullptr.
961 QPDF_DLL 969 QPDF_DLL
962 - std::string getUniqueResourceName(std::string const& prefix,  
963 - int& min_suffix); 970 + std::string
  971 + getUniqueResourceName(std::string const& prefix, int& min_suffix);
964 972
965 // Return the QPDF object that owns an indirect object. Returns 973 // Return the QPDF object that owns an indirect object. Returns
966 // null for a direct object. 974 // null for a direct object.
@@ -1081,8 +1089,8 @@ class QPDFObjectHandle @@ -1081,8 +1089,8 @@ class QPDFObjectHandle
1081 // Returns filtered (uncompressed) stream data. Throws an 1089 // Returns filtered (uncompressed) stream data. Throws an
1082 // exception if the stream is filtered and we can't decode it. 1090 // exception if the stream is filtered and we can't decode it.
1083 QPDF_DLL 1091 QPDF_DLL
1084 - PointerHolder<Buffer> getStreamData(  
1085 - qpdf_stream_decode_level_e level = qpdf_dl_generalized); 1092 + PointerHolder<Buffer>
  1093 + getStreamData(qpdf_stream_decode_level_e level = qpdf_dl_generalized);
1086 1094
1087 // Returns unfiltered (raw) stream data. 1095 // Returns unfiltered (raw) stream data.
1088 QPDF_DLL 1096 QPDF_DLL
@@ -1146,21 +1154,24 @@ class QPDFObjectHandle @@ -1146,21 +1154,24 @@ class QPDFObjectHandle
1146 // Return value is overall success, even if filtering is not 1154 // Return value is overall success, even if filtering is not
1147 // requested. 1155 // requested.
1148 QPDF_DLL 1156 QPDF_DLL
1149 - bool pipeStreamData(Pipeline*, bool* filtering_attempted,  
1150 - int encode_flags,  
1151 - qpdf_stream_decode_level_e decode_level,  
1152 - bool suppress_warnings = false,  
1153 - bool will_retry = false); 1157 + bool pipeStreamData(
  1158 + Pipeline*,
  1159 + bool* filtering_attempted,
  1160 + int encode_flags,
  1161 + qpdf_stream_decode_level_e decode_level,
  1162 + bool suppress_warnings = false,
  1163 + bool will_retry = false);
1154 1164
1155 // Legacy version. Return value is whether filtering was 1165 // Legacy version. Return value is whether filtering was
1156 // attempted. There is no way to determine success if filtering 1166 // attempted. There is no way to determine success if filtering
1157 // was not attempted. 1167 // was not attempted.
1158 QPDF_DLL 1168 QPDF_DLL
1159 - bool pipeStreamData(Pipeline*,  
1160 - int encode_flags,  
1161 - qpdf_stream_decode_level_e decode_level,  
1162 - bool suppress_warnings = false,  
1163 - bool will_retry = false); 1169 + bool pipeStreamData(
  1170 + Pipeline*,
  1171 + int encode_flags,
  1172 + qpdf_stream_decode_level_e decode_level,
  1173 + bool suppress_warnings = false,
  1174 + bool will_retry = false);
1164 1175
1165 // Legacy pipeStreamData. This maps to the the flags-based 1176 // Legacy pipeStreamData. This maps to the the flags-based
1166 // pipeStreamData as follows: 1177 // pipeStreamData as follows:
@@ -1170,8 +1181,7 @@ class QPDFObjectHandle @@ -1170,8 +1181,7 @@ class QPDFObjectHandle
1170 // compress = true -> encode_flags |= qpdf_sf_compress 1181 // compress = true -> encode_flags |= qpdf_sf_compress
1171 // Return value is whether filtering was attempted. 1182 // Return value is whether filtering was attempted.
1172 QPDF_DLL 1183 QPDF_DLL
1173 - bool pipeStreamData(Pipeline*, bool filter,  
1174 - bool normalize, bool compress); 1184 + bool pipeStreamData(Pipeline*, bool filter, bool normalize, bool compress);
1175 1185
1176 // Replace a stream's dictionary. The new dictionary must be 1186 // Replace a stream's dictionary. The new dictionary must be
1177 // consistent with the stream's data. This is most appropriately 1187 // consistent with the stream's data. This is most appropriately
@@ -1190,18 +1200,20 @@ class QPDFObjectHandle @@ -1190,18 +1200,20 @@ class QPDFObjectHandle
1190 // interpreted as if the data read from the file, after any 1200 // interpreted as if the data read from the file, after any
1191 // decryption filters have been applied, is as presented. 1201 // decryption filters have been applied, is as presented.
1192 QPDF_DLL 1202 QPDF_DLL
1193 - void replaceStreamData(PointerHolder<Buffer> data,  
1194 - QPDFObjectHandle const& filter,  
1195 - QPDFObjectHandle const& decode_parms); 1203 + void replaceStreamData(
  1204 + PointerHolder<Buffer> data,
  1205 + QPDFObjectHandle const& filter,
  1206 + QPDFObjectHandle const& decode_parms);
1196 1207
1197 // Replace the stream's stream data with the given string. 1208 // Replace the stream's stream data with the given string.
1198 // This method will create a copy of the data rather than using 1209 // This method will create a copy of the data rather than using
1199 // the user-provided buffer as in the PointerHolder<Buffer> version 1210 // the user-provided buffer as in the PointerHolder<Buffer> version
1200 // of replaceStreamData. 1211 // of replaceStreamData.
1201 QPDF_DLL 1212 QPDF_DLL
1202 - void replaceStreamData(std::string const& data,  
1203 - QPDFObjectHandle const& filter,  
1204 - QPDFObjectHandle const& decode_parms); 1213 + void replaceStreamData(
  1214 + std::string const& data,
  1215 + QPDFObjectHandle const& filter,
  1216 + QPDFObjectHandle const& decode_parms);
1205 1217
1206 // As above, replace this stream's stream data. Instead of 1218 // As above, replace this stream's stream data. Instead of
1207 // directly providing a buffer with the stream data, call the 1219 // directly providing a buffer with the stream data, call the
@@ -1229,9 +1241,10 @@ class QPDFObjectHandle @@ -1229,9 +1241,10 @@ class QPDFObjectHandle
1229 // parameter. You can also simplify your code by not having to 1241 // parameter. You can also simplify your code by not having to
1230 // compute the length in advance. 1242 // compute the length in advance.
1231 QPDF_DLL 1243 QPDF_DLL
1232 - void replaceStreamData(PointerHolder<StreamDataProvider> provider,  
1233 - QPDFObjectHandle const& filter,  
1234 - QPDFObjectHandle const& decode_parms); 1244 + void replaceStreamData(
  1245 + PointerHolder<StreamDataProvider> provider,
  1246 + QPDFObjectHandle const& filter,
  1247 + QPDFObjectHandle const& decode_parms);
1235 1248
1236 // Starting in qpdf 10.2, you can use C++-11 function objects 1249 // Starting in qpdf 10.2, you can use C++-11 function objects
1237 // instead of StreamDataProvider. 1250 // instead of StreamDataProvider.
@@ -1240,16 +1253,16 @@ class QPDFObjectHandle @@ -1240,16 +1253,16 @@ class QPDFObjectHandle
1240 // a one-liner to replace stream data with the contents of a file, 1253 // a one-liner to replace stream data with the contents of a file,
1241 // pass QUtil::file_provider(filename) as provider. 1254 // pass QUtil::file_provider(filename) as provider.
1242 QPDF_DLL 1255 QPDF_DLL
1243 - void replaceStreamData(std::function<void(Pipeline*)> provider,  
1244 - QPDFObjectHandle const& filter,  
1245 - QPDFObjectHandle const& decode_parms); 1256 + void replaceStreamData(
  1257 + std::function<void(Pipeline*)> provider,
  1258 + QPDFObjectHandle const& filter,
  1259 + QPDFObjectHandle const& decode_parms);
1246 // The provider should write the stream data to the pipeline, 1260 // The provider should write the stream data to the pipeline,
1247 // returning true if it succeeded without errors. 1261 // returning true if it succeeded without errors.
1248 QPDF_DLL 1262 QPDF_DLL
1249 void replaceStreamData( 1263 void replaceStreamData(
1250 - std::function<bool(Pipeline*,  
1251 - bool suppress_warnings,  
1252 - bool will_retry)> provider, 1264 + std::function<bool(Pipeline*, bool suppress_warnings, bool will_retry)>
  1265 + provider,
1253 QPDFObjectHandle const& filter, 1266 QPDFObjectHandle const& filter,
1254 QPDFObjectHandle const& decode_parms); 1267 QPDFObjectHandle const& decode_parms);
1255 1268
@@ -1321,8 +1334,8 @@ class QPDFObjectHandle @@ -1321,8 +1334,8 @@ class QPDFObjectHandle
1321 // descriptions. See comments on setObjectDescription for 1334 // descriptions. See comments on setObjectDescription for
1322 // additional details. 1335 // additional details.
1323 QPDF_DLL 1336 QPDF_DLL
1324 - void warnIfPossible(std::string const& warning,  
1325 - bool throw_if_no_description = false); 1337 + void warnIfPossible(
  1338 + std::string const& warning, bool throw_if_no_description = false);
1326 1339
1327 // Initializers for objects. This Factory class gives the QPDF 1340 // Initializers for objects. This Factory class gives the QPDF
1328 // class specific permission to call factory methods without 1341 // class specific permission to call factory methods without
@@ -1330,16 +1343,22 @@ class QPDFObjectHandle @@ -1330,16 +1343,22 @@ class QPDFObjectHandle
1330 class Factory 1343 class Factory
1331 { 1344 {
1332 friend class QPDF; 1345 friend class QPDF;
  1346 +
1333 private: 1347 private:
1334 - static QPDFObjectHandle newIndirect(QPDF* qpdf,  
1335 - int objid, int generation) 1348 + static QPDFObjectHandle
  1349 + newIndirect(QPDF* qpdf, int objid, int generation)
1336 { 1350 {
1337 return QPDFObjectHandle::newIndirect(qpdf, objid, generation); 1351 return QPDFObjectHandle::newIndirect(qpdf, objid, generation);
1338 } 1352 }
1339 // object must be dictionary object 1353 // object must be dictionary object
1340 - static QPDFObjectHandle newStream(  
1341 - QPDF* qpdf, int objid, int generation,  
1342 - QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length) 1354 + static QPDFObjectHandle
  1355 + newStream(
  1356 + QPDF* qpdf,
  1357 + int objid,
  1358 + int generation,
  1359 + QPDFObjectHandle stream_dict,
  1360 + qpdf_offset_t offset,
  1361 + size_t length)
1343 { 1362 {
1344 return QPDFObjectHandle::newStream( 1363 return QPDFObjectHandle::newStream(
1345 qpdf, objid, generation, stream_dict, offset, length); 1364 qpdf, objid, generation, stream_dict, offset, length);
@@ -1352,8 +1371,10 @@ class QPDFObjectHandle @@ -1352,8 +1371,10 @@ class QPDFObjectHandle
1352 class ObjAccessor 1371 class ObjAccessor
1353 { 1372 {
1354 friend class QPDF; 1373 friend class QPDF;
  1374 +
1355 private: 1375 private:
1356 - static PointerHolder<QPDFObject> getObject(QPDFObjectHandle& o) 1376 + static PointerHolder<QPDFObject>
  1377 + getObject(QPDFObjectHandle& o)
1357 { 1378 {
1358 o.dereference(); 1379 o.dereference();
1359 return o.obj; 1380 return o.obj;
@@ -1368,8 +1389,10 @@ class QPDFObjectHandle @@ -1368,8 +1389,10 @@ class QPDFObjectHandle
1368 friend class QPDF_Dictionary; 1389 friend class QPDF_Dictionary;
1369 friend class QPDF_Stream; 1390 friend class QPDF_Stream;
1370 friend class SparseOHArray; 1391 friend class SparseOHArray;
  1392 +
1371 private: 1393 private:
1372 - static void releaseResolved(QPDFObjectHandle& o) 1394 + static void
  1395 + releaseResolved(QPDFObjectHandle& o)
1373 { 1396 {
1374 o.releaseResolved(); 1397 o.releaseResolved();
1375 } 1398 }
@@ -1433,14 +1456,13 @@ class QPDFObjectHandle @@ -1433,14 +1456,13 @@ class QPDFObjectHandle
1433 // Indicate if this is an image. If exclude_imagemask is true, 1456 // Indicate if this is an image. If exclude_imagemask is true,
1434 // don't count image masks as images. 1457 // don't count image masks as images.
1435 QPDF_DLL 1458 QPDF_DLL
1436 - bool isImage(bool exclude_imagemask=true); 1459 + bool isImage(bool exclude_imagemask = true);
1437 1460
1438 private: 1461 private:
1439 QPDFObjectHandle(QPDF*, int objid, int generation); 1462 QPDFObjectHandle(QPDF*, int objid, int generation);
1440 QPDFObjectHandle(QPDFObject*); 1463 QPDFObjectHandle(QPDFObject*);
1441 1464
1442 - enum parser_state_e  
1443 - { 1465 + enum parser_state_e {
1444 st_top, 1466 st_top,
1445 st_start, 1467 st_start,
1446 st_stop, 1468 st_stop,
@@ -1452,31 +1474,41 @@ class QPDFObjectHandle @@ -1452,31 +1474,41 @@ class QPDFObjectHandle
1452 // Private object factory methods 1474 // Private object factory methods
1453 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation); 1475 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
1454 static QPDFObjectHandle newStream( 1476 static QPDFObjectHandle newStream(
1455 - QPDF* qpdf, int objid, int generation,  
1456 - QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length);  
1457 -  
1458 - void typeWarning(char const* expected_type,  
1459 - std::string const& warning); 1477 + QPDF* qpdf,
  1478 + int objid,
  1479 + int generation,
  1480 + QPDFObjectHandle stream_dict,
  1481 + qpdf_offset_t offset,
  1482 + size_t length);
  1483 +
  1484 + void typeWarning(char const* expected_type, std::string const& warning);
1460 void objectWarning(std::string const& warning); 1485 void objectWarning(std::string const& warning);
1461 void assertType(char const* type_name, bool istype); 1486 void assertType(char const* type_name, bool istype);
1462 void dereference(); 1487 void dereference();
1463 - void copyObject(std::set<QPDFObjGen>& visited, bool cross_indirect,  
1464 - bool first_level_only, bool stop_at_streams); 1488 + void copyObject(
  1489 + std::set<QPDFObjGen>& visited,
  1490 + bool cross_indirect,
  1491 + bool first_level_only,
  1492 + bool stop_at_streams);
1465 void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only); 1493 void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only);
1466 void releaseResolved(); 1494 void releaseResolved();
1467 static void setObjectDescriptionFromInput( 1495 static void setObjectDescriptionFromInput(
1468 - QPDFObjectHandle, QPDF*, std::string const&,  
1469 - PointerHolder<InputSource>, qpdf_offset_t); 1496 + QPDFObjectHandle,
  1497 + QPDF*,
  1498 + std::string const&,
  1499 + PointerHolder<InputSource>,
  1500 + qpdf_offset_t);
1470 static QPDFObjectHandle parseInternal( 1501 static QPDFObjectHandle parseInternal(
1471 PointerHolder<InputSource> input, 1502 PointerHolder<InputSource> input,
1472 std::string const& object_description, 1503 std::string const& object_description,
1473 - QPDFTokenizer& tokenizer, bool& empty,  
1474 - StringDecrypter* decrypter, QPDF* context, 1504 + QPDFTokenizer& tokenizer,
  1505 + bool& empty,
  1506 + StringDecrypter* decrypter,
  1507 + QPDF* context,
1475 bool content_stream); 1508 bool content_stream);
1476 void setParsedOffset(qpdf_offset_t offset); 1509 void setParsedOffset(qpdf_offset_t offset);
1477 void parseContentStream_internal( 1510 void parseContentStream_internal(
1478 - std::string const& description,  
1479 - ParserCallbacks* callbacks); 1511 + std::string const& description, ParserCallbacks* callbacks);
1480 static void parseContentStream_data( 1512 static void parseContentStream_data(
1481 PointerHolder<Buffer>, 1513 PointerHolder<Buffer>,
1482 std::string const& description, 1514 std::string const& description,
@@ -1493,7 +1525,7 @@ class QPDFObjectHandle @@ -1493,7 +1525,7 @@ class QPDFObjectHandle
1493 // a substantial performance penalty since QPDFObjectHandle 1525 // a substantial performance penalty since QPDFObjectHandle
1494 // objects are copied around so frequently. 1526 // objects are copied around so frequently.
1495 QPDF* qpdf; 1527 QPDF* qpdf;
1496 - int objid; // 0 for direct object 1528 + int objid; // 0 for direct object
1497 int generation; 1529 int generation;
1498 PointerHolder<QPDFObject> obj; 1530 PointerHolder<QPDFObject> obj;
1499 bool reserved; 1531 bool reserved;
@@ -1507,7 +1539,7 @@ class QPDFObjectHandle @@ -1507,7 +1539,7 @@ class QPDFObjectHandle
1507 // If this is causing problems in your code, define 1539 // If this is causing problems in your code, define
1508 // QPDF_NO_QPDF_STRING to prevent the declaration from being here. 1540 // QPDF_NO_QPDF_STRING to prevent the declaration from being here.
1509 QPDF_DLL 1541 QPDF_DLL
1510 -QPDFObjectHandle operator ""_qpdf(char const* v, size_t len); 1542 +QPDFObjectHandle operator""_qpdf(char const* v, size_t len);
1511 #endif // QPDF_NO_QPDF_STRING 1543 #endif // QPDF_NO_QPDF_STRING
1512 1544
1513 class QPDFObjectHandle::QPDFDictItems 1545 class QPDFObjectHandle::QPDFDictItems
@@ -1531,6 +1563,7 @@ class QPDFObjectHandle::QPDFDictItems @@ -1531,6 +1563,7 @@ class QPDFObjectHandle::QPDFDictItems
1531 class iterator 1563 class iterator
1532 { 1564 {
1533 friend class QPDFDictItems; 1565 friend class QPDFDictItems;
  1566 +
1534 public: 1567 public:
1535 typedef std::pair<std::string, QPDFObjectHandle> T; 1568 typedef std::pair<std::string, QPDFObjectHandle> T;
1536 using iterator_category = std::bidirectional_iterator_tag; 1569 using iterator_category = std::bidirectional_iterator_tag;
@@ -1544,7 +1577,8 @@ class QPDFObjectHandle::QPDFDictItems @@ -1544,7 +1577,8 @@ class QPDFObjectHandle::QPDFDictItems
1544 QPDF_DLL 1577 QPDF_DLL
1545 iterator& operator++(); 1578 iterator& operator++();
1546 QPDF_DLL 1579 QPDF_DLL
1547 - iterator operator++(int) 1580 + iterator
  1581 + operator++(int)
1548 { 1582 {
1549 iterator t = *this; 1583 iterator t = *this;
1550 ++(*this); 1584 ++(*this);
@@ -1553,7 +1587,8 @@ class QPDFObjectHandle::QPDFDictItems @@ -1553,7 +1587,8 @@ class QPDFObjectHandle::QPDFDictItems
1553 QPDF_DLL 1587 QPDF_DLL
1554 iterator& operator--(); 1588 iterator& operator--();
1555 QPDF_DLL 1589 QPDF_DLL
1556 - iterator operator--(int) 1590 + iterator
  1591 + operator--(int)
1557 { 1592 {
1558 iterator t = *this; 1593 iterator t = *this;
1559 --(*this); 1594 --(*this);
@@ -1566,9 +1601,10 @@ class QPDFObjectHandle::QPDFDictItems @@ -1566,9 +1601,10 @@ class QPDFObjectHandle::QPDFDictItems
1566 QPDF_DLL 1601 QPDF_DLL
1567 bool operator==(iterator const& other) const; 1602 bool operator==(iterator const& other) const;
1568 QPDF_DLL 1603 QPDF_DLL
1569 - bool operator!=(iterator const& other) const 1604 + bool
  1605 + operator!=(iterator const& other) const
1570 { 1606 {
1571 - return ! operator==(other); 1607 + return !operator==(other);
1572 } 1608 }
1573 1609
1574 private: 1610 private:
@@ -1626,6 +1662,7 @@ class QPDFObjectHandle::QPDFArrayItems @@ -1626,6 +1662,7 @@ class QPDFObjectHandle::QPDFArrayItems
1626 class iterator 1662 class iterator
1627 { 1663 {
1628 friend class QPDFArrayItems; 1664 friend class QPDFArrayItems;
  1665 +
1629 public: 1666 public:
1630 typedef QPDFObjectHandle T; 1667 typedef QPDFObjectHandle T;
1631 using iterator_category = std::bidirectional_iterator_tag; 1668 using iterator_category = std::bidirectional_iterator_tag;
@@ -1639,7 +1676,8 @@ class QPDFObjectHandle::QPDFArrayItems @@ -1639,7 +1676,8 @@ class QPDFObjectHandle::QPDFArrayItems
1639 QPDF_DLL 1676 QPDF_DLL
1640 iterator& operator++(); 1677 iterator& operator++();
1641 QPDF_DLL 1678 QPDF_DLL
1642 - iterator operator++(int) 1679 + iterator
  1680 + operator++(int)
1643 { 1681 {
1644 iterator t = *this; 1682 iterator t = *this;
1645 ++(*this); 1683 ++(*this);
@@ -1648,7 +1686,8 @@ class QPDFObjectHandle::QPDFArrayItems @@ -1648,7 +1686,8 @@ class QPDFObjectHandle::QPDFArrayItems
1648 QPDF_DLL 1686 QPDF_DLL
1649 iterator& operator--(); 1687 iterator& operator--();
1650 QPDF_DLL 1688 QPDF_DLL
1651 - iterator operator--(int) 1689 + iterator
  1690 + operator--(int)
1652 { 1691 {
1653 iterator t = *this; 1692 iterator t = *this;
1654 --(*this); 1693 --(*this);
@@ -1661,9 +1700,10 @@ class QPDFObjectHandle::QPDFArrayItems @@ -1661,9 +1700,10 @@ class QPDFObjectHandle::QPDFArrayItems
1661 QPDF_DLL 1700 QPDF_DLL
1662 bool operator==(iterator const& other) const; 1701 bool operator==(iterator const& other) const;
1663 QPDF_DLL 1702 QPDF_DLL
1664 - bool operator!=(iterator const& other) const 1703 + bool
  1704 + operator!=(iterator const& other) const
1665 { 1705 {
1666 - return ! operator==(other); 1706 + return !operator==(other);
1667 } 1707 }
1668 1708
1669 private: 1709 private:
@@ -1700,5 +1740,4 @@ class QPDFObjectHandle::QPDFArrayItems @@ -1700,5 +1740,4 @@ class QPDFObjectHandle::QPDFArrayItems
1700 QPDFObjectHandle oh; 1740 QPDFObjectHandle oh;
1701 }; 1741 };
1702 1742
1703 -  
1704 #endif // QPDFOBJECTHANDLE_HH 1743 #endif // QPDFOBJECTHANDLE_HH
include/qpdf/QPDFObjectHelper.hh
@@ -50,12 +50,14 @@ class QPDFObjectHelper @@ -50,12 +50,14 @@ class QPDFObjectHelper
50 { 50 {
51 } 51 }
52 QPDF_DLL 52 QPDF_DLL
53 - QPDFObjectHandle getObjectHandle() 53 + QPDFObjectHandle
  54 + getObjectHandle()
54 { 55 {
55 return this->oh; 56 return this->oh;
56 } 57 }
57 QPDF_DLL 58 QPDF_DLL
58 - QPDFObjectHandle const getObjectHandle() const 59 + QPDFObjectHandle const
  60 + getObjectHandle() const
59 { 61 {
60 return this->oh; 62 return this->oh;
61 } 63 }
include/qpdf/QPDFOutlineDocumentHelper.hh
@@ -23,8 +23,8 @@ @@ -23,8 +23,8 @@
23 #define QPDFOUTLINEDOCUMENTHELPER_HH 23 #define QPDFOUTLINEDOCUMENTHELPER_HH
24 24
25 #include <qpdf/QPDFDocumentHelper.hh> 25 #include <qpdf/QPDFDocumentHelper.hh>
26 -#include <qpdf/QPDFOutlineObjectHelper.hh>  
27 #include <qpdf/QPDFNameTreeObjectHelper.hh> 26 #include <qpdf/QPDFNameTreeObjectHelper.hh>
  27 +#include <qpdf/QPDFOutlineObjectHelper.hh>
28 28
29 #include <qpdf/QPDF.hh> 29 #include <qpdf/QPDF.hh>
30 #include <map> 30 #include <map>
@@ -58,8 +58,7 @@ class QPDFOutlineDocumentHelper: public QPDFDocumentHelper @@ -58,8 +58,7 @@ class QPDFOutlineDocumentHelper: public QPDFDocumentHelper
58 // the name tree pointed to by the /Dests key of the names 58 // the name tree pointed to by the /Dests key of the names
59 // dictionary. 59 // dictionary.
60 QPDF_DLL 60 QPDF_DLL
61 - QPDFObjectHandle  
62 - resolveNamedDest(QPDFObjectHandle name); 61 + QPDFObjectHandle resolveNamedDest(QPDFObjectHandle name);
63 62
64 // Return a list outlines that are known to target the specified 63 // Return a list outlines that are known to target the specified
65 // page 64 // page
@@ -99,7 +98,7 @@ class QPDFOutlineDocumentHelper: public QPDFDocumentHelper @@ -99,7 +98,7 @@ class QPDFOutlineDocumentHelper: public QPDFDocumentHelper
99 std::set<QPDFObjGen> seen; 98 std::set<QPDFObjGen> seen;
100 QPDFObjectHandle dest_dict; 99 QPDFObjectHandle dest_dict;
101 PointerHolder<QPDFNameTreeObjectHelper> names_dest; 100 PointerHolder<QPDFNameTreeObjectHelper> names_dest;
102 - std::map<QPDFObjGen, std::vector<QPDFOutlineObjectHelper> > by_page; 101 + std::map<QPDFObjGen, std::vector<QPDFOutlineObjectHelper>> by_page;
103 }; 102 };
104 103
105 PointerHolder<Members> m; 104 PointerHolder<Members> m;
include/qpdf/QPDFOutlineObjectHelper.hh
@@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
22 #ifndef QPDFOUTLINEOBJECTHELPER_HH 22 #ifndef QPDFOUTLINEOBJECTHELPER_HH
23 #define QPDFOUTLINEOBJECTHELPER_HH 23 #define QPDFOUTLINEOBJECTHELPER_HH
24 24
25 -#include <qpdf/QPDFObjectHelper.hh>  
26 #include <qpdf/QPDFObjGen.hh> 25 #include <qpdf/QPDFObjGen.hh>
  26 +#include <qpdf/QPDFObjectHelper.hh>
27 #include <vector> 27 #include <vector>
28 28
29 class QPDFOutlineDocumentHelper; 29 class QPDFOutlineDocumentHelper;
include/qpdf/QPDFPageDocumentHelper.hh
@@ -22,9 +22,9 @@ @@ -22,9 +22,9 @@
22 #ifndef QPDFPAGEDOCUMENTHELPER_HH 22 #ifndef QPDFPAGEDOCUMENTHELPER_HH
23 #define QPDFPAGEDOCUMENTHELPER_HH 23 #define QPDFPAGEDOCUMENTHELPER_HH
24 24
  25 +#include <qpdf/Constants.h>
25 #include <qpdf/QPDFDocumentHelper.hh> 26 #include <qpdf/QPDFDocumentHelper.hh>
26 #include <qpdf/QPDFPageObjectHelper.hh> 27 #include <qpdf/QPDFPageObjectHelper.hh>
27 -#include <qpdf/Constants.h>  
28 28
29 #include <qpdf/DLL.h> 29 #include <qpdf/DLL.h>
30 30
@@ -106,8 +106,10 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper @@ -106,8 +106,10 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper
106 // Add new page before or after refpage. See comments for addPage 106 // Add new page before or after refpage. See comments for addPage
107 // for details about what newpage should be. 107 // for details about what newpage should be.
108 QPDF_DLL 108 QPDF_DLL
109 - void addPageAt(QPDFPageObjectHelper newpage, bool before,  
110 - QPDFPageObjectHelper refpage); 109 + void addPageAt(
  110 + QPDFPageObjectHelper newpage,
  111 + bool before,
  112 + QPDFPageObjectHelper refpage);
111 113
112 // Remove page from the pdf. 114 // Remove page from the pdf.
113 QPDF_DLL 115 QPDF_DLL
@@ -126,8 +128,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper @@ -126,8 +128,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper
126 // those flags. 128 // those flags.
127 QPDF_DLL 129 QPDF_DLL
128 void flattenAnnotations( 130 void flattenAnnotations(
129 - int required_flags = 0,  
130 - int forbidden_flags = an_invisible | an_hidden); 131 + int required_flags = 0, int forbidden_flags = an_invisible | an_hidden);
131 132
132 private: 133 private:
133 void flattenAnnotationsForPage( 134 void flattenAnnotationsForPage(
include/qpdf/QPDFPageLabelDocumentHelper.hh
@@ -77,10 +77,11 @@ class QPDFPageLabelDocumentHelper: public QPDFDocumentHelper @@ -77,10 +77,11 @@ class QPDFPageLabelDocumentHelper: public QPDFDocumentHelper
77 // behavior facilitates using this function to incrementally build 77 // behavior facilitates using this function to incrementally build
78 // up a page labels tree when merging files. 78 // up a page labels tree when merging files.
79 QPDF_DLL 79 QPDF_DLL
80 - void  
81 - getLabelsForPageRange(long long start_idx, long long end_idx,  
82 - long long new_start_idx,  
83 - std::vector<QPDFObjectHandle>& new_labels); 80 + void getLabelsForPageRange(
  81 + long long start_idx,
  82 + long long end_idx,
  83 + long long new_start_idx,
  84 + std::vector<QPDFObjectHandle>& new_labels);
84 85
85 private: 86 private:
86 class Members 87 class Members
include/qpdf/QPDFPageObjectHelper.hh
@@ -22,9 +22,9 @@ @@ -22,9 +22,9 @@
22 #ifndef QPDFPAGEOBJECTHELPER_HH 22 #ifndef QPDFPAGEOBJECTHELPER_HH
23 #define QPDFPAGEOBJECTHELPER_HH 23 #define QPDFPAGEOBJECTHELPER_HH
24 24
25 -#include <qpdf/QPDFObjectHelper.hh>  
26 #include <qpdf/QPDFAnnotationObjectHelper.hh> 25 #include <qpdf/QPDFAnnotationObjectHelper.hh>
27 #include <qpdf/QPDFMatrix.hh> 26 #include <qpdf/QPDFMatrix.hh>
  27 +#include <qpdf/QPDFObjectHelper.hh>
28 28
29 #include <qpdf/DLL.h> 29 #include <qpdf/DLL.h>
30 30
@@ -57,23 +57,19 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -57,23 +57,19 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
57 // going to modify the returned object and want the modifications 57 // going to modify the returned object and want the modifications
58 // to apply to the current page/form XObject only. 58 // to apply to the current page/form XObject only.
59 QPDF_DLL 59 QPDF_DLL
60 - QPDFObjectHandle  
61 - getAttribute(std::string const& name, bool copy_if_shared); 60 + QPDFObjectHandle getAttribute(std::string const& name, bool copy_if_shared);
62 61
63 // Return the TrimBox. If not defined, fall back to CropBox 62 // Return the TrimBox. If not defined, fall back to CropBox
64 QPDF_DLL 63 QPDF_DLL
65 - QPDFObjectHandle  
66 - getTrimBox(bool copy_if_shared = false); 64 + QPDFObjectHandle getTrimBox(bool copy_if_shared = false);
67 65
68 // Return the CropBox. If not defined, fall back to MediaBox 66 // Return the CropBox. If not defined, fall back to MediaBox
69 QPDF_DLL 67 QPDF_DLL
70 - QPDFObjectHandle  
71 - getCropBox(bool copy_if_shared = false); 68 + QPDFObjectHandle getCropBox(bool copy_if_shared = false);
72 69
73 // Return the MediaBox 70 // Return the MediaBox
74 QPDF_DLL 71 QPDF_DLL
75 - QPDFObjectHandle  
76 - getMediaBox(bool copy_if_shared = false); 72 + QPDFObjectHandle getMediaBox(bool copy_if_shared = false);
77 73
78 // Iterate through XObjects, possibly recursing into form 74 // Iterate through XObjects, possibly recursing into form
79 // XObjects. This works with pages or form XObjects. Call action 75 // XObjects. This works with pages or form XObjects. Call action
@@ -86,24 +82,27 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -86,24 +82,27 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
86 QPDF_DLL 82 QPDF_DLL
87 void forEachXObject( 83 void forEachXObject(
88 bool recursive, 84 bool recursive,
89 - std::function<void(QPDFObjectHandle& obj,  
90 - QPDFObjectHandle& xobj_dict,  
91 - std::string const& key)> action,  
92 - std::function<bool(QPDFObjectHandle)> selector=nullptr); 85 + std::function<void(
  86 + QPDFObjectHandle& obj,
  87 + QPDFObjectHandle& xobj_dict,
  88 + std::string const& key)> action,
  89 + std::function<bool(QPDFObjectHandle)> selector = nullptr);
93 // Only call action for images 90 // Only call action for images
94 QPDF_DLL 91 QPDF_DLL
95 void forEachImage( 92 void forEachImage(
96 bool recursive, 93 bool recursive,
97 - std::function<void(QPDFObjectHandle& obj,  
98 - QPDFObjectHandle& xobj_dict,  
99 - std::string const& key)> action); 94 + std::function<void(
  95 + QPDFObjectHandle& obj,
  96 + QPDFObjectHandle& xobj_dict,
  97 + std::string const& key)> action);
100 // Only call action for form XObjects 98 // Only call action for form XObjects
101 QPDF_DLL 99 QPDF_DLL
102 void forEachFormXObject( 100 void forEachFormXObject(
103 bool recursive, 101 bool recursive,
104 - std::function<void(QPDFObjectHandle& obj,  
105 - QPDFObjectHandle& xobj_dict,  
106 - std::string const& key)> action); 102 + std::function<void(
  103 + QPDFObjectHandle& obj,
  104 + QPDFObjectHandle& xobj_dict,
  105 + std::string const& key)> action);
107 106
108 // Returns an empty map if there are no images or no resources. 107 // Returns an empty map if there are no images or no resources.
109 // Prior to qpdf 8.4.0, this function did not support inherited 108 // Prior to qpdf 8.4.0, this function did not support inherited
@@ -142,8 +141,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -142,8 +141,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
142 // only_subtype is non-empty, only include annotations of the 141 // only_subtype is non-empty, only include annotations of the
143 // given subtype. 142 // given subtype.
144 QPDF_DLL 143 QPDF_DLL
145 - std::vector<QPDFAnnotationObjectHelper> getAnnotations(  
146 - std::string const& only_subtype = ""); 144 + std::vector<QPDFAnnotationObjectHelper>
  145 + getAnnotations(std::string const& only_subtype = "");
147 146
148 // Returns a vector of stream objects representing the content 147 // Returns a vector of stream objects representing the content
149 // streams for the given page. This routine allows the caller to 148 // streams for the given page. This routine allows the caller to
@@ -203,13 +202,13 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -203,13 +202,13 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
203 // contents, as happens with addContentTokenFilter. See 202 // contents, as happens with addContentTokenFilter. See
204 // examples/pdf-count-strings.cc for an example. 203 // examples/pdf-count-strings.cc for an example.
205 QPDF_DLL 204 QPDF_DLL
206 - void filterContents(QPDFObjectHandle::TokenFilter* filter,  
207 - Pipeline* next = 0); 205 + void
  206 + filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next = 0);
208 207
209 // Old name -- calls filterContents() 208 // Old name -- calls filterContents()
210 QPDF_DLL 209 QPDF_DLL
211 - void filterPageContents(QPDFObjectHandle::TokenFilter* filter,  
212 - Pipeline* next = 0); 210 + void filterPageContents(
  211 + QPDFObjectHandle::TokenFilter* filter, Pipeline* next = 0);
213 212
214 // Pipe a page's contents through the given pipeline. This method 213 // Pipe a page's contents through the given pipeline. This method
215 // works whether the contents are a single stream or an array of 214 // works whether the contents are a single stream or an array of
@@ -303,7 +302,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -303,7 +302,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
303 // behavior. 302 // behavior.
304 QPDF_DLL 303 QPDF_DLL
305 std::string placeFormXObject( 304 std::string placeFormXObject(
306 - QPDFObjectHandle fo, std::string const& name, 305 + QPDFObjectHandle fo,
  306 + std::string const& name,
307 QPDFObjectHandle::Rectangle rect, 307 QPDFObjectHandle::Rectangle rect,
308 bool invert_transformations = true, 308 bool invert_transformations = true,
309 bool allow_shrink = true, 309 bool allow_shrink = true,
@@ -313,7 +313,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -313,7 +313,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
313 // matrix that was used. 313 // matrix that was used.
314 QPDF_DLL 314 QPDF_DLL
315 std::string placeFormXObject( 315 std::string placeFormXObject(
316 - QPDFObjectHandle fo, std::string const& name, 316 + QPDFObjectHandle fo,
  317 + std::string const& name,
317 QPDFObjectHandle::Rectangle rect, 318 QPDFObjectHandle::Rectangle rect,
318 QPDFMatrix& cm, 319 QPDFMatrix& cm,
319 bool invert_transformations = true, 320 bool invert_transformations = true,
@@ -326,9 +327,11 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -326,9 +327,11 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
326 // placeFormXObject. 327 // placeFormXObject.
327 QPDF_DLL 328 QPDF_DLL
328 QPDFMatrix getMatrixForFormXObjectPlacement( 329 QPDFMatrix getMatrixForFormXObjectPlacement(
329 - QPDFObjectHandle fo, QPDFObjectHandle::Rectangle rect, 330 + QPDFObjectHandle fo,
  331 + QPDFObjectHandle::Rectangle rect,
330 bool invert_transformations = true, 332 bool invert_transformations = true,
331 - bool allow_shrink = true, bool allow_expand = false); 333 + bool allow_shrink = true,
  334 + bool allow_expand = false);
332 335
333 // If a page is rotated using /Rotate in the page's dictionary, 336 // If a page is rotated using /Rotate in the page's dictionary,
334 // instead rotate the page by the same amount by altering the 337 // instead rotate the page by the same amount by altering the
@@ -372,13 +375,13 @@ class QPDFPageObjectHelper: public QPDFObjectHelper @@ -372,13 +375,13 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
372 // these outside and pass them in. 375 // these outside and pass them in.
373 QPDF_DLL 376 QPDF_DLL
374 void copyAnnotations( 377 void copyAnnotations(
375 - QPDFPageObjectHelper from_page, QPDFMatrix const& cm = QPDFMatrix(), 378 + QPDFPageObjectHelper from_page,
  379 + QPDFMatrix const& cm = QPDFMatrix(),
376 QPDFAcroFormDocumentHelper* afdh = nullptr, 380 QPDFAcroFormDocumentHelper* afdh = nullptr,
377 QPDFAcroFormDocumentHelper* from_afdh = nullptr); 381 QPDFAcroFormDocumentHelper* from_afdh = nullptr);
378 382
379 private: 383 private:
380 - static bool  
381 - removeUnreferencedResourcesHelper( 384 + static bool removeUnreferencedResourcesHelper(
382 QPDFPageObjectHelper ph, std::set<std::string>& unresolved); 385 QPDFPageObjectHelper ph, std::set<std::string>& unresolved);
383 386
384 class Members 387 class Members
include/qpdf/QPDFStreamFilter.hh
@@ -23,8 +23,8 @@ @@ -23,8 +23,8 @@
23 #define QPDFSTREAMFILTER_HH 23 #define QPDFSTREAMFILTER_HH
24 24
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 -#include <qpdf/QPDFObjectHandle.hh>  
27 #include <qpdf/Pipeline.hh> 26 #include <qpdf/Pipeline.hh>
  27 +#include <qpdf/QPDFObjectHandle.hh>
28 28
29 class QPDF_DLL_CLASS QPDFStreamFilter 29 class QPDF_DLL_CLASS QPDFStreamFilter
30 { 30 {
include/qpdf/QPDFSystemError.hh
@@ -22,19 +22,18 @@ @@ -22,19 +22,18 @@
22 #ifndef QPDFSYSTEMERROR_HH 22 #ifndef QPDFSYSTEMERROR_HH
23 #define QPDFSYSTEMERROR_HH 23 #define QPDFSYSTEMERROR_HH
24 24
  25 +#include <qpdf/Constants.h>
25 #include <qpdf/DLL.h> 26 #include <qpdf/DLL.h>
26 #include <qpdf/Types.h> 27 #include <qpdf/Types.h>
27 -#include <qpdf/Constants.h>  
28 28
29 -#include <string>  
30 #include <stdexcept> 29 #include <stdexcept>
  30 +#include <string>
31 31
32 class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error 32 class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error
33 { 33 {
34 public: 34 public:
35 QPDF_DLL 35 QPDF_DLL
36 - QPDFSystemError(std::string const& description,  
37 - int system_errno); 36 + QPDFSystemError(std::string const& description, int system_errno);
38 QPDF_DLL 37 QPDF_DLL
39 virtual ~QPDFSystemError() noexcept; 38 virtual ~QPDFSystemError() noexcept;
40 39
@@ -48,8 +47,8 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error @@ -48,8 +47,8 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error
48 int getErrno() const; 47 int getErrno() const;
49 48
50 private: 49 private:
51 - static std::string createWhat(std::string const& description,  
52 - int system_errno); 50 + static std::string
  51 + createWhat(std::string const& description, int system_errno);
53 52
54 // This class does not use the Members pattern to avoid needless 53 // This class does not use the Members pattern to avoid needless
55 // memory allocations during exception handling. 54 // memory allocations during exception handling.
include/qpdf/QPDFTokenizer.hh
@@ -27,9 +27,9 @@ @@ -27,9 +27,9 @@
27 #include <qpdf/InputSource.hh> 27 #include <qpdf/InputSource.hh>
28 #include <qpdf/PointerHolder.hh> 28 #include <qpdf/PointerHolder.hh>
29 29
30 -#include <string>  
31 -#include <stdio.h>  
32 #include <memory> 30 #include <memory>
  31 +#include <stdio.h>
  32 +#include <string>
33 33
34 class QPDFTokenizer 34 class QPDFTokenizer
35 { 35 {
@@ -38,8 +38,7 @@ class QPDFTokenizer @@ -38,8 +38,7 @@ class QPDFTokenizer
38 // the tokenizer. tt_eof was introduced in QPDF version 4.1. 38 // the tokenizer. tt_eof was introduced in QPDF version 4.1.
39 // tt_space, tt_comment, and tt_inline_image were added in QPDF 39 // tt_space, tt_comment, and tt_inline_image were added in QPDF
40 // version 8. 40 // version 8.
41 - enum token_type_e  
42 - { 41 + enum token_type_e {
43 tt_bad, 42 tt_bad,
44 tt_array_close, 43 tt_array_close,
45 tt_array_open, 44 tt_array_open,
@@ -63,39 +62,50 @@ class QPDFTokenizer @@ -63,39 +62,50 @@ class QPDFTokenizer
63 class Token 62 class Token
64 { 63 {
65 public: 64 public:
66 - Token() : type(tt_bad) {} 65 + Token() :
  66 + type(tt_bad)
  67 + {
  68 + }
67 QPDF_DLL 69 QPDF_DLL
68 Token(token_type_e type, std::string const& value); 70 Token(token_type_e type, std::string const& value);
69 - Token(token_type_e type, std::string const& value,  
70 - std::string raw_value, std::string error_message) : 71 + Token(
  72 + token_type_e type,
  73 + std::string const& value,
  74 + std::string raw_value,
  75 + std::string error_message) :
71 type(type), 76 type(type),
72 value(value), 77 value(value),
73 raw_value(raw_value), 78 raw_value(raw_value),
74 error_message(error_message) 79 error_message(error_message)
75 { 80 {
76 } 81 }
77 - token_type_e getType() const 82 + token_type_e
  83 + getType() const
78 { 84 {
79 return this->type; 85 return this->type;
80 } 86 }
81 - std::string const& getValue() const 87 + std::string const&
  88 + getValue() const
82 { 89 {
83 return this->value; 90 return this->value;
84 } 91 }
85 - std::string const& getRawValue() const 92 + std::string const&
  93 + getRawValue() const
86 { 94 {
87 return this->raw_value; 95 return this->raw_value;
88 } 96 }
89 - std::string const& getErrorMessage() const 97 + std::string const&
  98 + getErrorMessage() const
90 { 99 {
91 return this->error_message; 100 return this->error_message;
92 } 101 }
93 - bool operator==(Token const& rhs) const 102 + bool
  103 + operator==(Token const& rhs) const
94 { 104 {
95 // Ignore fields other than type and value 105 // Ignore fields other than type and value
96 - return ((this->type != tt_bad) &&  
97 - (this->type == rhs.type) &&  
98 - (this->value == rhs.value)); 106 + return (
  107 + (this->type != tt_bad) && (this->type == rhs.type) &&
  108 + (this->value == rhs.value));
99 } 109 }
100 110
101 private: 111 private:
@@ -162,10 +172,11 @@ class QPDFTokenizer @@ -162,10 +172,11 @@ class QPDFTokenizer
162 // offset" as returned by input->getLastOffset() points to the 172 // offset" as returned by input->getLastOffset() points to the
163 // beginning of the token. 173 // beginning of the token.
164 QPDF_DLL 174 QPDF_DLL
165 - Token readToken(PointerHolder<InputSource> input,  
166 - std::string const& context,  
167 - bool allow_bad = false,  
168 - size_t max_len = 0); 175 + Token readToken(
  176 + PointerHolder<InputSource> input,
  177 + std::string const& context,
  178 + bool allow_bad = false,
  179 + size_t max_len = 0);
169 180
170 // Calling this method puts the tokenizer in a state for reading 181 // Calling this method puts the tokenizer in a state for reading
171 // inline images. You should call this method after reading the 182 // inline images. You should call this method after reading the
@@ -188,8 +199,16 @@ class QPDFTokenizer @@ -188,8 +199,16 @@ class QPDFTokenizer
188 void findEI(PointerHolder<InputSource> input); 199 void findEI(PointerHolder<InputSource> input);
189 200
190 enum state_e { 201 enum state_e {
191 - st_top, st_in_space, st_in_comment, st_in_string, st_lt, st_gt,  
192 - st_literal, st_in_hexstring, st_inline_image, st_token_ready 202 + st_top,
  203 + st_in_space,
  204 + st_in_comment,
  205 + st_in_string,
  206 + st_lt,
  207 + st_gt,
  208 + st_literal,
  209 + st_in_hexstring,
  210 + st_inline_image,
  211 + st_token_ready
193 }; 212 };
194 213
195 class Members 214 class Members
include/qpdf/QPDFUsage.hh
@@ -24,8 +24,8 @@ @@ -24,8 +24,8 @@
24 24
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 26
27 -#include <string>  
28 #include <stdexcept> 27 #include <stdexcept>
  28 +#include <string>
29 29
30 class QPDF_DLL_CLASS QPDFUsage: public std::runtime_error 30 class QPDF_DLL_CLASS QPDFUsage: public std::runtime_error
31 { 31 {
include/qpdf/QPDFWriter.hh
@@ -29,24 +29,24 @@ @@ -29,24 +29,24 @@
29 #include <qpdf/DLL.h> 29 #include <qpdf/DLL.h>
30 #include <qpdf/Types.h> 30 #include <qpdf/Types.h>
31 31
32 -#include <stdio.h>  
33 -#include <string>  
34 #include <list> 32 #include <list>
35 -#include <vector>  
36 -#include <set>  
37 #include <map> 33 #include <map>
38 #include <memory> 34 #include <memory>
  35 +#include <set>
  36 +#include <stdio.h>
  37 +#include <string>
  38 +#include <vector>
39 39
40 #include <qpdf/Constants.h> 40 #include <qpdf/Constants.h>
41 41
42 -#include <qpdf/QPDFObjectHandle.hh>  
43 -#include <qpdf/QPDFObjGen.hh>  
44 -#include <qpdf/QPDFXRefEntry.hh>  
45 -#include <qpdf/Pl_Buffer.hh>  
46 -#include <qpdf/PointerHolder.hh>  
47 -#include <qpdf/Pipeline.hh>  
48 #include <qpdf/Buffer.hh> 42 #include <qpdf/Buffer.hh>
49 #include <qpdf/PDFVersion.hh> 43 #include <qpdf/PDFVersion.hh>
  44 +#include <qpdf/Pipeline.hh>
  45 +#include <qpdf/Pl_Buffer.hh>
  46 +#include <qpdf/PointerHolder.hh>
  47 +#include <qpdf/QPDFObjGen.hh>
  48 +#include <qpdf/QPDFObjectHandle.hh>
  49 +#include <qpdf/QPDFXRefEntry.hh>
50 50
51 class QPDF; 51 class QPDF;
52 class Pl_Count; 52 class Pl_Count;
@@ -372,72 +372,104 @@ class QPDFWriter @@ -372,72 +372,104 @@ class QPDFWriter
372 // it unless you have to. 372 // it unless you have to.
373 QPDF_DLL 373 QPDF_DLL
374 void setR2EncryptionParameters( 374 void setR2EncryptionParameters(
375 - char const* user_password, char const* owner_password,  
376 - bool allow_print, bool allow_modify,  
377 - bool allow_extract, bool allow_annotate); 375 + char const* user_password,
  376 + char const* owner_password,
  377 + bool allow_print,
  378 + bool allow_modify,
  379 + bool allow_extract,
  380 + bool allow_annotate);
378 // R3 uses RC4, which is a weak cryptographic algorithm. Don't use 381 // R3 uses RC4, which is a weak cryptographic algorithm. Don't use
379 // it unless you have to. 382 // it unless you have to.
380 QPDF_DLL 383 QPDF_DLL
381 void setR3EncryptionParameters( 384 void setR3EncryptionParameters(
382 - char const* user_password, char const* owner_password,  
383 - bool allow_accessibility, bool allow_extract,  
384 - bool allow_assemble, bool allow_annotate_and_form,  
385 - bool allow_form_filling, bool allow_modify_other, 385 + char const* user_password,
  386 + char const* owner_password,
  387 + bool allow_accessibility,
  388 + bool allow_extract,
  389 + bool allow_assemble,
  390 + bool allow_annotate_and_form,
  391 + bool allow_form_filling,
  392 + bool allow_modify_other,
386 qpdf_r3_print_e print); 393 qpdf_r3_print_e print);
387 // R4 uses RC4, which is a weak cryptographic algorithm, when 394 // R4 uses RC4, which is a weak cryptographic algorithm, when
388 // use_aes=false. Don't use it unless you have to. 395 // use_aes=false. Don't use it unless you have to.
389 QPDF_DLL 396 QPDF_DLL
390 void setR4EncryptionParameters( 397 void setR4EncryptionParameters(
391 - char const* user_password, char const* owner_password,  
392 - bool allow_accessibility, bool allow_extract,  
393 - bool allow_assemble, bool allow_annotate_and_form,  
394 - bool allow_form_filling, bool allow_modify_other,  
395 - qpdf_r3_print_e print, bool encrypt_metadata, bool use_aes); 398 + char const* user_password,
  399 + char const* owner_password,
  400 + bool allow_accessibility,
  401 + bool allow_extract,
  402 + bool allow_assemble,
  403 + bool allow_annotate_and_form,
  404 + bool allow_form_filling,
  405 + bool allow_modify_other,
  406 + qpdf_r3_print_e print,
  407 + bool encrypt_metadata,
  408 + bool use_aes);
396 // R5 is deprecated. Do not use it for production use. Writing 409 // R5 is deprecated. Do not use it for production use. Writing
397 // R5 is supported by qpdf primarily to generate test files for 410 // R5 is supported by qpdf primarily to generate test files for
398 // applications that may need to test R5 support. 411 // applications that may need to test R5 support.
399 QPDF_DLL 412 QPDF_DLL
400 void setR5EncryptionParameters( 413 void setR5EncryptionParameters(
401 - char const* user_password, char const* owner_password,  
402 - bool allow_accessibility, bool allow_extract,  
403 - bool allow_assemble, bool allow_annotate_and_form,  
404 - bool allow_form_filling, bool allow_modify_other,  
405 - qpdf_r3_print_e print, bool encrypt_metadata); 414 + char const* user_password,
  415 + char const* owner_password,
  416 + bool allow_accessibility,
  417 + bool allow_extract,
  418 + bool allow_assemble,
  419 + bool allow_annotate_and_form,
  420 + bool allow_form_filling,
  421 + bool allow_modify_other,
  422 + qpdf_r3_print_e print,
  423 + bool encrypt_metadata);
406 QPDF_DLL 424 QPDF_DLL
407 void setR6EncryptionParameters( 425 void setR6EncryptionParameters(
408 - char const* user_password, char const* owner_password,  
409 - bool allow_accessibility, bool allow_extract,  
410 - bool allow_assemble, bool allow_annotate_and_form,  
411 - bool allow_form_filling, bool allow_modify_other,  
412 - qpdf_r3_print_e print, bool encrypt_metadata_aes); 426 + char const* user_password,
  427 + char const* owner_password,
  428 + bool allow_accessibility,
  429 + bool allow_extract,
  430 + bool allow_assemble,
  431 + bool allow_annotate_and_form,
  432 + bool allow_form_filling,
  433 + bool allow_modify_other,
  434 + qpdf_r3_print_e print,
  435 + bool encrypt_metadata_aes);
413 436
414 // Pre qpdf 8.4.0 API 437 // Pre qpdf 8.4.0 API
415 - [[deprecated("see newer API above")]]  
416 - QPDF_DLL  
417 - void setR3EncryptionParameters(  
418 - char const* user_password, char const* owner_password,  
419 - bool allow_accessibility, bool allow_extract,  
420 - qpdf_r3_print_e print, qpdf_r3_modify_e modify);  
421 - [[deprecated("see newer API above")]]  
422 - QPDF_DLL  
423 - void setR4EncryptionParameters(  
424 - char const* user_password, char const* owner_password,  
425 - bool allow_accessibility, bool allow_extract,  
426 - qpdf_r3_print_e print, qpdf_r3_modify_e modify,  
427 - bool encrypt_metadata, bool use_aes);  
428 - [[deprecated("see newer API above")]]  
429 - QPDF_DLL  
430 - void setR5EncryptionParameters(  
431 - char const* user_password, char const* owner_password,  
432 - bool allow_accessibility, bool allow_extract,  
433 - qpdf_r3_print_e print, qpdf_r3_modify_e modify, 438 + [[deprecated("see newer API above")]] QPDF_DLL void
  439 + setR3EncryptionParameters(
  440 + char const* user_password,
  441 + char const* owner_password,
  442 + bool allow_accessibility,
  443 + bool allow_extract,
  444 + qpdf_r3_print_e print,
  445 + qpdf_r3_modify_e modify);
  446 + [[deprecated("see newer API above")]] QPDF_DLL void
  447 + setR4EncryptionParameters(
  448 + char const* user_password,
  449 + char const* owner_password,
  450 + bool allow_accessibility,
  451 + bool allow_extract,
  452 + qpdf_r3_print_e print,
  453 + qpdf_r3_modify_e modify,
  454 + bool encrypt_metadata,
  455 + bool use_aes);
  456 + [[deprecated("see newer API above")]] QPDF_DLL void
  457 + setR5EncryptionParameters(
  458 + char const* user_password,
  459 + char const* owner_password,
  460 + bool allow_accessibility,
  461 + bool allow_extract,
  462 + qpdf_r3_print_e print,
  463 + qpdf_r3_modify_e modify,
434 bool encrypt_metadata); 464 bool encrypt_metadata);
435 - [[deprecated("see newer API above")]]  
436 - QPDF_DLL  
437 - void setR6EncryptionParameters(  
438 - char const* user_password, char const* owner_password,  
439 - bool allow_accessibility, bool allow_extract,  
440 - qpdf_r3_print_e print, qpdf_r3_modify_e modify, 465 + [[deprecated("see newer API above")]] QPDF_DLL void
  466 + setR6EncryptionParameters(
  467 + char const* user_password,
  468 + char const* owner_password,
  469 + bool allow_accessibility,
  470 + bool allow_extract,
  471 + qpdf_r3_print_e print,
  472 + qpdf_r3_modify_e modify,
441 bool encrypt_metadata_aes); 473 bool encrypt_metadata_aes);
442 474
443 // Create linearized output. Disables qdf mode, content 475 // Create linearized output. Disables qdf mode, content
@@ -496,11 +528,11 @@ class QPDFWriter @@ -496,11 +528,11 @@ class QPDFWriter
496 528
497 private: 529 private:
498 // flags used by unparseObject 530 // flags used by unparseObject
499 - static int const f_stream = 1 << 0;  
500 - static int const f_filtered = 1 << 1;  
501 - static int const f_in_ostream = 1 << 2;  
502 - static int const f_hex_string = 1 << 3;  
503 - static int const f_no_encryption = 1 << 4; 531 + static int const f_stream = 1 << 0;
  532 + static int const f_filtered = 1 << 1;
  533 + static int const f_in_ostream = 1 << 2;
  534 + static int const f_hex_string = 1 << 3;
  535 + static int const f_no_encryption = 1 << 4;
504 536
505 enum trailer_e { t_normal, t_lin_first, t_lin_second }; 537 enum trailer_e { t_normal, t_lin_first, t_lin_second };
506 538
@@ -516,9 +548,9 @@ class QPDFWriter @@ -516,9 +548,9 @@ class QPDFWriter
516 class PipelinePopper 548 class PipelinePopper
517 { 549 {
518 friend class QPDFWriter; 550 friend class QPDFWriter;
  551 +
519 public: 552 public:
520 - PipelinePopper(QPDFWriter* qw,  
521 - PointerHolder<Buffer>* bp = 0) : 553 + PipelinePopper(QPDFWriter* qw, PointerHolder<Buffer>* bp = 0) :
522 qw(qw), 554 qw(qw),
523 bp(bp) 555 bp(bp)
524 { 556 {
@@ -545,15 +577,24 @@ class QPDFWriter @@ -545,15 +577,24 @@ class QPDFWriter
545 std::vector<qpdf_offset_t>& offsets, int first_obj); 577 std::vector<qpdf_offset_t>& offsets, int first_obj);
546 void writeObjectStream(QPDFObjectHandle object); 578 void writeObjectStream(QPDFObjectHandle object);
547 void writeObject(QPDFObjectHandle object, int object_stream_index = -1); 579 void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
548 - void writeTrailer(trailer_e which, int size,  
549 - bool xref_stream, qpdf_offset_t prev,  
550 - int linearization_pass);  
551 - bool willFilterStream(QPDFObjectHandle stream,  
552 - bool& compress_stream, bool& is_metadata,  
553 - PointerHolder<Buffer>* stream_data);  
554 - void unparseObject(QPDFObjectHandle object, int level, int flags,  
555 - // for stream dictionaries  
556 - size_t stream_length = 0, bool compress = false); 580 + void writeTrailer(
  581 + trailer_e which,
  582 + int size,
  583 + bool xref_stream,
  584 + qpdf_offset_t prev,
  585 + int linearization_pass);
  586 + bool willFilterStream(
  587 + QPDFObjectHandle stream,
  588 + bool& compress_stream,
  589 + bool& is_metadata,
  590 + PointerHolder<Buffer>* stream_data);
  591 + void unparseObject(
  592 + QPDFObjectHandle object,
  593 + int level,
  594 + int flags,
  595 + // for stream dictionaries
  596 + size_t stream_length = 0,
  597 + bool compress = false);
557 void unparseChild(QPDFObjectHandle child, int level, int flags); 598 void unparseChild(QPDFObjectHandle child, int level, int flags);
558 void initializeSpecialStreams(); 599 void initializeSpecialStreams();
559 void preserveObjectStreams(); 600 void preserveObjectStreams();
@@ -562,23 +603,39 @@ class QPDFWriter @@ -562,23 +603,39 @@ class QPDFWriter
562 void generateID(); 603 void generateID();
563 void interpretR3EncryptionParameters( 604 void interpretR3EncryptionParameters(
564 std::set<int>& bits_to_clear, 605 std::set<int>& bits_to_clear,
565 - char const* user_password, char const* owner_password,  
566 - bool allow_accessibility, bool allow_extract,  
567 - bool allow_assemble, bool allow_annotate_and_form,  
568 - bool allow_form_filling, bool allow_modify_other,  
569 - qpdf_r3_print_e print, qpdf_r3_modify_e modify);  
570 - void disableIncompatibleEncryption(int major, int minor,  
571 - int extension_level); 606 + char const* user_password,
  607 + char const* owner_password,
  608 + bool allow_accessibility,
  609 + bool allow_extract,
  610 + bool allow_assemble,
  611 + bool allow_annotate_and_form,
  612 + bool allow_form_filling,
  613 + bool allow_modify_other,
  614 + qpdf_r3_print_e print,
  615 + qpdf_r3_modify_e modify);
  616 + void
  617 + disableIncompatibleEncryption(int major, int minor, int extension_level);
572 void parseVersion(std::string const& version, int& major, int& minor) const; 618 void parseVersion(std::string const& version, int& major, int& minor) const;
573 int compareVersions(int major1, int minor1, int major2, int minor2) const; 619 int compareVersions(int major1, int minor1, int major2, int minor2) const;
574 void setEncryptionParameters( 620 void setEncryptionParameters(
575 - char const* user_password, char const* owner_password,  
576 - int V, int R, int key_len, std::set<int>& bits_to_clear); 621 + char const* user_password,
  622 + char const* owner_password,
  623 + int V,
  624 + int R,
  625 + int key_len,
  626 + std::set<int>& bits_to_clear);
577 void setEncryptionParametersInternal( 627 void setEncryptionParametersInternal(
578 - int V, int R, int key_len, int P,  
579 - std::string const& O, std::string const& U,  
580 - std::string const& OE, std::string const& UE, std::string const& Perms,  
581 - std::string const& id1, std::string const& user_password, 628 + int V,
  629 + int R,
  630 + int key_len,
  631 + int P,
  632 + std::string const& O,
  633 + std::string const& U,
  634 + std::string const& OE,
  635 + std::string const& UE,
  636 + std::string const& Perms,
  637 + std::string const& id1,
  638 + std::string const& user_password,
582 std::string const& encryption_key); 639 std::string const& encryption_key);
583 void setDataKey(int objid); 640 void setDataKey(int objid);
584 int openObject(int objid = 0); 641 int openObject(int objid = 0);
@@ -595,10 +652,13 @@ class QPDFWriter @@ -595,10 +652,13 @@ class QPDFWriter
595 void doWriteSetup(); 652 void doWriteSetup();
596 void writeHeader(); 653 void writeHeader();
597 void writeHintStream(int hint_id); 654 void writeHintStream(int hint_id);
  655 + qpdf_offset_t
  656 + writeXRefTable(trailer_e which, int first, int last, int size);
598 qpdf_offset_t writeXRefTable( 657 qpdf_offset_t writeXRefTable(
599 - trailer_e which, int first, int last, int size);  
600 - qpdf_offset_t writeXRefTable(  
601 - trailer_e which, int first, int last, int size, 658 + trailer_e which,
  659 + int first,
  660 + int last,
  661 + int size,
602 // for linearization 662 // for linearization
603 qpdf_offset_t prev, 663 qpdf_offset_t prev,
604 bool suppress_offsets, 664 bool suppress_offsets,
@@ -607,11 +667,21 @@ class QPDFWriter @@ -607,11 +667,21 @@ class QPDFWriter
607 qpdf_offset_t hint_length, 667 qpdf_offset_t hint_length,
608 int linearization_pass); 668 int linearization_pass);
609 qpdf_offset_t writeXRefStream( 669 qpdf_offset_t writeXRefStream(
610 - int objid, int max_id, qpdf_offset_t max_offset,  
611 - trailer_e which, int first, int last, int size); 670 + int objid,
  671 + int max_id,
  672 + qpdf_offset_t max_offset,
  673 + trailer_e which,
  674 + int first,
  675 + int last,
  676 + int size);
612 qpdf_offset_t writeXRefStream( 677 qpdf_offset_t writeXRefStream(
613 - int objid, int max_id, qpdf_offset_t max_offset,  
614 - trailer_e which, int first, int last, int size, 678 + int objid,
  679 + int max_id,
  680 + qpdf_offset_t max_offset,
  681 + trailer_e which,
  682 + int first,
  683 + int last,
  684 + int size,
615 // for linearization 685 // for linearization
616 qpdf_offset_t prev, 686 qpdf_offset_t prev,
617 int hint_id, 687 int hint_id,
@@ -627,7 +697,7 @@ class QPDFWriter @@ -627,7 +697,7 @@ class QPDFWriter
627 // popped. 697 // popped.
628 Pipeline* pushPipeline(Pipeline*); 698 Pipeline* pushPipeline(Pipeline*);
629 void activatePipelineStack(PipelinePopper&); 699 void activatePipelineStack(PipelinePopper&);
630 - void initializePipelineStack(Pipeline *); 700 + void initializePipelineStack(Pipeline*);
631 701
632 void adjustAESStreamLength(size_t& length); 702 void adjustAESStreamLength(size_t& length);
633 void pushEncryptionFilter(PipelinePopper&); 703 void pushEncryptionFilter(PipelinePopper&);
@@ -635,8 +705,8 @@ class QPDFWriter @@ -635,8 +705,8 @@ class QPDFWriter
635 void pushMD5Pipeline(PipelinePopper&); 705 void pushMD5Pipeline(PipelinePopper&);
636 void computeDeterministicIDData(); 706 void computeDeterministicIDData();
637 707
638 - void discardGeneration(std::map<QPDFObjGen, int> const& in,  
639 - std::map<int, int>& out); 708 + void discardGeneration(
  709 + std::map<QPDFObjGen, int> const& in, std::map<int, int>& out);
640 710
641 class Members 711 class Members
642 { 712 {
@@ -681,8 +751,8 @@ class QPDFWriter @@ -681,8 +751,8 @@ class QPDFWriter
681 int encryption_V; 751 int encryption_V;
682 int encryption_R; 752 int encryption_R;
683 753
684 - std::string id1; // for /ID key of  
685 - std::string id2; // trailer dictionary 754 + std::string id1; // for /ID key of
  755 + std::string id2; // trailer dictionary
686 std::string final_pdf_version; 756 std::string final_pdf_version;
687 int final_extension_level; 757 int final_extension_level;
688 std::string min_pdf_version; 758 std::string min_pdf_version;
@@ -707,7 +777,7 @@ class QPDFWriter @@ -707,7 +777,7 @@ class QPDFWriter
707 std::map<QPDFObjGen, int> page_object_to_seq; 777 std::map<QPDFObjGen, int> page_object_to_seq;
708 std::map<QPDFObjGen, int> contents_to_page_seq; 778 std::map<QPDFObjGen, int> contents_to_page_seq;
709 std::map<QPDFObjGen, int> object_to_object_stream; 779 std::map<QPDFObjGen, int> object_to_object_stream;
710 - std::map<int, std::set<QPDFObjGen> > object_stream_to_objects; 780 + std::map<int, std::set<QPDFObjGen>> object_stream_to_objects;
711 std::list<Pipeline*> pipeline_stack; 781 std::list<Pipeline*> pipeline_stack;
712 unsigned long long next_stack_id; 782 unsigned long long next_stack_id;
713 bool deterministic_id; 783 bool deterministic_id;
include/qpdf/QPDFXRefEntry.hh
@@ -42,11 +42,11 @@ class QPDFXRefEntry @@ -42,11 +42,11 @@ class QPDFXRefEntry
42 QPDF_DLL 42 QPDF_DLL
43 int getType() const; 43 int getType() const;
44 QPDF_DLL 44 QPDF_DLL
45 - qpdf_offset_t getOffset() const; // only for type 1 45 + qpdf_offset_t getOffset() const; // only for type 1
46 QPDF_DLL 46 QPDF_DLL
47 - int getObjStreamNumber() const; // only for type 2 47 + int getObjStreamNumber() const; // only for type 2
48 QPDF_DLL 48 QPDF_DLL
49 - int getObjStreamIndex() const; // only for type 2 49 + int getObjStreamIndex() const; // only for type 2
50 50
51 private: 51 private:
52 // This class does not use the Members pattern to avoid a memory 52 // This class does not use the Members pattern to avoid a memory
include/qpdf/QTC.hh
@@ -28,6 +28,6 @@ namespace QTC @@ -28,6 +28,6 @@ namespace QTC
28 { 28 {
29 QPDF_DLL 29 QPDF_DLL
30 void TC(char const* const scope, char const* const ccase, int n = 0); 30 void TC(char const* const scope, char const* const ccase, int n = 0);
31 -}; 31 +}; // namespace QTC
32 32
33 #endif // QTC_HH 33 #endif // QTC_HH
include/qpdf/QUtil.hh
@@ -23,16 +23,16 @@ @@ -23,16 +23,16 @@
23 #define QUTIL_HH 23 #define QUTIL_HH
24 24
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 -#include <qpdf/Types.h>  
27 #include <qpdf/PointerHolder.hh> 26 #include <qpdf/PointerHolder.hh>
28 -#include <string>  
29 -#include <list>  
30 -#include <vector>  
31 -#include <stdexcept> 27 +#include <qpdf/Types.h>
32 #include <functional> 28 #include <functional>
  29 +#include <list>
33 #include <memory> 30 #include <memory>
  31 +#include <stdexcept>
34 #include <stdio.h> 32 #include <stdio.h>
  33 +#include <string>
35 #include <time.h> 34 #include <time.h>
  35 +#include <vector>
36 36
37 class RandomDataProvider; 37 class RandomDataProvider;
38 class Pipeline; 38 class Pipeline;
@@ -48,16 +48,16 @@ namespace QUtil @@ -48,16 +48,16 @@ namespace QUtil
48 QPDF_DLL 48 QPDF_DLL
49 std::string int_to_string_base(long long, int base, int length = 0); 49 std::string int_to_string_base(long long, int base, int length = 0);
50 QPDF_DLL 50 QPDF_DLL
51 - std::string uint_to_string_base(unsigned long long, int base,  
52 - int length = 0); 51 + std::string
  52 + uint_to_string_base(unsigned long long, int base, int length = 0);
53 QPDF_DLL 53 QPDF_DLL
54 std::string double_to_string(double, int decimal_places = 0); 54 std::string double_to_string(double, int decimal_places = 0);
55 // ABI: combine with other double_to_string by adding 55 // ABI: combine with other double_to_string by adding
56 // trim_trailing_zeroes above as an optional parameter with a 56 // trim_trailing_zeroes above as an optional parameter with a
57 // default of true. 57 // default of true.
58 QPDF_DLL 58 QPDF_DLL
59 - std::string double_to_string(double, int decimal_places,  
60 - bool trim_trailing_zeroes); 59 + std::string
  60 + double_to_string(double, int decimal_places, bool trim_trailing_zeroes);
61 61
62 // These string to number methods throw std::runtime_error on 62 // These string to number methods throw std::runtime_error on
63 // underflow/overflow. 63 // underflow/overflow.
@@ -217,8 +217,14 @@ namespace QUtil @@ -217,8 +217,14 @@ namespace QUtil
217 QPDFTime() = default; 217 QPDFTime() = default;
218 QPDFTime(QPDFTime const&) = default; 218 QPDFTime(QPDFTime const&) = default;
219 QPDFTime& operator=(QPDFTime const&) = default; 219 QPDFTime& operator=(QPDFTime const&) = default;
220 - QPDFTime(int year, int month, int day, int hour,  
221 - int minute, int second, int tz_delta) : 220 + QPDFTime(
  221 + int year,
  222 + int month,
  223 + int day,
  224 + int hour,
  225 + int minute,
  226 + int second,
  227 + int tz_delta) :
222 year(year), 228 year(year),
223 month(month), 229 month(month),
224 day(day), 230 day(day),
@@ -228,13 +234,13 @@ namespace QUtil @@ -228,13 +234,13 @@ namespace QUtil
228 tz_delta(tz_delta) 234 tz_delta(tz_delta)
229 { 235 {
230 } 236 }
231 - int year; // actual year, no 1900 stuff  
232 - int month; // 1--12  
233 - int day; // 1--31 237 + int year; // actual year, no 1900 stuff
  238 + int month; // 1--12
  239 + int day; // 1--31
234 int hour; 240 int hour;
235 int minute; 241 int minute;
236 int second; 242 int second;
237 - int tz_delta; // minutes before UTC 243 + int tz_delta; // minutes before UTC
238 }; 244 };
239 245
240 QPDF_DLL 246 QPDF_DLL
@@ -284,17 +290,16 @@ namespace QUtil @@ -284,17 +290,16 @@ namespace QUtil
284 // encoding system by replacing all unsupported characters with 290 // encoding system by replacing all unsupported characters with
285 // the given unknown_char. 291 // the given unknown_char.
286 QPDF_DLL 292 QPDF_DLL
287 - std::string utf8_to_ascii(  
288 - std::string const& utf8, char unknown_char = '?'); 293 + std::string utf8_to_ascii(std::string const& utf8, char unknown_char = '?');
289 QPDF_DLL 294 QPDF_DLL
290 - std::string utf8_to_win_ansi(  
291 - std::string const& utf8, char unknown_char = '?'); 295 + std::string
  296 + utf8_to_win_ansi(std::string const& utf8, char unknown_char = '?');
292 QPDF_DLL 297 QPDF_DLL
293 - std::string utf8_to_mac_roman(  
294 - std::string const& utf8, char unknown_char = '?'); 298 + std::string
  299 + utf8_to_mac_roman(std::string const& utf8, char unknown_char = '?');
295 QPDF_DLL 300 QPDF_DLL
296 - std::string utf8_to_pdf_doc(  
297 - std::string const& utf8, char unknown_char = '?'); 301 + std::string
  302 + utf8_to_pdf_doc(std::string const& utf8, char unknown_char = '?');
298 303
299 // These versions return true if the conversion was successful and 304 // These versions return true if the conversion was successful and
300 // false if any unrepresentable characters were found and had to 305 // false if any unrepresentable characters were found and had to
@@ -338,10 +343,11 @@ namespace QUtil @@ -338,10 +343,11 @@ namespace QUtil
338 // the PDF spec requires UTF-16 to be UTF-16BE, qpdf (and just 343 // the PDF spec requires UTF-16 to be UTF-16BE, qpdf (and just
339 // about everything else) accepts UTF-16LE (as of 10.6.2). 344 // about everything else) accepts UTF-16LE (as of 10.6.2).
340 QPDF_DLL 345 QPDF_DLL
341 - void analyze_encoding(std::string const& str,  
342 - bool& has_8bit_chars,  
343 - bool& is_valid_utf8,  
344 - bool& is_utf16); 346 + void analyze_encoding(
  347 + std::string const& str,
  348 + bool& has_8bit_chars,
  349 + bool& is_valid_utf8,
  350 + bool& is_utf16);
345 351
346 // Try to compensate for previously incorrectly encoded strings. 352 // Try to compensate for previously incorrectly encoded strings.
347 // We want to compensate for the following errors: 353 // We want to compensate for the following errors:
@@ -398,14 +404,14 @@ namespace QUtil @@ -398,14 +404,14 @@ namespace QUtil
398 // Filename is UTF-8 encoded, even on Windows, as described in the 404 // Filename is UTF-8 encoded, even on Windows, as described in the
399 // comments for safe_fopen. 405 // comments for safe_fopen.
400 QPDF_DLL 406 QPDF_DLL
401 - std::list<std::string> read_lines_from_file(  
402 - char const* filename, bool preserve_eol = false); 407 + std::list<std::string>
  408 + read_lines_from_file(char const* filename, bool preserve_eol = false);
403 QPDF_DLL 409 QPDF_DLL
404 - std::list<std::string> read_lines_from_file(  
405 - std::istream&, bool preserve_eol = false); 410 + std::list<std::string>
  411 + read_lines_from_file(std::istream&, bool preserve_eol = false);
406 QPDF_DLL 412 QPDF_DLL
407 - std::list<std::string> read_lines_from_file(  
408 - FILE*, bool preserve_eol = false); 413 + std::list<std::string>
  414 + read_lines_from_file(FILE*, bool preserve_eol = false);
409 QPDF_DLL 415 QPDF_DLL
410 void read_lines_from_file( 416 void read_lines_from_file(
411 std::function<bool(char&)> next_char, 417 std::function<bool(char&)> next_char,
@@ -420,7 +426,7 @@ namespace QUtil @@ -420,7 +426,7 @@ namespace QUtil
420 // platforms, so we have to give it a name that is not likely to 426 // platforms, so we have to give it a name that is not likely to
421 // be a macro anywhere. 427 // be a macro anywhere.
422 QPDF_DLL 428 QPDF_DLL
423 - int str_compare_nocase(char const *, char const *); 429 + int str_compare_nocase(char const*, char const*);
424 430
425 // These routines help the tokenizer recognize certain character 431 // These routines help the tokenizer recognize certain character
426 // classes without using ctype, which we avoid because of locale 432 // classes without using ctype, which we avoid because of locale
@@ -454,13 +460,13 @@ namespace QUtil @@ -454,13 +460,13 @@ namespace QUtil
454 // another main. 460 // another main.
455 QPDF_DLL 461 QPDF_DLL
456 int call_main_from_wmain( 462 int call_main_from_wmain(
457 - int argc, wchar_t* argv[],  
458 - std::function<int(int, char*[])> realmain); 463 + int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain);
459 QPDF_DLL 464 QPDF_DLL
460 int call_main_from_wmain( 465 int call_main_from_wmain(
461 - int argc, wchar_t const* const argv[], 466 + int argc,
  467 + wchar_t const* const argv[],
462 std::function<int(int, char const* const[])> realmain); 468 std::function<int(int, char const* const[])> realmain);
463 #endif // QPDF_NO_WCHAR_T 469 #endif // QPDF_NO_WCHAR_T
464 -}; 470 +}; // namespace QUtil
465 471
466 #endif // QUTIL_HH 472 #endif // QUTIL_HH
include/qpdf/qpdf-c.h
@@ -137,9 +137,9 @@ @@ -137,9 +137,9 @@
137 * https://github.com/qpdf/qpdf/issues/new. 137 * https://github.com/qpdf/qpdf/issues/new.
138 */ 138 */
139 139
  140 +#include <qpdf/Constants.h>
140 #include <qpdf/DLL.h> 141 #include <qpdf/DLL.h>
141 #include <qpdf/Types.h> 142 #include <qpdf/Types.h>
142 -#include <qpdf/Constants.h>  
143 #include <string.h> 143 #include <string.h>
144 144
145 #ifdef __cplusplus 145 #ifdef __cplusplus
@@ -154,13 +154,13 @@ extern &quot;C&quot; { @@ -154,13 +154,13 @@ extern &quot;C&quot; {
154 * that the values below can be logically orred together. 154 * that the values below can be logically orred together.
155 */ 155 */
156 typedef int QPDF_ERROR_CODE; 156 typedef int QPDF_ERROR_CODE;
157 -# define QPDF_SUCCESS 0  
158 -# define QPDF_WARNINGS 1 << 0  
159 -# define QPDF_ERRORS 1 << 1 157 +#define QPDF_SUCCESS 0
  158 +#define QPDF_WARNINGS 1 << 0
  159 +#define QPDF_ERRORS 1 << 1
160 160
161 typedef int QPDF_BOOL; 161 typedef int QPDF_BOOL;
162 -# define QPDF_TRUE 1  
163 -# define QPDF_FALSE 0 162 +#define QPDF_TRUE 1
  163 +#define QPDF_FALSE 0
164 164
165 /* From qpdf 10.5: call this method to signal to the library that 165 /* From qpdf 10.5: call this method to signal to the library that
166 * you are explicitly handling errors from functions that don't 166 * you are explicitly handling errors from functions that don't
@@ -273,8 +273,8 @@ extern &quot;C&quot; { @@ -273,8 +273,8 @@ extern &quot;C&quot; {
273 * pointer or an empty string as the password. 273 * pointer or an empty string as the password.
274 */ 274 */
275 QPDF_DLL 275 QPDF_DLL
276 - QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename,  
277 - char const* password); 276 + QPDF_ERROR_CODE
  277 + qpdf_read(qpdf_data qpdf, char const* filename, char const* password);
278 278
279 /* Calling qpdf_read_memory causes processMemoryFile to be called 279 /* Calling qpdf_read_memory causes processMemoryFile to be called
280 * in the C++ API. Otherwise, it behaves in the same way as 280 * in the C++ API. Otherwise, it behaves in the same way as
@@ -283,11 +283,12 @@ extern &quot;C&quot; { @@ -283,11 +283,12 @@ extern &quot;C&quot; {
283 * library. 283 * library.
284 */ 284 */
285 QPDF_DLL 285 QPDF_DLL
286 - QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf,  
287 - char const* description,  
288 - char const* buffer,  
289 - unsigned long long size,  
290 - char const* password); 286 + QPDF_ERROR_CODE qpdf_read_memory(
  287 + qpdf_data qpdf,
  288 + char const* description,
  289 + char const* buffer,
  290 + unsigned long long size,
  291 + char const* password);
291 292
292 /* Calling qpdf_empty_pdf initializes this qpdf object with an 293 /* Calling qpdf_empty_pdf initializes this qpdf object with an
293 * empty PDF, making it possible to create a PDF from scratch 294 * empty PDF, making it possible to create a PDF from scratch
@@ -409,24 +410,23 @@ extern &quot;C&quot; { @@ -409,24 +410,23 @@ extern &quot;C&quot; {
409 unsigned char const* qpdf_get_buffer(qpdf_data qpdf); 410 unsigned char const* qpdf_get_buffer(qpdf_data qpdf);
410 411
411 QPDF_DLL 412 QPDF_DLL
412 - void qpdf_set_object_stream_mode(qpdf_data qpdf,  
413 - enum qpdf_object_stream_e mode); 413 + void
  414 + qpdf_set_object_stream_mode(qpdf_data qpdf, enum qpdf_object_stream_e mode);
414 415
415 QPDF_DLL 416 QPDF_DLL
416 - void qpdf_set_stream_data_mode(qpdf_data qpdf,  
417 - enum qpdf_stream_data_e mode); 417 + void
  418 + qpdf_set_stream_data_mode(qpdf_data qpdf, enum qpdf_stream_data_e mode);
418 419
419 QPDF_DLL 420 QPDF_DLL
420 void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value); 421 void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value);
421 422
422 -  
423 QPDF_DLL 423 QPDF_DLL
424 - void qpdf_set_decode_level(qpdf_data qpdf,  
425 - enum qpdf_stream_decode_level_e level); 424 + void qpdf_set_decode_level(
  425 + qpdf_data qpdf, enum qpdf_stream_decode_level_e level);
426 426
427 QPDF_DLL 427 QPDF_DLL
428 - void qpdf_set_preserve_unreferenced_objects(  
429 - qpdf_data qpdf, QPDF_BOOL value); 428 + void
  429 + qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value);
430 430
431 QPDF_DLL 431 QPDF_DLL
432 void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value); 432 void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value);
@@ -453,77 +453,120 @@ extern &quot;C&quot; { @@ -453,77 +453,120 @@ extern &quot;C&quot; {
453 void qpdf_set_static_aes_IV(qpdf_data qpdf, QPDF_BOOL value); 453 void qpdf_set_static_aes_IV(qpdf_data qpdf, QPDF_BOOL value);
454 454
455 QPDF_DLL 455 QPDF_DLL
456 - void qpdf_set_suppress_original_object_IDs(  
457 - qpdf_data qpdf, QPDF_BOOL value); 456 + void qpdf_set_suppress_original_object_IDs(qpdf_data qpdf, QPDF_BOOL value);
458 457
459 QPDF_DLL 458 QPDF_DLL
460 void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value); 459 void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value);
461 460
462 QPDF_DLL 461 QPDF_DLL
463 void qpdf_set_r2_encryption_parameters( 462 void qpdf_set_r2_encryption_parameters(
464 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
465 - QPDF_BOOL allow_print, QPDF_BOOL allow_modify,  
466 - QPDF_BOOL allow_extract, QPDF_BOOL allow_annotate); 463 + qpdf_data qpdf,
  464 + char const* user_password,
  465 + char const* owner_password,
  466 + QPDF_BOOL allow_print,
  467 + QPDF_BOOL allow_modify,
  468 + QPDF_BOOL allow_extract,
  469 + QPDF_BOOL allow_annotate);
467 470
468 QPDF_DLL 471 QPDF_DLL
469 void qpdf_set_r3_encryption_parameters2( 472 void qpdf_set_r3_encryption_parameters2(
470 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
471 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
472 - QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,  
473 - QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other, 473 + qpdf_data qpdf,
  474 + char const* user_password,
  475 + char const* owner_password,
  476 + QPDF_BOOL allow_accessibility,
  477 + QPDF_BOOL allow_extract,
  478 + QPDF_BOOL allow_assemble,
  479 + QPDF_BOOL allow_annotate_and_form,
  480 + QPDF_BOOL allow_form_filling,
  481 + QPDF_BOOL allow_modify_other,
474 enum qpdf_r3_print_e print); 482 enum qpdf_r3_print_e print);
475 483
476 QPDF_DLL 484 QPDF_DLL
477 void qpdf_set_r4_encryption_parameters2( 485 void qpdf_set_r4_encryption_parameters2(
478 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
479 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
480 - QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,  
481 - QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other, 486 + qpdf_data qpdf,
  487 + char const* user_password,
  488 + char const* owner_password,
  489 + QPDF_BOOL allow_accessibility,
  490 + QPDF_BOOL allow_extract,
  491 + QPDF_BOOL allow_assemble,
  492 + QPDF_BOOL allow_annotate_and_form,
  493 + QPDF_BOOL allow_form_filling,
  494 + QPDF_BOOL allow_modify_other,
482 enum qpdf_r3_print_e print, 495 enum qpdf_r3_print_e print,
483 - QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes); 496 + QPDF_BOOL encrypt_metadata,
  497 + QPDF_BOOL use_aes);
484 498
485 QPDF_DLL 499 QPDF_DLL
486 void qpdf_set_r5_encryption_parameters2( 500 void qpdf_set_r5_encryption_parameters2(
487 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
488 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
489 - QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,  
490 - QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,  
491 - enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata); 501 + qpdf_data qpdf,
  502 + char const* user_password,
  503 + char const* owner_password,
  504 + QPDF_BOOL allow_accessibility,
  505 + QPDF_BOOL allow_extract,
  506 + QPDF_BOOL allow_assemble,
  507 + QPDF_BOOL allow_annotate_and_form,
  508 + QPDF_BOOL allow_form_filling,
  509 + QPDF_BOOL allow_modify_other,
  510 + enum qpdf_r3_print_e print,
  511 + QPDF_BOOL encrypt_metadata);
492 512
493 QPDF_DLL 513 QPDF_DLL
494 void qpdf_set_r6_encryption_parameters2( 514 void qpdf_set_r6_encryption_parameters2(
495 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
496 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
497 - QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,  
498 - QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,  
499 - enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata); 515 + qpdf_data qpdf,
  516 + char const* user_password,
  517 + char const* owner_password,
  518 + QPDF_BOOL allow_accessibility,
  519 + QPDF_BOOL allow_extract,
  520 + QPDF_BOOL allow_assemble,
  521 + QPDF_BOOL allow_annotate_and_form,
  522 + QPDF_BOOL allow_form_filling,
  523 + QPDF_BOOL allow_modify_other,
  524 + enum qpdf_r3_print_e print,
  525 + QPDF_BOOL encrypt_metadata);
500 526
501 /* Pre 8.4.0 encryption API */ 527 /* Pre 8.4.0 encryption API */
502 QPDF_DLL 528 QPDF_DLL
503 void qpdf_set_r3_encryption_parameters( 529 void qpdf_set_r3_encryption_parameters(
504 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
505 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
506 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify); 530 + qpdf_data qpdf,
  531 + char const* user_password,
  532 + char const* owner_password,
  533 + QPDF_BOOL allow_accessibility,
  534 + QPDF_BOOL allow_extract,
  535 + enum qpdf_r3_print_e print,
  536 + enum qpdf_r3_modify_e modify);
507 537
508 QPDF_DLL 538 QPDF_DLL
509 void qpdf_set_r4_encryption_parameters( 539 void qpdf_set_r4_encryption_parameters(
510 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
511 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
512 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,  
513 - QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes); 540 + qpdf_data qpdf,
  541 + char const* user_password,
  542 + char const* owner_password,
  543 + QPDF_BOOL allow_accessibility,
  544 + QPDF_BOOL allow_extract,
  545 + enum qpdf_r3_print_e print,
  546 + enum qpdf_r3_modify_e modify,
  547 + QPDF_BOOL encrypt_metadata,
  548 + QPDF_BOOL use_aes);
514 549
515 QPDF_DLL 550 QPDF_DLL
516 void qpdf_set_r5_encryption_parameters( 551 void qpdf_set_r5_encryption_parameters(
517 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
518 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
519 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify, 552 + qpdf_data qpdf,
  553 + char const* user_password,
  554 + char const* owner_password,
  555 + QPDF_BOOL allow_accessibility,
  556 + QPDF_BOOL allow_extract,
  557 + enum qpdf_r3_print_e print,
  558 + enum qpdf_r3_modify_e modify,
520 QPDF_BOOL encrypt_metadata); 559 QPDF_BOOL encrypt_metadata);
521 560
522 QPDF_DLL 561 QPDF_DLL
523 void qpdf_set_r6_encryption_parameters( 562 void qpdf_set_r6_encryption_parameters(
524 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
525 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
526 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify, 563 + qpdf_data qpdf,
  564 + char const* user_password,
  565 + char const* owner_password,
  566 + QPDF_BOOL allow_accessibility,
  567 + QPDF_BOOL allow_extract,
  568 + enum qpdf_r3_print_e print,
  569 + enum qpdf_r3_modify_e modify,
527 QPDF_BOOL encrypt_metadata); 570 QPDF_BOOL encrypt_metadata);
528 571
529 QPDF_DLL 572 QPDF_DLL
@@ -648,8 +691,8 @@ extern &quot;C&quot; { @@ -648,8 +691,8 @@ extern &quot;C&quot; {
648 QPDF_DLL 691 QPDF_DLL
649 qpdf_oh qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh); 692 qpdf_oh qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh);
650 QPDF_DLL 693 QPDF_DLL
651 - void qpdf_replace_object(  
652 - qpdf_data qpdf, int objid, int generation, qpdf_oh oh); 694 + void
  695 + qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh);
653 696
654 /* Wrappers around QPDFObjectHandle methods. Be sure to read 697 /* Wrappers around QPDFObjectHandle methods. Be sure to read
655 * corresponding comments in QPDFObjectHandle.hh to understand 698 * corresponding comments in QPDFObjectHandle.hh to understand
@@ -690,8 +733,8 @@ extern &quot;C&quot; { @@ -690,8 +733,8 @@ extern &quot;C&quot; {
690 QPDF_BOOL qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh); 733 QPDF_BOOL qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh);
691 734
692 QPDF_DLL 735 QPDF_DLL
693 - QPDF_BOOL qpdf_oh_is_name_and_equals(  
694 - qpdf_data qpdf, qpdf_oh oh, char const* name); 736 + QPDF_BOOL
  737 + qpdf_oh_is_name_and_equals(qpdf_data qpdf, qpdf_oh oh, char const* name);
695 738
696 QPDF_DLL 739 QPDF_DLL
697 QPDF_BOOL qpdf_oh_is_dictionary_of_type( 740 QPDF_BOOL qpdf_oh_is_dictionary_of_type(
@@ -711,19 +754,18 @@ extern &quot;C&quot; { @@ -711,19 +754,18 @@ extern &quot;C&quot; {
711 QPDF_DLL 754 QPDF_DLL
712 QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh); 755 QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh);
713 QPDF_DLL 756 QPDF_DLL
714 - QPDF_BOOL qpdf_oh_get_value_as_bool(  
715 - qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value); 757 + QPDF_BOOL
  758 + qpdf_oh_get_value_as_bool(qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value);
716 759
717 QPDF_DLL 760 QPDF_DLL
718 long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh); 761 long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh);
719 QPDF_DLL 762 QPDF_DLL
720 - QPDF_BOOL qpdf_oh_get_value_as_longlong(  
721 - qpdf_data qpdf, qpdf_oh oh, long long* value); 763 + QPDF_BOOL
  764 + qpdf_oh_get_value_as_longlong(qpdf_data qpdf, qpdf_oh oh, long long* value);
722 QPDF_DLL 765 QPDF_DLL
723 int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh); 766 int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh);
724 QPDF_DLL 767 QPDF_DLL
725 - QPDF_BOOL qpdf_oh_get_value_as_int(  
726 - qpdf_data qpdf, qpdf_oh oh, int* value); 768 + QPDF_BOOL qpdf_oh_get_value_as_int(qpdf_data qpdf, qpdf_oh oh, int* value);
727 QPDF_DLL 769 QPDF_DLL
728 unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh); 770 unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh);
729 QPDF_DLL 771 QPDF_DLL
@@ -732,8 +774,8 @@ extern &quot;C&quot; { @@ -732,8 +774,8 @@ extern &quot;C&quot; {
732 QPDF_DLL 774 QPDF_DLL
733 unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh); 775 unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh);
734 QPDF_DLL 776 QPDF_DLL
735 - QPDF_BOOL qpdf_oh_get_value_as_uint(  
736 - qpdf_data qpdf, qpdf_oh oh, unsigned int* value); 777 + QPDF_BOOL
  778 + qpdf_oh_get_value_as_uint(qpdf_data qpdf, qpdf_oh oh, unsigned int* value);
737 779
738 QPDF_DLL 780 QPDF_DLL
739 char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh); 781 char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh);
@@ -746,8 +788,8 @@ extern &quot;C&quot; { @@ -746,8 +788,8 @@ extern &quot;C&quot; {
746 QPDF_DLL 788 QPDF_DLL
747 double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh); 789 double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh);
748 QPDF_DLL 790 QPDF_DLL
749 - QPDF_BOOL qpdf_oh_get_value_as_number(  
750 - qpdf_data qpdf, qpdf_oh oh, double* value); 791 + QPDF_BOOL
  792 + qpdf_oh_get_value_as_number(qpdf_data qpdf, qpdf_oh oh, double* value);
751 793
752 QPDF_DLL 794 QPDF_DLL
753 char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh); 795 char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh);
@@ -782,11 +824,11 @@ extern &quot;C&quot; { @@ -782,11 +824,11 @@ extern &quot;C&quot; {
782 QPDF_BOOL qpdf_oh_get_value_as_utf8( 824 QPDF_BOOL qpdf_oh_get_value_as_utf8(
783 qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); 825 qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
784 QPDF_DLL 826 QPDF_DLL
785 - char const* qpdf_oh_get_binary_string_value(  
786 - qpdf_data qpdf, qpdf_oh oh, size_t* length); 827 + char const*
  828 + qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length);
787 QPDF_DLL 829 QPDF_DLL
788 - char const* qpdf_oh_get_binary_utf8_value(  
789 - qpdf_data qpdf, qpdf_oh oh, size_t* length); 830 + char const*
  831 + qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length);
790 832
791 QPDF_DLL 833 QPDF_DLL
792 int qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh); 834 int qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh);
@@ -822,12 +864,12 @@ extern &quot;C&quot; { @@ -822,12 +864,12 @@ extern &quot;C&quot; {
822 QPDF_DLL 864 QPDF_DLL
823 qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key); 865 qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key);
824 QPDF_DLL 866 QPDF_DLL
825 - qpdf_oh qpdf_oh_get_key_if_dict(  
826 - qpdf_data qpdf, qpdf_oh oh, char const* key); 867 + qpdf_oh
  868 + qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key);
827 869
828 QPDF_DLL 870 QPDF_DLL
829 - QPDF_BOOL qpdf_oh_is_or_has_name(  
830 - qpdf_data qpdf, qpdf_oh oh, char const* key); 871 + QPDF_BOOL
  872 + qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key);
831 873
832 QPDF_DLL 874 QPDF_DLL
833 qpdf_oh qpdf_oh_new_uninitialized(qpdf_data qpdf); 875 qpdf_oh qpdf_oh_new_uninitialized(qpdf_data qpdf);
@@ -840,8 +882,8 @@ extern &quot;C&quot; { @@ -840,8 +882,8 @@ extern &quot;C&quot; {
840 QPDF_DLL 882 QPDF_DLL
841 qpdf_oh qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value); 883 qpdf_oh qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value);
842 QPDF_DLL 884 QPDF_DLL
843 - qpdf_oh qpdf_oh_new_real_from_double(qpdf_data qpdf,  
844 - double value, int decimal_places); 885 + qpdf_oh qpdf_oh_new_real_from_double(
  886 + qpdf_data qpdf, double value, int decimal_places);
845 QPDF_DLL 887 QPDF_DLL
846 qpdf_oh qpdf_oh_new_name(qpdf_data qpdf, char const* name); 888 qpdf_oh qpdf_oh_new_name(qpdf_data qpdf, char const* name);
847 QPDF_DLL 889 QPDF_DLL
@@ -852,9 +894,9 @@ extern &quot;C&quot; { @@ -852,9 +894,9 @@ extern &quot;C&quot; {
852 * contain atrbitary binary data including embedded null characters. 894 * contain atrbitary binary data including embedded null characters.
853 */ 895 */
854 QPDF_DLL 896 QPDF_DLL
855 - qpdf_oh qpdf_oh_new_binary_string(  
856 - qpdf_data qpdf, char const* str, size_t length);  
857 - QPDF_DLL 897 + qpdf_oh
  898 + qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length);
  899 + QPDF_DLL
858 qpdf_oh qpdf_oh_new_binary_unicode_string( 900 qpdf_oh qpdf_oh_new_binary_unicode_string(
859 qpdf_data qpdf, char const* str, size_t length); 901 qpdf_data qpdf, char const* str, size_t length);
860 QPDF_DLL 902 QPDF_DLL
@@ -867,7 +909,7 @@ extern &quot;C&quot; { @@ -867,7 +909,7 @@ extern &quot;C&quot; {
867 * comments in QPDFObjectHandle.hh for newStream() for additional 909 * comments in QPDFObjectHandle.hh for newStream() for additional
868 * notes. You must call qpdf_oh_replace_stream_data to provide 910 * notes. You must call qpdf_oh_replace_stream_data to provide
869 * data for the stream. See STREAM FUNCTIONS below. 911 * data for the stream. See STREAM FUNCTIONS below.
870 - */ 912 + */
871 QPDF_DLL 913 QPDF_DLL
872 qpdf_oh qpdf_oh_new_stream(qpdf_data qpdf); 914 qpdf_oh qpdf_oh_new_stream(qpdf_data qpdf);
873 915
@@ -875,8 +917,8 @@ extern &quot;C&quot; { @@ -875,8 +917,8 @@ extern &quot;C&quot; {
875 void qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh); 917 void qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh);
876 918
877 QPDF_DLL 919 QPDF_DLL
878 - void qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh,  
879 - int at, qpdf_oh item); 920 + void
  921 + qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item);
880 QPDF_DLL 922 QPDF_DLL
881 void qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item); 923 void qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item);
882 QPDF_DLL 924 QPDF_DLL
@@ -885,13 +927,13 @@ extern &quot;C&quot; { @@ -885,13 +927,13 @@ extern &quot;C&quot; {
885 void qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at); 927 void qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at);
886 928
887 QPDF_DLL 929 QPDF_DLL
888 - void qpdf_oh_replace_key(qpdf_data qpdf, qpdf_oh oh,  
889 - char const* key, qpdf_oh item); 930 + void qpdf_oh_replace_key(
  931 + qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item);
890 QPDF_DLL 932 QPDF_DLL
891 void qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key); 933 void qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key);
892 QPDF_DLL 934 QPDF_DLL
893 - void qpdf_oh_replace_or_remove_key(qpdf_data qpdf, qpdf_oh oh,  
894 - char const* key, qpdf_oh item); 935 + void qpdf_oh_replace_or_remove_key(
  936 + qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item);
895 937
896 QPDF_DLL 938 QPDF_DLL
897 qpdf_oh qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh); 939 qpdf_oh qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh);
@@ -946,9 +988,12 @@ extern &quot;C&quot; { @@ -946,9 +988,12 @@ extern &quot;C&quot; {
946 */ 988 */
947 QPDF_DLL 989 QPDF_DLL
948 QPDF_ERROR_CODE qpdf_oh_get_stream_data( 990 QPDF_ERROR_CODE qpdf_oh_get_stream_data(
949 - qpdf_data qpdf, qpdf_oh stream_oh,  
950 - enum qpdf_stream_decode_level_e decode_level, QPDF_BOOL* filtered,  
951 - unsigned char** bufp, size_t* len); 991 + qpdf_data qpdf,
  992 + qpdf_oh stream_oh,
  993 + enum qpdf_stream_decode_level_e decode_level,
  994 + QPDF_BOOL* filtered,
  995 + unsigned char** bufp,
  996 + size_t* len);
952 997
953 /* This function returns the concatenation of all of a page's 998 /* This function returns the concatenation of all of a page's
954 * content streams as a single, dynamically allocated buffer. As 999 * content streams as a single, dynamically allocated buffer. As
@@ -957,17 +1002,19 @@ extern &quot;C&quot; { @@ -957,17 +1002,19 @@ extern &quot;C&quot; {
957 */ 1002 */
958 QPDF_DLL 1003 QPDF_DLL
959 QPDF_ERROR_CODE qpdf_oh_get_page_content_data( 1004 QPDF_ERROR_CODE qpdf_oh_get_page_content_data(
960 - qpdf_data qpdf, qpdf_oh page_oh,  
961 - unsigned char** bufp, size_t* len); 1005 + qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len);
962 1006
963 /* The data pointed to by bufp will be copied by the library. It 1007 /* The data pointed to by bufp will be copied by the library. It
964 * does not need to remain valid after the call returns. 1008 * does not need to remain valid after the call returns.
965 */ 1009 */
966 QPDF_DLL 1010 QPDF_DLL
967 void qpdf_oh_replace_stream_data( 1011 void qpdf_oh_replace_stream_data(
968 - qpdf_data qpdf, qpdf_oh stream_oh,  
969 - unsigned char const* buf, size_t len,  
970 - qpdf_oh filter, qpdf_oh decode_parms); 1012 + qpdf_data qpdf,
  1013 + qpdf_oh stream_oh,
  1014 + unsigned char const* buf,
  1015 + size_t len,
  1016 + qpdf_oh filter,
  1017 + qpdf_oh decode_parms);
971 1018
972 /* PAGE FUNCTIONS */ 1019 /* PAGE FUNCTIONS */
973 1020
@@ -1018,14 +1065,17 @@ extern &quot;C&quot; { @@ -1018,14 +1065,17 @@ extern &quot;C&quot; {
1018 QPDF_DLL 1065 QPDF_DLL
1019 QPDF_ERROR_CODE qpdf_add_page( 1066 QPDF_ERROR_CODE qpdf_add_page(
1020 qpdf_data qpdf, 1067 qpdf_data qpdf,
1021 - qpdf_data newpage_qpdf, qpdf_oh newpage, 1068 + qpdf_data newpage_qpdf,
  1069 + qpdf_oh newpage,
1022 QPDF_BOOL first); 1070 QPDF_BOOL first);
1023 /* addPageAt() */ 1071 /* addPageAt() */
1024 QPDF_DLL 1072 QPDF_DLL
1025 QPDF_ERROR_CODE qpdf_add_page_at( 1073 QPDF_ERROR_CODE qpdf_add_page_at(
1026 qpdf_data qpdf, 1074 qpdf_data qpdf,
1027 - qpdf_data newpage_qpdf, qpdf_oh newpage,  
1028 - QPDF_BOOL before, qpdf_oh refpage); 1075 + qpdf_data newpage_qpdf,
  1076 + qpdf_oh newpage,
  1077 + QPDF_BOOL before,
  1078 + qpdf_oh refpage);
1029 /* removePage() */ 1079 /* removePage() */
1030 QPDF_DLL 1080 QPDF_DLL
1031 QPDF_ERROR_CODE qpdf_remove_page(qpdf_data qpdf, qpdf_oh page); 1081 QPDF_ERROR_CODE qpdf_remove_page(qpdf_data qpdf, qpdf_oh page);
@@ -1033,5 +1083,4 @@ extern &quot;C&quot; { @@ -1033,5 +1083,4 @@ extern &quot;C&quot; {
1033 } 1083 }
1034 #endif 1084 #endif
1035 1085
1036 -  
1037 #endif /* QPDF_C_H */ 1086 #endif /* QPDF_C_H */
include/qpdf/qpdfjob-c.h
@@ -75,5 +75,4 @@ extern &quot;C&quot; { @@ -75,5 +75,4 @@ extern &quot;C&quot; {
75 } 75 }
76 #endif 76 #endif
77 77
78 -  
79 #endif /* QPDFJOB_C_H */ 78 #endif /* QPDFJOB_C_H */
libqpdf/AES_PDF_native.cc
1 #include <qpdf/AES_PDF_native.hh> 1 #include <qpdf/AES_PDF_native.hh>
2 2
  3 +#include <qpdf/QIntC.hh>
  4 +#include <qpdf/QPDFCryptoImpl.hh>
3 #include <qpdf/QUtil.hh> 5 #include <qpdf/QUtil.hh>
4 -#include <cstring> 6 +#include <qpdf/rijndael.h>
5 #include <assert.h> 7 #include <assert.h>
  8 +#include <cstring>
6 #include <stdexcept> 9 #include <stdexcept>
7 -#include <qpdf/rijndael.h>  
8 -#include <qpdf/QIntC.hh>  
9 -#include <string>  
10 #include <stdlib.h> 10 #include <stdlib.h>
11 -#include <qpdf/QPDFCryptoImpl.hh> 11 +#include <string>
12 12
13 -AES_PDF_native::AES_PDF_native(bool encrypt, unsigned char const* key,  
14 - size_t key_bytes, bool cbc_mode,  
15 - unsigned char* cbc_block) : 13 +AES_PDF_native::AES_PDF_native(
  14 + bool encrypt,
  15 + unsigned char const* key,
  16 + size_t key_bytes,
  17 + bool cbc_mode,
  18 + unsigned char* cbc_block) :
16 encrypt(encrypt), 19 encrypt(encrypt),
17 cbc_mode(cbc_mode), 20 cbc_mode(cbc_mode),
18 cbc_block(cbc_block), 21 cbc_block(cbc_block),
@@ -24,15 +27,12 @@ AES_PDF_native::AES_PDF_native(bool encrypt, unsigned char const* key, @@ -24,15 +27,12 @@ AES_PDF_native::AES_PDF_native(bool encrypt, unsigned char const* key,
24 size_t rk_bytes = RKLENGTH(keybits) * sizeof(uint32_t); 27 size_t rk_bytes = RKLENGTH(keybits) * sizeof(uint32_t);
25 std::memcpy(this->key.get(), key, key_bytes); 28 std::memcpy(this->key.get(), key, key_bytes);
26 std::memset(this->rk.get(), 0, rk_bytes); 29 std::memset(this->rk.get(), 0, rk_bytes);
27 - if (encrypt)  
28 - {  
29 - this->nrounds = rijndaelSetupEncrypt(  
30 - this->rk.get(), this->key.get(), keybits);  
31 - }  
32 - else  
33 - {  
34 - this->nrounds = rijndaelSetupDecrypt(  
35 - this->rk.get(), this->key.get(), keybits); 30 + if (encrypt) {
  31 + this->nrounds =
  32 + rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits);
  33 + } else {
  34 + this->nrounds =
  35 + rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits);
36 } 36 }
37 } 37 }
38 38
@@ -43,35 +43,24 @@ AES_PDF_native::~AES_PDF_native() @@ -43,35 +43,24 @@ AES_PDF_native::~AES_PDF_native()
43 void 43 void
44 AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) 44 AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data)
45 { 45 {
46 - if (this->encrypt)  
47 - {  
48 - if (this->cbc_mode)  
49 - {  
50 - for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i)  
51 - { 46 + if (this->encrypt) {
  47 + if (this->cbc_mode) {
  48 + for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) {
52 in_data[i] ^= this->cbc_block[i]; 49 in_data[i] ^= this->cbc_block[i];
53 } 50 }
54 } 51 }
55 - rijndaelEncrypt(this->rk.get(),  
56 - this->nrounds, in_data, out_data);  
57 - if (this->cbc_mode)  
58 - {  
59 - memcpy(this->cbc_block, out_data,  
60 - QPDFCryptoImpl::rijndael_buf_size); 52 + rijndaelEncrypt(this->rk.get(), this->nrounds, in_data, out_data);
  53 + if (this->cbc_mode) {
  54 + memcpy(
  55 + this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size);
61 } 56 }
62 - }  
63 - else  
64 - {  
65 - rijndaelDecrypt(this->rk.get(),  
66 - this->nrounds, in_data, out_data);  
67 - if (this->cbc_mode)  
68 - {  
69 - for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i)  
70 - { 57 + } else {
  58 + rijndaelDecrypt(this->rk.get(), this->nrounds, in_data, out_data);
  59 + if (this->cbc_mode) {
  60 + for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) {
71 out_data[i] ^= this->cbc_block[i]; 61 out_data[i] ^= this->cbc_block[i];
72 } 62 }
73 - memcpy(this->cbc_block, in_data,  
74 - QPDFCryptoImpl::rijndael_buf_size); 63 + memcpy(this->cbc_block, in_data, QPDFCryptoImpl::rijndael_buf_size);
75 } 64 }
76 } 65 }
77 } 66 }
libqpdf/BitStream.cc
@@ -18,8 +18,7 @@ BitStream::reset() @@ -18,8 +18,7 @@ BitStream::reset()
18 { 18 {
19 p = start; 19 p = start;
20 bit_offset = 7; 20 bit_offset = 7;
21 - if (QIntC::to_uint(nbytes) > static_cast<unsigned int>(-1) / 8)  
22 - { 21 + if (QIntC::to_uint(nbytes) > static_cast<unsigned int>(-1) / 8) {
23 throw std::runtime_error("array too large for bitstream"); 22 throw std::runtime_error("array too large for bitstream");
24 } 23 }
25 bits_available = 8 * nbytes; 24 bits_available = 8 * nbytes;
@@ -28,22 +27,18 @@ BitStream::reset() @@ -28,22 +27,18 @@ BitStream::reset()
28 unsigned long long 27 unsigned long long
29 BitStream::getBits(size_t nbits) 28 BitStream::getBits(size_t nbits)
30 { 29 {
31 - return read_bits(this->p, this->bit_offset,  
32 - this->bits_available, nbits); 30 + return read_bits(this->p, this->bit_offset, this->bits_available, nbits);
33 } 31 }
34 32
35 long long 33 long long
36 BitStream::getBitsSigned(size_t nbits) 34 BitStream::getBitsSigned(size_t nbits)
37 { 35 {
38 - unsigned long long bits = read_bits(this->p, this->bit_offset,  
39 - this->bits_available, nbits); 36 + unsigned long long bits =
  37 + read_bits(this->p, this->bit_offset, this->bits_available, nbits);
40 long long result = 0; 38 long long result = 0;
41 - if (static_cast<long long>(bits) > 1LL << (nbits - 1))  
42 - {  
43 - result = static_cast<long long>(bits -(1ULL << nbits));  
44 - }  
45 - else  
46 - { 39 + if (static_cast<long long>(bits) > 1LL << (nbits - 1)) {
  40 + result = static_cast<long long>(bits - (1ULL << nbits));
  41 + } else {
47 result = static_cast<long long>(bits); 42 result = static_cast<long long>(bits);
48 } 43 }
49 return result; 44 return result;
@@ -52,20 +47,16 @@ BitStream::getBitsSigned(size_t nbits) @@ -52,20 +47,16 @@ BitStream::getBitsSigned(size_t nbits)
52 int 47 int
53 BitStream::getBitsInt(size_t nbits) 48 BitStream::getBitsInt(size_t nbits)
54 { 49 {
55 - return static_cast<int>(  
56 - QIntC::to_uint(  
57 - read_bits(this->p, this->bit_offset,  
58 - this->bits_available, nbits))); 50 + return static_cast<int>(QIntC::to_uint(
  51 + read_bits(this->p, this->bit_offset, this->bits_available, nbits)));
59 } 52 }
60 53
61 void 54 void
62 BitStream::skipToNextByte() 55 BitStream::skipToNextByte()
63 { 56 {
64 - if (bit_offset != 7)  
65 - { 57 + if (bit_offset != 7) {
66 size_t bits_to_skip = bit_offset + 1; 58 size_t bits_to_skip = bit_offset + 1;
67 - if (bits_available < bits_to_skip)  
68 - { 59 + if (bits_available < bits_to_skip) {
69 throw std::logic_error( 60 throw std::logic_error(
70 "INTERNAL ERROR: overflow skipping to next byte in bitstream"); 61 "INTERNAL ERROR: overflow skipping to next byte in bitstream");
71 } 62 }
libqpdf/BitWriter.cc
@@ -21,12 +21,9 @@ void @@ -21,12 +21,9 @@ void
21 BitWriter::writeBitsSigned(long long val, size_t bits) 21 BitWriter::writeBitsSigned(long long val, size_t bits)
22 { 22 {
23 unsigned long long uval = 0; 23 unsigned long long uval = 0;
24 - if (val < 0)  
25 - { 24 + if (val < 0) {
26 uval = (1ULL << bits) + static_cast<unsigned long long>(val); 25 uval = (1ULL << bits) + static_cast<unsigned long long>(val);
27 - }  
28 - else  
29 - { 26 + } else {
30 uval = static_cast<unsigned long long>(val); 27 uval = static_cast<unsigned long long>(val);
31 } 28 }
32 writeBits(uval, bits); 29 writeBits(uval, bits);
@@ -41,8 +38,7 @@ BitWriter::writeBitsInt(int val, size_t bits) @@ -41,8 +38,7 @@ BitWriter::writeBitsInt(int val, size_t bits)
41 void 38 void
42 BitWriter::flush() 39 BitWriter::flush()
43 { 40 {
44 - if (bit_offset < 7)  
45 - { 41 + if (bit_offset < 7) {
46 size_t bits_to_write = bit_offset + 1; 42 size_t bits_to_write = bit_offset + 1;
47 write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl); 43 write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
48 } 44 }
libqpdf/Buffer.cc
@@ -7,21 +7,17 @@ Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) : @@ -7,21 +7,17 @@ Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) :
7 size(size), 7 size(size),
8 buf(0) 8 buf(0)
9 { 9 {
10 - if (own_memory)  
11 - { 10 + if (own_memory) {
12 this->buf = (size ? new unsigned char[size] : 0); 11 this->buf = (size ? new unsigned char[size] : 0);
13 - }  
14 - else  
15 - { 12 + } else {
16 this->buf = buf; 13 this->buf = buf;
17 } 14 }
18 } 15 }
19 16
20 Buffer::Members::~Members() 17 Buffer::Members::~Members()
21 { 18 {
22 - if (this->own_memory)  
23 - {  
24 - delete [] this->buf; 19 + if (this->own_memory) {
  20 + delete[] this->buf;
25 } 21 }
26 } 22 }
27 23
@@ -55,11 +51,9 @@ Buffer::operator=(Buffer const&amp; rhs) @@ -55,11 +51,9 @@ Buffer::operator=(Buffer const&amp; rhs)
55 void 51 void
56 Buffer::copy(Buffer const& rhs) 52 Buffer::copy(Buffer const& rhs)
57 { 53 {
58 - if (this != &rhs)  
59 - { 54 + if (this != &rhs) {
60 this->m = PointerHolder<Members>(new Members(rhs.m->size, 0, true)); 55 this->m = PointerHolder<Members>(new Members(rhs.m->size, 0, true));
61 - if (this->m->size)  
62 - { 56 + if (this->m->size) {
63 memcpy(this->m->buf, rhs.m->buf, this->m->size); 57 memcpy(this->m->buf, rhs.m->buf, this->m->size);
64 } 58 }
65 } 59 }
libqpdf/BufferInputSource.cc
1 #include <qpdf/BufferInputSource.hh> 1 #include <qpdf/BufferInputSource.hh>
2 2
3 #include <qpdf/QIntC.hh> 3 #include <qpdf/QIntC.hh>
4 -#include <string.h>  
5 -#include <stdexcept>  
6 #include <algorithm> 4 #include <algorithm>
7 #include <limits> 5 #include <limits>
8 #include <sstream> 6 #include <sstream>
  7 +#include <stdexcept>
  8 +#include <string.h>
9 9
10 -BufferInputSource::Members::Members(bool own_memory,  
11 - std::string const& description,  
12 - Buffer* buf) : 10 +BufferInputSource::Members::Members(
  11 + bool own_memory, std::string const& description, Buffer* buf) :
13 own_memory(own_memory), 12 own_memory(own_memory),
14 description(description), 13 description(description),
15 buf(buf), 14 buf(buf),
@@ -22,14 +21,14 @@ BufferInputSource::Members::~Members() @@ -22,14 +21,14 @@ BufferInputSource::Members::~Members()
22 { 21 {
23 } 22 }
24 23
25 -BufferInputSource::BufferInputSource(std::string const& description,  
26 - Buffer* buf, bool own_memory) : 24 +BufferInputSource::BufferInputSource(
  25 + std::string const& description, Buffer* buf, bool own_memory) :
27 m(new Members(own_memory, description, buf)) 26 m(new Members(own_memory, description, buf))
28 { 27 {
29 } 28 }
30 29
31 -BufferInputSource::BufferInputSource(std::string const& description,  
32 - std::string const& contents) : 30 +BufferInputSource::BufferInputSource(
  31 + std::string const& description, std::string const& contents) :
33 m(new Members(true, description, 0)) 32 m(new Members(true, description, 0))
34 { 33 {
35 this->m->buf = new Buffer(contents.length()); 34 this->m->buf = new Buffer(contents.length());
@@ -40,8 +39,7 @@ BufferInputSource::BufferInputSource(std::string const&amp; description, @@ -40,8 +39,7 @@ BufferInputSource::BufferInputSource(std::string const&amp; description,
40 39
41 BufferInputSource::~BufferInputSource() 40 BufferInputSource::~BufferInputSource()
42 { 41 {
43 - if (this->m->own_memory)  
44 - { 42 + if (this->m->own_memory) {
45 delete this->m->buf; 43 delete this->m->buf;
46 } 44 }
47 } 45 }
@@ -49,13 +47,11 @@ BufferInputSource::~BufferInputSource() @@ -49,13 +47,11 @@ BufferInputSource::~BufferInputSource()
49 qpdf_offset_t 47 qpdf_offset_t
50 BufferInputSource::findAndSkipNextEOL() 48 BufferInputSource::findAndSkipNextEOL()
51 { 49 {
52 - if (this->m->cur_offset < 0)  
53 - { 50 + if (this->m->cur_offset < 0) {
54 throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); 51 throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0");
55 } 52 }
56 qpdf_offset_t end_pos = this->m->max_offset; 53 qpdf_offset_t end_pos = this->m->max_offset;
57 - if (this->m->cur_offset >= end_pos)  
58 - { 54 + if (this->m->cur_offset >= end_pos) {
59 this->last_offset = end_pos; 55 this->last_offset = end_pos;
60 this->m->cur_offset = end_pos; 56 this->m->cur_offset = end_pos;
61 return end_pos; 57 return end_pos;
@@ -66,24 +62,19 @@ BufferInputSource::findAndSkipNextEOL() @@ -66,24 +62,19 @@ BufferInputSource::findAndSkipNextEOL()
66 unsigned char const* end = buffer + end_pos; 62 unsigned char const* end = buffer + end_pos;
67 unsigned char const* p = buffer + this->m->cur_offset; 63 unsigned char const* p = buffer + this->m->cur_offset;
68 64
69 - while ((p < end) && !((*p == '\r') || (*p == '\n')))  
70 - { 65 + while ((p < end) && !((*p == '\r') || (*p == '\n'))) {
71 ++p; 66 ++p;
72 } 67 }
73 - if (p < end)  
74 - { 68 + if (p < end) {
75 result = p - buffer; 69 result = p - buffer;
76 this->m->cur_offset = result + 1; 70 this->m->cur_offset = result + 1;
77 ++p; 71 ++p;
78 while ((this->m->cur_offset < end_pos) && 72 while ((this->m->cur_offset < end_pos) &&
79 - ((*p == '\r') || (*p == '\n')))  
80 - { 73 + ((*p == '\r') || (*p == '\n'))) {
81 ++p; 74 ++p;
82 ++this->m->cur_offset; 75 ++this->m->cur_offset;
83 } 76 }
84 - }  
85 - else  
86 - { 77 + } else {
87 this->m->cur_offset = end_pos; 78 this->m->cur_offset = end_pos;
88 result = end_pos; 79 result = end_pos;
89 } 80 }
@@ -105,30 +96,28 @@ BufferInputSource::tell() @@ -105,30 +96,28 @@ BufferInputSource::tell()
105 void 96 void
106 BufferInputSource::seek(qpdf_offset_t offset, int whence) 97 BufferInputSource::seek(qpdf_offset_t offset, int whence)
107 { 98 {
108 - switch (whence)  
109 - {  
110 - case SEEK_SET: 99 + switch (whence) {
  100 + case SEEK_SET:
111 this->m->cur_offset = offset; 101 this->m->cur_offset = offset;
112 break; 102 break;
113 103
114 - case SEEK_END: 104 + case SEEK_END:
115 QIntC::range_check(this->m->max_offset, offset); 105 QIntC::range_check(this->m->max_offset, offset);
116 this->m->cur_offset = this->m->max_offset + offset; 106 this->m->cur_offset = this->m->max_offset + offset;
117 break; 107 break;
118 108
119 - case SEEK_CUR: 109 + case SEEK_CUR:
120 QIntC::range_check(this->m->cur_offset, offset); 110 QIntC::range_check(this->m->cur_offset, offset);
121 this->m->cur_offset += offset; 111 this->m->cur_offset += offset;
122 break; 112 break;
123 113
124 - default: 114 + default:
125 throw std::logic_error( 115 throw std::logic_error(
126 "INTERNAL ERROR: invalid argument to BufferInputSource::seek"); 116 "INTERNAL ERROR: invalid argument to BufferInputSource::seek");
127 break; 117 break;
128 } 118 }
129 119
130 - if (this->m->cur_offset < 0)  
131 - { 120 + if (this->m->cur_offset < 0) {
132 throw std::runtime_error( 121 throw std::runtime_error(
133 this->m->description + ": seek before beginning of buffer"); 122 this->m->description + ": seek before beginning of buffer");
134 } 123 }
@@ -143,20 +132,18 @@ BufferInputSource::rewind() @@ -143,20 +132,18 @@ BufferInputSource::rewind()
143 size_t 132 size_t
144 BufferInputSource::read(char* buffer, size_t length) 133 BufferInputSource::read(char* buffer, size_t length)
145 { 134 {
146 - if (this->m->cur_offset < 0)  
147 - { 135 + if (this->m->cur_offset < 0) {
148 throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); 136 throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0");
149 } 137 }
150 qpdf_offset_t end_pos = this->m->max_offset; 138 qpdf_offset_t end_pos = this->m->max_offset;
151 - if (this->m->cur_offset >= end_pos)  
152 - { 139 + if (this->m->cur_offset >= end_pos) {
153 this->last_offset = end_pos; 140 this->last_offset = end_pos;
154 return 0; 141 return 0;
155 } 142 }
156 143
157 this->last_offset = this->m->cur_offset; 144 this->last_offset = this->m->cur_offset;
158 - size_t len = std::min(  
159 - QIntC::to_size(end_pos - this->m->cur_offset), length); 145 + size_t len =
  146 + std::min(QIntC::to_size(end_pos - this->m->cur_offset), length);
160 memcpy(buffer, this->m->buf->getBuffer() + this->m->cur_offset, len); 147 memcpy(buffer, this->m->buf->getBuffer() + this->m->cur_offset, len);
161 this->m->cur_offset += QIntC::to_offset(len); 148 this->m->cur_offset += QIntC::to_offset(len);
162 return len; 149 return len;
@@ -165,8 +152,7 @@ BufferInputSource::read(char* buffer, size_t length) @@ -165,8 +152,7 @@ BufferInputSource::read(char* buffer, size_t length)
165 void 152 void
166 BufferInputSource::unreadCh(char ch) 153 BufferInputSource::unreadCh(char ch)
167 { 154 {
168 - if (this->m->cur_offset > 0)  
169 - { 155 + if (this->m->cur_offset > 0) {
170 --this->m->cur_offset; 156 --this->m->cur_offset;
171 } 157 }
172 } 158 }
libqpdf/ClosedFileInputSource.cc
@@ -25,8 +25,7 @@ ClosedFileInputSource::~ClosedFileInputSource() @@ -25,8 +25,7 @@ ClosedFileInputSource::~ClosedFileInputSource()
25 void 25 void
26 ClosedFileInputSource::before() 26 ClosedFileInputSource::before()
27 { 27 {
28 - if (0 == this->m->fis.get())  
29 - { 28 + if (0 == this->m->fis.get()) {
30 this->m->fis = make_pointer_holder<FileInputSource>(); 29 this->m->fis = make_pointer_holder<FileInputSource>();
31 this->m->fis->setFilename(this->m->filename.c_str()); 30 this->m->fis->setFilename(this->m->filename.c_str());
32 this->m->fis->seek(this->m->offset, SEEK_SET); 31 this->m->fis->seek(this->m->offset, SEEK_SET);
@@ -39,8 +38,7 @@ ClosedFileInputSource::after() @@ -39,8 +38,7 @@ ClosedFileInputSource::after()
39 { 38 {
40 this->last_offset = this->m->fis->getLastOffset(); 39 this->last_offset = this->m->fis->getLastOffset();
41 this->m->offset = this->m->fis->tell(); 40 this->m->offset = this->m->fis->tell();
42 - if (this->m->stay_open)  
43 - { 41 + if (this->m->stay_open) {
44 return; 42 return;
45 } 43 }
46 this->m->fis = 0; 44 this->m->fis = 0;
@@ -82,8 +80,7 @@ void @@ -82,8 +80,7 @@ void
82 ClosedFileInputSource::rewind() 80 ClosedFileInputSource::rewind()
83 { 81 {
84 this->m->offset = 0; 82 this->m->offset = 0;
85 - if (this->m->fis.get())  
86 - { 83 + if (this->m->fis.get()) {
87 this->m->fis->rewind(); 84 this->m->fis->rewind();
88 } 85 }
89 } 86 }
@@ -110,8 +107,7 @@ void @@ -110,8 +107,7 @@ void
110 ClosedFileInputSource::stayOpen(bool val) 107 ClosedFileInputSource::stayOpen(bool val)
111 { 108 {
112 this->m->stay_open = val; 109 this->m->stay_open = val;
113 - if ((! val) && this->m->fis.get())  
114 - { 110 + if ((!val) && this->m->fis.get()) {
115 after(); 111 after();
116 } 112 }
117 } 113 }
libqpdf/ContentNormalizer.cc
@@ -18,57 +18,46 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const&amp; token) @@ -18,57 +18,46 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const&amp; token)
18 std::string value = token.getRawValue(); 18 std::string value = token.getRawValue();
19 QPDFTokenizer::token_type_e token_type = token.getType(); 19 QPDFTokenizer::token_type_e token_type = token.getType();
20 20
21 - if (token_type == QPDFTokenizer::tt_bad)  
22 - { 21 + if (token_type == QPDFTokenizer::tt_bad) {
23 this->any_bad_tokens = true; 22 this->any_bad_tokens = true;
24 this->last_token_was_bad = true; 23 this->last_token_was_bad = true;
25 - }  
26 - else if (token_type != QPDFTokenizer::tt_eof)  
27 - { 24 + } else if (token_type != QPDFTokenizer::tt_eof) {
28 this->last_token_was_bad = false; 25 this->last_token_was_bad = false;
29 } 26 }
30 27
31 - switch (token_type)  
32 - {  
33 - case QPDFTokenizer::tt_space: 28 + switch (token_type) {
  29 + case QPDFTokenizer::tt_space:
34 { 30 {
35 size_t len = value.length(); 31 size_t len = value.length();
36 - for (size_t i = 0; i < len; ++i)  
37 - { 32 + for (size_t i = 0; i < len; ++i) {
38 char ch = value.at(i); 33 char ch = value.at(i);
39 - if (ch == '\r')  
40 - {  
41 - if ((i + 1 < len) && (value.at(i + 1) == '\n'))  
42 - { 34 + if (ch == '\r') {
  35 + if ((i + 1 < len) && (value.at(i + 1) == '\n')) {
43 // ignore 36 // ignore
44 - }  
45 - else  
46 - { 37 + } else {
47 write("\n"); 38 write("\n");
48 } 39 }
49 - }  
50 - else  
51 - { 40 + } else {
52 write(&ch, 1); 41 write(&ch, 1);
53 } 42 }
54 } 43 }
55 } 44 }
56 break; 45 break;
57 46
58 - case QPDFTokenizer::tt_string: 47 + case QPDFTokenizer::tt_string:
59 // Replacing string and name tokens in this way normalizes 48 // Replacing string and name tokens in this way normalizes
60 // their representation as this will automatically handle 49 // their representation as this will automatically handle
61 // quoting of unprintable characters, etc. 50 // quoting of unprintable characters, etc.
62 - writeToken(QPDFTokenizer::Token(  
63 - QPDFTokenizer::tt_string, token.getValue())); 51 + writeToken(
  52 + QPDFTokenizer::Token(QPDFTokenizer::tt_string, token.getValue()));
64 break; 53 break;
65 54
66 - case QPDFTokenizer::tt_name:  
67 - writeToken(QPDFTokenizer::Token(  
68 - QPDFTokenizer::tt_name, token.getValue())); 55 + case QPDFTokenizer::tt_name:
  56 + writeToken(
  57 + QPDFTokenizer::Token(QPDFTokenizer::tt_name, token.getValue()));
69 break; 58 break;
70 59
71 - default: 60 + default:
72 writeToken(token); 61 writeToken(token);
73 break; 62 break;
74 } 63 }
@@ -77,8 +66,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const&amp; token) @@ -77,8 +66,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const&amp; token)
77 if (((token_type == QPDFTokenizer::tt_string) || 66 if (((token_type == QPDFTokenizer::tt_string) ||
78 (token_type == QPDFTokenizer::tt_name)) && 67 (token_type == QPDFTokenizer::tt_name)) &&
79 ((value.find('\r') != std::string::npos) || 68 ((value.find('\r') != std::string::npos) ||
80 - (value.find('\n') != std::string::npos)))  
81 - { 69 + (value.find('\n') != std::string::npos))) {
82 write("\n"); 70 write("\n");
83 } 71 }
84 } 72 }
@@ -90,7 +78,7 @@ ContentNormalizer::anyBadTokens() const @@ -90,7 +78,7 @@ ContentNormalizer::anyBadTokens() const
90 } 78 }
91 79
92 bool 80 bool
93 -ContentNormalizer::lastTokenWasBad()const 81 +ContentNormalizer::lastTokenWasBad() const
94 { 82 {
95 return this->last_token_was_bad; 83 return this->last_token_was_bad;
96 } 84 }
libqpdf/FileInputSource.cc
1 #include <qpdf/FileInputSource.hh> 1 #include <qpdf/FileInputSource.hh>
2 2
3 -#include <string.h>  
4 -#include <qpdf/QUtil.hh>  
5 #include <qpdf/QPDFExc.hh> 3 #include <qpdf/QPDFExc.hh>
  4 +#include <qpdf/QUtil.hh>
6 #include <algorithm> 5 #include <algorithm>
  6 +#include <string.h>
7 7
8 FileInputSource::Members::Members(bool close_file) : 8 FileInputSource::Members::Members(bool close_file) :
9 close_file(close_file), 9 close_file(close_file),
@@ -13,8 +13,7 @@ FileInputSource::Members::Members(bool close_file) : @@ -13,8 +13,7 @@ FileInputSource::Members::Members(bool close_file) :
13 13
14 FileInputSource::Members::~Members() 14 FileInputSource::Members::~Members()
15 { 15 {
16 - if (this->file && this->close_file)  
17 - { 16 + if (this->file && this->close_file) {
18 fclose(this->file); 17 fclose(this->file);
19 } 18 }
20 } 19 }
@@ -33,8 +32,7 @@ FileInputSource::setFilename(char const* filename) @@ -33,8 +32,7 @@ FileInputSource::setFilename(char const* filename)
33 } 32 }
34 33
35 void 34 void
36 -FileInputSource::setFile(  
37 - char const* description, FILE* filep, bool close_file) 35 +FileInputSource::setFile(char const* description, FILE* filep, bool close_file)
38 { 36 {
39 this->m = PointerHolder<Members>(new Members(close_file)); 37 this->m = PointerHolder<Members>(new Members(close_file));
40 this->m->filename = description; 38 this->m->filename = description;
@@ -52,35 +50,26 @@ FileInputSource::findAndSkipNextEOL() @@ -52,35 +50,26 @@ FileInputSource::findAndSkipNextEOL()
52 qpdf_offset_t result = 0; 50 qpdf_offset_t result = 0;
53 bool done = false; 51 bool done = false;
54 char buf[10240]; 52 char buf[10240];
55 - while (! done)  
56 - { 53 + while (!done) {
57 qpdf_offset_t cur_offset = QUtil::tell(this->m->file); 54 qpdf_offset_t cur_offset = QUtil::tell(this->m->file);
58 size_t len = this->read(buf, sizeof(buf)); 55 size_t len = this->read(buf, sizeof(buf));
59 - if (len == 0)  
60 - { 56 + if (len == 0) {
61 done = true; 57 done = true;
62 result = this->tell(); 58 result = this->tell();
63 - }  
64 - else  
65 - { 59 + } else {
66 char* p1 = static_cast<char*>(memchr(buf, '\r', len)); 60 char* p1 = static_cast<char*>(memchr(buf, '\r', len));
67 char* p2 = static_cast<char*>(memchr(buf, '\n', len)); 61 char* p2 = static_cast<char*>(memchr(buf, '\n', len));
68 char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; 62 char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2;
69 - if (p)  
70 - { 63 + if (p) {
71 result = cur_offset + (p - buf); 64 result = cur_offset + (p - buf);
72 // We found \r or \n. Keep reading until we get past 65 // We found \r or \n. Keep reading until we get past
73 // \r and \n characters. 66 // \r and \n characters.
74 this->seek(result + 1, SEEK_SET); 67 this->seek(result + 1, SEEK_SET);
75 char ch; 68 char ch;
76 - while (! done)  
77 - {  
78 - if (this->read(&ch, 1) == 0)  
79 - { 69 + while (!done) {
  70 + if (this->read(&ch, 1) == 0) {
80 done = true; 71 done = true;
81 - }  
82 - else if (! ((ch == '\r') || (ch == '\n')))  
83 - { 72 + } else if (!((ch == '\r') || (ch == '\n'))) {
84 this->unreadCh(ch); 73 this->unreadCh(ch);
85 done = true; 74 done = true;
86 } 75 }
@@ -106,11 +95,11 @@ FileInputSource::tell() @@ -106,11 +95,11 @@ FileInputSource::tell()
106 void 95 void
107 FileInputSource::seek(qpdf_offset_t offset, int whence) 96 FileInputSource::seek(qpdf_offset_t offset, int whence)
108 { 97 {
109 - QUtil::os_wrapper(std::string("seek to ") +  
110 - this->m->filename + ", offset " +  
111 - QUtil::int_to_string(offset) + " (" +  
112 - QUtil::int_to_string(whence) + ")",  
113 - QUtil::seek(this->m->file, offset, whence)); 98 + QUtil::os_wrapper(
  99 + std::string("seek to ") + this->m->filename + ", offset " +
  100 + QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) +
  101 + ")",
  102 + QUtil::seek(this->m->file, offset, whence));
114 } 103 }
115 104
116 void 105 void
@@ -124,18 +113,16 @@ FileInputSource::read(char* buffer, size_t length) @@ -124,18 +113,16 @@ FileInputSource::read(char* buffer, size_t length)
124 { 113 {
125 this->last_offset = this->tell(); 114 this->last_offset = this->tell();
126 size_t len = fread(buffer, 1, length, this->m->file); 115 size_t len = fread(buffer, 1, length, this->m->file);
127 - if (len == 0)  
128 - {  
129 - if (ferror(this->m->file))  
130 - {  
131 - throw QPDFExc(qpdf_e_system,  
132 - this->m->filename, "",  
133 - this->last_offset,  
134 - std::string("read ") +  
135 - QUtil::uint_to_string(length) + " bytes");  
136 - }  
137 - else if (length > 0)  
138 - { 116 + if (len == 0) {
  117 + if (ferror(this->m->file)) {
  118 + throw QPDFExc(
  119 + qpdf_e_system,
  120 + this->m->filename,
  121 + "",
  122 + this->last_offset,
  123 + std::string("read ") + QUtil::uint_to_string(length) +
  124 + " bytes");
  125 + } else if (length > 0) {
139 this->seek(0, SEEK_END); 126 this->seek(0, SEEK_END);
140 this->last_offset = this->tell(); 127 this->last_offset = this->tell();
141 } 128 }
@@ -146,6 +133,7 @@ FileInputSource::read(char* buffer, size_t length) @@ -146,6 +133,7 @@ FileInputSource::read(char* buffer, size_t length)
146 void 133 void
147 FileInputSource::unreadCh(char ch) 134 FileInputSource::unreadCh(char ch)
148 { 135 {
149 - QUtil::os_wrapper(this->m->filename + ": unread character",  
150 - ungetc(static_cast<unsigned char>(ch), this->m->file)); 136 + QUtil::os_wrapper(
  137 + this->m->filename + ": unread character",
  138 + ungetc(static_cast<unsigned char>(ch), this->m->file));
151 } 139 }
libqpdf/InputSource.cc
1 #include <qpdf/InputSource.hh> 1 #include <qpdf/InputSource.hh>
2 2
3 -#include <string.h>  
4 -#include <stdexcept>  
5 -#include <qpdf/QTC.hh>  
6 #include <qpdf/PointerHolder.hh> 3 #include <qpdf/PointerHolder.hh>
7 #include <qpdf/QIntC.hh> 4 #include <qpdf/QIntC.hh>
  5 +#include <qpdf/QTC.hh>
  6 +#include <stdexcept>
  7 +#include <string.h>
8 8
9 InputSource::Members::Members() 9 InputSource::Members::Members()
10 { 10 {
@@ -45,17 +45,15 @@ InputSource::readLine(size_t max_line_length) @@ -45,17 +45,15 @@ InputSource::readLine(size_t max_line_length)
45 qpdf_offset_t eol = this->findAndSkipNextEOL(); 45 qpdf_offset_t eol = this->findAndSkipNextEOL();
46 this->last_offset = offset; 46 this->last_offset = offset;
47 size_t line_length = QIntC::to_size(eol - offset); 47 size_t line_length = QIntC::to_size(eol - offset);
48 - if (line_length < max_line_length)  
49 - { 48 + if (line_length < max_line_length) {
50 buf[line_length] = '\0'; 49 buf[line_length] = '\0';
51 } 50 }
52 return std::string(buf); 51 return std::string(buf);
53 } 52 }
54 53
55 bool 54 bool
56 -InputSource::findFirst(char const* start_chars,  
57 - qpdf_offset_t offset, size_t len,  
58 - Finder& finder) 55 +InputSource::findFirst(
  56 + char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
59 { 57 {
60 // Basic approach: search for the first character of start_chars 58 // Basic approach: search for the first character of start_chars
61 // starting from offset but not going past len (if len != 0). Once 59 // starting from offset but not going past len (if len != 0). Once
@@ -74,8 +72,7 @@ InputSource::findFirst(char const* start_chars, @@ -74,8 +72,7 @@ InputSource::findFirst(char const* start_chars,
74 // To enable us to guarantee null-termination, save an extra byte 72 // To enable us to guarantee null-termination, save an extra byte
75 // so that buf[size] is valid memory. 73 // so that buf[size] is valid memory.
76 size_t size = sizeof(buf) - 1; 74 size_t size = sizeof(buf) - 1;
77 - if ((strlen(start_chars) < 1) || (strlen(start_chars) > size))  
78 - { 75 + if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) {
79 throw std::logic_error( 76 throw std::logic_error(
80 "InputSource::findSource called with" 77 "InputSource::findSource called with"
81 " too small or too large of a character sequence"); 78 " too small or too large of a character sequence");
@@ -90,8 +87,7 @@ InputSource::findFirst(char const* start_chars, @@ -90,8 +87,7 @@ InputSource::findFirst(char const* start_chars,
90 // that will cause return on the next pass. Eventually we will 87 // that will cause return on the next pass. Eventually we will
91 // either be out of range or hit EOF, either of which forces us to 88 // either be out of range or hit EOF, either of which forces us to
92 // return. 89 // return.
93 - while (true)  
94 - { 90 + while (true) {
95 // Do we need to read more data? Pretend size = 5, buf starts 91 // Do we need to read more data? Pretend size = 5, buf starts
96 // at 0, and start_chars has 3 characters. buf[5] is valid and 92 // at 0, and start_chars has 3 characters. buf[5] is valid and
97 // null. If p == 2, start_chars could be buf[2] through 93 // null. If p == 2, start_chars could be buf[2] through
@@ -99,12 +95,12 @@ InputSource::findFirst(char const* start_chars, @@ -99,12 +95,12 @@ InputSource::findFirst(char const* start_chars,
99 // If p points to buf[size], since strlen(start_chars) is 95 // If p points to buf[size], since strlen(start_chars) is
100 // always >= 1, this overflow test will be correct for that 96 // always >= 1, this overflow test will be correct for that
101 // case regardless of start_chars. 97 // case regardless of start_chars.
102 - if ((p == 0) || ((p + strlen(start_chars)) > (buf + bytes_read)))  
103 - {  
104 - if (p)  
105 - {  
106 - QTC::TC("libtests", "InputSource read next block",  
107 - ((p == buf + bytes_read) ? 0 : 1)); 98 + if ((p == 0) || ((p + strlen(start_chars)) > (buf + bytes_read))) {
  99 + if (p) {
  100 + QTC::TC(
  101 + "libtests",
  102 + "InputSource read next block",
  103 + ((p == buf + bytes_read) ? 0 : 1));
108 buf_offset += (p - buf); 104 buf_offset += (p - buf);
109 } 105 }
110 this->seek(buf_offset, SEEK_SET); 106 this->seek(buf_offset, SEEK_SET);
@@ -113,10 +109,11 @@ InputSource::findFirst(char const* start_chars, @@ -113,10 +109,11 @@ InputSource::findFirst(char const* start_chars,
113 // we could guarantee null termination as an extra 109 // we could guarantee null termination as an extra
114 // protection against overrun when using string functions. 110 // protection against overrun when using string functions.
115 bytes_read = this->read(buf, size); 111 bytes_read = this->read(buf, size);
116 - if (bytes_read < strlen(start_chars))  
117 - {  
118 - QTC::TC("libtests", "InputSource find EOF",  
119 - bytes_read == 0 ? 0 : 1); 112 + if (bytes_read < strlen(start_chars)) {
  113 + QTC::TC(
  114 + "libtests",
  115 + "InputSource find EOF",
  116 + bytes_read == 0 ? 0 : 1);
120 return false; 117 return false;
121 } 118 }
122 memset(buf + bytes_read, '\0', 1 + (size - bytes_read)); 119 memset(buf + bytes_read, '\0', 1 + (size - bytes_read));
@@ -124,29 +121,24 @@ InputSource::findFirst(char const* start_chars, @@ -124,29 +121,24 @@ InputSource::findFirst(char const* start_chars,
124 } 121 }
125 122
126 // Search for the first character. 123 // Search for the first character.
127 - if ((p = static_cast<char*>(  
128 - memchr(p, start_chars[0],  
129 - bytes_read - QIntC::to_size(p - buf)))) != 0)  
130 - {  
131 - if (p == buf)  
132 - { 124 + if ((p = static_cast<char*>(memchr(
  125 + p, start_chars[0], bytes_read - QIntC::to_size(p - buf)))) !=
  126 + 0) {
  127 + if (p == buf) {
133 QTC::TC("libtests", "InputSource found match at buf[0]"); 128 QTC::TC("libtests", "InputSource found match at buf[0]");
134 } 129 }
135 // Found first letter. 130 // Found first letter.
136 - if (len != 0)  
137 - { 131 + if (len != 0) {
138 // Make sure it's in range. 132 // Make sure it's in range.
139 size_t p_relative_offset = 133 size_t p_relative_offset =
140 QIntC::to_size((p - buf) + (buf_offset - offset)); 134 QIntC::to_size((p - buf) + (buf_offset - offset));
141 - if (p_relative_offset >= len)  
142 - { 135 + if (p_relative_offset >= len) {
143 // out of range 136 // out of range
144 QTC::TC("libtests", "InputSource out of range"); 137 QTC::TC("libtests", "InputSource out of range");
145 return false; 138 return false;
146 } 139 }
147 } 140 }
148 - if ((p + strlen(start_chars)) > (buf + bytes_read))  
149 - { 141 + if ((p + strlen(start_chars)) > (buf + bytes_read)) {
150 // If there are not enough bytes left in the file for 142 // If there are not enough bytes left in the file for
151 // start_chars, we will detect this on the next pass 143 // start_chars, we will detect this on the next pass
152 // as EOF and return. 144 // as EOF and return.
@@ -157,30 +149,26 @@ InputSource::findFirst(char const* start_chars, @@ -157,30 +149,26 @@ InputSource::findFirst(char const* start_chars,
157 // See if p points to a sequence matching start_chars. We 149 // See if p points to a sequence matching start_chars. We
158 // already checked above to make sure we are not going to 150 // already checked above to make sure we are not going to
159 // overrun memory. 151 // overrun memory.
160 - if (strncmp(p, start_chars, strlen(start_chars)) == 0)  
161 - { 152 + if (strncmp(p, start_chars, strlen(start_chars)) == 0) {
162 // Call finder.check() with the input source 153 // Call finder.check() with the input source
163 // positioned to the point of the match. 154 // positioned to the point of the match.
164 this->seek(buf_offset + (p - buf), SEEK_SET); 155 this->seek(buf_offset + (p - buf), SEEK_SET);
165 - if (finder.check())  
166 - { 156 + if (finder.check()) {
167 return true; 157 return true;
  158 + } else {
  159 + QTC::TC(
  160 + "libtests",
  161 + "InputSource start_chars matched but not check");
168 } 162 }
169 - else  
170 - {  
171 - QTC::TC("libtests", "InputSource start_chars matched but not check");  
172 - }  
173 - }  
174 - else  
175 - {  
176 - QTC::TC("libtests", "InputSource first char matched but not string"); 163 + } else {
  164 + QTC::TC(
  165 + "libtests",
  166 + "InputSource first char matched but not string");
177 } 167 }
178 // This occurrence of the first character wasn't a match. 168 // This occurrence of the first character wasn't a match.
179 // Skip over it and keep searching. 169 // Skip over it and keep searching.
180 ++p; 170 ++p;
181 - }  
182 - else  
183 - { 171 + } else {
184 // Trigger reading the next block 172 // Trigger reading the next block
185 p = buf + bytes_read; 173 p = buf + bytes_read;
186 } 174 }
@@ -189,30 +177,24 @@ InputSource::findFirst(char const* start_chars, @@ -189,30 +177,24 @@ InputSource::findFirst(char const* start_chars,
189 } 177 }
190 178
191 bool 179 bool
192 -InputSource::findLast(char const* start_chars,  
193 - qpdf_offset_t offset, size_t len,  
194 - Finder& finder) 180 +InputSource::findLast(
  181 + char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
195 { 182 {
196 bool found = false; 183 bool found = false;
197 qpdf_offset_t after_found_offset = 0; 184 qpdf_offset_t after_found_offset = 0;
198 qpdf_offset_t cur_offset = offset; 185 qpdf_offset_t cur_offset = offset;
199 size_t cur_len = len; 186 size_t cur_len = len;
200 - while (this->findFirst(start_chars, cur_offset, cur_len, finder))  
201 - {  
202 - if (found)  
203 - { 187 + while (this->findFirst(start_chars, cur_offset, cur_len, finder)) {
  188 + if (found) {
204 QTC::TC("libtests", "InputSource findLast found more than one"); 189 QTC::TC("libtests", "InputSource findLast found more than one");
205 - }  
206 - else  
207 - { 190 + } else {
208 found = true; 191 found = true;
209 } 192 }
210 after_found_offset = this->tell(); 193 after_found_offset = this->tell();
211 cur_offset = after_found_offset; 194 cur_offset = after_found_offset;
212 cur_len = len - QIntC::to_size((cur_offset - offset)); 195 cur_len = len - QIntC::to_size((cur_offset - offset));
213 } 196 }
214 - if (found)  
215 - { 197 + if (found) {
216 this->seek(after_found_offset, SEEK_SET); 198 this->seek(after_found_offset, SEEK_SET);
217 } 199 }
218 return found; 200 return found;
libqpdf/InsecureRandomDataProvider.cc
1 #include <qpdf/InsecureRandomDataProvider.hh> 1 #include <qpdf/InsecureRandomDataProvider.hh>
2 2
3 -#include <qpdf/qpdf-config.h>  
4 #include <qpdf/QUtil.hh> 3 #include <qpdf/QUtil.hh>
  4 +#include <qpdf/qpdf-config.h>
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 InsecureRandomDataProvider::InsecureRandomDataProvider() : 7 InsecureRandomDataProvider::InsecureRandomDataProvider() :
@@ -16,8 +16,7 @@ InsecureRandomDataProvider::~InsecureRandomDataProvider() @@ -16,8 +16,7 @@ InsecureRandomDataProvider::~InsecureRandomDataProvider()
16 void 16 void
17 InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) 17 InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len)
18 { 18 {
19 - for (size_t i = 0; i < len; ++i)  
20 - { 19 + for (size_t i = 0; i < len; ++i) {
21 data[i] = static_cast<unsigned char>((this->random() & 0xff0) >> 4); 20 data[i] = static_cast<unsigned char>((this->random() & 0xff0) >> 4);
22 } 21 }
23 } 22 }
@@ -25,13 +24,12 @@ InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) @@ -25,13 +24,12 @@ InsecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len)
25 long 24 long
26 InsecureRandomDataProvider::random() 25 InsecureRandomDataProvider::random()
27 { 26 {
28 - if (! this->seeded_random)  
29 - { 27 + if (!this->seeded_random) {
30 // Seed the random number generator with something simple, but 28 // Seed the random number generator with something simple, but
31 // just to be interesting, don't use the unmodified current 29 // just to be interesting, don't use the unmodified current
32 // time. It would be better if this were a more secure seed. 30 // time. It would be better if this were a more secure seed.
33 - unsigned int seed = static_cast<unsigned int>(  
34 - QUtil::get_current_time() ^ 0xcccc); 31 + unsigned int seed =
  32 + static_cast<unsigned int>(QUtil::get_current_time() ^ 0xcccc);
35 #ifdef HAVE_RANDOM 33 #ifdef HAVE_RANDOM
36 ::srandom(seed); 34 ::srandom(seed);
37 #else 35 #else
@@ -40,11 +38,11 @@ InsecureRandomDataProvider::random() @@ -40,11 +38,11 @@ InsecureRandomDataProvider::random()
40 this->seeded_random = true; 38 this->seeded_random = true;
41 } 39 }
42 40
43 -# ifdef HAVE_RANDOM 41 +#ifdef HAVE_RANDOM
44 return ::random(); 42 return ::random();
45 -# else 43 +#else
46 return rand(); 44 return rand();
47 -# endif 45 +#endif
48 } 46 }
49 47
50 RandomDataProvider* 48 RandomDataProvider*
libqpdf/JSON.cc
1 #include <qpdf/JSON.hh> 1 #include <qpdf/JSON.hh>
2 2
3 -#include <qpdf/QUtil.hh>  
4 #include <qpdf/QTC.hh> 3 #include <qpdf/QTC.hh>
5 -#include <stdexcept> 4 +#include <qpdf/QUtil.hh>
6 #include <cstring> 5 #include <cstring>
  6 +#include <stdexcept>
7 7
8 JSON::Members::~Members() 8 JSON::Members::~Members()
9 { 9 {
@@ -27,27 +27,23 @@ JSON::JSON_dictionary::~JSON_dictionary() @@ -27,27 +27,23 @@ JSON::JSON_dictionary::~JSON_dictionary()
27 { 27 {
28 } 28 }
29 29
30 -std::string JSON::JSON_dictionary::unparse(size_t depth) const 30 +std::string
  31 +JSON::JSON_dictionary::unparse(size_t depth) const
31 { 32 {
32 std::string result = "{"; 33 std::string result = "{";
33 bool first = true; 34 bool first = true;
34 - for (auto const& iter: members)  
35 - {  
36 - if (first)  
37 - { 35 + for (auto const& iter : members) {
  36 + if (first) {
38 first = false; 37 first = false;
39 - }  
40 - else  
41 - { 38 + } else {
42 result.append(1, ','); 39 result.append(1, ',');
43 } 40 }
44 result.append(1, '\n'); 41 result.append(1, '\n');
45 result.append(2 * (1 + depth), ' '); 42 result.append(2 * (1 + depth), ' ');
46 - result += ("\"" + iter.first + "\": " +  
47 - iter.second->unparse(1 + depth)); 43 + result +=
  44 + ("\"" + iter.first + "\": " + iter.second->unparse(1 + depth));
48 } 45 }
49 - if (! first)  
50 - { 46 + if (!first) {
51 result.append(1, '\n'); 47 result.append(1, '\n');
52 result.append(2 * depth, ' '); 48 result.append(2 * depth, ' ');
53 } 49 }
@@ -59,26 +55,22 @@ JSON::JSON_array::~JSON_array() @@ -59,26 +55,22 @@ JSON::JSON_array::~JSON_array()
59 { 55 {
60 } 56 }
61 57
62 -std::string JSON::JSON_array::unparse(size_t depth) const 58 +std::string
  59 +JSON::JSON_array::unparse(size_t depth) const
63 { 60 {
64 std::string result = "["; 61 std::string result = "[";
65 bool first = true; 62 bool first = true;
66 - for (auto const& element: elements)  
67 - {  
68 - if (first)  
69 - { 63 + for (auto const& element : elements) {
  64 + if (first) {
70 first = false; 65 first = false;
71 - }  
72 - else  
73 - { 66 + } else {
74 result.append(1, ','); 67 result.append(1, ',');
75 } 68 }
76 result.append(1, '\n'); 69 result.append(1, '\n');
77 result.append(2 * (1 + depth), ' '); 70 result.append(2 * (1 + depth), ' ');
78 result += element->unparse(1 + depth); 71 result += element->unparse(1 + depth);
79 } 72 }
80 - if (! first)  
81 - { 73 + if (!first) {
82 result.append(1, '\n'); 74 result.append(1, '\n');
83 result.append(2 * depth, ' '); 75 result.append(2 * depth, ' ');
84 } 76 }
@@ -96,7 +88,8 @@ JSON::JSON_string::~JSON_string() @@ -96,7 +88,8 @@ JSON::JSON_string::~JSON_string()
96 { 88 {
97 } 89 }
98 90
99 -std::string JSON::JSON_string::unparse(size_t) const 91 +std::string
  92 +JSON::JSON_string::unparse(size_t) const
100 { 93 {
101 return "\"" + encoded + "\""; 94 return "\"" + encoded + "\"";
102 } 95 }
@@ -120,7 +113,8 @@ JSON::JSON_number::~JSON_number() @@ -120,7 +113,8 @@ JSON::JSON_number::~JSON_number()
120 { 113 {
121 } 114 }
122 115
123 -std::string JSON::JSON_number::unparse(size_t) const 116 +std::string
  117 +JSON::JSON_number::unparse(size_t) const
124 { 118 {
125 return encoded; 119 return encoded;
126 } 120 }
@@ -134,7 +128,8 @@ JSON::JSON_bool::~JSON_bool() @@ -134,7 +128,8 @@ JSON::JSON_bool::~JSON_bool()
134 { 128 {
135 } 129 }
136 130
137 -std::string JSON::JSON_bool::unparse(size_t) const 131 +std::string
  132 +JSON::JSON_bool::unparse(size_t) const
138 { 133 {
139 return value ? "true" : "false"; 134 return value ? "true" : "false";
140 } 135 }
@@ -143,7 +138,8 @@ JSON::JSON_null::~JSON_null() @@ -143,7 +138,8 @@ JSON::JSON_null::~JSON_null()
143 { 138 {
144 } 139 }
145 140
146 -std::string JSON::JSON_null::unparse(size_t) const 141 +std::string
  142 +JSON::JSON_null::unparse(size_t) const
147 { 143 {
148 return "null"; 144 return "null";
149 } 145 }
@@ -151,12 +147,9 @@ std::string JSON::JSON_null::unparse(size_t) const @@ -151,12 +147,9 @@ std::string JSON::JSON_null::unparse(size_t) const
151 std::string 147 std::string
152 JSON::unparse() const 148 JSON::unparse() const
153 { 149 {
154 - if (0 == this->m->value.get())  
155 - { 150 + if (0 == this->m->value.get()) {
156 return "null"; 151 return "null";
157 - }  
158 - else  
159 - { 152 + } else {
160 return this->m->value->unparse(0); 153 return this->m->value->unparse(0);
161 } 154 }
162 } 155 }
@@ -166,39 +159,34 @@ JSON::encode_string(std::string const&amp; str) @@ -166,39 +159,34 @@ JSON::encode_string(std::string const&amp; str)
166 { 159 {
167 std::string result; 160 std::string result;
168 size_t len = str.length(); 161 size_t len = str.length();
169 - for (size_t i = 0; i < len; ++i)  
170 - { 162 + for (size_t i = 0; i < len; ++i) {
171 unsigned char ch = static_cast<unsigned char>(str.at(i)); 163 unsigned char ch = static_cast<unsigned char>(str.at(i));
172 - switch (ch)  
173 - {  
174 - case '\\': 164 + switch (ch) {
  165 + case '\\':
175 result += "\\\\"; 166 result += "\\\\";
176 break; 167 break;
177 - case '\"': 168 + case '\"':
178 result += "\\\""; 169 result += "\\\"";
179 break; 170 break;
180 - case '\b': 171 + case '\b':
181 result += "\\b"; 172 result += "\\b";
182 break; 173 break;
183 - case '\f': 174 + case '\f':
184 result += "\\f"; 175 result += "\\f";
185 break; 176 break;
186 - case '\n': 177 + case '\n':
187 result += "\\n"; 178 result += "\\n";
188 break; 179 break;
189 - case '\r': 180 + case '\r':
190 result += "\\r"; 181 result += "\\r";
191 break; 182 break;
192 - case '\t': 183 + case '\t':
193 result += "\\t"; 184 result += "\\t";
194 break; 185 break;
195 - default:  
196 - if (ch < 32)  
197 - { 186 + default:
  187 + if (ch < 32) {
198 result += "\\u" + QUtil::int_to_string_base(ch, 16, 4); 188 result += "\\u" + QUtil::int_to_string_base(ch, 16, 4);
199 - }  
200 - else  
201 - { 189 + } else {
202 result.append(1, static_cast<char>(ch)); 190 result.append(1, static_cast<char>(ch));
203 } 191 }
204 } 192 }
@@ -215,19 +203,14 @@ JSON::makeDictionary() @@ -215,19 +203,14 @@ JSON::makeDictionary()
215 JSON 203 JSON
216 JSON::addDictionaryMember(std::string const& key, JSON const& val) 204 JSON::addDictionaryMember(std::string const& key, JSON const& val)
217 { 205 {
218 - JSON_dictionary* obj = dynamic_cast<JSON_dictionary*>(  
219 - this->m->value.get());  
220 - if (0 == obj)  
221 - { 206 + JSON_dictionary* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get());
  207 + if (0 == obj) {
222 throw std::runtime_error( 208 throw std::runtime_error(
223 "JSON::addDictionaryMember called on non-dictionary"); 209 "JSON::addDictionaryMember called on non-dictionary");
224 } 210 }
225 - if (val.m->value.get())  
226 - { 211 + if (val.m->value.get()) {
227 obj->members[encode_string(key)] = val.m->value; 212 obj->members[encode_string(key)] = val.m->value;
228 - }  
229 - else  
230 - { 213 + } else {
231 obj->members[encode_string(key)] = std::make_shared<JSON_null>(); 214 obj->members[encode_string(key)] = std::make_shared<JSON_null>();
232 } 215 }
233 return obj->members[encode_string(key)]; 216 return obj->members[encode_string(key)];
@@ -242,18 +225,13 @@ JSON::makeArray() @@ -242,18 +225,13 @@ JSON::makeArray()
242 JSON 225 JSON
243 JSON::addArrayElement(JSON const& val) 226 JSON::addArrayElement(JSON const& val)
244 { 227 {
245 - JSON_array* arr = dynamic_cast<JSON_array*>(  
246 - this->m->value.get());  
247 - if (0 == arr)  
248 - { 228 + JSON_array* arr = dynamic_cast<JSON_array*>(this->m->value.get());
  229 + if (0 == arr) {
249 throw std::runtime_error("JSON::addArrayElement called on non-array"); 230 throw std::runtime_error("JSON::addArrayElement called on non-array");
250 } 231 }
251 - if (val.m->value.get())  
252 - { 232 + if (val.m->value.get()) {
253 arr->elements.push_back(val.m->value); 233 arr->elements.push_back(val.m->value);
254 - }  
255 - else  
256 - { 234 + } else {
257 arr->elements.push_back(std::make_shared<JSON_null>()); 235 arr->elements.push_back(std::make_shared<JSON_null>());
258 } 236 }
259 return arr->elements.back(); 237 return arr->elements.back();
@@ -298,23 +276,21 @@ JSON::makeNull() @@ -298,23 +276,21 @@ JSON::makeNull()
298 bool 276 bool
299 JSON::isArray() const 277 JSON::isArray() const
300 { 278 {
301 - return nullptr != dynamic_cast<JSON_array const*>(  
302 - this->m->value.get()); 279 + return nullptr != dynamic_cast<JSON_array const*>(this->m->value.get());
303 } 280 }
304 281
305 bool 282 bool
306 JSON::isDictionary() const 283 JSON::isDictionary() const
307 { 284 {
308 - return nullptr != dynamic_cast<JSON_dictionary const*>(  
309 - this->m->value.get()); 285 + return nullptr !=
  286 + dynamic_cast<JSON_dictionary const*>(this->m->value.get());
310 } 287 }
311 288
312 bool 289 bool
313 JSON::getString(std::string& utf8) const 290 JSON::getString(std::string& utf8) const
314 { 291 {
315 auto v = dynamic_cast<JSON_string const*>(this->m->value.get()); 292 auto v = dynamic_cast<JSON_string const*>(this->m->value.get());
316 - if (v == nullptr)  
317 - { 293 + if (v == nullptr) {
318 return false; 294 return false;
319 } 295 }
320 utf8 = v->utf8; 296 utf8 = v->utf8;
@@ -325,8 +301,7 @@ bool @@ -325,8 +301,7 @@ bool
325 JSON::getNumber(std::string& value) const 301 JSON::getNumber(std::string& value) const
326 { 302 {
327 auto v = dynamic_cast<JSON_number const*>(this->m->value.get()); 303 auto v = dynamic_cast<JSON_number const*>(this->m->value.get());
328 - if (v == nullptr)  
329 - { 304 + if (v == nullptr) {
330 return false; 305 return false;
331 } 306 }
332 value = v->encoded; 307 value = v->encoded;
@@ -337,8 +312,7 @@ bool @@ -337,8 +312,7 @@ bool
337 JSON::getBool(bool& value) const 312 JSON::getBool(bool& value) const
338 { 313 {
339 auto v = dynamic_cast<JSON_bool const*>(this->m->value.get()); 314 auto v = dynamic_cast<JSON_bool const*>(this->m->value.get());
340 - if (v == nullptr)  
341 - { 315 + if (v == nullptr) {
342 return false; 316 return false;
343 } 317 }
344 value = v->value; 318 value = v->value;
@@ -348,8 +322,7 @@ JSON::getBool(bool&amp; value) const @@ -348,8 +322,7 @@ JSON::getBool(bool&amp; value) const
348 bool 322 bool
349 JSON::isNull() const 323 JSON::isNull() const
350 { 324 {
351 - if (dynamic_cast<JSON_null const*>(this->m->value.get()))  
352 - { 325 + if (dynamic_cast<JSON_null const*>(this->m->value.get())) {
353 return true; 326 return true;
354 } 327 }
355 return false; 328 return false;
@@ -360,12 +333,10 @@ JSON::forEachDictItem( @@ -360,12 +333,10 @@ JSON::forEachDictItem(
360 std::function<void(std::string const& key, JSON value)> fn) const 333 std::function<void(std::string const& key, JSON value)> fn) const
361 { 334 {
362 auto v = dynamic_cast<JSON_dictionary const*>(this->m->value.get()); 335 auto v = dynamic_cast<JSON_dictionary const*>(this->m->value.get());
363 - if (v == nullptr)  
364 - { 336 + if (v == nullptr) {
365 return false; 337 return false;
366 } 338 }
367 - for (auto const& k: v->members)  
368 - { 339 + for (auto const& k : v->members) {
369 fn(k.first, JSON(k.second)); 340 fn(k.first, JSON(k.second));
370 } 341 }
371 return true; 342 return true;
@@ -375,12 +346,10 @@ bool @@ -375,12 +346,10 @@ bool
375 JSON::forEachArrayItem(std::function<void(JSON value)> fn) const 346 JSON::forEachArrayItem(std::function<void(JSON value)> fn) const
376 { 347 {
377 auto v = dynamic_cast<JSON_array const*>(this->m->value.get()); 348 auto v = dynamic_cast<JSON_array const*>(this->m->value.get());
378 - if (v == nullptr)  
379 - { 349 + if (v == nullptr) {
380 return false; 350 return false;
381 } 351 }
382 - for (auto const& i: v->elements)  
383 - { 352 + for (auto const& i : v->elements) {
384 fn(JSON(i)); 353 fn(JSON(i));
385 } 354 }
386 return true; 355 return true;
@@ -389,25 +358,25 @@ JSON::forEachArrayItem(std::function&lt;void(JSON value)&gt; fn) const @@ -389,25 +358,25 @@ JSON::forEachArrayItem(std::function&lt;void(JSON value)&gt; fn) const
389 bool 358 bool
390 JSON::checkSchema(JSON schema, std::list<std::string>& errors) 359 JSON::checkSchema(JSON schema, std::list<std::string>& errors)
391 { 360 {
392 - return checkSchemaInternal(this->m->value.get(),  
393 - schema.m->value.get(),  
394 - 0, errors, ""); 361 + return checkSchemaInternal(
  362 + this->m->value.get(), schema.m->value.get(), 0, errors, "");
395 } 363 }
396 364
397 bool 365 bool
398 -JSON::checkSchema(JSON schema, unsigned long flags,  
399 - std::list<std::string>& errors) 366 +JSON::checkSchema(
  367 + JSON schema, unsigned long flags, std::list<std::string>& errors)
400 { 368 {
401 - return checkSchemaInternal(this->m->value.get(),  
402 - schema.m->value.get(),  
403 - flags, errors, ""); 369 + return checkSchemaInternal(
  370 + this->m->value.get(), schema.m->value.get(), flags, errors, "");
404 } 371 }
405 372
406 bool 373 bool
407 -JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,  
408 - unsigned long flags,  
409 - std::list<std::string>& errors,  
410 - std::string prefix) 374 +JSON::checkSchemaInternal(
  375 + JSON_value* this_v,
  376 + JSON_value* sch_v,
  377 + unsigned long flags,
  378 + std::list<std::string>& errors,
  379 + std::string prefix)
411 { 380 {
412 JSON_array* this_arr = dynamic_cast<JSON_array*>(this_v); 381 JSON_array* this_arr = dynamic_cast<JSON_array*>(this_v);
413 JSON_dictionary* this_dict = dynamic_cast<JSON_dictionary*>(this_v); 382 JSON_dictionary* this_dict = dynamic_cast<JSON_dictionary*>(this_v);
@@ -418,20 +387,15 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v, @@ -418,20 +387,15 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,
418 JSON_string* sch_str = dynamic_cast<JSON_string*>(sch_v); 387 JSON_string* sch_str = dynamic_cast<JSON_string*>(sch_v);
419 388
420 std::string err_prefix; 389 std::string err_prefix;
421 - if (prefix.empty())  
422 - { 390 + if (prefix.empty()) {
423 err_prefix = "top-level object"; 391 err_prefix = "top-level object";
424 - }  
425 - else  
426 - { 392 + } else {
427 err_prefix = "json key \"" + prefix + "\""; 393 err_prefix = "json key \"" + prefix + "\"";
428 } 394 }
429 395
430 std::string pattern_key; 396 std::string pattern_key;
431 - if (sch_dict)  
432 - {  
433 - if (! this_dict)  
434 - { 397 + if (sch_dict) {
  398 + if (!this_dict) {
435 QTC::TC("libtests", "JSON wanted dictionary"); 399 QTC::TC("libtests", "JSON wanted dictionary");
436 errors.push_back(err_prefix + " is supposed to be a dictionary"); 400 errors.push_back(err_prefix + " is supposed to be a dictionary");
437 return false; 401 return false;
@@ -440,44 +404,36 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v, @@ -440,44 +404,36 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,
440 std::string key; 404 std::string key;
441 if ((members.size() == 1) && 405 if ((members.size() == 1) &&
442 ((key = members.begin()->first, key.length() > 2) && 406 ((key = members.begin()->first, key.length() > 2) &&
443 - (key.at(0) == '<') &&  
444 - (key.at(key.length() - 1) == '>')))  
445 - { 407 + (key.at(0) == '<') && (key.at(key.length() - 1) == '>'))) {
446 pattern_key = key; 408 pattern_key = key;
447 } 409 }
448 } 410 }
449 411
450 - if (sch_dict && (! pattern_key.empty()))  
451 - { 412 + if (sch_dict && (!pattern_key.empty())) {
452 auto pattern_schema = sch_dict->members[pattern_key].get(); 413 auto pattern_schema = sch_dict->members[pattern_key].get();
453 - for (auto const& iter: this_dict->members)  
454 - { 414 + for (auto const& iter : this_dict->members) {
455 std::string const& key = iter.first; 415 std::string const& key = iter.first;
456 checkSchemaInternal( 416 checkSchemaInternal(
457 - this_dict->members[key].get(), pattern_schema,  
458 - flags, errors, prefix + "." + key); 417 + this_dict->members[key].get(),
  418 + pattern_schema,
  419 + flags,
  420 + errors,
  421 + prefix + "." + key);
459 } 422 }
460 - }  
461 - else if (sch_dict)  
462 - {  
463 - for (auto& iter: sch_dict->members)  
464 - { 423 + } else if (sch_dict) {
  424 + for (auto& iter : sch_dict->members) {
465 std::string const& key = iter.first; 425 std::string const& key = iter.first;
466 - if (this_dict->members.count(key))  
467 - { 426 + if (this_dict->members.count(key)) {
468 checkSchemaInternal( 427 checkSchemaInternal(
469 this_dict->members[key].get(), 428 this_dict->members[key].get(),
470 iter.second.get(), 429 iter.second.get(),
471 - flags, errors, prefix + "." + key);  
472 - }  
473 - else  
474 - {  
475 - if (flags & f_optional)  
476 - { 430 + flags,
  431 + errors,
  432 + prefix + "." + key);
  433 + } else {
  434 + if (flags & f_optional) {
477 QTC::TC("libtests", "JSON optional key"); 435 QTC::TC("libtests", "JSON optional key");
478 - }  
479 - else  
480 - { 436 + } else {
481 QTC::TC("libtests", "JSON key missing in object"); 437 QTC::TC("libtests", "JSON key missing in object");
482 errors.push_back( 438 errors.push_back(
483 err_prefix + ": key \"" + key + 439 err_prefix + ": key \"" + key +
@@ -485,55 +441,49 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v, @@ -485,55 +441,49 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,
485 } 441 }
486 } 442 }
487 } 443 }
488 - for (auto const& iter: this_dict->members)  
489 - { 444 + for (auto const& iter : this_dict->members) {
490 std::string const& key = iter.first; 445 std::string const& key = iter.first;
491 - if (sch_dict->members.count(key) == 0)  
492 - { 446 + if (sch_dict->members.count(key) == 0) {
493 QTC::TC("libtests", "JSON key extra in object"); 447 QTC::TC("libtests", "JSON key extra in object");
494 errors.push_back( 448 errors.push_back(
495 err_prefix + ": key \"" + key + 449 err_prefix + ": key \"" + key +
496 "\" is not present in schema but appears in object"); 450 "\" is not present in schema but appears in object");
497 } 451 }
498 } 452 }
499 - }  
500 - else if (sch_arr)  
501 - {  
502 - if (! this_arr)  
503 - { 453 + } else if (sch_arr) {
  454 + if (!this_arr) {
504 QTC::TC("libtests", "JSON wanted array"); 455 QTC::TC("libtests", "JSON wanted array");
505 errors.push_back(err_prefix + " is supposed to be an array"); 456 errors.push_back(err_prefix + " is supposed to be an array");
506 return false; 457 return false;
507 } 458 }
508 - if (sch_arr->elements.size() != 1)  
509 - { 459 + if (sch_arr->elements.size() != 1) {
510 QTC::TC("libtests", "JSON schema array error"); 460 QTC::TC("libtests", "JSON schema array error");
511 - errors.push_back(err_prefix +  
512 - " schema array contains other than one item"); 461 + errors.push_back(
  462 + err_prefix + " schema array contains other than one item");
513 return false; 463 return false;
514 } 464 }
515 int i = 0; 465 int i = 0;
516 - for (auto const& element: this_arr->elements)  
517 - { 466 + for (auto const& element : this_arr->elements) {
518 checkSchemaInternal( 467 checkSchemaInternal(
519 element.get(), 468 element.get(),
520 sch_arr->elements.at(0).get(), 469 sch_arr->elements.at(0).get(),
521 - flags, errors, prefix + "." + QUtil::int_to_string(i)); 470 + flags,
  471 + errors,
  472 + prefix + "." + QUtil::int_to_string(i));
522 ++i; 473 ++i;
523 } 474 }
524 - }  
525 - else if (! sch_str)  
526 - { 475 + } else if (!sch_str) {
527 QTC::TC("libtests", "JSON schema other type"); 476 QTC::TC("libtests", "JSON schema other type");
528 - errors.push_back(err_prefix +  
529 - " schema value is not dictionary, array, or string"); 477 + errors.push_back(
  478 + err_prefix + " schema value is not dictionary, array, or string");
530 return false; 479 return false;
531 } 480 }
532 481
533 return errors.empty(); 482 return errors.empty();
534 } 483 }
535 484
536 -namespace { 485 +namespace
  486 +{
537 class JSONParser 487 class JSONParser
538 { 488 {
539 public: 489 public:
@@ -597,7 +547,7 @@ namespace { @@ -597,7 +547,7 @@ namespace {
597 std::vector<parser_state_e> ps_stack; 547 std::vector<parser_state_e> ps_stack;
598 std::string dict_key; 548 std::string dict_key;
599 }; 549 };
600 -} 550 +} // namespace
601 551
602 std::string 552 std::string
603 JSONParser::decode_string(std::string const& str) 553 JSONParser::decode_string(std::string const& str)
@@ -606,8 +556,7 @@ JSONParser::decode_string(std::string const&amp; str) @@ -606,8 +556,7 @@ JSONParser::decode_string(std::string const&amp; str)
606 // is called, so errors are logic errors instead of runtime 556 // is called, so errors are logic errors instead of runtime
607 // errors. 557 // errors.
608 size_t len = str.length(); 558 size_t len = str.length();
609 - if ((len < 2) || (str.at(0) != '"') || (str.at(len-1) != '"'))  
610 - { 559 + if ((len < 2) || (str.at(0) != '"') || (str.at(len - 1) != '"')) {
611 throw std::logic_error( 560 throw std::logic_error(
612 "JSON Parse: decode_string called with other than \"...\""); 561 "JSON Parse: decode_string called with other than \"...\"");
613 } 562 }
@@ -616,48 +565,43 @@ JSONParser::decode_string(std::string const&amp; str) @@ -616,48 +565,43 @@ JSONParser::decode_string(std::string const&amp; str)
616 ++s; 565 ++s;
617 len -= 2; 566 len -= 2;
618 std::string result; 567 std::string result;
619 - for (size_t i = 0; i < len; ++i)  
620 - {  
621 - if (s[i] == '\\')  
622 - {  
623 - if (i + 1 >= len)  
624 - { 568 + for (size_t i = 0; i < len; ++i) {
  569 + if (s[i] == '\\') {
  570 + if (i + 1 >= len) {
625 throw std::logic_error("JSON parse: nothing after \\"); 571 throw std::logic_error("JSON parse: nothing after \\");
626 } 572 }
627 char ch = s[++i]; 573 char ch = s[++i];
628 - switch (ch)  
629 - {  
630 - case '\\':  
631 - case '\"':  
632 - case '/': 574 + switch (ch) {
  575 + case '\\':
  576 + case '\"':
  577 + case '/':
633 // \/ is allowed in json input, but so is /, so we 578 // \/ is allowed in json input, but so is /, so we
634 // don't map / to \/ in output. 579 // don't map / to \/ in output.
635 result.append(1, ch); 580 result.append(1, ch);
636 break; 581 break;
637 - case 'b': 582 + case 'b':
638 result.append(1, '\b'); 583 result.append(1, '\b');
639 break; 584 break;
640 - case 'f': 585 + case 'f':
641 result.append(1, '\f'); 586 result.append(1, '\f');
642 break; 587 break;
643 - case 'n': 588 + case 'n':
644 result.append(1, '\n'); 589 result.append(1, '\n');
645 break; 590 break;
646 - case 'r': 591 + case 'r':
647 result.append(1, '\r'); 592 result.append(1, '\r');
648 break; 593 break;
649 - case 't': 594 + case 't':
650 result.append(1, '\t'); 595 result.append(1, '\t');
651 break; 596 break;
652 - case 'u':  
653 - if (i + 4 >= len)  
654 - { 597 + case 'u':
  598 + if (i + 4 >= len) {
655 throw std::logic_error( 599 throw std::logic_error(
656 "JSON parse: not enough characters after \\u"); 600 "JSON parse: not enough characters after \\u");
657 } 601 }
658 { 602 {
659 std::string hex = 603 std::string hex =
660 - QUtil::hex_decode(std::string(s+i+1, s+i+5)); 604 + QUtil::hex_decode(std::string(s + i + 1, s + i + 5));
661 i += 4; 605 i += 4;
662 unsigned char high = static_cast<unsigned char>(hex.at(0)); 606 unsigned char high = static_cast<unsigned char>(hex.at(0));
663 unsigned char low = static_cast<unsigned char>(hex.at(1)); 607 unsigned char low = static_cast<unsigned char>(hex.at(1));
@@ -667,52 +611,40 @@ JSONParser::decode_string(std::string const&amp; str) @@ -667,52 +611,40 @@ JSONParser::decode_string(std::string const&amp; str)
667 result += QUtil::toUTF8(codepoint); 611 result += QUtil::toUTF8(codepoint);
668 } 612 }
669 break; 613 break;
670 - default:  
671 - throw std::logic_error(  
672 - "JSON parse: bad character after \\"); 614 + default:
  615 + throw std::logic_error("JSON parse: bad character after \\");
673 break; 616 break;
674 } 617 }
675 - }  
676 - else  
677 - { 618 + } else {
678 result.append(1, s[i]); 619 result.append(1, s[i]);
679 } 620 }
680 } 621 }
681 return result; 622 return result;
682 } 623 }
683 624
684 -void JSONParser::getToken() 625 +void
  626 +JSONParser::getToken()
685 { 627 {
686 - while (p < end)  
687 - {  
688 - if (*p == 0)  
689 - { 628 + while (p < end) {
  629 + if (*p == 0) {
690 QTC::TC("libtests", "JSON parse null character"); 630 QTC::TC("libtests", "JSON parse null character");
691 throw std::runtime_error( 631 throw std::runtime_error(
692 "JSON: null character at offset " + 632 "JSON: null character at offset " +
693 QUtil::int_to_string(p - cstr)); 633 QUtil::int_to_string(p - cstr));
694 } 634 }
695 - switch (lex_state)  
696 - {  
697 - case ls_top:  
698 - if (*p == '"')  
699 - { 635 + switch (lex_state) {
  636 + case ls_top:
  637 + if (*p == '"') {
700 tok_start = p; 638 tok_start = p;
701 tok_end = nullptr; 639 tok_end = nullptr;
702 lex_state = ls_string; 640 lex_state = ls_string;
703 - }  
704 - else if (QUtil::is_space(*p))  
705 - { 641 + } else if (QUtil::is_space(*p)) {
706 // ignore 642 // ignore
707 - }  
708 - else if ((*p >= 'a') && (*p <= 'z'))  
709 - { 643 + } else if ((*p >= 'a') && (*p <= 'z')) {
710 tok_start = p; 644 tok_start = p;
711 tok_end = nullptr; 645 tok_end = nullptr;
712 lex_state = ls_alpha; 646 lex_state = ls_alpha;
713 - }  
714 - else if (*p == '-')  
715 - { 647 + } else if (*p == '-') {
716 tok_start = p; 648 tok_start = p;
717 tok_end = nullptr; 649 tok_end = nullptr;
718 lex_state = ls_number; 650 lex_state = ls_number;
@@ -721,9 +653,7 @@ void JSONParser::getToken() @@ -721,9 +653,7 @@ void JSONParser::getToken()
721 number_after_e = 0; 653 number_after_e = 0;
722 number_saw_point = false; 654 number_saw_point = false;
723 number_saw_e = false; 655 number_saw_e = false;
724 - }  
725 - else if ((*p >= '0') && (*p <= '9'))  
726 - { 656 + } else if ((*p >= '0') && (*p <= '9')) {
727 tok_start = p; 657 tok_start = p;
728 tok_end = nullptr; 658 tok_end = nullptr;
729 lex_state = ls_number; 659 lex_state = ls_number;
@@ -732,9 +662,7 @@ void JSONParser::getToken() @@ -732,9 +662,7 @@ void JSONParser::getToken()
732 number_after_e = 0; 662 number_after_e = 0;
733 number_saw_point = false; 663 number_saw_point = false;
734 number_saw_e = false; 664 number_saw_e = false;
735 - }  
736 - else if (*p == '.')  
737 - { 665 + } else if (*p == '.') {
738 tok_start = p; 666 tok_start = p;
739 tok_end = nullptr; 667 tok_end = nullptr;
740 lex_state = ls_number; 668 lex_state = ls_number;
@@ -743,14 +671,10 @@ void JSONParser::getToken() @@ -743,14 +671,10 @@ void JSONParser::getToken()
743 number_after_e = 0; 671 number_after_e = 0;
744 number_saw_point = true; 672 number_saw_point = true;
745 number_saw_e = false; 673 number_saw_e = false;
746 - }  
747 - else if (strchr("{}[]:,", *p))  
748 - { 674 + } else if (strchr("{}[]:,", *p)) {
749 tok_start = p; 675 tok_start = p;
750 tok_end = p + 1; 676 tok_end = p + 1;
751 - }  
752 - else  
753 - { 677 + } else {
754 QTC::TC("libtests", "JSON parse bad character"); 678 QTC::TC("libtests", "JSON parse bad character");
755 throw std::runtime_error( 679 throw std::runtime_error(
756 "JSON: offset " + QUtil::int_to_string(p - cstr) + 680 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -758,82 +682,53 @@ void JSONParser::getToken() @@ -758,82 +682,53 @@ void JSONParser::getToken()
758 } 682 }
759 break; 683 break;
760 684
761 - case ls_number:  
762 - if ((*p >= '0') && (*p <= '9'))  
763 - {  
764 - if (number_saw_e)  
765 - { 685 + case ls_number:
  686 + if ((*p >= '0') && (*p <= '9')) {
  687 + if (number_saw_e) {
766 ++number_after_e; 688 ++number_after_e;
767 - }  
768 - else if (number_saw_point)  
769 - { 689 + } else if (number_saw_point) {
770 ++number_after_point; 690 ++number_after_point;
771 - }  
772 - else  
773 - { 691 + } else {
774 ++number_before_point; 692 ++number_before_point;
775 } 693 }
776 - }  
777 - else if (*p == '.')  
778 - {  
779 - if (number_saw_e)  
780 - { 694 + } else if (*p == '.') {
  695 + if (number_saw_e) {
781 QTC::TC("libtests", "JSON parse point after e"); 696 QTC::TC("libtests", "JSON parse point after e");
782 throw std::runtime_error( 697 throw std::runtime_error(
783 "JSON: offset " + QUtil::int_to_string(p - cstr) + 698 "JSON: offset " + QUtil::int_to_string(p - cstr) +
784 ": numeric literal: decimal point after e"); 699 ": numeric literal: decimal point after e");
785 - }  
786 - else if (number_saw_point)  
787 - { 700 + } else if (number_saw_point) {
788 QTC::TC("libtests", "JSON parse duplicate point"); 701 QTC::TC("libtests", "JSON parse duplicate point");
789 throw std::runtime_error( 702 throw std::runtime_error(
790 "JSON: offset " + QUtil::int_to_string(p - cstr) + 703 "JSON: offset " + QUtil::int_to_string(p - cstr) +
791 ": numeric literal: decimal point already seen"); 704 ": numeric literal: decimal point already seen");
792 - }  
793 - else  
794 - { 705 + } else {
795 number_saw_point = true; 706 number_saw_point = true;
796 } 707 }
797 - }  
798 - else if (*p == 'e')  
799 - {  
800 - if (number_saw_e)  
801 - { 708 + } else if (*p == 'e') {
  709 + if (number_saw_e) {
802 QTC::TC("libtests", "JSON parse duplicate e"); 710 QTC::TC("libtests", "JSON parse duplicate e");
803 throw std::runtime_error( 711 throw std::runtime_error(
804 "JSON: offset " + QUtil::int_to_string(p - cstr) + 712 "JSON: offset " + QUtil::int_to_string(p - cstr) +
805 ": numeric literal: e already seen"); 713 ": numeric literal: e already seen");
806 - }  
807 - else  
808 - { 714 + } else {
809 number_saw_e = true; 715 number_saw_e = true;
810 } 716 }
811 - }  
812 - else if ((*p == '+') || (*p == '-'))  
813 - {  
814 - if (number_saw_e && (number_after_e == 0))  
815 - { 717 + } else if ((*p == '+') || (*p == '-')) {
  718 + if (number_saw_e && (number_after_e == 0)) {
816 // okay 719 // okay
817 - }  
818 - else  
819 - { 720 + } else {
820 QTC::TC("libtests", "JSON parse unexpected sign"); 721 QTC::TC("libtests", "JSON parse unexpected sign");
821 throw std::runtime_error( 722 throw std::runtime_error(
822 "JSON: offset " + QUtil::int_to_string(p - cstr) + 723 "JSON: offset " + QUtil::int_to_string(p - cstr) +
823 ": numeric literal: unexpected sign"); 724 ": numeric literal: unexpected sign");
824 } 725 }
825 - }  
826 - else if (QUtil::is_space(*p))  
827 - { 726 + } else if (QUtil::is_space(*p)) {
828 tok_end = p; 727 tok_end = p;
829 - }  
830 - else if (strchr("{}[]:,", *p))  
831 - { 728 + } else if (strchr("{}[]:,", *p)) {
832 tok_end = p; 729 tok_end = p;
833 --p; 730 --p;
834 - }  
835 - else  
836 - { 731 + } else {
837 QTC::TC("libtests", "JSON parse numeric bad character"); 732 QTC::TC("libtests", "JSON parse numeric bad character");
838 throw std::runtime_error( 733 throw std::runtime_error(
839 "JSON: offset " + QUtil::int_to_string(p - cstr) + 734 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -842,22 +737,15 @@ void JSONParser::getToken() @@ -842,22 +737,15 @@ void JSONParser::getToken()
842 } 737 }
843 break; 738 break;
844 739
845 - case ls_alpha:  
846 - if ((*p >= 'a') && (*p <= 'z'))  
847 - { 740 + case ls_alpha:
  741 + if ((*p >= 'a') && (*p <= 'z')) {
848 // okay 742 // okay
849 - }  
850 - else if (QUtil::is_space(*p))  
851 - { 743 + } else if (QUtil::is_space(*p)) {
852 tok_end = p; 744 tok_end = p;
853 - }  
854 - else if (strchr("{}[]:,", *p))  
855 - { 745 + } else if (strchr("{}[]:,", *p)) {
856 tok_end = p; 746 tok_end = p;
857 --p; 747 --p;
858 - }  
859 - else  
860 - { 748 + } else {
861 QTC::TC("libtests", "JSON parse keyword bad character"); 749 QTC::TC("libtests", "JSON parse keyword bad character");
862 throw std::runtime_error( 750 throw std::runtime_error(
863 "JSON: offset " + QUtil::int_to_string(p - cstr) + 751 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -865,36 +753,27 @@ void JSONParser::getToken() @@ -865,36 +753,27 @@ void JSONParser::getToken()
865 } 753 }
866 break; 754 break;
867 755
868 - case ls_string:  
869 - if (*p == '"')  
870 - { 756 + case ls_string:
  757 + if (*p == '"') {
871 tok_end = p + 1; 758 tok_end = p + 1;
872 - }  
873 - else if (*p == '\\')  
874 - { 759 + } else if (*p == '\\') {
875 lex_state = ls_backslash; 760 lex_state = ls_backslash;
876 } 761 }
877 break; 762 break;
878 763
879 - case ls_backslash: 764 + case ls_backslash:
880 /* cSpell: ignore bfnrt */ 765 /* cSpell: ignore bfnrt */
881 - if (strchr("\\\"/bfnrt", *p))  
882 - { 766 + if (strchr("\\\"/bfnrt", *p)) {
883 lex_state = ls_string; 767 lex_state = ls_string;
884 - }  
885 - else if (*p == 'u')  
886 - {  
887 - if (p + 4 >= end)  
888 - { 768 + } else if (*p == 'u') {
  769 + if (p + 4 >= end) {
889 QTC::TC("libtests", "JSON parse premature end of u"); 770 QTC::TC("libtests", "JSON parse premature end of u");
890 throw std::runtime_error( 771 throw std::runtime_error(
891 "JSON: offset " + QUtil::int_to_string(p - cstr) + 772 "JSON: offset " + QUtil::int_to_string(p - cstr) +
892 ": \\u must be followed by four characters"); 773 ": \\u must be followed by four characters");
893 } 774 }
894 - for (size_t i = 1; i <= 4; ++i)  
895 - {  
896 - if (! QUtil::is_hex_digit(p[i]))  
897 - { 775 + for (size_t i = 1; i <= 4; ++i) {
  776 + if (!QUtil::is_hex_digit(p[i])) {
898 QTC::TC("libtests", "JSON parse bad hex after u"); 777 QTC::TC("libtests", "JSON parse bad hex after u");
899 throw std::runtime_error( 778 throw std::runtime_error(
900 "JSON: offset " + QUtil::int_to_string(p - cstr) + 779 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -903,9 +782,7 @@ void JSONParser::getToken() @@ -903,9 +782,7 @@ void JSONParser::getToken()
903 } 782 }
904 p += 4; 783 p += 4;
905 lex_state = ls_string; 784 lex_state = ls_string;
906 - }  
907 - else  
908 - { 785 + } else {
909 QTC::TC("libtests", "JSON parse backslash bad character"); 786 QTC::TC("libtests", "JSON parse backslash bad character");
910 throw std::runtime_error( 787 throw std::runtime_error(
911 "JSON: offset " + QUtil::int_to_string(p - cstr) + 788 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -915,31 +792,27 @@ void JSONParser::getToken() @@ -915,31 +792,27 @@ void JSONParser::getToken()
915 break; 792 break;
916 } 793 }
917 ++p; 794 ++p;
918 - if (tok_start && tok_end)  
919 - { 795 + if (tok_start && tok_end) {
920 break; 796 break;
921 } 797 }
922 } 798 }
923 - if (p == end)  
924 - {  
925 - if (tok_start && (! tok_end))  
926 - {  
927 - switch (lex_state)  
928 - {  
929 - case ls_top: 799 + if (p == end) {
  800 + if (tok_start && (!tok_end)) {
  801 + switch (lex_state) {
  802 + case ls_top:
930 // Can't happen 803 // Can't happen
931 throw std::logic_error( 804 throw std::logic_error(
932 "tok_start set in ls_top while parsing " + 805 "tok_start set in ls_top while parsing " +
933 std::string(cstr)); 806 std::string(cstr));
934 break; 807 break;
935 808
936 - case ls_number:  
937 - case ls_alpha: 809 + case ls_number:
  810 + case ls_alpha:
938 tok_end = p; 811 tok_end = p;
939 break; 812 break;
940 813
941 - case ls_string:  
942 - case ls_backslash: 814 + case ls_string:
  815 + case ls_backslash:
943 QTC::TC("libtests", "JSON parse unterminated string"); 816 QTC::TC("libtests", "JSON parse unterminated string");
944 throw std::runtime_error( 817 throw std::runtime_error(
945 "JSON: offset " + QUtil::int_to_string(p - cstr) + 818 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -953,16 +826,14 @@ void JSONParser::getToken() @@ -953,16 +826,14 @@ void JSONParser::getToken()
953 void 826 void
954 JSONParser::handleToken() 827 JSONParser::handleToken()
955 { 828 {
956 - if (! (tok_start && tok_end))  
957 - { 829 + if (!(tok_start && tok_end)) {
958 return; 830 return;
959 } 831 }
960 832
961 // Get token value. 833 // Get token value.
962 std::string value(tok_start, tok_end); 834 std::string value(tok_start, tok_end);
963 835
964 - if (parser_state == ps_done)  
965 - { 836 + if (parser_state == ps_done) {
966 QTC::TC("libtests", "JSON parse junk after object"); 837 QTC::TC("libtests", "JSON parse junk after object");
967 throw std::runtime_error( 838 throw std::runtime_error(
968 "JSON: offset " + QUtil::int_to_string(p - cstr) + 839 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -971,11 +842,9 @@ JSONParser::handleToken() @@ -971,11 +842,9 @@ JSONParser::handleToken()
971 842
972 // Git string value 843 // Git string value
973 std::string s_value; 844 std::string s_value;
974 - if (lex_state == ls_string)  
975 - { 845 + if (lex_state == ls_string) {
976 // Token includes the quotation marks 846 // Token includes the quotation marks
977 - if (tok_end - tok_start < 2)  
978 - { 847 + if (tok_end - tok_start < 2) {
979 throw std::logic_error("JSON string length < 2"); 848 throw std::logic_error("JSON string length < 2");
980 } 849 }
981 s_value = decode_string(value); 850 s_value = decode_string(value);
@@ -986,28 +855,25 @@ JSONParser::handleToken() @@ -986,28 +855,25 @@ JSONParser::handleToken()
986 855
987 std::shared_ptr<JSON> item; 856 std::shared_ptr<JSON> item;
988 char delimiter = '\0'; 857 char delimiter = '\0';
989 - switch (lex_state)  
990 - {  
991 - case ls_top:  
992 - switch (*tok_start)  
993 - {  
994 - case '{': 858 + switch (lex_state) {
  859 + case ls_top:
  860 + switch (*tok_start) {
  861 + case '{':
995 item = std::make_shared<JSON>(JSON::makeDictionary()); 862 item = std::make_shared<JSON>(JSON::makeDictionary());
996 break; 863 break;
997 864
998 - case '[': 865 + case '[':
999 item = std::make_shared<JSON>(JSON::makeArray()); 866 item = std::make_shared<JSON>(JSON::makeArray());
1000 break; 867 break;
1001 868
1002 - default: 869 + default:
1003 delimiter = *tok_start; 870 delimiter = *tok_start;
1004 break; 871 break;
1005 } 872 }
1006 break; 873 break;
1007 874
1008 - case ls_number:  
1009 - if (number_saw_point && (number_after_point == 0))  
1010 - { 875 + case ls_number:
  876 + if (number_saw_point && (number_after_point == 0)) {
1011 QTC::TC("libtests", "JSON parse decimal with no digits"); 877 QTC::TC("libtests", "JSON parse decimal with no digits");
1012 throw std::runtime_error( 878 throw std::runtime_error(
1013 "JSON: offset " + QUtil::int_to_string(p - cstr) + 879 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -1015,15 +881,13 @@ JSONParser::handleToken() @@ -1015,15 +881,13 @@ JSONParser::handleToken()
1015 } 881 }
1016 if ((number_before_point > 1) && 882 if ((number_before_point > 1) &&
1017 ((tok_start[0] == '0') || 883 ((tok_start[0] == '0') ||
1018 - ((tok_start[0] == '-') && (tok_start[1] == '0'))))  
1019 - { 884 + ((tok_start[0] == '-') && (tok_start[1] == '0')))) {
1020 QTC::TC("libtests", "JSON parse leading zero"); 885 QTC::TC("libtests", "JSON parse leading zero");
1021 throw std::runtime_error( 886 throw std::runtime_error(
1022 "JSON: offset " + QUtil::int_to_string(p - cstr) + 887 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1023 ": number with leading zero"); 888 ": number with leading zero");
1024 } 889 }
1025 - if ((number_before_point == 0) && (number_after_point == 0))  
1026 - { 890 + if ((number_before_point == 0) && (number_after_point == 0)) {
1027 QTC::TC("libtests", "JSON parse number no digits"); 891 QTC::TC("libtests", "JSON parse number no digits");
1028 throw std::runtime_error( 892 throw std::runtime_error(
1029 "JSON: offset " + QUtil::int_to_string(p - cstr) + 893 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -1032,21 +896,14 @@ JSONParser::handleToken() @@ -1032,21 +896,14 @@ JSONParser::handleToken()
1032 item = std::make_shared<JSON>(JSON::makeNumber(value)); 896 item = std::make_shared<JSON>(JSON::makeNumber(value));
1033 break; 897 break;
1034 898
1035 - case ls_alpha:  
1036 - if (value == "true")  
1037 - { 899 + case ls_alpha:
  900 + if (value == "true") {
1038 item = std::make_shared<JSON>(JSON::makeBool(true)); 901 item = std::make_shared<JSON>(JSON::makeBool(true));
1039 - }  
1040 - else if (value == "false")  
1041 - { 902 + } else if (value == "false") {
1042 item = std::make_shared<JSON>(JSON::makeBool(false)); 903 item = std::make_shared<JSON>(JSON::makeBool(false));
1043 - }  
1044 - else if (value == "null")  
1045 - { 904 + } else if (value == "null") {
1046 item = std::make_shared<JSON>(JSON::makeNull()); 905 item = std::make_shared<JSON>(JSON::makeNull());
1047 - }  
1048 - else  
1049 - { 906 + } else {
1050 QTC::TC("libtests", "JSON parse invalid keyword"); 907 QTC::TC("libtests", "JSON parse invalid keyword");
1051 throw std::runtime_error( 908 throw std::runtime_error(
1052 "JSON: offset " + QUtil::int_to_string(p - cstr) + 909 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -1054,18 +911,16 @@ JSONParser::handleToken() @@ -1054,18 +911,16 @@ JSONParser::handleToken()
1054 } 911 }
1055 break; 912 break;
1056 913
1057 - case ls_string: 914 + case ls_string:
1058 item = std::make_shared<JSON>(JSON::makeString(s_value)); 915 item = std::make_shared<JSON>(JSON::makeString(s_value));
1059 break; 916 break;
1060 917
1061 - case ls_backslash:  
1062 - throw std::logic_error(  
1063 - "tok_end is set while state = ls_backslash"); 918 + case ls_backslash:
  919 + throw std::logic_error("tok_end is set while state = ls_backslash");
1064 break; 920 break;
1065 } 921 }
1066 922
1067 - if ((item.get() == nullptr) == (delimiter == '\0'))  
1068 - { 923 + if ((item.get() == nullptr) == (delimiter == '\0')) {
1069 throw std::logic_error( 924 throw std::logic_error(
1070 "JSONParser::handleToken: logic error: exactly one of item" 925 "JSONParser::handleToken: logic error: exactly one of item"
1071 " or delimiter must be set"); 926 " or delimiter must be set");
@@ -1073,39 +928,36 @@ JSONParser::handleToken() @@ -1073,39 +928,36 @@ JSONParser::handleToken()
1073 928
1074 // See whether what we have is allowed at this point. 929 // See whether what we have is allowed at this point.
1075 930
1076 - if (item.get())  
1077 - {  
1078 - switch (parser_state)  
1079 - {  
1080 - case ps_done: 931 + if (item.get()) {
  932 + switch (parser_state) {
  933 + case ps_done:
1081 throw std::logic_error("can't happen; ps_done already handled"); 934 throw std::logic_error("can't happen; ps_done already handled");
1082 break; 935 break;
1083 936
1084 - case ps_dict_after_key: 937 + case ps_dict_after_key:
1085 QTC::TC("libtests", "JSON parse expected colon"); 938 QTC::TC("libtests", "JSON parse expected colon");
1086 throw std::runtime_error( 939 throw std::runtime_error(
1087 "JSON: offset " + QUtil::int_to_string(p - cstr) + 940 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1088 ": expected ':'"); 941 ": expected ':'");
1089 break; 942 break;
1090 943
1091 - case ps_dict_after_item: 944 + case ps_dict_after_item:
1092 QTC::TC("libtests", "JSON parse expected , or }"); 945 QTC::TC("libtests", "JSON parse expected , or }");
1093 throw std::runtime_error( 946 throw std::runtime_error(
1094 "JSON: offset " + QUtil::int_to_string(p - cstr) + 947 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1095 ": expected ',' or '}'"); 948 ": expected ',' or '}'");
1096 break; 949 break;
1097 950
1098 - case ps_array_after_item: 951 + case ps_array_after_item:
1099 QTC::TC("libtests", "JSON parse expected, or ]"); 952 QTC::TC("libtests", "JSON parse expected, or ]");
1100 throw std::runtime_error( 953 throw std::runtime_error(
1101 "JSON: offset " + QUtil::int_to_string(p - cstr) + 954 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1102 ": expected ',' or ']'"); 955 ": expected ',' or ']'");
1103 break; 956 break;
1104 957
1105 - case ps_dict_begin:  
1106 - case ps_dict_after_comma:  
1107 - if (lex_state != ls_string)  
1108 - { 958 + case ps_dict_begin:
  959 + case ps_dict_after_comma:
  960 + if (lex_state != ls_string) {
1109 QTC::TC("libtests", "JSON parse string as dict key"); 961 QTC::TC("libtests", "JSON parse string as dict key");
1110 throw std::runtime_error( 962 throw std::runtime_error(
1111 "JSON: offset " + QUtil::int_to_string(p - cstr) + 963 "JSON: offset " + QUtil::int_to_string(p - cstr) +
@@ -1113,18 +965,16 @@ JSONParser::handleToken() @@ -1113,18 +965,16 @@ JSONParser::handleToken()
1113 } 965 }
1114 break; 966 break;
1115 967
1116 - case ps_top:  
1117 - case ps_dict_after_colon:  
1118 - case ps_array_begin:  
1119 - case ps_array_after_comma: 968 + case ps_top:
  969 + case ps_dict_after_colon:
  970 + case ps_array_begin:
  971 + case ps_array_after_comma:
1120 break; 972 break;
1121 // okay 973 // okay
1122 } 974 }
1123 - }  
1124 - else if (delimiter == '}')  
1125 - {  
1126 - if (! ((parser_state == ps_dict_begin) ||  
1127 - (parser_state == ps_dict_after_item))) 975 + } else if (delimiter == '}') {
  976 + if (!((parser_state == ps_dict_begin) ||
  977 + (parser_state == ps_dict_after_item)))
1128 978
1129 { 979 {
1130 QTC::TC("libtests", "JSON parse unexpected }"); 980 QTC::TC("libtests", "JSON parse unexpected }");
@@ -1132,11 +982,9 @@ JSONParser::handleToken() @@ -1132,11 +982,9 @@ JSONParser::handleToken()
1132 "JSON: offset " + QUtil::int_to_string(p - cstr) + 982 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1133 ": unexpected dictionary end delimiter"); 983 ": unexpected dictionary end delimiter");
1134 } 984 }
1135 - }  
1136 - else if (delimiter == ']')  
1137 - {  
1138 - if (! ((parser_state == ps_array_begin) ||  
1139 - (parser_state == ps_array_after_item))) 985 + } else if (delimiter == ']') {
  986 + if (!((parser_state == ps_array_begin) ||
  987 + (parser_state == ps_array_after_item)))
1140 988
1141 { 989 {
1142 QTC::TC("libtests", "JSON parse unexpected ]"); 990 QTC::TC("libtests", "JSON parse unexpected ]");
@@ -1144,30 +992,22 @@ JSONParser::handleToken() @@ -1144,30 +992,22 @@ JSONParser::handleToken()
1144 "JSON: offset " + QUtil::int_to_string(p - cstr) + 992 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1145 ": unexpected array end delimiter"); 993 ": unexpected array end delimiter");
1146 } 994 }
1147 - }  
1148 - else if (delimiter == ':')  
1149 - {  
1150 - if (parser_state != ps_dict_after_key)  
1151 - { 995 + } else if (delimiter == ':') {
  996 + if (parser_state != ps_dict_after_key) {
1152 QTC::TC("libtests", "JSON parse unexpected :"); 997 QTC::TC("libtests", "JSON parse unexpected :");
1153 throw std::runtime_error( 998 throw std::runtime_error(
1154 "JSON: offset " + QUtil::int_to_string(p - cstr) + 999 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1155 ": unexpected colon"); 1000 ": unexpected colon");
1156 } 1001 }
1157 - }  
1158 - else if (delimiter == ',')  
1159 - {  
1160 - if (! ((parser_state == ps_dict_after_item) ||  
1161 - (parser_state == ps_array_after_item)))  
1162 - { 1002 + } else if (delimiter == ',') {
  1003 + if (!((parser_state == ps_dict_after_item) ||
  1004 + (parser_state == ps_array_after_item))) {
1163 QTC::TC("libtests", "JSON parse unexpected ,"); 1005 QTC::TC("libtests", "JSON parse unexpected ,");
1164 throw std::runtime_error( 1006 throw std::runtime_error(
1165 "JSON: offset " + QUtil::int_to_string(p - cstr) + 1007 "JSON: offset " + QUtil::int_to_string(p - cstr) +
1166 ": unexpected comma"); 1008 ": unexpected comma");
1167 } 1009 }
1168 - }  
1169 - else if (delimiter != '\0')  
1170 - { 1010 + } else if (delimiter != '\0') {
1171 throw std::logic_error("JSONParser::handleToken: bad delimiter"); 1011 throw std::logic_error("JSONParser::handleToken: bad delimiter");
1172 } 1012 }
1173 1013
@@ -1175,103 +1015,77 @@ JSONParser::handleToken() @@ -1175,103 +1015,77 @@ JSONParser::handleToken()
1175 // whatever we need to do with it. 1015 // whatever we need to do with it.
1176 1016
1177 parser_state_e next_state = ps_top; 1017 parser_state_e next_state = ps_top;
1178 - if (delimiter == ':')  
1179 - { 1018 + if (delimiter == ':') {
1180 next_state = ps_dict_after_colon; 1019 next_state = ps_dict_after_colon;
1181 - }  
1182 - else if (delimiter == ',')  
1183 - {  
1184 - if (parser_state == ps_dict_after_item)  
1185 - { 1020 + } else if (delimiter == ',') {
  1021 + if (parser_state == ps_dict_after_item) {
1186 next_state = ps_dict_after_comma; 1022 next_state = ps_dict_after_comma;
1187 - }  
1188 - else if (parser_state == ps_array_after_item)  
1189 - { 1023 + } else if (parser_state == ps_array_after_item) {
1190 next_state = ps_array_after_comma; 1024 next_state = ps_array_after_comma;
  1025 + } else {
  1026 + throw std::logic_error("JSONParser::handleToken: unexpected parser"
  1027 + " state for comma");
1191 } 1028 }
1192 - else  
1193 - {  
1194 - throw std::logic_error(  
1195 - "JSONParser::handleToken: unexpected parser"  
1196 - " state for comma");  
1197 - }  
1198 - }  
1199 - else if ((delimiter == '}') || (delimiter == ']'))  
1200 - { 1029 + } else if ((delimiter == '}') || (delimiter == ']')) {
1201 next_state = ps_stack.back(); 1030 next_state = ps_stack.back();
1202 ps_stack.pop_back(); 1031 ps_stack.pop_back();
1203 - if (next_state != ps_done)  
1204 - { 1032 + if (next_state != ps_done) {
1205 stack.pop_back(); 1033 stack.pop_back();
1206 } 1034 }
1207 - }  
1208 - else if (delimiter != '\0')  
1209 - { 1035 + } else if (delimiter != '\0') {
1210 throw std::logic_error( 1036 throw std::logic_error(
1211 "JSONParser::handleToken: unexpected delimiter in transition"); 1037 "JSONParser::handleToken: unexpected delimiter in transition");
1212 - }  
1213 - else if (item.get())  
1214 - { 1038 + } else if (item.get()) {
1215 std::shared_ptr<JSON> tos; 1039 std::shared_ptr<JSON> tos;
1216 - if (! stack.empty())  
1217 - { 1040 + if (!stack.empty()) {
1218 tos = stack.back(); 1041 tos = stack.back();
1219 } 1042 }
1220 - switch (parser_state)  
1221 - {  
1222 - case ps_dict_begin:  
1223 - case ps_dict_after_comma: 1043 + switch (parser_state) {
  1044 + case ps_dict_begin:
  1045 + case ps_dict_after_comma:
1224 this->dict_key = s_value; 1046 this->dict_key = s_value;
1225 item = nullptr; 1047 item = nullptr;
1226 next_state = ps_dict_after_key; 1048 next_state = ps_dict_after_key;
1227 break; 1049 break;
1228 1050
1229 - case ps_dict_after_colon: 1051 + case ps_dict_after_colon:
1230 tos->addDictionaryMember(dict_key, *item); 1052 tos->addDictionaryMember(dict_key, *item);
1231 next_state = ps_dict_after_item; 1053 next_state = ps_dict_after_item;
1232 break; 1054 break;
1233 1055
1234 - case ps_array_begin:  
1235 - case ps_array_after_comma: 1056 + case ps_array_begin:
  1057 + case ps_array_after_comma:
1236 next_state = ps_array_after_item; 1058 next_state = ps_array_after_item;
1237 tos->addArrayElement(*item); 1059 tos->addArrayElement(*item);
1238 break; 1060 break;
1239 1061
1240 - case ps_top: 1062 + case ps_top:
1241 next_state = ps_done; 1063 next_state = ps_done;
1242 break; 1064 break;
1243 1065
1244 - case ps_dict_after_key:  
1245 - case ps_dict_after_item:  
1246 - case ps_array_after_item:  
1247 - case ps_done: 1066 + case ps_dict_after_key:
  1067 + case ps_dict_after_item:
  1068 + case ps_array_after_item:
  1069 + case ps_done:
1248 throw std::logic_error( 1070 throw std::logic_error(
1249 "JSONParser::handleToken: unexpected parser state"); 1071 "JSONParser::handleToken: unexpected parser state");
1250 } 1072 }
1251 - }  
1252 - else  
1253 - { 1073 + } else {
1254 throw std::logic_error( 1074 throw std::logic_error(
1255 "JSONParser::handleToken: unexpected null item in transition"); 1075 "JSONParser::handleToken: unexpected null item in transition");
1256 } 1076 }
1257 1077
1258 // Prepare for next token 1078 // Prepare for next token
1259 - if (item.get())  
1260 - {  
1261 - if (item->isDictionary())  
1262 - { 1079 + if (item.get()) {
  1080 + if (item->isDictionary()) {
1263 stack.push_back(item); 1081 stack.push_back(item);
1264 ps_stack.push_back(next_state); 1082 ps_stack.push_back(next_state);
1265 next_state = ps_dict_begin; 1083 next_state = ps_dict_begin;
1266 - }  
1267 - else if (item->isArray())  
1268 - { 1084 + } else if (item->isArray()) {
1269 stack.push_back(item); 1085 stack.push_back(item);
1270 ps_stack.push_back(next_state); 1086 ps_stack.push_back(next_state);
1271 next_state = ps_array_begin; 1087 next_state = ps_array_begin;
1272 - }  
1273 - else if (parser_state == ps_top)  
1274 - { 1088 + } else if (parser_state == ps_top) {
1275 stack.push_back(item); 1089 stack.push_back(item);
1276 } 1090 }
1277 } 1091 }
@@ -1288,13 +1102,11 @@ JSONParser::parse(std::string const&amp; s) @@ -1288,13 +1102,11 @@ JSONParser::parse(std::string const&amp; s)
1288 end = cstr + s.length(); 1102 end = cstr + s.length();
1289 p = cstr; 1103 p = cstr;
1290 1104
1291 - while (p < end)  
1292 - { 1105 + while (p < end) {
1293 getToken(); 1106 getToken();
1294 handleToken(); 1107 handleToken();
1295 } 1108 }
1296 - if (parser_state != ps_done)  
1297 - { 1109 + if (parser_state != ps_done) {
1298 QTC::TC("libtests", "JSON parse premature EOF"); 1110 QTC::TC("libtests", "JSON parse premature EOF");
1299 throw std::runtime_error("JSON: premature end of input"); 1111 throw std::runtime_error("JSON: premature end of input");
1300 } 1112 }
libqpdf/JSONHandler.cc
1 #include <qpdf/JSONHandler.hh> 1 #include <qpdf/JSONHandler.hh>
2 2
3 -#include <qpdf/QUtil.hh>  
4 -#include <qpdf/QTC.hh>  
5 #include <qpdf/QPDFUsage.hh> 3 #include <qpdf/QPDFUsage.hh>
  4 +#include <qpdf/QTC.hh>
  5 +#include <qpdf/QUtil.hh>
6 6
7 JSONHandler::JSONHandler() : 7 JSONHandler::JSONHandler() :
8 m(new Members()) 8 m(new Members())
@@ -70,9 +70,10 @@ JSONHandler::addFallbackDictHandler(std::shared_ptr&lt;JSONHandler&gt; fdh) @@ -70,9 +70,10 @@ JSONHandler::addFallbackDictHandler(std::shared_ptr&lt;JSONHandler&gt; fdh)
70 } 70 }
71 71
72 void 72 void
73 -JSONHandler::addArrayHandlers(json_handler_t start_fn,  
74 - void_handler_t end_fn,  
75 - std::shared_ptr<JSONHandler> ah) 73 +JSONHandler::addArrayHandlers(
  74 + json_handler_t start_fn,
  75 + void_handler_t end_fn,
  76 + std::shared_ptr<JSONHandler> ah)
76 { 77 {
77 this->m->h.array_start_handler = start_fn; 78 this->m->h.array_start_handler = start_fn;
78 this->m->h.array_end_handler = end_fn; 79 this->m->h.array_end_handler = end_fn;
@@ -82,69 +83,55 @@ JSONHandler::addArrayHandlers(json_handler_t start_fn, @@ -82,69 +83,55 @@ JSONHandler::addArrayHandlers(json_handler_t start_fn,
82 void 83 void
83 JSONHandler::handle(std::string const& path, JSON j) 84 JSONHandler::handle(std::string const& path, JSON j)
84 { 85 {
85 - if (this->m->h.any_handler)  
86 - { 86 + if (this->m->h.any_handler) {
87 this->m->h.any_handler(path, j); 87 this->m->h.any_handler(path, j);
88 return; 88 return;
89 } 89 }
90 bool handled = false; 90 bool handled = false;
91 bool bvalue = false; 91 bool bvalue = false;
92 std::string s_value; 92 std::string s_value;
93 - if (this->m->h.null_handler && j.isNull())  
94 - { 93 + if (this->m->h.null_handler && j.isNull()) {
95 this->m->h.null_handler(path); 94 this->m->h.null_handler(path);
96 handled = true; 95 handled = true;
97 } 96 }
98 - if (this->m->h.string_handler && j.getString(s_value))  
99 - { 97 + if (this->m->h.string_handler && j.getString(s_value)) {
100 this->m->h.string_handler(path, s_value); 98 this->m->h.string_handler(path, s_value);
101 handled = true; 99 handled = true;
102 } 100 }
103 - if (this->m->h.number_handler && j.getNumber(s_value))  
104 - { 101 + if (this->m->h.number_handler && j.getNumber(s_value)) {
105 this->m->h.number_handler(path, s_value); 102 this->m->h.number_handler(path, s_value);
106 handled = true; 103 handled = true;
107 } 104 }
108 - if (this->m->h.bool_handler && j.getBool(bvalue))  
109 - { 105 + if (this->m->h.bool_handler && j.getBool(bvalue)) {
110 this->m->h.bool_handler(path, bvalue); 106 this->m->h.bool_handler(path, bvalue);
111 handled = true; 107 handled = true;
112 } 108 }
113 - if (this->m->h.dict_start_handler && j.isDictionary())  
114 - { 109 + if (this->m->h.dict_start_handler && j.isDictionary()) {
115 this->m->h.dict_start_handler(path, j); 110 this->m->h.dict_start_handler(path, j);
116 std::string path_base = path; 111 std::string path_base = path;
117 - if (path_base != ".")  
118 - { 112 + if (path_base != ".") {
119 path_base += "."; 113 path_base += ".";
120 } 114 }
121 j.forEachDictItem([&path, &path_base, this]( 115 j.forEachDictItem([&path, &path_base, this](
122 std::string const& k, JSON v) { 116 std::string const& k, JSON v) {
123 auto i = this->m->h.dict_handlers.find(k); 117 auto i = this->m->h.dict_handlers.find(k);
124 - if (i == this->m->h.dict_handlers.end())  
125 - {  
126 - if (this->m->h.fallback_dict_handler.get())  
127 - {  
128 - this->m->h.fallback_dict_handler->handle(  
129 - path_base + k, v);  
130 - }  
131 - else  
132 - { 118 + if (i == this->m->h.dict_handlers.end()) {
  119 + if (this->m->h.fallback_dict_handler.get()) {
  120 + this->m->h.fallback_dict_handler->handle(path_base + k, v);
  121 + } else {
133 QTC::TC("libtests", "JSONHandler unexpected key"); 122 QTC::TC("libtests", "JSONHandler unexpected key");
134 - usage("JSON handler found unexpected key " + k +  
135 - " in object at " + path); 123 + usage(
  124 + "JSON handler found unexpected key " + k +
  125 + " in object at " + path);
136 } 126 }
137 - }  
138 - else  
139 - { 127 + } else {
140 i->second->handle(path_base + k, v); 128 i->second->handle(path_base + k, v);
141 } 129 }
142 }); 130 });
143 this->m->h.dict_end_handler(path); 131 this->m->h.dict_end_handler(path);
144 handled = true; 132 handled = true;
145 } 133 }
146 - if (this->m->h.array_start_handler && j.isArray())  
147 - { 134 + if (this->m->h.array_start_handler && j.isArray()) {
148 this->m->h.array_start_handler(path, j); 135 this->m->h.array_start_handler(path, j);
149 size_t i = 0; 136 size_t i = 0;
150 j.forEachArrayItem([&i, &path, this](JSON v) { 137 j.forEachArrayItem([&i, &path, this](JSON v) {
@@ -156,8 +143,7 @@ JSONHandler::handle(std::string const&amp; path, JSON j) @@ -156,8 +143,7 @@ JSONHandler::handle(std::string const&amp; path, JSON j)
156 handled = true; 143 handled = true;
157 } 144 }
158 145
159 - if (! handled)  
160 - { 146 + if (!handled) {
161 // It would be nice to include information about what type the 147 // It would be nice to include information about what type the
162 // object was and what types were allowed, but we're relying 148 // object was and what types were allowed, but we're relying
163 // on schema validation to make sure input is properly 149 // on schema validation to make sure input is properly
libqpdf/MD5.cc
1 #include <qpdf/MD5.hh> 1 #include <qpdf/MD5.hh>
2 2
3 -#include <qpdf/QUtil.hh>  
4 #include <qpdf/QIntC.hh> 3 #include <qpdf/QIntC.hh>
5 #include <qpdf/QPDFCryptoProvider.hh> 4 #include <qpdf/QPDFCryptoProvider.hh>
  5 +#include <qpdf/QUtil.hh>
6 6
7 -#include <stdio.h> 7 +#include <errno.h>
8 #include <memory.h> 8 #include <memory.h>
  9 +#include <stdio.h>
9 #include <stdlib.h> 10 #include <stdlib.h>
10 #include <string.h> 11 #include <string.h>
11 -#include <errno.h>  
12 12
13 MD5::MD5() 13 MD5::MD5()
14 { 14 {
@@ -28,12 +28,14 @@ MD5::finalize() @@ -28,12 +28,14 @@ MD5::finalize()
28 this->crypto->MD5_finalize(); 28 this->crypto->MD5_finalize();
29 } 29 }
30 30
31 -void MD5::reset() 31 +void
  32 +MD5::reset()
32 { 33 {
33 init(); 34 init();
34 } 35 }
35 36
36 -void MD5::encodeString(char const* str) 37 +void
  38 +MD5::encodeString(char const* str)
37 { 39 {
38 size_t len = strlen(str); 40 size_t len = strlen(str);
39 crypto->MD5_init(); 41 crypto->MD5_init();
@@ -41,79 +43,78 @@ void MD5::encodeString(char const* str) @@ -41,79 +43,78 @@ void MD5::encodeString(char const* str)
41 crypto->MD5_finalize(); 43 crypto->MD5_finalize();
42 } 44 }
43 45
44 -void MD5::appendString(char const* input_string) 46 +void
  47 +MD5::appendString(char const* input_string)
45 { 48 {
46 encodeDataIncrementally(input_string, strlen(input_string)); 49 encodeDataIncrementally(input_string, strlen(input_string));
47 } 50 }
48 51
49 -void MD5::encodeDataIncrementally(char const* data, size_t len) 52 +void
  53 +MD5::encodeDataIncrementally(char const* data, size_t len)
50 { 54 {
51 this->crypto->MD5_update(QUtil::unsigned_char_pointer(data), len); 55 this->crypto->MD5_update(QUtil::unsigned_char_pointer(data), len);
52 } 56 }
53 57
54 -void MD5::encodeFile(char const *filename, qpdf_offset_t up_to_offset) 58 +void
  59 +MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset)
55 { 60 {
56 char buffer[1024]; 61 char buffer[1024];
57 62
58 - FILE *file = QUtil::safe_fopen(filename, "rb"); 63 + FILE* file = QUtil::safe_fopen(filename, "rb");
59 size_t len; 64 size_t len;
60 size_t so_far = 0; 65 size_t so_far = 0;
61 size_t to_try = 1024; 66 size_t to_try = 1024;
62 size_t up_to_size = 0; 67 size_t up_to_size = 0;
63 - if (up_to_offset >= 0)  
64 - { 68 + if (up_to_offset >= 0) {
65 up_to_size = QIntC::to_size(up_to_offset); 69 up_to_size = QIntC::to_size(up_to_offset);
66 } 70 }
67 - do  
68 - {  
69 - if ((up_to_offset >= 0) && ((so_far + to_try) > up_to_size))  
70 - { 71 + do {
  72 + if ((up_to_offset >= 0) && ((so_far + to_try) > up_to_size)) {
71 to_try = up_to_size - so_far; 73 to_try = up_to_size - so_far;
72 } 74 }
73 len = fread(buffer, 1, to_try, file); 75 len = fread(buffer, 1, to_try, file);
74 - if (len > 0)  
75 - { 76 + if (len > 0) {
76 encodeDataIncrementally(buffer, len); 77 encodeDataIncrementally(buffer, len);
77 so_far += len; 78 so_far += len;
78 - if ((up_to_offset >= 0) && (so_far >= up_to_size))  
79 - { 79 + if ((up_to_offset >= 0) && (so_far >= up_to_size)) {
80 break; 80 break;
81 } 81 }
82 } 82 }
83 } while (len > 0); 83 } while (len > 0);
84 - if (ferror(file))  
85 - { 84 + if (ferror(file)) {
86 // Assume, perhaps incorrectly, that errno was set by the 85 // Assume, perhaps incorrectly, that errno was set by the
87 // underlying call to read.... 86 // underlying call to read....
88 - (void) fclose(file); 87 + (void)fclose(file);
89 QUtil::throw_system_error( 88 QUtil::throw_system_error(
90 std::string("MD5: read error on ") + filename); 89 std::string("MD5: read error on ") + filename);
91 } 90 }
92 - (void) fclose(file); 91 + (void)fclose(file);
93 92
94 this->crypto->MD5_finalize(); 93 this->crypto->MD5_finalize();
95 } 94 }
96 95
97 -void MD5::digest(Digest result) 96 +void
  97 +MD5::digest(Digest result)
98 { 98 {
99 this->crypto->MD5_finalize(); 99 this->crypto->MD5_finalize();
100 this->crypto->MD5_digest(result); 100 this->crypto->MD5_digest(result);
101 } 101 }
102 102
103 -void MD5::print() 103 +void
  104 +MD5::print()
104 { 105 {
105 Digest digest_val; 106 Digest digest_val;
106 digest(digest_val); 107 digest(digest_val);
107 108
108 unsigned int i; 109 unsigned int i;
109 - for (i = 0; i < 16; ++i)  
110 - { 110 + for (i = 0; i < 16; ++i) {
111 printf("%02x", digest_val[i]); 111 printf("%02x", digest_val[i]);
112 } 112 }
113 printf("\n"); 113 printf("\n");
114 } 114 }
115 115
116 -std::string MD5::unparse() 116 +std::string
  117 +MD5::unparse()
117 { 118 {
118 this->crypto->MD5_finalize(); 119 this->crypto->MD5_finalize();
119 Digest digest_val; 120 Digest digest_val;
@@ -139,25 +140,23 @@ MD5::getFileChecksum(char const* filename, qpdf_offset_t up_to_offset) @@ -139,25 +140,23 @@ MD5::getFileChecksum(char const* filename, qpdf_offset_t up_to_offset)
139 } 140 }
140 141
141 bool 142 bool
142 -MD5::checkDataChecksum(char const* const checksum,  
143 - char const* buf, size_t len) 143 +MD5::checkDataChecksum(char const* const checksum, char const* buf, size_t len)
144 { 144 {
145 std::string actual_checksum = getDataChecksum(buf, len); 145 std::string actual_checksum = getDataChecksum(buf, len);
146 return (checksum == actual_checksum); 146 return (checksum == actual_checksum);
147 } 147 }
148 148
149 bool 149 bool
150 -MD5::checkFileChecksum(char const* const checksum,  
151 - char const* filename, qpdf_offset_t up_to_offset) 150 +MD5::checkFileChecksum(
  151 + char const* const checksum,
  152 + char const* filename,
  153 + qpdf_offset_t up_to_offset)
152 { 154 {
153 bool result = false; 155 bool result = false;
154 - try  
155 - { 156 + try {
156 std::string actual_checksum = getFileChecksum(filename, up_to_offset); 157 std::string actual_checksum = getFileChecksum(filename, up_to_offset);
157 result = (checksum == actual_checksum); 158 result = (checksum == actual_checksum);
158 - }  
159 - catch (std::runtime_error const&)  
160 - { 159 + } catch (std::runtime_error const&) {
161 // Ignore -- return false 160 // Ignore -- return false
162 } 161 }
163 return result; 162 return result;
libqpdf/NNTree.cc
@@ -9,8 +9,7 @@ static std::string @@ -9,8 +9,7 @@ static std::string
9 get_description(QPDFObjectHandle& node) 9 get_description(QPDFObjectHandle& node)
10 { 10 {
11 std::string result("Name/Number tree node"); 11 std::string result("Name/Number tree node");
12 - if (node.isIndirect())  
13 - { 12 + if (node.isIndirect()) {
14 result += " (object " + QUtil::int_to_string(node.getObjectID()) + ")"; 13 result += " (object " + QUtil::int_to_string(node.getObjectID()) + ")";
15 } 14 }
16 return result; 15 return result;
@@ -21,11 +20,13 @@ warn(QPDF* qpdf, QPDFObjectHandle&amp; node, std::string const&amp; msg) @@ -21,11 +20,13 @@ warn(QPDF* qpdf, QPDFObjectHandle&amp; node, std::string const&amp; msg)
21 { 20 {
22 // ABI: in qpdf 11, change to a reference. 21 // ABI: in qpdf 11, change to a reference.
23 22
24 - if (qpdf)  
25 - { 23 + if (qpdf) {
26 qpdf->warn(QPDFExc( 24 qpdf->warn(QPDFExc(
27 - qpdf_e_damaged_pdf,  
28 - qpdf->getFilename(), get_description(node), 0, msg)); 25 + qpdf_e_damaged_pdf,
  26 + qpdf->getFilename(),
  27 + get_description(node),
  28 + 0,
  29 + msg));
29 } 30 }
30 } 31 }
31 32
@@ -34,13 +35,14 @@ error(QPDF* qpdf, QPDFObjectHandle&amp; node, std::string const&amp; msg) @@ -34,13 +35,14 @@ error(QPDF* qpdf, QPDFObjectHandle&amp; node, std::string const&amp; msg)
34 { 35 {
35 // ABI: in qpdf 11, change to a reference. 36 // ABI: in qpdf 11, change to a reference.
36 37
37 - if (qpdf)  
38 - {  
39 - throw QPDFExc(qpdf_e_damaged_pdf,  
40 - qpdf->getFilename(), get_description(node), 0, msg);  
41 - }  
42 - else  
43 - { 38 + if (qpdf) {
  39 + throw QPDFExc(
  40 + qpdf_e_damaged_pdf,
  41 + qpdf->getFilename(),
  42 + get_description(node),
  43 + 0,
  44 + msg);
  45 + } else {
44 throw std::runtime_error(get_description(node) + ": " + msg); 46 throw std::runtime_error(get_description(node) + ": " + msg);
45 } 47 }
46 } 48 }
@@ -73,29 +75,21 @@ NNTreeIterator::updateIValue(bool allow_invalid) @@ -73,29 +75,21 @@ NNTreeIterator::updateIValue(bool allow_invalid)
73 // measure, we also call updateIValue in operator* and operator->. 75 // measure, we also call updateIValue in operator* and operator->.
74 76
75 bool okay = false; 77 bool okay = false;
76 - if ((item_number >= 0) &&  
77 - this->node.isInitialized() &&  
78 - this->node.isDictionary())  
79 - { 78 + if ((item_number >= 0) && this->node.isInitialized() &&
  79 + this->node.isDictionary()) {
80 auto items = this->node.getKey(impl.details.itemsKey()); 80 auto items = this->node.getKey(impl.details.itemsKey());
81 - if (this->item_number + 1 < items.getArrayNItems())  
82 - { 81 + if (this->item_number + 1 < items.getArrayNItems()) {
83 okay = true; 82 okay = true;
84 this->ivalue.first = items.getArrayItem(this->item_number); 83 this->ivalue.first = items.getArrayItem(this->item_number);
85 - this->ivalue.second = items.getArrayItem(1+this->item_number);  
86 - }  
87 - else  
88 - { 84 + this->ivalue.second = items.getArrayItem(1 + this->item_number);
  85 + } else {
89 error(impl.qpdf, node, "update ivalue: items array is too short"); 86 error(impl.qpdf, node, "update ivalue: items array is too short");
90 } 87 }
91 } 88 }
92 - if (! okay)  
93 - {  
94 - if (! allow_invalid)  
95 - {  
96 - throw std::logic_error(  
97 - "attempt made to dereference an invalid"  
98 - " name/number tree iterator"); 89 + if (!okay) {
  90 + if (!allow_invalid) {
  91 + throw std::logic_error("attempt made to dereference an invalid"
  92 + " name/number tree iterator");
99 } 93 }
100 this->ivalue.first = QPDFObjectHandle(); 94 this->ivalue.first = QPDFObjectHandle();
101 this->ivalue.second = QPDFObjectHandle(); 95 this->ivalue.second = QPDFObjectHandle();
@@ -114,29 +108,24 @@ NNTreeIterator::getNextKid(PathElement&amp; pe, bool backward) @@ -114,29 +108,24 @@ NNTreeIterator::getNextKid(PathElement&amp; pe, bool backward)
114 { 108 {
115 QPDFObjectHandle result; 109 QPDFObjectHandle result;
116 bool found = false; 110 bool found = false;
117 - while (! found)  
118 - { 111 + while (!found) {
119 pe.kid_number += backward ? -1 : 1; 112 pe.kid_number += backward ? -1 : 1;
120 auto kids = pe.node.getKey("/Kids"); 113 auto kids = pe.node.getKey("/Kids");
121 - if ((pe.kid_number >= 0) && (pe.kid_number < kids.getArrayNItems()))  
122 - { 114 + if ((pe.kid_number >= 0) && (pe.kid_number < kids.getArrayNItems())) {
123 result = kids.getArrayItem(pe.kid_number); 115 result = kids.getArrayItem(pe.kid_number);
124 if (result.isDictionary() && 116 if (result.isDictionary() &&
125 (result.hasKey("/Kids") || 117 (result.hasKey("/Kids") ||
126 - result.hasKey(impl.details.itemsKey())))  
127 - { 118 + result.hasKey(impl.details.itemsKey()))) {
128 found = true; 119 found = true;
129 - }  
130 - else  
131 - { 120 + } else {
132 QTC::TC("qpdf", "NNTree skip invalid kid"); 121 QTC::TC("qpdf", "NNTree skip invalid kid");
133 - warn(impl.qpdf, pe.node,  
134 - "skipping over invalid kid at index " +  
135 - QUtil::int_to_string(pe.kid_number)); 122 + warn(
  123 + impl.qpdf,
  124 + pe.node,
  125 + "skipping over invalid kid at index " +
  126 + QUtil::int_to_string(pe.kid_number));
136 } 127 }
137 - }  
138 - else  
139 - { 128 + } else {
140 result = QPDFObjectHandle::newNull(); 129 result = QPDFObjectHandle::newNull();
141 found = true; 130 found = true;
142 } 131 }
@@ -153,55 +142,46 @@ NNTreeIterator::valid() const @@ -153,55 +142,46 @@ NNTreeIterator::valid() const
153 void 142 void
154 NNTreeIterator::increment(bool backward) 143 NNTreeIterator::increment(bool backward)
155 { 144 {
156 - if (this->item_number < 0)  
157 - { 145 + if (this->item_number < 0) {
158 QTC::TC("qpdf", "NNTree increment end()"); 146 QTC::TC("qpdf", "NNTree increment end()");
159 - deepen(impl.oh, ! backward, true); 147 + deepen(impl.oh, !backward, true);
160 return; 148 return;
161 } 149 }
162 bool found_valid_key = false; 150 bool found_valid_key = false;
163 - while (valid() && (! found_valid_key))  
164 - { 151 + while (valid() && (!found_valid_key)) {
165 this->item_number += backward ? -2 : 2; 152 this->item_number += backward ? -2 : 2;
166 auto items = this->node.getKey(impl.details.itemsKey()); 153 auto items = this->node.getKey(impl.details.itemsKey());
167 if ((this->item_number < 0) || 154 if ((this->item_number < 0) ||
168 - (this->item_number >= items.getArrayNItems()))  
169 - { 155 + (this->item_number >= items.getArrayNItems())) {
170 bool found = false; 156 bool found = false;
171 setItemNumber(QPDFObjectHandle(), -1); 157 setItemNumber(QPDFObjectHandle(), -1);
172 - while (! (found || this->path.empty()))  
173 - { 158 + while (!(found || this->path.empty())) {
174 auto& element = this->path.back(); 159 auto& element = this->path.back();
175 auto pe_node = getNextKid(element, backward); 160 auto pe_node = getNextKid(element, backward);
176 - if (pe_node.isNull())  
177 - { 161 + if (pe_node.isNull()) {
178 this->path.pop_back(); 162 this->path.pop_back();
179 - }  
180 - else  
181 - {  
182 - found = deepen(pe_node, ! backward, false); 163 + } else {
  164 + found = deepen(pe_node, !backward, false);
183 } 165 }
184 } 166 }
185 } 167 }
186 - if (this->item_number >= 0)  
187 - { 168 + if (this->item_number >= 0) {
188 items = this->node.getKey(impl.details.itemsKey()); 169 items = this->node.getKey(impl.details.itemsKey());
189 - if (this->item_number + 1 >= items.getArrayNItems())  
190 - { 170 + if (this->item_number + 1 >= items.getArrayNItems()) {
191 QTC::TC("qpdf", "NNTree skip item at end of short items"); 171 QTC::TC("qpdf", "NNTree skip item at end of short items");
192 - warn(impl.qpdf, this->node,  
193 - "items array doesn't have enough elements");  
194 - }  
195 - else if (! impl.details.keyValid(  
196 - items.getArrayItem(this->item_number)))  
197 - { 172 + warn(
  173 + impl.qpdf,
  174 + this->node,
  175 + "items array doesn't have enough elements");
  176 + } else if (!impl.details.keyValid(
  177 + items.getArrayItem(this->item_number))) {
198 QTC::TC("qpdf", "NNTree skip invalid key"); 178 QTC::TC("qpdf", "NNTree skip invalid key");
199 - warn(impl.qpdf, this->node,  
200 - "item " + QUtil::int_to_string(this->item_number) +  
201 - " has the wrong type");  
202 - }  
203 - else  
204 - { 179 + warn(
  180 + impl.qpdf,
  181 + this->node,
  182 + "item " + QUtil::int_to_string(this->item_number) +
  183 + " has the wrong type");
  184 + } else {
205 found_valid_key = true; 185 found_valid_key = true;
206 } 186 }
207 } 187 }
@@ -209,14 +189,12 @@ NNTreeIterator::increment(bool backward) @@ -209,14 +189,12 @@ NNTreeIterator::increment(bool backward)
209 } 189 }
210 190
211 void 191 void
212 -NNTreeIterator::resetLimits(QPDFObjectHandle node,  
213 - std::list<PathElement>::iterator parent) 192 +NNTreeIterator::resetLimits(
  193 + QPDFObjectHandle node, std::list<PathElement>::iterator parent)
214 { 194 {
215 bool done = false; 195 bool done = false;
216 - while (! done)  
217 - {  
218 - if (parent == this->path.end())  
219 - { 196 + while (!done) {
  197 + if (parent == this->path.end()) {
220 QTC::TC("qpdf", "NNTree remove limits from root"); 198 QTC::TC("qpdf", "NNTree remove limits from root");
221 node.removeKey("/Limits"); 199 node.removeKey("/Limits");
222 done = true; 200 done = true;
@@ -230,65 +208,51 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, @@ -230,65 +208,51 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node,
230 bool changed = true; 208 bool changed = true;
231 QPDFObjectHandle first; 209 QPDFObjectHandle first;
232 QPDFObjectHandle last; 210 QPDFObjectHandle last;
233 - if (nitems >= 2)  
234 - { 211 + if (nitems >= 2) {
235 first = items.getArrayItem(0); 212 first = items.getArrayItem(0);
236 last = items.getArrayItem((nitems - 1) & ~1); 213 last = items.getArrayItem((nitems - 1) & ~1);
237 - }  
238 - else if (nkids > 0)  
239 - { 214 + } else if (nkids > 0) {
240 auto first_kid = kids.getArrayItem(0); 215 auto first_kid = kids.getArrayItem(0);
241 auto last_kid = kids.getArrayItem(nkids - 1); 216 auto last_kid = kids.getArrayItem(nkids - 1);
242 - if (first_kid.isDictionary() && last_kid.isDictionary())  
243 - { 217 + if (first_kid.isDictionary() && last_kid.isDictionary()) {
244 auto first_limits = first_kid.getKey("/Limits"); 218 auto first_limits = first_kid.getKey("/Limits");
245 auto last_limits = last_kid.getKey("/Limits"); 219 auto last_limits = last_kid.getKey("/Limits");
246 if (first_limits.isArray() && 220 if (first_limits.isArray() &&
247 (first_limits.getArrayNItems() >= 2) && 221 (first_limits.getArrayNItems() >= 2) &&
248 last_limits.isArray() && 222 last_limits.isArray() &&
249 - (last_limits.getArrayNItems() >= 2))  
250 - { 223 + (last_limits.getArrayNItems() >= 2)) {
251 first = first_limits.getArrayItem(0); 224 first = first_limits.getArrayItem(0);
252 last = last_limits.getArrayItem(1); 225 last = last_limits.getArrayItem(1);
253 } 226 }
254 } 227 }
255 } 228 }
256 - if (first.isInitialized() && last.isInitialized())  
257 - { 229 + if (first.isInitialized() && last.isInitialized()) {
258 auto limits = QPDFObjectHandle::newArray(); 230 auto limits = QPDFObjectHandle::newArray();
259 limits.appendItem(first); 231 limits.appendItem(first);
260 limits.appendItem(last); 232 limits.appendItem(last);
261 auto olimits = node.getKey("/Limits"); 233 auto olimits = node.getKey("/Limits");
262 - if (olimits.isArray() && (olimits.getArrayNItems() == 2))  
263 - { 234 + if (olimits.isArray() && (olimits.getArrayNItems() == 2)) {
264 auto ofirst = olimits.getArrayItem(0); 235 auto ofirst = olimits.getArrayItem(0);
265 auto olast = olimits.getArrayItem(1); 236 auto olast = olimits.getArrayItem(1);
266 if (impl.details.keyValid(ofirst) && 237 if (impl.details.keyValid(ofirst) &&
267 impl.details.keyValid(olast) && 238 impl.details.keyValid(olast) &&
268 (impl.details.compareKeys(first, ofirst) == 0) && 239 (impl.details.compareKeys(first, ofirst) == 0) &&
269 - (impl.details.compareKeys(last, olast) == 0))  
270 - { 240 + (impl.details.compareKeys(last, olast) == 0)) {
271 QTC::TC("qpdf", "NNTree limits didn't change"); 241 QTC::TC("qpdf", "NNTree limits didn't change");
272 changed = false; 242 changed = false;
273 } 243 }
274 } 244 }
275 - if (changed)  
276 - { 245 + if (changed) {
277 node.replaceKey("/Limits", limits); 246 node.replaceKey("/Limits", limits);
278 } 247 }
279 - }  
280 - else  
281 - { 248 + } else {
282 QTC::TC("qpdf", "NNTree unable to determine limits"); 249 QTC::TC("qpdf", "NNTree unable to determine limits");
283 warn(impl.qpdf, node, "unable to determine limits"); 250 warn(impl.qpdf, node, "unable to determine limits");
284 } 251 }
285 252
286 - if ((! changed) || (parent == this->path.begin()))  
287 - { 253 + if ((!changed) || (parent == this->path.begin())) {
288 done = true; 254 done = true;
289 - }  
290 - else  
291 - { 255 + } else {
292 node = parent->node; 256 node = parent->node;
293 --parent; 257 --parent;
294 } 258 }
@@ -296,8 +260,8 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, @@ -296,8 +260,8 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node,
296 } 260 }
297 261
298 void 262 void
299 -NNTreeIterator::split(QPDFObjectHandle to_split,  
300 - std::list<PathElement>::iterator parent) 263 +NNTreeIterator::split(
  264 + QPDFObjectHandle to_split, std::list<PathElement>::iterator parent)
301 { 265 {
302 // Split some node along the path to the item pointed to by this 266 // Split some node along the path to the item pointed to by this
303 // iterator, and adjust the iterator so it points to the same 267 // iterator, and adjust the iterator so it points to the same
@@ -327,13 +291,10 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -327,13 +291,10 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
327 // node: A 291 // node: A
328 // item_number: 0 292 // item_number: 0
329 293
330 - if (! this->impl.qpdf)  
331 - {  
332 - throw std::logic_error(  
333 - "NNTreeIterator::split called with null qpdf"); 294 + if (!this->impl.qpdf) {
  295 + throw std::logic_error("NNTreeIterator::split called with null qpdf");
334 } 296 }
335 - if (! valid())  
336 - { 297 + if (!valid()) {
337 throw std::logic_error( 298 throw std::logic_error(
338 "NNTreeIterator::split called an invalid iterator"); 299 "NNTreeIterator::split called an invalid iterator");
339 } 300 }
@@ -349,29 +310,23 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -349,29 +310,23 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
349 int n = 0; 310 int n = 0;
350 std::string key; 311 std::string key;
351 int threshold = 0; 312 int threshold = 0;
352 - if (nkids > 0)  
353 - { 313 + if (nkids > 0) {
354 QTC::TC("qpdf", "NNTree split kids"); 314 QTC::TC("qpdf", "NNTree split kids");
355 first_half = kids; 315 first_half = kids;
356 n = nkids; 316 n = nkids;
357 threshold = impl.split_threshold; 317 threshold = impl.split_threshold;
358 key = "/Kids"; 318 key = "/Kids";
359 - }  
360 - else if (nitems > 0)  
361 - { 319 + } else if (nitems > 0) {
362 QTC::TC("qpdf", "NNTree split items"); 320 QTC::TC("qpdf", "NNTree split items");
363 first_half = items; 321 first_half = items;
364 n = nitems; 322 n = nitems;
365 threshold = 2 * impl.split_threshold; 323 threshold = 2 * impl.split_threshold;
366 key = impl.details.itemsKey(); 324 key = impl.details.itemsKey();
367 - }  
368 - else  
369 - { 325 + } else {
370 throw std::logic_error("NNTreeIterator::split called on invalid node"); 326 throw std::logic_error("NNTreeIterator::split called on invalid node");
371 } 327 }
372 328
373 - if (n <= threshold)  
374 - { 329 + if (n <= threshold) {
375 return; 330 return;
376 } 331 }
377 332
@@ -381,8 +336,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -381,8 +336,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
381 // CURRENT STATE: tree is in original state; iterator is valid and 336 // CURRENT STATE: tree is in original state; iterator is valid and
382 // unchanged. 337 // unchanged.
383 338
384 - if (is_root)  
385 - { 339 + if (is_root) {
386 // What we want to do is to create a new node for the second 340 // What we want to do is to create a new node for the second
387 // half of the items and put it in the parent's /Kids array 341 // half of the items and put it in the parent's /Kids array
388 // right after the element that points to the current to_split 342 // right after the element that points to the current to_split
@@ -404,21 +358,18 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -404,21 +358,18 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
404 // non-root case so remaining logic can handle them in the 358 // non-root case so remaining logic can handle them in the
405 // same way. 359 // same way.
406 360
407 - auto first_node = impl.qpdf->makeIndirectObject(  
408 - QPDFObjectHandle::newDictionary()); 361 + auto first_node =
  362 + impl.qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary());
409 first_node.replaceKey(key, first_half); 363 first_node.replaceKey(key, first_half);
410 QPDFObjectHandle new_kids = QPDFObjectHandle::newArray(); 364 QPDFObjectHandle new_kids = QPDFObjectHandle::newArray();
411 new_kids.appendItem(first_node); 365 new_kids.appendItem(first_node);
412 to_split.removeKey("/Limits"); // already shouldn't be there for root 366 to_split.removeKey("/Limits"); // already shouldn't be there for root
413 to_split.removeKey(impl.details.itemsKey()); 367 to_split.removeKey(impl.details.itemsKey());
414 to_split.replaceKey("/Kids", new_kids); 368 to_split.replaceKey("/Kids", new_kids);
415 - if (is_leaf)  
416 - { 369 + if (is_leaf) {
417 QTC::TC("qpdf", "NNTree split root + leaf"); 370 QTC::TC("qpdf", "NNTree split root + leaf");
418 this->node = first_node; 371 this->node = first_node;
419 - }  
420 - else  
421 - { 372 + } else {
422 QTC::TC("qpdf", "NNTree split root + !leaf"); 373 QTC::TC("qpdf", "NNTree split root + !leaf");
423 auto next = this->path.begin(); 374 auto next = this->path.begin();
424 next->node = first_node; 375 next->node = first_node;
@@ -436,16 +387,15 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -436,16 +387,15 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
436 // items into the second half array. 387 // items into the second half array.
437 QPDFObjectHandle second_half = QPDFObjectHandle::newArray(); 388 QPDFObjectHandle second_half = QPDFObjectHandle::newArray();
438 int start_idx = ((n / 2) & ~1); 389 int start_idx = ((n / 2) & ~1);
439 - while (first_half.getArrayNItems() > start_idx)  
440 - { 390 + while (first_half.getArrayNItems() > start_idx) {
441 second_half.appendItem(first_half.getArrayItem(start_idx)); 391 second_half.appendItem(first_half.getArrayItem(start_idx));
442 first_half.eraseItem(start_idx); 392 first_half.eraseItem(start_idx);
443 } 393 }
444 resetLimits(to_split, parent); 394 resetLimits(to_split, parent);
445 395
446 // Create a new node to contain the second half 396 // Create a new node to contain the second half
447 - QPDFObjectHandle second_node = impl.qpdf->makeIndirectObject(  
448 - QPDFObjectHandle::newDictionary()); 397 + QPDFObjectHandle second_node =
  398 + impl.qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary());
449 second_node.replaceKey(key, second_half); 399 second_node.replaceKey(key, second_half);
450 resetLimits(second_node, parent); 400 resetLimits(second_node, parent);
451 401
@@ -464,23 +414,18 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -464,23 +414,18 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
464 auto cur_elem = parent; 414 auto cur_elem = parent;
465 ++cur_elem; // points to end() for leaf nodes 415 ++cur_elem; // points to end() for leaf nodes
466 int old_idx = (is_leaf ? this->item_number : cur_elem->kid_number); 416 int old_idx = (is_leaf ? this->item_number : cur_elem->kid_number);
467 - if (old_idx >= start_idx)  
468 - { 417 + if (old_idx >= start_idx) {
469 ++parent->kid_number; 418 ++parent->kid_number;
470 - if (is_leaf)  
471 - { 419 + if (is_leaf) {
472 QTC::TC("qpdf", "NNTree split second half item"); 420 QTC::TC("qpdf", "NNTree split second half item");
473 setItemNumber(second_node, this->item_number - start_idx); 421 setItemNumber(second_node, this->item_number - start_idx);
474 - }  
475 - else  
476 - { 422 + } else {
477 QTC::TC("qpdf", "NNTree split second half kid"); 423 QTC::TC("qpdf", "NNTree split second half kid");
478 cur_elem->node = second_node; 424 cur_elem->node = second_node;
479 cur_elem->kid_number -= start_idx; 425 cur_elem->kid_number -= start_idx;
480 } 426 }
481 } 427 }
482 - if (! is_root)  
483 - { 428 + if (!is_root) {
484 QTC::TC("qpdf", "NNTree split parent"); 429 QTC::TC("qpdf", "NNTree split parent");
485 auto next = parent->node; 430 auto next = parent->node;
486 resetLimits(next, parent); 431 resetLimits(next, parent);
@@ -493,8 +438,7 @@ std::list&lt;NNTreeIterator::PathElement&gt;::iterator @@ -493,8 +438,7 @@ std::list&lt;NNTreeIterator::PathElement&gt;::iterator
493 NNTreeIterator::lastPathElement() 438 NNTreeIterator::lastPathElement()
494 { 439 {
495 auto result = this->path.end(); 440 auto result = this->path.end();
496 - if (! this->path.empty())  
497 - { 441 + if (!this->path.empty()) {
498 --result; 442 --result;
499 } 443 }
500 return result; 444 return result;
@@ -503,8 +447,7 @@ NNTreeIterator::lastPathElement() @@ -503,8 +447,7 @@ NNTreeIterator::lastPathElement()
503 void 447 void
504 NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) 448 NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value)
505 { 449 {
506 - if (! valid())  
507 - { 450 + if (!valid()) {
508 QTC::TC("qpdf", "NNTree insertAfter inserts first"); 451 QTC::TC("qpdf", "NNTree insertAfter inserts first");
509 impl.insertFirst(key, value); 452 impl.insertFirst(key, value);
510 deepen(impl.oh, true, false); 453 deepen(impl.oh, true, false);
@@ -512,12 +455,10 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) @@ -512,12 +455,10 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value)
512 } 455 }
513 456
514 auto items = this->node.getKey(impl.details.itemsKey()); 457 auto items = this->node.getKey(impl.details.itemsKey());
515 - if (! items.isArray())  
516 - { 458 + if (!items.isArray()) {
517 error(impl.qpdf, node, "node contains no items array"); 459 error(impl.qpdf, node, "node contains no items array");
518 } 460 }
519 - if (items.getArrayNItems() < this->item_number + 2)  
520 - { 461 + if (items.getArrayNItems() < this->item_number + 2) {
521 error(impl.qpdf, node, "insert: items array is too short"); 462 error(impl.qpdf, node, "insert: items array is too short");
522 } 463 }
523 items.insertItem(this->item_number + 2, key); 464 items.insertItem(this->item_number + 2, key);
@@ -533,51 +474,44 @@ NNTreeIterator::remove() @@ -533,51 +474,44 @@ NNTreeIterator::remove()
533 // Remove this item, leaving the tree valid and this iterator 474 // Remove this item, leaving the tree valid and this iterator
534 // pointing to the next item. 475 // pointing to the next item.
535 476
536 - if (! valid())  
537 - { 477 + if (!valid()) {
538 throw std::logic_error("attempt made to remove an invalid iterator"); 478 throw std::logic_error("attempt made to remove an invalid iterator");
539 } 479 }
540 auto items = this->node.getKey(impl.details.itemsKey()); 480 auto items = this->node.getKey(impl.details.itemsKey());
541 int nitems = items.getArrayNItems(); 481 int nitems = items.getArrayNItems();
542 - if (this->item_number + 2 > nitems)  
543 - {  
544 - error(impl.qpdf, this->node,  
545 - "found short items array while removing an item"); 482 + if (this->item_number + 2 > nitems) {
  483 + error(
  484 + impl.qpdf,
  485 + this->node,
  486 + "found short items array while removing an item");
546 } 487 }
547 488
548 items.eraseItem(this->item_number); 489 items.eraseItem(this->item_number);
549 items.eraseItem(this->item_number); 490 items.eraseItem(this->item_number);
550 nitems -= 2; 491 nitems -= 2;
551 492
552 - if (nitems > 0)  
553 - { 493 + if (nitems > 0) {
554 // There are still items left 494 // There are still items left
555 495
556 - if ((this->item_number == 0) || (this->item_number == nitems))  
557 - { 496 + if ((this->item_number == 0) || (this->item_number == nitems)) {
558 // We removed either the first or last item of an items array 497 // We removed either the first or last item of an items array
559 // that remains non-empty, so we have to adjust limits. 498 // that remains non-empty, so we have to adjust limits.
560 QTC::TC("qpdf", "NNTree remove reset limits"); 499 QTC::TC("qpdf", "NNTree remove reset limits");
561 resetLimits(this->node, lastPathElement()); 500 resetLimits(this->node, lastPathElement());
562 } 501 }
563 502
564 - if (this->item_number == nitems)  
565 - { 503 + if (this->item_number == nitems) {
566 // We removed the last item of a non-empty items array, so 504 // We removed the last item of a non-empty items array, so
567 // advance to the successor of the previous item. 505 // advance to the successor of the previous item.
568 QTC::TC("qpdf", "NNTree erased last item"); 506 QTC::TC("qpdf", "NNTree erased last item");
569 this->item_number -= 2; 507 this->item_number -= 2;
570 increment(false); 508 increment(false);
571 - }  
572 - else if (this->item_number < nitems)  
573 - { 509 + } else if (this->item_number < nitems) {
574 // We don't have to do anything since the removed item's 510 // We don't have to do anything since the removed item's
575 // successor now occupies its former location. 511 // successor now occupies its former location.
576 QTC::TC("qpdf", "NNTree erased non-last item"); 512 QTC::TC("qpdf", "NNTree erased non-last item");
577 updateIValue(); 513 updateIValue();
578 - }  
579 - else  
580 - { 514 + } else {
581 // We already checked to ensure this condition would not 515 // We already checked to ensure this condition would not
582 // happen. 516 // happen.
583 throw std::logic_error( 517 throw std::logic_error(
@@ -586,8 +520,7 @@ NNTreeIterator::remove() @@ -586,8 +520,7 @@ NNTreeIterator::remove()
586 return; 520 return;
587 } 521 }
588 522
589 - if (this->path.empty())  
590 - { 523 + if (this->path.empty()) {
591 // Special case: if this is the root node, we can leave it 524 // Special case: if this is the root node, we can leave it
592 // empty. 525 // empty.
593 QTC::TC("qpdf", "NNTree erased all items on leaf/root"); 526 QTC::TC("qpdf", "NNTree erased all items on leaf/root");
@@ -601,64 +534,50 @@ NNTreeIterator::remove() @@ -601,64 +534,50 @@ NNTreeIterator::remove()
601 // remove this node from the parent on up the tree. Then we need 534 // remove this node from the parent on up the tree. Then we need
602 // to position ourselves at the removed item's successor. 535 // to position ourselves at the removed item's successor.
603 bool done = false; 536 bool done = false;
604 - while (! done)  
605 - { 537 + while (!done) {
606 auto element = lastPathElement(); 538 auto element = lastPathElement();
607 auto parent = element; 539 auto parent = element;
608 --parent; 540 --parent;
609 auto kids = element->node.getKey("/Kids"); 541 auto kids = element->node.getKey("/Kids");
610 kids.eraseItem(element->kid_number); 542 kids.eraseItem(element->kid_number);
611 auto nkids = kids.getArrayNItems(); 543 auto nkids = kids.getArrayNItems();
612 - if (nkids > 0)  
613 - { 544 + if (nkids > 0) {
614 // The logic here is similar to the items case. 545 // The logic here is similar to the items case.
615 - if ((element->kid_number == 0) || (element->kid_number == nkids))  
616 - { 546 + if ((element->kid_number == 0) || (element->kid_number == nkids)) {
617 QTC::TC("qpdf", "NNTree erased first or last kid"); 547 QTC::TC("qpdf", "NNTree erased first or last kid");
618 resetLimits(element->node, parent); 548 resetLimits(element->node, parent);
619 } 549 }
620 - if (element->kid_number == nkids)  
621 - { 550 + if (element->kid_number == nkids) {
622 // Move to the successor of the last child of the 551 // Move to the successor of the last child of the
623 // previous kid. 552 // previous kid.
624 setItemNumber(QPDFObjectHandle(), -1); 553 setItemNumber(QPDFObjectHandle(), -1);
625 --element->kid_number; 554 --element->kid_number;
626 deepen(kids.getArrayItem(element->kid_number), false, true); 555 deepen(kids.getArrayItem(element->kid_number), false, true);
627 - if (valid())  
628 - { 556 + if (valid()) {
629 increment(false); 557 increment(false);
630 - if (! valid())  
631 - { 558 + if (!valid()) {
632 QTC::TC("qpdf", "NNTree erased last item in tree"); 559 QTC::TC("qpdf", "NNTree erased last item in tree");
633 - }  
634 - else  
635 - { 560 + } else {
636 QTC::TC("qpdf", "NNTree erased last kid"); 561 QTC::TC("qpdf", "NNTree erased last kid");
637 } 562 }
638 } 563 }
639 - }  
640 - else  
641 - { 564 + } else {
642 // Next kid is in deleted kid's position 565 // Next kid is in deleted kid's position
643 QTC::TC("qpdf", "NNTree erased non-last kid"); 566 QTC::TC("qpdf", "NNTree erased non-last kid");
644 deepen(kids.getArrayItem(element->kid_number), true, true); 567 deepen(kids.getArrayItem(element->kid_number), true, true);
645 } 568 }
646 done = true; 569 done = true;
647 - }  
648 - else if (parent == this->path.end())  
649 - { 570 + } else if (parent == this->path.end()) {
650 // We erased the very last item. Convert the root to an 571 // We erased the very last item. Convert the root to an
651 // empty items array. 572 // empty items array.
652 QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); 573 QTC::TC("qpdf", "NNTree non-flat tree is empty after remove");
653 element->node.removeKey("/Kids"); 574 element->node.removeKey("/Kids");
654 - element->node.replaceKey(impl.details.itemsKey(),  
655 - QPDFObjectHandle::newArray()); 575 + element->node.replaceKey(
  576 + impl.details.itemsKey(), QPDFObjectHandle::newArray());
656 this->path.clear(); 577 this->path.clear();
657 setItemNumber(impl.oh, -1); 578 setItemNumber(impl.oh, -1);
658 done = true; 579 done = true;
659 - }  
660 - else  
661 - { 580 + } else {
662 // Walk up the tree and continue 581 // Walk up the tree and continue
663 QTC::TC("qpdf", "NNTree remove walking up tree"); 582 QTC::TC("qpdf", "NNTree remove walking up tree");
664 this->path.pop_back(); 583 this->path.pop_back();
@@ -697,27 +616,22 @@ NNTreeIterator::operator-&gt;() @@ -697,27 +616,22 @@ NNTreeIterator::operator-&gt;()
697 bool 616 bool
698 NNTreeIterator::operator==(NNTreeIterator const& other) const 617 NNTreeIterator::operator==(NNTreeIterator const& other) const
699 { 618 {
700 - if ((this->item_number == -1) && (other.item_number == -1))  
701 - { 619 + if ((this->item_number == -1) && (other.item_number == -1)) {
702 return true; 620 return true;
703 } 621 }
704 - if (this->path.size() != other.path.size())  
705 - { 622 + if (this->path.size() != other.path.size()) {
706 return false; 623 return false;
707 } 624 }
708 auto tpi = this->path.begin(); 625 auto tpi = this->path.begin();
709 auto opi = other.path.begin(); 626 auto opi = other.path.begin();
710 - while (tpi != this->path.end())  
711 - {  
712 - if (tpi->kid_number != opi->kid_number)  
713 - { 627 + while (tpi != this->path.end()) {
  628 + if (tpi->kid_number != opi->kid_number) {
714 return false; 629 return false;
715 } 630 }
716 ++tpi; 631 ++tpi;
717 ++opi; 632 ++opi;
718 } 633 }
719 - if (this->item_number != other.item_number)  
720 - { 634 + if (this->item_number != other.item_number) {
721 return false; 635 return false;
722 } 636 }
723 return true; 637 return true;
@@ -732,8 +646,7 @@ NNTreeIterator::setItemNumber(QPDFObjectHandle const&amp; node, int n) @@ -732,8 +646,7 @@ NNTreeIterator::setItemNumber(QPDFObjectHandle const&amp; node, int n)
732 } 646 }
733 647
734 void 648 void
735 -NNTreeIterator::addPathElement(QPDFObjectHandle const& node,  
736 - int kid_number) 649 +NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number)
737 { 650 {
738 this->path.push_back(PathElement(node, kid_number)); 651 this->path.push_back(PathElement(node, kid_number));
739 } 652 }
@@ -749,33 +662,31 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) @@ -749,33 +662,31 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
749 bool failed = false; 662 bool failed = false;
750 663
751 std::set<QPDFObjGen> seen; 664 std::set<QPDFObjGen> seen;
752 - for (auto i: this->path)  
753 - {  
754 - if (i.node.isIndirect())  
755 - { 665 + for (auto i : this->path) {
  666 + if (i.node.isIndirect()) {
756 seen.insert(i.node.getObjGen()); 667 seen.insert(i.node.getObjGen());
757 } 668 }
758 } 669 }
759 - while (! failed)  
760 - {  
761 - if (node.isIndirect())  
762 - { 670 + while (!failed) {
  671 + if (node.isIndirect()) {
763 auto og = node.getObjGen(); 672 auto og = node.getObjGen();
764 - if (seen.count(og))  
765 - { 673 + if (seen.count(og)) {
766 QTC::TC("qpdf", "NNTree deepen: loop"); 674 QTC::TC("qpdf", "NNTree deepen: loop");
767 - warn(impl.qpdf, node,  
768 - "loop detected while traversing name/number tree"); 675 + warn(
  676 + impl.qpdf,
  677 + node,
  678 + "loop detected while traversing name/number tree");
769 failed = true; 679 failed = true;
770 break; 680 break;
771 } 681 }
772 seen.insert(og); 682 seen.insert(og);
773 } 683 }
774 - if (! node.isDictionary())  
775 - { 684 + if (!node.isDictionary()) {
776 QTC::TC("qpdf", "NNTree node is not a dictionary"); 685 QTC::TC("qpdf", "NNTree node is not a dictionary");
777 - warn(impl.qpdf, node,  
778 - "non-dictionary node while traversing name/number tree"); 686 + warn(
  687 + impl.qpdf,
  688 + node,
  689 + "non-dictionary node while traversing name/number tree");
779 failed = true; 690 failed = true;
780 break; 691 break;
781 } 692 }
@@ -784,66 +695,61 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) @@ -784,66 +695,61 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
784 int nkids = kids.isArray() ? kids.getArrayNItems() : 0; 695 int nkids = kids.isArray() ? kids.getArrayNItems() : 0;
785 auto items = node.getKey(impl.details.itemsKey()); 696 auto items = node.getKey(impl.details.itemsKey());
786 int nitems = items.isArray() ? items.getArrayNItems() : 0; 697 int nitems = items.isArray() ? items.getArrayNItems() : 0;
787 - if (nitems > 0)  
788 - { 698 + if (nitems > 0) {
789 setItemNumber(node, first ? 0 : nitems - 2); 699 setItemNumber(node, first ? 0 : nitems - 2);
790 break; 700 break;
791 - }  
792 - else if (nkids > 0)  
793 - { 701 + } else if (nkids > 0) {
794 int kid_number = first ? 0 : nkids - 1; 702 int kid_number = first ? 0 : nkids - 1;
795 addPathElement(node, kid_number); 703 addPathElement(node, kid_number);
796 auto next = kids.getArrayItem(kid_number); 704 auto next = kids.getArrayItem(kid_number);
797 - if (! next.isIndirect())  
798 - {  
799 - if (impl.qpdf && impl.auto_repair)  
800 - { 705 + if (!next.isIndirect()) {
  706 + if (impl.qpdf && impl.auto_repair) {
801 QTC::TC("qpdf", "NNTree fix indirect kid"); 707 QTC::TC("qpdf", "NNTree fix indirect kid");
802 - warn(impl.qpdf, node,  
803 - "converting kid number " +  
804 - QUtil::int_to_string(kid_number) +  
805 - " to an indirect object"); 708 + warn(
  709 + impl.qpdf,
  710 + node,
  711 + "converting kid number " +
  712 + QUtil::int_to_string(kid_number) +
  713 + " to an indirect object");
806 next = impl.qpdf->makeIndirectObject(next); 714 next = impl.qpdf->makeIndirectObject(next);
807 kids.setArrayItem(kid_number, next); 715 kids.setArrayItem(kid_number, next);
808 - }  
809 - else  
810 - { 716 + } else {
811 QTC::TC("qpdf", "NNTree warn indirect kid"); 717 QTC::TC("qpdf", "NNTree warn indirect kid");
812 - warn(impl.qpdf, node,  
813 - "kid number " + QUtil::int_to_string(kid_number) +  
814 - " is not an indirect object"); 718 + warn(
  719 + impl.qpdf,
  720 + node,
  721 + "kid number " + QUtil::int_to_string(kid_number) +
  722 + " is not an indirect object");
815 } 723 }
816 } 724 }
817 node = next; 725 node = next;
818 - }  
819 - else if (allow_empty && items.isArray())  
820 - { 726 + } else if (allow_empty && items.isArray()) {
821 QTC::TC("qpdf", "NNTree deepen found empty"); 727 QTC::TC("qpdf", "NNTree deepen found empty");
822 setItemNumber(node, -1); 728 setItemNumber(node, -1);
823 break; 729 break;
824 - }  
825 - else  
826 - { 730 + } else {
827 QTC::TC("qpdf", "NNTree deepen: invalid node"); 731 QTC::TC("qpdf", "NNTree deepen: invalid node");
828 - warn(impl.qpdf, node,  
829 - "name/number tree node has neither non-empty " +  
830 - impl.details.itemsKey() + " nor /Kids"); 732 + warn(
  733 + impl.qpdf,
  734 + node,
  735 + "name/number tree node has neither non-empty " +
  736 + impl.details.itemsKey() + " nor /Kids");
831 failed = true; 737 failed = true;
832 break; 738 break;
833 } 739 }
834 } 740 }
835 - if (failed)  
836 - { 741 + if (failed) {
837 this->path = opath; 742 this->path = opath;
838 return false; 743 return false;
839 } 744 }
840 return true; 745 return true;
841 } 746 }
842 747
843 -NNTreeImpl::NNTreeImpl(NNTreeDetails const& details,  
844 - QPDF* qpdf,  
845 - QPDFObjectHandle& oh,  
846 - bool auto_repair) : 748 +NNTreeImpl::NNTreeImpl(
  749 + NNTreeDetails const& details,
  750 + QPDF* qpdf,
  751 + QPDFObjectHandle& oh,
  752 + bool auto_repair) :
847 details(details), 753 details(details),
848 qpdf(qpdf), 754 qpdf(qpdf),
849 split_threshold(32), 755 split_threshold(32),
@@ -887,19 +793,13 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node) @@ -887,19 +793,13 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node)
887 auto limits = node.getKey("/Limits"); 793 auto limits = node.getKey("/Limits");
888 if (limits.isArray() && (limits.getArrayNItems() >= 2) && 794 if (limits.isArray() && (limits.getArrayNItems() >= 2) &&
889 details.keyValid(limits.getArrayItem(0)) && 795 details.keyValid(limits.getArrayItem(0)) &&
890 - details.keyValid(limits.getArrayItem(1)))  
891 - {  
892 - if (details.compareKeys(key, limits.getArrayItem(0)) < 0)  
893 - { 796 + details.keyValid(limits.getArrayItem(1))) {
  797 + if (details.compareKeys(key, limits.getArrayItem(0)) < 0) {
894 result = -1; 798 result = -1;
895 - }  
896 - else if (details.compareKeys(key, limits.getArrayItem(1)) > 0)  
897 - { 799 + } else if (details.compareKeys(key, limits.getArrayItem(1)) > 0) {
898 result = 1; 800 result = 1;
899 } 801 }
900 - }  
901 - else  
902 - { 802 + } else {
903 QTC::TC("qpdf", "NNTree missing limits"); 803 QTC::TC("qpdf", "NNTree missing limits");
904 error(qpdf, node, "node is missing /Limits"); 804 error(qpdf, node, "node is missing /Limits");
905 } 805 }
@@ -908,15 +808,15 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node) @@ -908,15 +808,15 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node)
908 808
909 int 809 int
910 NNTreeImpl::binarySearch( 810 NNTreeImpl::binarySearch(
911 - QPDFObjectHandle key, QPDFObjectHandle items,  
912 - int num_items, bool return_prev_if_not_found,  
913 - int (NNTreeImpl::*compare)(QPDFObjectHandle& key,  
914 - QPDFObjectHandle& arr,  
915 - int item)) 811 + QPDFObjectHandle key,
  812 + QPDFObjectHandle items,
  813 + int num_items,
  814 + bool return_prev_if_not_found,
  815 + int (NNTreeImpl::*compare)(
  816 + QPDFObjectHandle& key, QPDFObjectHandle& arr, int item))
916 { 817 {
917 int max_idx = 1; 818 int max_idx = 1;
918 - while (max_idx < num_items)  
919 - { 819 + while (max_idx < num_items) {
920 max_idx <<= 1; 820 max_idx <<= 1;
921 } 821 }
922 822
@@ -928,56 +828,40 @@ NNTreeImpl::binarySearch( @@ -928,56 +828,40 @@ NNTreeImpl::binarySearch(
928 bool found_leq = false; 828 bool found_leq = false;
929 int status = 0; 829 int status = 0;
930 830
931 - while ((! found) && (checks > 0))  
932 - {  
933 - if (idx < num_items)  
934 - { 831 + while ((!found) && (checks > 0)) {
  832 + if (idx < num_items) {
935 status = (this->*compare)(key, items, idx); 833 status = (this->*compare)(key, items, idx);
936 - if (status >= 0)  
937 - { 834 + if (status >= 0) {
938 found_leq = true; 835 found_leq = true;
939 found_idx = idx; 836 found_idx = idx;
940 } 837 }
941 - }  
942 - else  
943 - { 838 + } else {
944 // consider item to be below anything after the top 839 // consider item to be below anything after the top
945 status = -1; 840 status = -1;
946 } 841 }
947 842
948 - if (status == 0)  
949 - { 843 + if (status == 0) {
950 found = true; 844 found = true;
951 - }  
952 - else  
953 - { 845 + } else {
954 checks >>= 1; 846 checks >>= 1;
955 - if (checks > 0)  
956 - { 847 + if (checks > 0) {
957 step >>= 1; 848 step >>= 1;
958 - if (step == 0)  
959 - { 849 + if (step == 0) {
960 step = 1; 850 step = 1;
961 } 851 }
962 852
963 - if (status < 0)  
964 - { 853 + if (status < 0) {
965 idx -= step; 854 idx -= step;
966 - }  
967 - else  
968 - { 855 + } else {
969 idx += step; 856 idx += step;
970 } 857 }
971 } 858 }
972 } 859 }
973 } 860 }
974 861
975 - if (found || (found_leq && return_prev_if_not_found))  
976 - { 862 + if (found || (found_leq && return_prev_if_not_found)) {
977 return found_idx; 863 return found_idx;
978 - }  
979 - else  
980 - { 864 + } else {
981 return -1; 865 return -1;
982 } 866 }
983 } 867 }
@@ -986,13 +870,14 @@ int @@ -986,13 +870,14 @@ int
986 NNTreeImpl::compareKeyItem( 870 NNTreeImpl::compareKeyItem(
987 QPDFObjectHandle& key, QPDFObjectHandle& items, int idx) 871 QPDFObjectHandle& key, QPDFObjectHandle& items, int idx)
988 { 872 {
989 - if (! ((items.isArray() && (items.getArrayNItems() > (2 * idx)) &&  
990 - details.keyValid(items.getArrayItem(2 * idx)))))  
991 - { 873 + if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) &&
  874 + details.keyValid(items.getArrayItem(2 * idx))))) {
992 QTC::TC("qpdf", "NNTree item is wrong type"); 875 QTC::TC("qpdf", "NNTree item is wrong type");
993 - error(qpdf, this->oh,  
994 - "item at index " + QUtil::int_to_string(2 * idx) +  
995 - " is not the right type"); 876 + error(
  877 + qpdf,
  878 + this->oh,
  879 + "item at index " + QUtil::int_to_string(2 * idx) +
  880 + " is not the right type");
996 } 881 }
997 return details.compareKeys(key, items.getArrayItem(2 * idx)); 882 return details.compareKeys(key, items.getArrayItem(2 * idx));
998 } 883 }
@@ -1001,25 +886,24 @@ int @@ -1001,25 +886,24 @@ int
1001 NNTreeImpl::compareKeyKid( 886 NNTreeImpl::compareKeyKid(
1002 QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx) 887 QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx)
1003 { 888 {
1004 - if (! (kids.isArray() && (idx < kids.getArrayNItems()) &&  
1005 - kids.getArrayItem(idx).isDictionary()))  
1006 - { 889 + if (!(kids.isArray() && (idx < kids.getArrayNItems()) &&
  890 + kids.getArrayItem(idx).isDictionary())) {
1007 QTC::TC("qpdf", "NNTree kid is invalid"); 891 QTC::TC("qpdf", "NNTree kid is invalid");
1008 - error(qpdf, this->oh,  
1009 - "invalid kid at index " + QUtil::int_to_string(idx)); 892 + error(
  893 + qpdf,
  894 + this->oh,
  895 + "invalid kid at index " + QUtil::int_to_string(idx));
1010 } 896 }
1011 return withinLimits(key, kids.getArrayItem(idx)); 897 return withinLimits(key, kids.getArrayItem(idx));
1012 } 898 }
1013 899
1014 -  
1015 void 900 void
1016 NNTreeImpl::repair() 901 NNTreeImpl::repair()
1017 { 902 {
1018 auto new_node = QPDFObjectHandle::newDictionary(); 903 auto new_node = QPDFObjectHandle::newDictionary();
1019 new_node.replaceKey(details.itemsKey(), QPDFObjectHandle::newArray()); 904 new_node.replaceKey(details.itemsKey(), QPDFObjectHandle::newArray());
1020 NNTreeImpl repl(details, qpdf, new_node, false); 905 NNTreeImpl repl(details, qpdf, new_node, false);
1021 - for (auto const& i: *this)  
1022 - { 906 + for (auto const& i : *this) {
1023 repl.insert(i.first, i.second); 907 repl.insert(i.first, i.second);
1024 } 908 }
1025 this->oh.replaceKey("/Kids", new_node.getKey("/Kids")); 909 this->oh.replaceKey("/Kids", new_node.getKey("/Kids"));
@@ -1030,22 +914,18 @@ NNTreeImpl::repair() @@ -1030,22 +914,18 @@ NNTreeImpl::repair()
1030 NNTreeImpl::iterator 914 NNTreeImpl::iterator
1031 NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found) 915 NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found)
1032 { 916 {
1033 - try  
1034 - { 917 + try {
1035 return findInternal(key, return_prev_if_not_found); 918 return findInternal(key, return_prev_if_not_found);
1036 - }  
1037 - catch (QPDFExc& e)  
1038 - {  
1039 - if (this->auto_repair)  
1040 - { 919 + } catch (QPDFExc& e) {
  920 + if (this->auto_repair) {
1041 QTC::TC("qpdf", "NNTree repair"); 921 QTC::TC("qpdf", "NNTree repair");
1042 - warn(qpdf, this->oh,  
1043 - std::string("attempting to repair after error: ") + e.what()); 922 + warn(
  923 + qpdf,
  924 + this->oh,
  925 + std::string("attempting to repair after error: ") + e.what());
1044 repair(); 926 repair();
1045 return findInternal(key, return_prev_if_not_found); 927 return findInternal(key, return_prev_if_not_found);
1046 - }  
1047 - else  
1048 - { 928 + } else {
1049 throw e; 929 throw e;
1050 } 930 }
1051 } 931 }
@@ -1056,29 +936,21 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) @@ -1056,29 +936,21 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found)
1056 { 936 {
1057 auto first_item = begin(); 937 auto first_item = begin();
1058 auto last_item = end(); 938 auto last_item = end();
1059 - if (first_item == end())  
1060 - { 939 + if (first_item == end()) {
1061 // Empty 940 // Empty
1062 return end(); 941 return end();
1063 - }  
1064 - else if (first_item.valid() &&  
1065 - details.keyValid(first_item->first) &&  
1066 - details.compareKeys(key, first_item->first) < 0)  
1067 - { 942 + } else if (
  943 + first_item.valid() && details.keyValid(first_item->first) &&
  944 + details.compareKeys(key, first_item->first) < 0) {
1068 // Before the first key 945 // Before the first key
1069 return end(); 946 return end();
1070 - }  
1071 - else if (last_item.valid() &&  
1072 - details.keyValid(last_item->first) &&  
1073 - details.compareKeys(key, last_item->first) > 0)  
1074 - { 947 + } else if (
  948 + last_item.valid() && details.keyValid(last_item->first) &&
  949 + details.compareKeys(key, last_item->first) > 0) {
1075 // After the last key 950 // After the last key
1076 - if (return_prev_if_not_found)  
1077 - { 951 + if (return_prev_if_not_found) {
1078 return last_item; 952 return last_item;
1079 - }  
1080 - else  
1081 - { 953 + } else {
1082 return end(); 954 return end();
1083 } 955 }
1084 } 956 }
@@ -1087,11 +959,9 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) @@ -1087,11 +959,9 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found)
1087 auto node = this->oh; 959 auto node = this->oh;
1088 iterator result(*this); 960 iterator result(*this);
1089 961
1090 - while (true)  
1091 - { 962 + while (true) {
1092 auto og = node.getObjGen(); 963 auto og = node.getObjGen();
1093 - if (seen.count(og))  
1094 - { 964 + if (seen.count(og)) {
1095 QTC::TC("qpdf", "NNTree loop in find"); 965 QTC::TC("qpdf", "NNTree loop in find");
1096 error(qpdf, node, "loop detected in find"); 966 error(qpdf, node, "loop detected in find");
1097 } 967 }
@@ -1101,34 +971,31 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) @@ -1101,34 +971,31 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found)
1101 int nkids = kids.isArray() ? kids.getArrayNItems() : 0; 971 int nkids = kids.isArray() ? kids.getArrayNItems() : 0;
1102 auto items = node.getKey(details.itemsKey()); 972 auto items = node.getKey(details.itemsKey());
1103 int nitems = items.isArray() ? items.getArrayNItems() : 0; 973 int nitems = items.isArray() ? items.getArrayNItems() : 0;
1104 - if (nitems > 0)  
1105 - { 974 + if (nitems > 0) {
1106 int idx = binarySearch( 975 int idx = binarySearch(
1107 - key, items, nitems / 2, return_prev_if_not_found, 976 + key,
  977 + items,
  978 + nitems / 2,
  979 + return_prev_if_not_found,
1108 &NNTreeImpl::compareKeyItem); 980 &NNTreeImpl::compareKeyItem);
1109 - if (idx >= 0)  
1110 - { 981 + if (idx >= 0) {
1111 result.setItemNumber(node, 2 * idx); 982 result.setItemNumber(node, 2 * idx);
1112 } 983 }
1113 break; 984 break;
1114 - }  
1115 - else if (nkids > 0)  
1116 - { 985 + } else if (nkids > 0) {
1117 int idx = binarySearch( 986 int idx = binarySearch(
1118 - key, kids, nkids, true,  
1119 - &NNTreeImpl::compareKeyKid);  
1120 - if (idx == -1)  
1121 - { 987 + key, kids, nkids, true, &NNTreeImpl::compareKeyKid);
  988 + if (idx == -1) {
1122 QTC::TC("qpdf", "NNTree -1 in binary search"); 989 QTC::TC("qpdf", "NNTree -1 in binary search");
1123 - error(qpdf, node,  
1124 - "unexpected -1 from binary search of kids;"  
1125 - " limits may by wrong"); 990 + error(
  991 + qpdf,
  992 + node,
  993 + "unexpected -1 from binary search of kids;"
  994 + " limits may by wrong");
1126 } 995 }
1127 result.addPathElement(node, idx); 996 result.addPathElement(node, idx);
1128 node = kids.getArrayItem(idx); 997 node = kids.getArrayItem(idx);
1129 - }  
1130 - else  
1131 - { 998 + } else {
1132 QTC::TC("qpdf", "NNTree bad node during find"); 999 QTC::TC("qpdf", "NNTree bad node during find");
1133 error(qpdf, node, "bad node during find"); 1000 error(qpdf, node, "bad node during find");
1134 } 1001 }
@@ -1142,13 +1009,10 @@ NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value) @@ -1142,13 +1009,10 @@ NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value)
1142 { 1009 {
1143 auto iter = begin(); 1010 auto iter = begin();
1144 QPDFObjectHandle items; 1011 QPDFObjectHandle items;
1145 - if (iter.node.isInitialized() &&  
1146 - iter.node.isDictionary())  
1147 - { 1012 + if (iter.node.isInitialized() && iter.node.isDictionary()) {
1148 items = iter.node.getKey(details.itemsKey()); 1013 items = iter.node.getKey(details.itemsKey());
1149 } 1014 }
1150 - if (! (items.isInitialized() && items.isArray()))  
1151 - { 1015 + if (!(items.isInitialized() && items.isArray())) {
1152 QTC::TC("qpdf", "NNTree no valid items node in insertFirst"); 1016 QTC::TC("qpdf", "NNTree no valid items node in insertFirst");
1153 error(qpdf, this->oh, "unable to find a valid items node"); 1017 error(qpdf, this->oh, "unable to find a valid items node");
1154 } 1018 }
@@ -1164,20 +1028,15 @@ NNTreeImpl::iterator @@ -1164,20 +1028,15 @@ NNTreeImpl::iterator
1164 NNTreeImpl::insert(QPDFObjectHandle key, QPDFObjectHandle value) 1028 NNTreeImpl::insert(QPDFObjectHandle key, QPDFObjectHandle value)
1165 { 1029 {
1166 auto iter = find(key, true); 1030 auto iter = find(key, true);
1167 - if (! iter.valid())  
1168 - { 1031 + if (!iter.valid()) {
1169 QTC::TC("qpdf", "NNTree insert inserts first"); 1032 QTC::TC("qpdf", "NNTree insert inserts first");
1170 return insertFirst(key, value); 1033 return insertFirst(key, value);
1171 - }  
1172 - else if (details.compareKeys(key, iter->first) == 0)  
1173 - { 1034 + } else if (details.compareKeys(key, iter->first) == 0) {
1174 QTC::TC("qpdf", "NNTree insert replaces"); 1035 QTC::TC("qpdf", "NNTree insert replaces");
1175 auto items = iter.node.getKey(details.itemsKey()); 1036 auto items = iter.node.getKey(details.itemsKey());
1176 items.setArrayItem(iter.item_number + 1, value); 1037 items.setArrayItem(iter.item_number + 1, value);
1177 iter.updateIValue(); 1038 iter.updateIValue();
1178 - }  
1179 - else  
1180 - { 1039 + } else {
1181 QTC::TC("qpdf", "NNTree insert inserts after"); 1040 QTC::TC("qpdf", "NNTree insert inserts after");
1182 iter.insertAfter(key, value); 1041 iter.insertAfter(key, value);
1183 } 1042 }
@@ -1188,13 +1047,11 @@ bool @@ -1188,13 +1047,11 @@ bool
1188 NNTreeImpl::remove(QPDFObjectHandle key, QPDFObjectHandle* value) 1047 NNTreeImpl::remove(QPDFObjectHandle key, QPDFObjectHandle* value)
1189 { 1048 {
1190 auto iter = find(key, false); 1049 auto iter = find(key, false);
1191 - if (! iter.valid())  
1192 - { 1050 + if (!iter.valid()) {
1193 QTC::TC("qpdf", "NNTree remove not found"); 1051 QTC::TC("qpdf", "NNTree remove not found");
1194 return false; 1052 return false;
1195 } 1053 }
1196 - if (value)  
1197 - { 1054 + if (value) {
1198 *value = iter->second; 1055 *value = iter->second;
1199 } 1056 }
1200 iter.remove(); 1057 iter.remove();
libqpdf/OffsetInputSource.cc
@@ -4,13 +4,12 @@ @@ -4,13 +4,12 @@
4 #include <sstream> 4 #include <sstream>
5 #include <stdexcept> 5 #include <stdexcept>
6 6
7 -OffsetInputSource::OffsetInputSource(PointerHolder<InputSource> proxied,  
8 - qpdf_offset_t global_offset) : 7 +OffsetInputSource::OffsetInputSource(
  8 + PointerHolder<InputSource> proxied, qpdf_offset_t global_offset) :
9 proxied(proxied), 9 proxied(proxied),
10 global_offset(global_offset) 10 global_offset(global_offset)
11 { 11 {
12 - if (global_offset < 0)  
13 - { 12 + if (global_offset < 0) {
14 throw std::logic_error( 13 throw std::logic_error(
15 "OffsetInputSource constructed with negative offset"); 14 "OffsetInputSource constructed with negative offset");
16 } 15 }
@@ -43,25 +42,19 @@ OffsetInputSource::tell() @@ -43,25 +42,19 @@ OffsetInputSource::tell()
43 void 42 void
44 OffsetInputSource::seek(qpdf_offset_t offset, int whence) 43 OffsetInputSource::seek(qpdf_offset_t offset, int whence)
45 { 44 {
46 - if (whence == SEEK_SET)  
47 - {  
48 - if (offset > this->max_safe_offset)  
49 - { 45 + if (whence == SEEK_SET) {
  46 + if (offset > this->max_safe_offset) {
50 std::ostringstream msg; 47 std::ostringstream msg;
51 msg.imbue(std::locale::classic()); 48 msg.imbue(std::locale::classic());
52 - msg << "seeking to " << offset  
53 - << " offset by " << global_offset 49 + msg << "seeking to " << offset << " offset by " << global_offset
54 << " would cause an overflow of the offset type"; 50 << " would cause an overflow of the offset type";
55 throw std::range_error(msg.str()); 51 throw std::range_error(msg.str());
56 } 52 }
57 this->proxied->seek(offset + global_offset, whence); 53 this->proxied->seek(offset + global_offset, whence);
58 - }  
59 - else  
60 - { 54 + } else {
61 this->proxied->seek(offset, whence); 55 this->proxied->seek(offset, whence);
62 } 56 }
63 - if (tell() < 0)  
64 - { 57 + if (tell() < 0) {
65 throw std::runtime_error( 58 throw std::runtime_error(
66 "offset input source: seek before beginning of file"); 59 "offset input source: seek before beginning of file");
67 } 60 }
libqpdf/PDFVersion.cc
@@ -7,7 +7,8 @@ PDFVersion::PDFVersion() : @@ -7,7 +7,8 @@ PDFVersion::PDFVersion() :
7 { 7 {
8 } 8 }
9 9
10 -PDFVersion::PDFVersion(int major_version, int minor_version, int extension_level) : 10 +PDFVersion::PDFVersion(
  11 + int major_version, int minor_version, int extension_level) :
11 major_version(major_version), 12 major_version(major_version),
12 minor_version(minor_version), 13 minor_version(minor_version),
13 extension_level(extension_level) 14 extension_level(extension_level)
@@ -17,27 +18,28 @@ PDFVersion::PDFVersion(int major_version, int minor_version, int extension_level @@ -17,27 +18,28 @@ PDFVersion::PDFVersion(int major_version, int minor_version, int extension_level
17 bool 18 bool
18 PDFVersion::operator<(PDFVersion const& rhs) const 19 PDFVersion::operator<(PDFVersion const& rhs) const
19 { 20 {
20 - return ((this->major_version < rhs.major_version) ? true :  
21 - (this->major_version > rhs.major_version) ? false :  
22 - (this->minor_version < rhs.minor_version) ? true :  
23 - (this->minor_version > rhs.minor_version) ? false :  
24 - (this->extension_level < rhs.extension_level) ? true :  
25 - false); 21 + return (
  22 + (this->major_version < rhs.major_version) ? true
  23 + : (this->major_version > rhs.major_version) ? false
  24 + : (this->minor_version < rhs.minor_version) ? true
  25 + : (this->minor_version > rhs.minor_version) ? false
  26 + : (this->extension_level < rhs.extension_level) ? true
  27 + : false);
26 } 28 }
27 29
28 bool 30 bool
29 PDFVersion::operator==(PDFVersion const& rhs) const 31 PDFVersion::operator==(PDFVersion const& rhs) const
30 { 32 {
31 - return ((this->major_version == rhs.major_version) &&  
32 - (this->minor_version == rhs.minor_version) &&  
33 - (this->extension_level == rhs.extension_level)); 33 + return (
  34 + (this->major_version == rhs.major_version) &&
  35 + (this->minor_version == rhs.minor_version) &&
  36 + (this->extension_level == rhs.extension_level));
34 } 37 }
35 38
36 void 39 void
37 PDFVersion::updateIfGreater(PDFVersion const& other) 40 PDFVersion::updateIfGreater(PDFVersion const& other)
38 { 41 {
39 - if (*this < other)  
40 - { 42 + if (*this < other) {
41 *this = other; 43 *this = other;
42 } 44 }
43 } 45 }
libqpdf/Pipeline.cc
@@ -15,8 +15,7 @@ Pipeline::~Pipeline() @@ -15,8 +15,7 @@ Pipeline::~Pipeline()
15 Pipeline* 15 Pipeline*
16 Pipeline::getNext(bool allow_null) 16 Pipeline::getNext(bool allow_null)
17 { 17 {
18 - if ((this->next == 0) && (! allow_null))  
19 - { 18 + if ((this->next == 0) && (!allow_null)) {
20 throw std::logic_error( 19 throw std::logic_error(
21 this->identifier + 20 this->identifier +
22 ": Pipeline::getNext() called on pipeline with no next"); 21 ": Pipeline::getNext() called on pipeline with no next");
libqpdf/Pl_AES_PDF.cc
1 #include <qpdf/Pl_AES_PDF.hh> 1 #include <qpdf/Pl_AES_PDF.hh>
2 2
  3 +#include <qpdf/QIntC.hh>
  4 +#include <qpdf/QPDFCryptoProvider.hh>
3 #include <qpdf/QUtil.hh> 5 #include <qpdf/QUtil.hh>
4 -#include <cstring>  
5 #include <assert.h> 6 #include <assert.h>
  7 +#include <cstring>
6 #include <stdexcept> 8 #include <stdexcept>
7 -#include <qpdf/QIntC.hh>  
8 -#include <qpdf/QPDFCryptoProvider.hh>  
9 -#include <string>  
10 #include <stdlib.h> 9 #include <stdlib.h>
  10 +#include <string>
11 11
12 bool Pl_AES_PDF::use_static_iv = false; 12 bool Pl_AES_PDF::use_static_iv = false;
13 13
14 -Pl_AES_PDF::Pl_AES_PDF(char const* identifier, Pipeline* next,  
15 - bool encrypt, unsigned char const* key,  
16 - size_t key_bytes) : 14 +Pl_AES_PDF::Pl_AES_PDF(
  15 + char const* identifier,
  16 + Pipeline* next,
  17 + bool encrypt,
  18 + unsigned char const* key,
  19 + size_t key_bytes) :
17 Pipeline(identifier, next), 20 Pipeline(identifier, next),
18 crypto(QPDFCryptoProvider::getImpl()), 21 crypto(QPDFCryptoProvider::getImpl()),
19 encrypt(encrypt), 22 encrypt(encrypt),
@@ -51,11 +54,11 @@ Pl_AES_PDF::disablePadding() @@ -51,11 +54,11 @@ Pl_AES_PDF::disablePadding()
51 void 54 void
52 Pl_AES_PDF::setIV(unsigned char const* iv, size_t bytes) 55 Pl_AES_PDF::setIV(unsigned char const* iv, size_t bytes)
53 { 56 {
54 - if (bytes != this->buf_size)  
55 - { 57 + if (bytes != this->buf_size) {
56 throw std::logic_error( 58 throw std::logic_error(
57 "Pl_AES_PDF: specified initialization vector" 59 "Pl_AES_PDF: specified initialization vector"
58 - " size in bytes must be " + QUtil::uint_to_string(bytes)); 60 + " size in bytes must be " +
  61 + QUtil::uint_to_string(bytes));
59 } 62 }
60 this->use_specified_iv = true; 63 this->use_specified_iv = true;
61 memcpy(this->specified_iv, iv, bytes); 64 memcpy(this->specified_iv, iv, bytes);
@@ -79,10 +82,8 @@ Pl_AES_PDF::write(unsigned char* data, size_t len) @@ -79,10 +82,8 @@ Pl_AES_PDF::write(unsigned char* data, size_t len)
79 size_t bytes_left = len; 82 size_t bytes_left = len;
80 unsigned char* p = data; 83 unsigned char* p = data;
81 84
82 - while (bytes_left > 0)  
83 - {  
84 - if (this->offset == this->buf_size)  
85 - { 85 + while (bytes_left > 0) {
  86 + if (this->offset == this->buf_size) {
86 flush(false); 87 flush(false);
87 } 88 }
88 89
@@ -98,39 +99,32 @@ Pl_AES_PDF::write(unsigned char* data, size_t len) @@ -98,39 +99,32 @@ Pl_AES_PDF::write(unsigned char* data, size_t len)
98 void 99 void
99 Pl_AES_PDF::finish() 100 Pl_AES_PDF::finish()
100 { 101 {
101 - if (this->encrypt)  
102 - {  
103 - if (this->offset == this->buf_size)  
104 - { 102 + if (this->encrypt) {
  103 + if (this->offset == this->buf_size) {
105 flush(false); 104 flush(false);
106 } 105 }
107 - if (! this->disable_padding)  
108 - { 106 + if (!this->disable_padding) {
109 // Pad as described in section 3.5.1 of version 1.7 of the PDF 107 // Pad as described in section 3.5.1 of version 1.7 of the PDF
110 // specification, including providing an entire block of padding 108 // specification, including providing an entire block of padding
111 // if the input was a multiple of 16 bytes. 109 // if the input was a multiple of 16 bytes.
112 - unsigned char pad =  
113 - QIntC::to_uchar(this->buf_size - this->offset); 110 + unsigned char pad = QIntC::to_uchar(this->buf_size - this->offset);
114 memset(this->inbuf + this->offset, pad, pad); 111 memset(this->inbuf + this->offset, pad, pad);
115 this->offset = this->buf_size; 112 this->offset = this->buf_size;
116 flush(false); 113 flush(false);
117 } 114 }
118 - }  
119 - else  
120 - {  
121 - if (this->offset != this->buf_size)  
122 - { 115 + } else {
  116 + if (this->offset != this->buf_size) {
123 // This is never supposed to happen as the output is 117 // This is never supposed to happen as the output is
124 // always supposed to be padded. However, we have 118 // always supposed to be padded. However, we have
125 // encountered files for which the output is not a 119 // encountered files for which the output is not a
126 // multiple of the block size. In this case, pad with 120 // multiple of the block size. In this case, pad with
127 // zeroes and hope for the best. 121 // zeroes and hope for the best.
128 assert(this->buf_size > this->offset); 122 assert(this->buf_size > this->offset);
129 - std::memset(this->inbuf + this->offset, 0,  
130 - this->buf_size - this->offset); 123 + std::memset(
  124 + this->inbuf + this->offset, 0, this->buf_size - this->offset);
131 this->offset = this->buf_size; 125 this->offset = this->buf_size;
132 } 126 }
133 - flush(! this->disable_padding); 127 + flush(!this->disable_padding);
134 } 128 }
135 this->crypto->rijndael_finalize(); 129 this->crypto->rijndael_finalize();
136 getNext()->finish(); 130 getNext()->finish();
@@ -139,26 +133,17 @@ Pl_AES_PDF::finish() @@ -139,26 +133,17 @@ Pl_AES_PDF::finish()
139 void 133 void
140 Pl_AES_PDF::initializeVector() 134 Pl_AES_PDF::initializeVector()
141 { 135 {
142 - if (use_zero_iv)  
143 - {  
144 - for (unsigned int i = 0; i < this->buf_size; ++i)  
145 - { 136 + if (use_zero_iv) {
  137 + for (unsigned int i = 0; i < this->buf_size; ++i) {
146 this->cbc_block[i] = 0; 138 this->cbc_block[i] = 0;
147 } 139 }
148 - }  
149 - else if (use_specified_iv)  
150 - { 140 + } else if (use_specified_iv) {
151 std::memcpy(this->cbc_block, this->specified_iv, this->buf_size); 141 std::memcpy(this->cbc_block, this->specified_iv, this->buf_size);
152 - }  
153 - else if (use_static_iv)  
154 - {  
155 - for (unsigned int i = 0; i < this->buf_size; ++i)  
156 - { 142 + } else if (use_static_iv) {
  143 + for (unsigned int i = 0; i < this->buf_size; ++i) {
157 this->cbc_block[i] = static_cast<unsigned char>(14U * (1U + i)); 144 this->cbc_block[i] = static_cast<unsigned char>(14U * (1U + i));
158 } 145 }
159 - }  
160 - else  
161 - { 146 + } else {
162 QUtil::initializeWithRandomBytes(this->cbc_block, this->buf_size); 147 QUtil::initializeWithRandomBytes(this->cbc_block, this->buf_size);
163 } 148 }
164 } 149 }
@@ -168,30 +153,22 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -168,30 +153,22 @@ Pl_AES_PDF::flush(bool strip_padding)
168 { 153 {
169 assert(this->offset == this->buf_size); 154 assert(this->offset == this->buf_size);
170 155
171 - if (first)  
172 - { 156 + if (first) {
173 first = false; 157 first = false;
174 bool return_after_init = false; 158 bool return_after_init = false;
175 - if (this->cbc_mode)  
176 - {  
177 - if (encrypt)  
178 - { 159 + if (this->cbc_mode) {
  160 + if (encrypt) {
179 // Set cbc_block to the initialization vector, and if 161 // Set cbc_block to the initialization vector, and if
180 // not zero, write it to the output stream. 162 // not zero, write it to the output stream.
181 initializeVector(); 163 initializeVector();
182 - if (! (this->use_zero_iv || this->use_specified_iv))  
183 - { 164 + if (!(this->use_zero_iv || this->use_specified_iv)) {
184 getNext()->write(this->cbc_block, this->buf_size); 165 getNext()->write(this->cbc_block, this->buf_size);
185 } 166 }
186 - }  
187 - else if (this->use_zero_iv || this->use_specified_iv)  
188 - { 167 + } else if (this->use_zero_iv || this->use_specified_iv) {
189 // Initialize vector with zeroes; zero vector was not 168 // Initialize vector with zeroes; zero vector was not
190 // written to the beginning of the input file. 169 // written to the beginning of the input file.
191 initializeVector(); 170 initializeVector();
192 - }  
193 - else  
194 - { 171 + } else {
195 // Take the first block of input as the initialization 172 // Take the first block of input as the initialization
196 // vector. There's nothing to write at this time. 173 // vector. There's nothing to write at this time.
197 memcpy(this->cbc_block, this->inbuf, this->buf_size); 174 memcpy(this->cbc_block, this->inbuf, this->buf_size);
@@ -200,32 +177,29 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -200,32 +177,29 @@ Pl_AES_PDF::flush(bool strip_padding)
200 } 177 }
201 } 178 }
202 this->crypto->rijndael_init( 179 this->crypto->rijndael_init(
203 - encrypt, this->key.get(), key_bytes,  
204 - this->cbc_mode, this->cbc_block);  
205 - if (return_after_init)  
206 - { 180 + encrypt,
  181 + this->key.get(),
  182 + key_bytes,
  183 + this->cbc_mode,
  184 + this->cbc_block);
  185 + if (return_after_init) {
207 return; 186 return;
208 } 187 }
209 } 188 }
210 189
211 this->crypto->rijndael_process(this->inbuf, this->outbuf); 190 this->crypto->rijndael_process(this->inbuf, this->outbuf);
212 unsigned int bytes = this->buf_size; 191 unsigned int bytes = this->buf_size;
213 - if (strip_padding)  
214 - { 192 + if (strip_padding) {
215 unsigned char last = this->outbuf[this->buf_size - 1]; 193 unsigned char last = this->outbuf[this->buf_size - 1];
216 - if (last <= this->buf_size)  
217 - { 194 + if (last <= this->buf_size) {
218 bool strip = true; 195 bool strip = true;
219 - for (unsigned int i = 1; i <= last; ++i)  
220 - {  
221 - if (this->outbuf[this->buf_size - i] != last)  
222 - { 196 + for (unsigned int i = 1; i <= last; ++i) {
  197 + if (this->outbuf[this->buf_size - i] != last) {
223 strip = false; 198 strip = false;
224 break; 199 break;
225 } 200 }
226 } 201 }
227 - if (strip)  
228 - { 202 + if (strip) {
229 bytes -= last; 203 bytes -= last;
230 } 204 }
231 } 205 }
libqpdf/Pl_ASCII85Decoder.cc
@@ -19,55 +19,41 @@ Pl_ASCII85Decoder::~Pl_ASCII85Decoder() @@ -19,55 +19,41 @@ Pl_ASCII85Decoder::~Pl_ASCII85Decoder()
19 void 19 void
20 Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) 20 Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
21 { 21 {
22 - if (eod > 1)  
23 - { 22 + if (eod > 1) {
24 return; 23 return;
25 } 24 }
26 - for (size_t i = 0; i < len; ++i)  
27 - {  
28 - if (eod > 1)  
29 - { 25 + for (size_t i = 0; i < len; ++i) {
  26 + if (eod > 1) {
30 break; 27 break;
31 - }  
32 - else if (eod == 1)  
33 - {  
34 - if (buf[i] == '>')  
35 - { 28 + } else if (eod == 1) {
  29 + if (buf[i] == '>') {
36 flush(); 30 flush();
37 eod = 2; 31 eod = 2;
38 - }  
39 - else  
40 - { 32 + } else {
41 throw std::runtime_error( 33 throw std::runtime_error(
42 "broken end-of-data sequence in base 85 data"); 34 "broken end-of-data sequence in base 85 data");
43 } 35 }
44 - }  
45 - else  
46 - {  
47 - switch (buf[i])  
48 - {  
49 - case ' ':  
50 - case '\f':  
51 - case '\v':  
52 - case '\t':  
53 - case '\r':  
54 - case '\n': 36 + } else {
  37 + switch (buf[i]) {
  38 + case ' ':
  39 + case '\f':
  40 + case '\v':
  41 + case '\t':
  42 + case '\r':
  43 + case '\n':
55 QTC::TC("libtests", "Pl_ASCII85Decoder ignore space"); 44 QTC::TC("libtests", "Pl_ASCII85Decoder ignore space");
56 // ignore whitespace 45 // ignore whitespace
57 break; 46 break;
58 47
59 - case '~': 48 + case '~':
60 eod = 1; 49 eod = 1;
61 break; 50 break;
62 51
63 - case 'z':  
64 - if (pos != 0)  
65 - { 52 + case 'z':
  53 + if (pos != 0) {
66 throw std::runtime_error( 54 throw std::runtime_error(
67 "unexpected z during base 85 decode"); 55 "unexpected z during base 85 decode");
68 - }  
69 - else  
70 - { 56 + } else {
71 QTC::TC("libtests", "Pl_ASCII85Decoder read z"); 57 QTC::TC("libtests", "Pl_ASCII85Decoder read z");
72 unsigned char zeroes[4]; 58 unsigned char zeroes[4];
73 memset(zeroes, '\0', 4); 59 memset(zeroes, '\0', 4);
@@ -75,17 +61,13 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) @@ -75,17 +61,13 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
75 } 61 }
76 break; 62 break;
77 63
78 - default:  
79 - if ((buf[i] < 33) || (buf[i] > 117))  
80 - { 64 + default:
  65 + if ((buf[i] < 33) || (buf[i] > 117)) {
81 throw std::runtime_error( 66 throw std::runtime_error(
82 "character out of range during base 85 decode"); 67 "character out of range during base 85 decode");
83 - }  
84 - else  
85 - { 68 + } else {
86 this->inbuf[this->pos++] = buf[i]; 69 this->inbuf[this->pos++] = buf[i];
87 - if (pos == 5)  
88 - { 70 + if (pos == 5) {
89 flush(); 71 flush();
90 } 72 }
91 } 73 }
@@ -98,28 +80,27 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) @@ -98,28 +80,27 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
98 void 80 void
99 Pl_ASCII85Decoder::flush() 81 Pl_ASCII85Decoder::flush()
100 { 82 {
101 - if (this->pos == 0)  
102 - { 83 + if (this->pos == 0) {
103 QTC::TC("libtests", "Pl_ASCII85Decoder no-op flush"); 84 QTC::TC("libtests", "Pl_ASCII85Decoder no-op flush");
104 return; 85 return;
105 } 86 }
106 unsigned long lval = 0; 87 unsigned long lval = 0;
107 - for (int i = 0; i < 5; ++i)  
108 - { 88 + for (int i = 0; i < 5; ++i) {
109 lval *= 85; 89 lval *= 85;
110 lval += (this->inbuf[i] - 33U); 90 lval += (this->inbuf[i] - 33U);
111 } 91 }
112 92
113 unsigned char outbuf[4]; 93 unsigned char outbuf[4];
114 memset(outbuf, 0, 4); 94 memset(outbuf, 0, 4);
115 - for (int i = 3; i >= 0; --i)  
116 - { 95 + for (int i = 3; i >= 0; --i) {
117 outbuf[i] = lval & 0xff; 96 outbuf[i] = lval & 0xff;
118 lval >>= 8; 97 lval >>= 8;
119 } 98 }
120 99
121 - QTC::TC("libtests", "Pl_ASCII85Decoder partial flush",  
122 - (this->pos == 5) ? 0 : 1); 100 + QTC::TC(
  101 + "libtests",
  102 + "Pl_ASCII85Decoder partial flush",
  103 + (this->pos == 5) ? 0 : 1);
123 // Reset before calling getNext()->write in case that throws an 104 // Reset before calling getNext()->write in case that throws an
124 // exception. 105 // exception.
125 auto t = this->pos - 1; 106 auto t = this->pos - 1;
libqpdf/Pl_ASCIIHexDecoder.cc
1 #include <qpdf/Pl_ASCIIHexDecoder.hh> 1 #include <qpdf/Pl_ASCIIHexDecoder.hh>
2 2
3 #include <qpdf/QTC.hh> 3 #include <qpdf/QTC.hh>
  4 +#include <ctype.h>
4 #include <stdexcept> 5 #include <stdexcept>
5 #include <string.h> 6 #include <string.h>
6 -#include <ctype.h>  
7 7
8 Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) : 8 Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) :
9 Pipeline(identifier, next), 9 Pipeline(identifier, next),
@@ -22,53 +22,45 @@ Pl_ASCIIHexDecoder::~Pl_ASCIIHexDecoder() @@ -22,53 +22,45 @@ Pl_ASCIIHexDecoder::~Pl_ASCIIHexDecoder()
22 void 22 void
23 Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len) 23 Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len)
24 { 24 {
25 - if (this->eod)  
26 - { 25 + if (this->eod) {
27 return; 26 return;
28 } 27 }
29 - for (size_t i = 0; i < len; ++i)  
30 - { 28 + for (size_t i = 0; i < len; ++i) {
31 char ch = static_cast<char>(toupper(buf[i])); 29 char ch = static_cast<char>(toupper(buf[i]));
32 - switch (ch)  
33 - {  
34 - case ' ':  
35 - case '\f':  
36 - case '\v':  
37 - case '\t':  
38 - case '\r':  
39 - case '\n': 30 + switch (ch) {
  31 + case ' ':
  32 + case '\f':
  33 + case '\v':
  34 + case '\t':
  35 + case '\r':
  36 + case '\n':
40 QTC::TC("libtests", "Pl_ASCIIHexDecoder ignore space"); 37 QTC::TC("libtests", "Pl_ASCIIHexDecoder ignore space");
41 // ignore whitespace 38 // ignore whitespace
42 break; 39 break;
43 40
44 - case '>': 41 + case '>':
45 this->eod = true; 42 this->eod = true;
46 flush(); 43 flush();
47 break; 44 break;
48 45
49 - default:  
50 - if (((ch >= '0') && (ch <= '9')) ||  
51 - ((ch >= 'A') && (ch <= 'F')))  
52 - { 46 + default:
  47 + if (((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'F'))) {
53 this->inbuf[this->pos++] = ch; 48 this->inbuf[this->pos++] = ch;
54 - if (this->pos == 2)  
55 - { 49 + if (this->pos == 2) {
56 flush(); 50 flush();
57 } 51 }
58 - }  
59 - else  
60 - { 52 + } else {
61 char t[2]; 53 char t[2];
62 t[0] = ch; 54 t[0] = ch;
63 t[1] = 0; 55 t[1] = 0;
64 throw std::runtime_error( 56 throw std::runtime_error(
65 std::string("character out of range" 57 std::string("character out of range"
66 - " during base Hex decode: ") + t); 58 + " during base Hex decode: ") +
  59 + t);
67 } 60 }
68 break; 61 break;
69 } 62 }
70 - if (this->eod)  
71 - { 63 + if (this->eod) {
72 break; 64 break;
73 } 65 }
74 } 66 }
@@ -77,27 +69,24 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len) @@ -77,27 +69,24 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len)
77 void 69 void
78 Pl_ASCIIHexDecoder::flush() 70 Pl_ASCIIHexDecoder::flush()
79 { 71 {
80 - if (this->pos == 0)  
81 - { 72 + if (this->pos == 0) {
82 QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush"); 73 QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush");
83 return; 74 return;
84 } 75 }
85 int b[2]; 76 int b[2];
86 - for (int i = 0; i < 2; ++i)  
87 - {  
88 - if (this->inbuf[i] >= 'A')  
89 - { 77 + for (int i = 0; i < 2; ++i) {
  78 + if (this->inbuf[i] >= 'A') {
90 b[i] = this->inbuf[i] - 'A' + 10; 79 b[i] = this->inbuf[i] - 'A' + 10;
91 - }  
92 - else  
93 - { 80 + } else {
94 b[i] = this->inbuf[i] - '0'; 81 b[i] = this->inbuf[i] - '0';
95 } 82 }
96 } 83 }
97 unsigned char ch = static_cast<unsigned char>((b[0] << 4) + b[1]); 84 unsigned char ch = static_cast<unsigned char>((b[0] << 4) + b[1]);
98 85
99 - QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush",  
100 - (this->pos == 2) ? 0 : 1); 86 + QTC::TC(
  87 + "libtests",
  88 + "Pl_ASCIIHexDecoder partial flush",
  89 + (this->pos == 2) ? 0 : 1);
101 // Reset before calling getNext()->write in case that throws an 90 // Reset before calling getNext()->write in case that throws an
102 // exception. 91 // exception.
103 this->pos = 0; 92 this->pos = 0;
libqpdf/Pl_Buffer.cc
1 #include <qpdf/Pl_Buffer.hh> 1 #include <qpdf/Pl_Buffer.hh>
2 2
3 -#include <stdexcept>  
4 #include <algorithm> 3 #include <algorithm>
5 #include <assert.h> 4 #include <assert.h>
6 -#include <string.h> 5 +#include <stdexcept>
7 #include <stdlib.h> 6 #include <stdlib.h>
  7 +#include <string.h>
8 8
9 Pl_Buffer::Members::Members() : 9 Pl_Buffer::Members::Members() :
10 ready(true), 10 ready(true),
@@ -29,28 +29,24 @@ Pl_Buffer::~Pl_Buffer() @@ -29,28 +29,24 @@ Pl_Buffer::~Pl_Buffer()
29 void 29 void
30 Pl_Buffer::write(unsigned char* buf, size_t len) 30 Pl_Buffer::write(unsigned char* buf, size_t len)
31 { 31 {
32 - if (this->m->data.get() == 0)  
33 - { 32 + if (this->m->data.get() == 0) {
34 this->m->data = make_pointer_holder<Buffer>(len); 33 this->m->data = make_pointer_holder<Buffer>(len);
35 } 34 }
36 size_t cur_size = this->m->data->getSize(); 35 size_t cur_size = this->m->data->getSize();
37 size_t left = cur_size - this->m->total_size; 36 size_t left = cur_size - this->m->total_size;
38 - if (left < len)  
39 - { 37 + if (left < len) {
40 size_t new_size = std::max(this->m->total_size + len, 2 * cur_size); 38 size_t new_size = std::max(this->m->total_size + len, 2 * cur_size);
41 auto b = make_pointer_holder<Buffer>(new_size); 39 auto b = make_pointer_holder<Buffer>(new_size);
42 memcpy(b->getBuffer(), this->m->data->getBuffer(), this->m->total_size); 40 memcpy(b->getBuffer(), this->m->data->getBuffer(), this->m->total_size);
43 this->m->data = b; 41 this->m->data = b;
44 } 42 }
45 - if (len)  
46 - { 43 + if (len) {
47 memcpy(this->m->data->getBuffer() + this->m->total_size, buf, len); 44 memcpy(this->m->data->getBuffer() + this->m->total_size, buf, len);
48 this->m->total_size += len; 45 this->m->total_size += len;
49 } 46 }
50 this->m->ready = false; 47 this->m->ready = false;
51 48
52 - if (getNext(true))  
53 - { 49 + if (getNext(true)) {
54 getNext()->write(buf, len); 50 getNext()->write(buf, len);
55 } 51 }
56 } 52 }
@@ -59,8 +55,7 @@ void @@ -59,8 +55,7 @@ void
59 Pl_Buffer::finish() 55 Pl_Buffer::finish()
60 { 56 {
61 this->m->ready = true; 57 this->m->ready = true;
62 - if (getNext(true))  
63 - { 58 + if (getNext(true)) {
64 getNext()->finish(); 59 getNext()->finish();
65 } 60 }
66 } 61 }
@@ -68,14 +63,12 @@ Pl_Buffer::finish() @@ -68,14 +63,12 @@ Pl_Buffer::finish()
68 Buffer* 63 Buffer*
69 Pl_Buffer::getBuffer() 64 Pl_Buffer::getBuffer()
70 { 65 {
71 - if (! this->m->ready)  
72 - { 66 + if (!this->m->ready) {
73 throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); 67 throw std::logic_error("Pl_Buffer::getBuffer() called when not ready");
74 } 68 }
75 69
76 Buffer* b = new Buffer(this->m->total_size); 70 Buffer* b = new Buffer(this->m->total_size);
77 - if (this->m->total_size > 0)  
78 - { 71 + if (this->m->total_size > 0) {
79 unsigned char* p = b->getBuffer(); 72 unsigned char* p = b->getBuffer();
80 memcpy(p, this->m->data->getBuffer(), this->m->total_size); 73 memcpy(p, this->m->data->getBuffer(), this->m->total_size);
81 } 74 }
@@ -90,22 +83,18 @@ Pl_Buffer::getBufferSharedPointer() @@ -90,22 +83,18 @@ Pl_Buffer::getBufferSharedPointer()
90 } 83 }
91 84
92 void 85 void
93 -Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len) 86 +Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len)
94 { 87 {
95 - if (! this->m->ready)  
96 - { 88 + if (!this->m->ready) {
97 throw std::logic_error( 89 throw std::logic_error(
98 "Pl_Buffer::getMallocBuffer() called when not ready"); 90 "Pl_Buffer::getMallocBuffer() called when not ready");
99 } 91 }
100 92
101 *len = this->m->total_size; 93 *len = this->m->total_size;
102 - if (this->m->total_size > 0)  
103 - { 94 + if (this->m->total_size > 0) {
104 *buf = reinterpret_cast<unsigned char*>(malloc(this->m->total_size)); 95 *buf = reinterpret_cast<unsigned char*>(malloc(this->m->total_size));
105 memcpy(*buf, this->m->data->getBuffer(), this->m->total_size); 96 memcpy(*buf, this->m->data->getBuffer(), this->m->total_size);
106 - }  
107 - else  
108 - { 97 + } else {
109 *buf = nullptr; 98 *buf = nullptr;
110 } 99 }
111 this->m = PointerHolder<Members>(new Members()); 100 this->m = PointerHolder<Members>(new Members());
libqpdf/Pl_Concatenate.cc
@@ -33,4 +33,3 @@ Pl_Concatenate::manualFinish() @@ -33,4 +33,3 @@ Pl_Concatenate::manualFinish()
33 { 33 {
34 getNext()->finish(); 34 getNext()->finish();
35 } 35 }
36 -  
libqpdf/Pl_Count.cc
@@ -25,8 +25,7 @@ Pl_Count::~Pl_Count() @@ -25,8 +25,7 @@ Pl_Count::~Pl_Count()
25 void 25 void
26 Pl_Count::write(unsigned char* buf, size_t len) 26 Pl_Count::write(unsigned char* buf, size_t len)
27 { 27 {
28 - if (len)  
29 - { 28 + if (len) {
30 this->m->count += QIntC::to_offset(len); 29 this->m->count += QIntC::to_offset(len);
31 this->m->last_char = buf[len - 1]; 30 this->m->last_char = buf[len - 1];
32 getNext()->write(buf, len); 31 getNext()->write(buf, len);
libqpdf/Pl_DCT.cc
1 #include <qpdf/Pl_DCT.hh> 1 #include <qpdf/Pl_DCT.hh>
2 2
3 -#include <qpdf/QUtil.hh>  
4 -#include <qpdf/QTC.hh>  
5 #include <qpdf/QIntC.hh> 3 #include <qpdf/QIntC.hh>
  4 +#include <qpdf/QTC.hh>
  5 +#include <qpdf/QUtil.hh>
6 6
  7 +#include <cstring>
7 #include <setjmp.h> 8 #include <setjmp.h>
8 #include <stdexcept> 9 #include <stdexcept>
9 #include <stdlib.h> 10 #include <stdlib.h>
10 #include <string> 11 #include <string>
11 -#include <cstring>  
12 12
13 #if BITS_IN_JSAMPLE != 8 13 #if BITS_IN_JSAMPLE != 8
14 # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8" 14 # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8"
@@ -32,13 +32,14 @@ error_handler(j_common_ptr cinfo) @@ -32,13 +32,14 @@ error_handler(j_common_ptr cinfo)
32 longjmp(jerr->jmpbuf, 1); 32 longjmp(jerr->jmpbuf, 1);
33 } 33 }
34 34
35 -Pl_DCT::Members::Members(action_e action,  
36 - char const* buf_description,  
37 - JDIMENSION image_width,  
38 - JDIMENSION image_height,  
39 - int components,  
40 - J_COLOR_SPACE color_space,  
41 - CompressConfig* config_callback) : 35 +Pl_DCT::Members::Members(
  36 + action_e action,
  37 + char const* buf_description,
  38 + JDIMENSION image_width,
  39 + JDIMENSION image_height,
  40 + int components,
  41 + J_COLOR_SPACE color_space,
  42 + CompressConfig* config_callback) :
42 action(action), 43 action(action),
43 buf(buf_description), 44 buf(buf_description),
44 image_width(image_width), 45 image_width(image_width),
@@ -59,15 +60,23 @@ Pl_DCT::Pl_DCT(char const* identifier, Pipeline* next) : @@ -59,15 +60,23 @@ Pl_DCT::Pl_DCT(char const* identifier, Pipeline* next) :
59 { 60 {
60 } 61 }
61 62
62 -Pl_DCT::Pl_DCT(char const* identifier, Pipeline* next,  
63 - JDIMENSION image_width,  
64 - JDIMENSION image_height,  
65 - int components,  
66 - J_COLOR_SPACE color_space,  
67 - CompressConfig* config_callback) : 63 +Pl_DCT::Pl_DCT(
  64 + char const* identifier,
  65 + Pipeline* next,
  66 + JDIMENSION image_width,
  67 + JDIMENSION image_height,
  68 + int components,
  69 + J_COLOR_SPACE color_space,
  70 + CompressConfig* config_callback) :
68 Pipeline(identifier, next), 71 Pipeline(identifier, next),
69 - m(new Members(a_compress, "DCT uncompressed image",  
70 - image_width, image_height, components, color_space, config_callback)) 72 + m(new Members(
  73 + a_compress,
  74 + "DCT uncompressed image",
  75 + image_width,
  76 + image_height,
  77 + components,
  78 + color_space,
  79 + config_callback))
71 { 80 {
72 } 81 }
73 82
@@ -90,8 +99,7 @@ Pl_DCT::finish() @@ -90,8 +99,7 @@ Pl_DCT::finish()
90 // and decompress causes a memory leak with setjmp/longjmp. Just 99 // and decompress causes a memory leak with setjmp/longjmp. Just
91 // use a pointer and delete it. 100 // use a pointer and delete it.
92 Buffer* b = this->m->buf.getBuffer(); 101 Buffer* b = this->m->buf.getBuffer();
93 - if (b->getSize() == 0)  
94 - { 102 + if (b->getSize() == 0) {
95 // Special case: empty data will never succeed and probably 103 // Special case: empty data will never succeed and probably
96 // means we're calling finish a second time from an exception 104 // means we're calling finish a second time from an exception
97 // handler. 105 // handler.
@@ -111,44 +119,32 @@ Pl_DCT::finish() @@ -111,44 +119,32 @@ Pl_DCT::finish()
111 bool error = false; 119 bool error = false;
112 // The jpeg library is a "C" library, so we use setjmp and longjmp 120 // The jpeg library is a "C" library, so we use setjmp and longjmp
113 // for exception handling. 121 // for exception handling.
114 - if (setjmp(jerr.jmpbuf) == 0)  
115 - {  
116 - try  
117 - {  
118 - if (this->m->action == a_compress)  
119 - { 122 + if (setjmp(jerr.jmpbuf) == 0) {
  123 + try {
  124 + if (this->m->action == a_compress) {
120 compress(reinterpret_cast<void*>(&cinfo_compress), b); 125 compress(reinterpret_cast<void*>(&cinfo_compress), b);
121 - }  
122 - else  
123 - { 126 + } else {
124 decompress(reinterpret_cast<void*>(&cinfo_decompress), b); 127 decompress(reinterpret_cast<void*>(&cinfo_decompress), b);
125 } 128 }
126 - }  
127 - catch (std::exception& e)  
128 - { 129 + } catch (std::exception& e) {
129 // Convert an exception back to a longjmp so we can ensure 130 // Convert an exception back to a longjmp so we can ensure
130 // that the right cleanup happens. This will get converted 131 // that the right cleanup happens. This will get converted
131 // back to an exception. 132 // back to an exception.
132 jerr.msg = e.what(); 133 jerr.msg = e.what();
133 longjmp(jerr.jmpbuf, 1); 134 longjmp(jerr.jmpbuf, 1);
134 } 135 }
135 - }  
136 - else  
137 - { 136 + } else {
138 error = true; 137 error = true;
139 } 138 }
140 delete b; 139 delete b;
141 140
142 - if (this->m->action == a_compress)  
143 - { 141 + if (this->m->action == a_compress) {
144 jpeg_destroy_compress(&cinfo_compress); 142 jpeg_destroy_compress(&cinfo_compress);
145 } 143 }
146 - if (this->m->action == a_decompress)  
147 - { 144 + if (this->m->action == a_decompress) {
148 jpeg_destroy_decompress(&cinfo_decompress); 145 jpeg_destroy_decompress(&cinfo_decompress);
149 } 146 }
150 - if (error)  
151 - { 147 + if (error) {
152 throw std::runtime_error(jerr.msg); 148 throw std::runtime_error(jerr.msg);
153 } 149 }
154 } 150 }
@@ -170,8 +166,7 @@ static boolean @@ -170,8 +166,7 @@ static boolean
170 empty_pipeline_output_buffer(j_compress_ptr cinfo) 166 empty_pipeline_output_buffer(j_compress_ptr cinfo)
171 { 167 {
172 QTC::TC("libtests", "Pl_DCT empty_pipeline_output_buffer"); 168 QTC::TC("libtests", "Pl_DCT empty_pipeline_output_buffer");
173 - dct_pipeline_dest* dest =  
174 - reinterpret_cast<dct_pipeline_dest*>(cinfo->dest); 169 + dct_pipeline_dest* dest = reinterpret_cast<dct_pipeline_dest*>(cinfo->dest);
175 dest->next->write(dest->buffer, dest->size); 170 dest->next->write(dest->buffer, dest->size);
176 dest->pub.next_output_byte = dest->buffer; 171 dest->pub.next_output_byte = dest->buffer;
177 dest->pub.free_in_buffer = dest->size; 172 dest->pub.free_in_buffer = dest->size;
@@ -182,22 +177,20 @@ static void @@ -182,22 +177,20 @@ static void
182 term_pipeline_destination(j_compress_ptr cinfo) 177 term_pipeline_destination(j_compress_ptr cinfo)
183 { 178 {
184 QTC::TC("libtests", "Pl_DCT term_pipeline_destination"); 179 QTC::TC("libtests", "Pl_DCT term_pipeline_destination");
185 - dct_pipeline_dest* dest =  
186 - reinterpret_cast<dct_pipeline_dest*>(cinfo->dest); 180 + dct_pipeline_dest* dest = reinterpret_cast<dct_pipeline_dest*>(cinfo->dest);
187 dest->next->write(dest->buffer, dest->size - dest->pub.free_in_buffer); 181 dest->next->write(dest->buffer, dest->size - dest->pub.free_in_buffer);
188 } 182 }
189 183
190 static void 184 static void
191 -jpeg_pipeline_dest(j_compress_ptr cinfo,  
192 - unsigned char* outbuffer, size_t size,  
193 - Pipeline* next) 185 +jpeg_pipeline_dest(
  186 + j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next)
194 { 187 {
195 - cinfo->dest = static_cast<struct jpeg_destination_mgr *>(  
196 - (*cinfo->mem->alloc_small)(reinterpret_cast<j_common_ptr>(cinfo),  
197 - JPOOL_PERMANENT,  
198 - sizeof(dct_pipeline_dest)));  
199 - dct_pipeline_dest* dest =  
200 - reinterpret_cast<dct_pipeline_dest*>(cinfo->dest); 188 + cinfo->dest =
  189 + static_cast<struct jpeg_destination_mgr*>((*cinfo->mem->alloc_small)(
  190 + reinterpret_cast<j_common_ptr>(cinfo),
  191 + JPOOL_PERMANENT,
  192 + sizeof(dct_pipeline_dest)));
  193 + dct_pipeline_dest* dest = reinterpret_cast<dct_pipeline_dest*>(cinfo->dest);
201 dest->pub.init_destination = init_pipeline_destination; 194 dest->pub.init_destination = init_pipeline_destination;
202 dest->pub.empty_output_buffer = empty_pipeline_output_buffer; 195 dest->pub.empty_output_buffer = empty_pipeline_output_buffer;
203 dest->pub.term_destination = term_pipeline_destination; 196 dest->pub.term_destination = term_pipeline_destination;
@@ -224,20 +217,15 @@ fill_buffer_input_buffer(j_decompress_ptr) @@ -224,20 +217,15 @@ fill_buffer_input_buffer(j_decompress_ptr)
224 static void 217 static void
225 skip_buffer_input_data(j_decompress_ptr cinfo, long num_bytes) 218 skip_buffer_input_data(j_decompress_ptr cinfo, long num_bytes)
226 { 219 {
227 - if (num_bytes < 0)  
228 - {  
229 - throw std::runtime_error(  
230 - "reading jpeg: jpeg library requested"  
231 - " skipping a negative number of bytes"); 220 + if (num_bytes < 0) {
  221 + throw std::runtime_error("reading jpeg: jpeg library requested"
  222 + " skipping a negative number of bytes");
232 } 223 }
233 size_t to_skip = QIntC::to_size(num_bytes); 224 size_t to_skip = QIntC::to_size(num_bytes);
234 - if ((to_skip > 0) && (to_skip <= cinfo->src->bytes_in_buffer))  
235 - { 225 + if ((to_skip > 0) && (to_skip <= cinfo->src->bytes_in_buffer)) {
236 cinfo->src->next_input_byte += to_skip; 226 cinfo->src->next_input_byte += to_skip;
237 cinfo->src->bytes_in_buffer -= to_skip; 227 cinfo->src->bytes_in_buffer -= to_skip;
238 - }  
239 - else if (to_skip != 0)  
240 - { 228 + } else if (to_skip != 0) {
241 cinfo->src->next_input_byte += cinfo->src->bytes_in_buffer; 229 cinfo->src->next_input_byte += cinfo->src->bytes_in_buffer;
242 cinfo->src->bytes_in_buffer = 0; 230 cinfo->src->bytes_in_buffer = 0;
243 } 231 }
@@ -251,10 +239,10 @@ term_buffer_source(j_decompress_ptr) @@ -251,10 +239,10 @@ term_buffer_source(j_decompress_ptr)
251 static void 239 static void
252 jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer) 240 jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer)
253 { 241 {
254 - cinfo->src = reinterpret_cast<jpeg_source_mgr *>(  
255 - (*cinfo->mem->alloc_small)(reinterpret_cast<j_common_ptr>(cinfo),  
256 - JPOOL_PERMANENT,  
257 - sizeof(jpeg_source_mgr))); 242 + cinfo->src = reinterpret_cast<jpeg_source_mgr*>((*cinfo->mem->alloc_small)(
  243 + reinterpret_cast<j_common_ptr>(cinfo),
  244 + JPOOL_PERMANENT,
  245 + sizeof(jpeg_source_mgr)));
258 246
259 jpeg_source_mgr* src = cinfo->src; 247 jpeg_source_mgr* src = cinfo->src;
260 src->init_source = init_buffer_source; 248 src->init_source = init_buffer_source;
@@ -272,15 +260,17 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) @@ -272,15 +260,17 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
272 struct jpeg_compress_struct* cinfo = 260 struct jpeg_compress_struct* cinfo =
273 reinterpret_cast<jpeg_compress_struct*>(cinfo_p); 261 reinterpret_cast<jpeg_compress_struct*>(cinfo_p);
274 262
275 -#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \  
276 - defined(__clang__))  
277 -# pragma GCC diagnostic push  
278 -# pragma GCC diagnostic ignored "-Wold-style-cast" 263 +#if ( \
  264 + (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
  265 + defined(__clang__))
  266 +# pragma GCC diagnostic push
  267 +# pragma GCC diagnostic ignored "-Wold-style-cast"
279 #endif 268 #endif
280 jpeg_create_compress(cinfo); 269 jpeg_create_compress(cinfo);
281 -#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \  
282 - defined(__clang__))  
283 -# pragma GCC diagnostic pop 270 +#if ( \
  271 + (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
  272 + defined(__clang__))
  273 +# pragma GCC diagnostic pop
284 #endif 274 #endif
285 static int const BUF_SIZE = 65536; 275 static int const BUF_SIZE = 65536;
286 auto outbuffer_ph = std::make_unique<unsigned char[]>(BUF_SIZE); 276 auto outbuffer_ph = std::make_unique<unsigned char[]>(BUF_SIZE);
@@ -292,33 +282,29 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) @@ -292,33 +282,29 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
292 cinfo->input_components = this->m->components; 282 cinfo->input_components = this->m->components;
293 cinfo->in_color_space = this->m->color_space; 283 cinfo->in_color_space = this->m->color_space;
294 jpeg_set_defaults(cinfo); 284 jpeg_set_defaults(cinfo);
295 - if (this->m->config_callback)  
296 - { 285 + if (this->m->config_callback) {
297 this->m->config_callback->apply(cinfo); 286 this->m->config_callback->apply(cinfo);
298 } 287 }
299 288
300 jpeg_start_compress(cinfo, TRUE); 289 jpeg_start_compress(cinfo, TRUE);
301 290
302 - unsigned int width = cinfo->image_width *  
303 - QIntC::to_uint(cinfo->input_components);  
304 - size_t expected_size =  
305 - QIntC::to_size(cinfo->image_height) * 291 + unsigned int width =
  292 + cinfo->image_width * QIntC::to_uint(cinfo->input_components);
  293 + size_t expected_size = QIntC::to_size(cinfo->image_height) *
306 QIntC::to_size(cinfo->image_width) * 294 QIntC::to_size(cinfo->image_width) *
307 QIntC::to_size(cinfo->input_components); 295 QIntC::to_size(cinfo->input_components);
308 - if (b->getSize() != expected_size)  
309 - { 296 + if (b->getSize() != expected_size) {
310 throw std::runtime_error( 297 throw std::runtime_error(
311 "Pl_DCT: image buffer size = " + 298 "Pl_DCT: image buffer size = " +
312 - QUtil::uint_to_string(b->getSize()) + "; expected size = " +  
313 - QUtil::uint_to_string(expected_size)); 299 + QUtil::uint_to_string(b->getSize()) +
  300 + "; expected size = " + QUtil::uint_to_string(expected_size));
314 } 301 }
315 JSAMPROW row_pointer[1]; 302 JSAMPROW row_pointer[1];
316 unsigned char* buffer = b->getBuffer(); 303 unsigned char* buffer = b->getBuffer();
317 - while (cinfo->next_scanline < cinfo->image_height)  
318 - { 304 + while (cinfo->next_scanline < cinfo->image_height) {
319 // We already verified that the buffer is big enough. 305 // We already verified that the buffer is big enough.
320 row_pointer[0] = &buffer[cinfo->next_scanline * width]; 306 row_pointer[0] = &buffer[cinfo->next_scanline * width];
321 - (void) jpeg_write_scanlines(cinfo, row_pointer, 1); 307 + (void)jpeg_write_scanlines(cinfo, row_pointer, 1);
322 } 308 }
323 jpeg_finish_compress(cinfo); 309 jpeg_finish_compress(cinfo);
324 this->getNext()->finish(); 310 this->getNext()->finish();
@@ -330,33 +316,35 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) @@ -330,33 +316,35 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b)
330 struct jpeg_decompress_struct* cinfo = 316 struct jpeg_decompress_struct* cinfo =
331 reinterpret_cast<jpeg_decompress_struct*>(cinfo_p); 317 reinterpret_cast<jpeg_decompress_struct*>(cinfo_p);
332 318
333 -#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \  
334 - defined(__clang__))  
335 -# pragma GCC diagnostic push  
336 -# pragma GCC diagnostic ignored "-Wold-style-cast" 319 +#if ( \
  320 + (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
  321 + defined(__clang__))
  322 +# pragma GCC diagnostic push
  323 +# pragma GCC diagnostic ignored "-Wold-style-cast"
337 #endif 324 #endif
338 jpeg_create_decompress(cinfo); 325 jpeg_create_decompress(cinfo);
339 -#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \  
340 - defined(__clang__))  
341 -# pragma GCC diagnostic pop 326 +#if ( \
  327 + (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
  328 + defined(__clang__))
  329 +# pragma GCC diagnostic pop
342 #endif 330 #endif
343 jpeg_buffer_src(cinfo, b); 331 jpeg_buffer_src(cinfo, b);
344 332
345 - (void) jpeg_read_header(cinfo, TRUE);  
346 - (void) jpeg_calc_output_dimensions(cinfo); 333 + (void)jpeg_read_header(cinfo, TRUE);
  334 + (void)jpeg_calc_output_dimensions(cinfo);
347 335
348 - unsigned int width = cinfo->output_width *  
349 - QIntC::to_uint(cinfo->output_components);  
350 - JSAMPARRAY buffer = (*cinfo->mem->alloc_sarray)  
351 - (reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE, width, 1); 336 + unsigned int width =
  337 + cinfo->output_width * QIntC::to_uint(cinfo->output_components);
  338 + JSAMPARRAY buffer = (*cinfo->mem->alloc_sarray)(
  339 + reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE, width, 1);
352 340
353 - (void) jpeg_start_decompress(cinfo);  
354 - while (cinfo->output_scanline < cinfo->output_height)  
355 - {  
356 - (void) jpeg_read_scanlines(cinfo, buffer, 1);  
357 - this->getNext()->write(reinterpret_cast<unsigned char*>(buffer[0]),  
358 - width * sizeof(buffer[0][0])); 341 + (void)jpeg_start_decompress(cinfo);
  342 + while (cinfo->output_scanline < cinfo->output_height) {
  343 + (void)jpeg_read_scanlines(cinfo, buffer, 1);
  344 + this->getNext()->write(
  345 + reinterpret_cast<unsigned char*>(buffer[0]),
  346 + width * sizeof(buffer[0][0]));
359 } 347 }
360 - (void) jpeg_finish_decompress(cinfo); 348 + (void)jpeg_finish_decompress(cinfo);
361 this->getNext()->finish(); 349 this->getNext()->finish();
362 } 350 }