Commit 2878c186bf6828589d220d5b19388934514d08a7
1 parent
ab9d557c
Use fluent appendItem
Showing
4 changed files
with
41 additions
and
40 deletions
libqpdf/NNTree.cc
| ... | ... | @@ -208,9 +208,8 @@ NNTreeIterator::resetLimits( |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | if (first.isInitialized() && last.isInitialized()) { |
| 211 | - auto limits = QPDFObjectHandle::newArray(); | |
| 212 | - limits.appendItem(first); | |
| 213 | - limits.appendItem(last); | |
| 211 | + auto limits = | |
| 212 | + QPDFObjectHandle::newArray().appendItem(first).appendItem(last); | |
| 214 | 213 | auto olimits = node.getKey("/Limits"); |
| 215 | 214 | if (olimits.isArray() && (olimits.getArrayNItems() == 2)) { |
| 216 | 215 | auto ofirst = olimits.getArrayItem(0); | ... | ... |
libtests/nntree.cc
| ... | ... | @@ -62,13 +62,13 @@ test_bsearch() |
| 62 | 62 | auto mk = [&q](std::vector<int> const& v) { |
| 63 | 63 | auto nums = QPDFObjectHandle::newArray(); |
| 64 | 64 | for (auto i : v) { |
| 65 | - nums.appendItem(QPDFObjectHandle::newInteger(i)); | |
| 66 | - nums.appendItem(QPDFObjectHandle::newString( | |
| 67 | - "-" + QUtil::int_to_string(i) + "-")); | |
| 65 | + nums.appendItem(QPDFObjectHandle::newInteger(i)) | |
| 66 | + .appendItem(QPDFObjectHandle::newString( | |
| 67 | + "-" + QUtil::int_to_string(i) + "-")); | |
| 68 | 68 | } |
| 69 | 69 | auto limits = QPDFObjectHandle::newArray(); |
| 70 | - limits.appendItem(QPDFObjectHandle::newInteger(v.at(0))); | |
| 71 | - limits.appendItem(QPDFObjectHandle::newInteger(v.at(v.size() - 1))); | |
| 70 | + limits.appendItem(QPDFObjectHandle::newInteger(v.at(0))) | |
| 71 | + .appendItem(QPDFObjectHandle::newInteger(v.at(v.size() - 1))); | |
| 72 | 72 | auto node = q.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 73 | 73 | node.replaceKey("/Nums", nums).replaceKey("/Limits", limits); |
| 74 | 74 | return node; |
| ... | ... | @@ -168,8 +168,8 @@ test_depth() |
| 168 | 168 | int val = |
| 169 | 169 | (((((i1 * NITEMS) + i2) * NITEMS) + i3) * NITEMS) + i4; |
| 170 | 170 | std::string str = QUtil::int_to_string(10 * val, 6); |
| 171 | - items.appendItem(QPDFObjectHandle::newString(str)); | |
| 172 | - items.appendItem(QPDFObjectHandle::newString("val " + str)); | |
| 171 | + items.appendItem(QPDFObjectHandle::newString(str)) | |
| 172 | + .appendItem(QPDFObjectHandle::newString("val " + str)); | |
| 173 | 173 | if (i4 == 0) { |
| 174 | 174 | first = str; |
| 175 | 175 | } else if (i4 == NITEMS - 1) { |
| ... | ... | @@ -178,21 +178,23 @@ test_depth() |
| 178 | 178 | } |
| 179 | 179 | auto limits = QPDFObjectHandle::newArray(); |
| 180 | 180 | n3.replaceKey("/Limits", limits); |
| 181 | - limits.appendItem(QPDFObjectHandle::newString(first)); | |
| 182 | - limits.appendItem(QPDFObjectHandle::newString(last)); | |
| 181 | + limits.appendItem(QPDFObjectHandle::newString(first)) | |
| 182 | + .appendItem(QPDFObjectHandle::newString(last)); | |
| 183 | 183 | } |
| 184 | 184 | auto limits = QPDFObjectHandle::newArray(); |
| 185 | 185 | n2.replaceKey("/Limits", limits); |
| 186 | - limits.appendItem( | |
| 187 | - k2.getArrayItem(0).getKey("/Limits").getArrayItem(0)); | |
| 188 | - limits.appendItem( | |
| 189 | - k2.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); | |
| 186 | + limits | |
| 187 | + .appendItem( | |
| 188 | + k2.getArrayItem(0).getKey("/Limits").getArrayItem(0)) | |
| 189 | + .appendItem(k2.getArrayItem(NITEMS - 1) | |
| 190 | + .getKey("/Limits") | |
| 191 | + .getArrayItem(1)); | |
| 190 | 192 | } |
| 191 | 193 | auto limits = QPDFObjectHandle::newArray(); |
| 192 | 194 | n1.replaceKey("/Limits", limits); |
| 193 | - limits.appendItem(k1.getArrayItem(0).getKey("/Limits").getArrayItem(0)); | |
| 194 | - limits.appendItem( | |
| 195 | - k1.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); | |
| 195 | + limits.appendItem(k1.getArrayItem(0).getKey("/Limits").getArrayItem(0)) | |
| 196 | + .appendItem( | |
| 197 | + k1.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); | |
| 196 | 198 | } |
| 197 | 199 | |
| 198 | 200 | QPDFNameTreeObjectHelper nh(n0, q); | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -912,10 +912,8 @@ test_24(QPDF& pdf, char const* arg2) |
| 912 | 912 | |
| 913 | 913 | QPDFObjectHandle array1 = QPDFObjectHandle::newArray(); |
| 914 | 914 | QPDFObjectHandle array2 = QPDFObjectHandle::newArray(); |
| 915 | - array1.appendItem(res2); | |
| 916 | - array1.appendItem(QPDFObjectHandle::newInteger(1)); | |
| 917 | - array2.appendItem(res1); | |
| 918 | - array2.appendItem(QPDFObjectHandle::newInteger(2)); | |
| 915 | + array1.appendItem(res2).appendItem(QPDFObjectHandle::newInteger(1)); | |
| 916 | + array2.appendItem(res1).appendItem(QPDFObjectHandle::newInteger(2)); | |
| 919 | 917 | // Make sure trying to ask questions about a reserved object |
| 920 | 918 | // doesn't break it. |
| 921 | 919 | if (res1.isArray()) { |
| ... | ... | @@ -1087,12 +1085,11 @@ test_27(QPDF& pdf, char const* arg2) |
| 1087 | 1085 | pdf.getTrailer() |
| 1088 | 1086 | .replaceKey("/QTest", pdf.copyForeignObject(qtest)) |
| 1089 | 1087 | .replaceKey("/QTest2", QPDFObjectHandle::newArray()); |
| 1090 | - pdf.getTrailer().getKey("/QTest2").appendItem( | |
| 1091 | - pdf.copyForeignObject(s1)); | |
| 1092 | - pdf.getTrailer().getKey("/QTest2").appendItem( | |
| 1093 | - pdf.copyForeignObject(s2)); | |
| 1094 | - pdf.getTrailer().getKey("/QTest2").appendItem( | |
| 1095 | - pdf.copyForeignObject(s3)); | |
| 1088 | + pdf.getTrailer() | |
| 1089 | + .getKey("/QTest2") | |
| 1090 | + .appendItem(pdf.copyForeignObject(s1)) | |
| 1091 | + .appendItem(pdf.copyForeignObject(s2)) | |
| 1092 | + .appendItem(pdf.copyForeignObject(s3)); | |
| 1096 | 1093 | } |
| 1097 | 1094 | |
| 1098 | 1095 | QPDFWriter w(pdf, "a.pdf"); |
| ... | ... | @@ -2099,10 +2096,13 @@ test_55(QPDF& pdf, char const* arg2) |
| 2099 | 2096 | std::vector<QPDFPageObjectHelper> pages = |
| 2100 | 2097 | QPDFPageDocumentHelper(pdf).getAllPages(); |
| 2101 | 2098 | QPDFObjectHandle qtest = QPDFObjectHandle::newArray(); |
| 2102 | - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); | |
| 2103 | - iter != pages.end(); | |
| 2104 | - ++iter) { | |
| 2105 | - QPDFPageObjectHelper& ph(*iter); | |
| 2099 | + for (auto& ph: pages) { | |
| 2100 | + // Note: using fluent appendItem causes a test failure with | |
| 2101 | + // MSVC 19.31.31107, which appears to evaluate the argument to | |
| 2102 | + // the second appendItem before the first. Since these | |
| 2103 | + // arguments have the side effect of creating objects, the | |
| 2104 | + // object numbers end up being different even though the | |
| 2105 | + // resulting file is semantically correct. | |
| 2106 | 2106 | qtest.appendItem(ph.getFormXObjectForPage()); |
| 2107 | 2107 | qtest.appendItem(ph.getFormXObjectForPage(false)); |
| 2108 | 2108 | } | ... | ... |
qpdf/test_large_file.cc
| ... | ... | @@ -199,18 +199,18 @@ create_pdf(char const* filename) |
| 199 | 199 | |
| 200 | 200 | QPDFObjectHandle procset = |
| 201 | 201 | pdf.makeIndirectObject(QPDFObjectHandle::newArray()); |
| 202 | - procset.appendItem(newName("/PDF")); | |
| 203 | - procset.appendItem(newName("/Text")); | |
| 204 | - procset.appendItem(newName("/ImageC")); | |
| 202 | + procset.appendItem(newName("/PDF")) | |
| 203 | + .appendItem(newName("/Text")) | |
| 204 | + .appendItem(newName("/ImageC")); | |
| 205 | 205 | |
| 206 | 206 | QPDFObjectHandle rfont = QPDFObjectHandle::newDictionary(); |
| 207 | 207 | rfont.replaceKey("/F1", font); |
| 208 | 208 | |
| 209 | 209 | QPDFObjectHandle mediabox = QPDFObjectHandle::newArray(); |
| 210 | - mediabox.appendItem(newInteger(0)); | |
| 211 | - mediabox.appendItem(newInteger(0)); | |
| 212 | - mediabox.appendItem(newInteger(612)); | |
| 213 | - mediabox.appendItem(newInteger(792)); | |
| 210 | + mediabox.appendItem(newInteger(0)) | |
| 211 | + .appendItem(newInteger(0)) | |
| 212 | + .appendItem(newInteger(612)) | |
| 213 | + .appendItem(newInteger(792)); | |
| 214 | 214 | |
| 215 | 215 | QPDFPageDocumentHelper dh(pdf); |
| 216 | 216 | for (size_t pageno = 1; pageno <= npages; ++pageno) { | ... | ... |