diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 5a544bd..31e622c 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -12,11 +12,59 @@ d740c6ccced02147f84a39d5e5f0984d12bac6cb # Switch line length from 80 to 100 columns 6b077332d38c093de2618d5e1481b42222106065 60965d5f4d608bdccc2ffd4e8753e12cbbbd71d2 -# Reflow comments and strings to 100 columns +# Reflow comments and strings 698a70e6a84cf7c0db667e9d9e021b4c34c85a3e 3c5700c255f4603b5df9c6d183d13dd71a083cc3 9ae7bdea966102f9621b22192747a891078e7470 +a9b5ebef1f19ae50deee68401dd090c0f5587400 # Normalize white space in ChangeLog d7b909f97d3effc9540c35b0251bdf1c9abf187c +# Revert PRs 1272, 1289, 1297, 1301 +0d5c57c151a35be81b98eef6051303301d253112 +f1800410b6c1f1510890b97fe5e8ce962b69ac94 +efb2e8f613511616744eb16aafc8f7138cd821a1 +4bf09ff1cdda1eed496f2e670ef803175b7fed1e +# PR 1301 +54cf0e519c49e3fb44c7ca1de95a1fffbafc211c +1eb5df92f49111e2ef1b9d0d8f12b849720b08c6 +# PR 1297 +c648b9a018105a3c30b3e7f3c5f8a058d3ddd92c +acc57ca09095d5e6247893a54d94e99ba2304c52 +336d7833250b9d8d8a28a6f232f659b765925593 +113ea4e7ae962d3d0c54cb6bedf255f55b23de84 +9e03dc54cc50c173f75375e76b31607a03c3f4a4 +83fc18af095248ae22f38a52bf4e7e336f0a7c12 +6c9903062ff10d35f6fb387f983e02b0134ecb82 +83443c116d84494da3ee859f0115898118769dca +b5a5780019a5b75465671a23f55772a20b007115 +a3f693c8f982462ce03421e187504efbe31788b9 +2015f71c7d6e316db6ae3cd6a9189b8ed8308c04 +83897e8789acc07c7bc72f24ab1aff7ababaca66 +9f0cc086b158b477ad942eb159b929b7b9ae7a0b +# PR 1289 +0e92cf6bf399249c603c3d0212e898fd29e71fcd +477fbd9839b0c876bfafdcc26b492548f253b2bb +21f176d374dd229401b5de5bf8a4cb89b10e1731 +44a13951940def9699b2c169e8a8eabd35973934 +# PR 1272 +ff2a78f579ebdd06b417e34260a17dba06e71137 +cb7180b1bafd075a00d31dc598ebb01e755a2f09 +28c13f5492ecc8bb6b8e5419f66ad6e66d5869e7 +ad10fa30067308d985b8a612a0f6a5390696ce25 +0f0747b3ae9b2b74d337f92c2861a11e0d0573d4 +965f0fcd6352348760e77004c8af5b9b44e74326 +98c14e7740cb879be05ce95a22a3c1f2c403bea0 +7775aec33e55db7a9440b6bcf402c062df1ee967 +a1b646fccafbdbc39c78f2bad4c21aa507f0477f +6b9eb14c76cdbee063051d0ba987e8a2961a4139 +a4db9b3149562a6117b1d9edf89e3853480aeba8 +f30a5eb05a8fe763184cd8167a4d4531909a34d5 +253d3aee8fb231a777cae127af52c262dcdeb9a6 +3fbff845949c56180dfdafc0812da95a168f224b +1e072e223a61d26b612864978b21aac6a0d0dc19 +0ac37bc9561f1cf1aca2c55fc0e4702d3febcf75 +f8e6274a2e004e1b0f0bb5ac8f8fb0fb76f34c66 +d42fda60d55d27bc61828901d09d15d2d536e5a7 # Remove 'this->' f5cac93ac63559ddc0aec1b1c61c9e2503c7b8e0 +7ede03992a963d56754fc522f4c6f0bf944947cd diff --git a/libqpdf/InputSource.cc b/libqpdf/InputSource.cc index 8055330..405494e 100644 --- a/libqpdf/InputSource.cc +++ b/libqpdf/InputSource.cc @@ -58,8 +58,7 @@ InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len size_t size = sizeof(buf) - 1; if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) { throw std::logic_error( - "InputSource::findSource called with" - " too small or too large of a character sequence"); + "InputSource::findSource called with too small or too large of a character sequence"); } char* p = nullptr; diff --git a/libqpdf/NNTree.cc b/libqpdf/NNTree.cc index b71f8a1..ac06512 100644 --- a/libqpdf/NNTree.cc +++ b/libqpdf/NNTree.cc @@ -63,8 +63,7 @@ NNTreeIterator::updateIValue(bool allow_invalid) if (!okay) { if (!allow_invalid) { throw std::logic_error( - "attempt made to dereference an invalid" - " name/number tree iterator"); + "attempt made to dereference an invalid name/number tree iterator"); } this->ivalue.first = QPDFObjectHandle(); this->ivalue.second = QPDFObjectHandle(); diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc index 2236486..303f9c8 100644 --- a/libqpdf/Pl_AES_PDF.cc +++ b/libqpdf/Pl_AES_PDF.cc @@ -111,9 +111,7 @@ Pl_AES_PDF::finish() // However, we have encountered files for which the output is not a multiple of the // block size. In this case, pad with zeroes and hope for the best. if (this->offset >= this->buf_size) { - throw std::logic_error( - "buffer overflow in AES encryption" - " pipeline"); + throw std::logic_error("buffer overflow in AES encryption pipeline"); } std::memset(this->inbuf + this->offset, 0, this->buf_size - this->offset); this->offset = this->buf_size; diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc index dd2cd46..3f80cf4 100644 --- a/libqpdf/Pl_ASCIIHexDecoder.cc +++ b/libqpdf/Pl_ASCIIHexDecoder.cc @@ -4,6 +4,8 @@ #include #include +using namespace std::literals; + Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) : Pipeline(identifier, next) { @@ -46,11 +48,7 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) char t[2]; t[0] = ch; t[1] = 0; - throw std::runtime_error( - std::string( - "character out of range" - " during base Hex decode: ") + - t); + throw std::runtime_error("character out of range during base Hex decode: "s + t); } break; } diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 430a7c5..d38f4d7 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -1390,9 +1390,7 @@ QPDF::showXRefTable() break; default: - throw std::logic_error( - "unknown cross-reference table type while" - " showing xref_table"); + throw std::logic_error("unknown cross-reference table type while showing xref_table"); break; } m->log->info("\n"); @@ -2296,8 +2294,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) ObjCopier& obj_copier = m->object_copiers[other.m->unique_id]; if (!obj_copier.visiting.empty()) { throw std::logic_error( - "obj_copier.visiting is not empty" - " at the beginning of copyForeignObject"); + "obj_copier.visiting is not empty at the beginning of copyForeignObject"); } // Make sure we have an object in this file for every referenced object in the old file. diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 2857870..8f47616 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -34,16 +34,16 @@ QPDFAcroFormDocumentHelper::invalidateCache() bool QPDFAcroFormDocumentHelper::hasAcroForm() { - return this->qpdf.getRoot().hasKey("/AcroForm"); + return qpdf.getRoot().hasKey("/AcroForm"); } QPDFObjectHandle QPDFAcroFormDocumentHelper::getOrCreateAcroForm() { - auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); + auto acroform = qpdf.getRoot().getKey("/AcroForm"); if (!acroform.isDictionary()) { - acroform = this->qpdf.getRoot().replaceKeyAndGetNew( - "/AcroForm", this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary())); + acroform = qpdf.getRoot().replaceKeyAndGetNew( + "/AcroForm", qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary())); } return acroform; } @@ -115,7 +115,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(std::vector void QPDFAcroFormDocumentHelper::removeFormFields(std::set const& to_remove) { - auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); + auto acroform = qpdf.getRoot().getKey("/AcroForm"); if (!acroform.isDictionary()) { return; } @@ -168,7 +168,7 @@ QPDFAcroFormDocumentHelper::getFormFields() analyze(); std::vector result; for (auto const& iter: m->field_to_annotations) { - result.emplace_back(this->qpdf.getObject(iter.first)); + result.emplace_back(qpdf.getObject(iter.first)); } return result; } @@ -267,7 +267,7 @@ QPDFAcroFormDocumentHelper::analyze() // a file that contains this kind of error will probably not // actually work with most viewers. - for (auto const& ph: QPDFPageDocumentHelper(this->qpdf).getAllPages()) { + for (auto const& ph: QPDFPageDocumentHelper(qpdf).getAllPages()) { for (auto const& iter: getWidgetAnnotationsForPage(ph)) { QPDFObjectHandle annot(iter.getObjectHandle()); QPDFObjGen og(annot.getObjGen()); @@ -368,7 +368,7 @@ bool QPDFAcroFormDocumentHelper::getNeedAppearances() { bool result = false; - QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); + QPDFObjectHandle acroform = qpdf.getRoot().getKey("/AcroForm"); if (acroform.isDictionary() && acroform.getKey("/NeedAppearances").isBool()) { result = acroform.getKey("/NeedAppearances").getBoolValue(); } @@ -378,9 +378,9 @@ QPDFAcroFormDocumentHelper::getNeedAppearances() void QPDFAcroFormDocumentHelper::setNeedAppearances(bool val) { - QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); + QPDFObjectHandle acroform = qpdf.getRoot().getKey("/AcroForm"); if (!acroform.isDictionary()) { - this->qpdf.getRoot().warnIfPossible( + qpdf.getRoot().warnIfPossible( "ignoring call to QPDFAcroFormDocumentHelper::setNeedAppearances" " on a file that lacks an /AcroForm dictionary"); return; @@ -399,7 +399,7 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() return; } - for (auto const& page: QPDFPageDocumentHelper(this->qpdf).getAllPages()) { + for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) { for (auto& aoh: getWidgetAnnotationsForPage(page)) { QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh); if (ffh.getFieldType() == "/Btn") { @@ -548,7 +548,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token) wrote = true; } } - this->offset += token.getRawValue().length(); + offset += token.getRawValue().length(); if (!wrote) { writeToken(token); } @@ -590,11 +590,11 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( // stream out of the string and then filter it. We don't attach the stream to anything, so it // will get discarded. ResourceFinder rf; - auto da_stream = QPDFObjectHandle::newStream(&this->qpdf, DA.getUTF8Value()); + auto da_stream = QPDFObjectHandle::newStream(&qpdf, DA.getUTF8Value()); try { - auto nwarnings = this->qpdf.numWarnings(); + auto nwarnings = qpdf.numWarnings(); da_stream.parseAsContents(&rf); - if (this->qpdf.numWarnings() > nwarnings) { + if (qpdf.numWarnings() > nwarnings) { QTC::TC("qpdf", "QPDFAcroFormDocumentHelper /DA parse error"); } } catch (std::exception& e) { @@ -632,7 +632,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( bool was_indirect = resources.isIndirect(); resources = resources.shallowCopy(); if (was_indirect) { - resources = this->qpdf.makeIndirectObject(resources); + resources = qpdf.makeIndirectObject(resources); } dict.replaceKey("/Resources", resources); // Create a dictionary with top-level keys so we can use mergeResources to force them to be @@ -683,9 +683,9 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( // Now attach a token filter to replace the actual resources. ResourceFinder rf; try { - auto nwarnings = this->qpdf.numWarnings(); + auto nwarnings = qpdf.numWarnings(); stream.parseAsContents(&rf); - if (this->qpdf.numWarnings() > nwarnings) { + if (qpdf.numWarnings() > nwarnings) { QTC::TC("qpdf", "QPDFAcroFormDocumentHelper AP parse error"); } auto rr = new ResourceReplacer(dr_map, rf.getNamesByResourceType()); @@ -711,18 +711,18 @@ QPDFAcroFormDocumentHelper::transformAnnotations( std::shared_ptr afdhph; if (!from_qpdf) { // Assume these are from the same QPDF. - from_qpdf = &this->qpdf; + from_qpdf = &qpdf; from_afdh = this; - } else if ((from_qpdf != &this->qpdf) && (!from_afdh)) { + } else if ((from_qpdf != &qpdf) && (!from_afdh)) { afdhph = std::make_shared(*from_qpdf); from_afdh = afdhph.get(); } - bool foreign = (from_qpdf != &this->qpdf); + bool foreign = (from_qpdf != &qpdf); // It's possible that we will transform annotations that don't include any form fields. This // code takes care not to muck around with /AcroForm unless we have to. - QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); + QPDFObjectHandle acroform = qpdf.getRoot().getKey("/AcroForm"); QPDFObjectHandle from_acroform = from_qpdf->getRoot().getKey("/AcroForm"); // /DA and /Q may be inherited from the document-level /AcroForm dictionary. If we are copying a @@ -753,7 +753,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( if (!from_dr.isIndirect()) { from_dr = from_qpdf->makeIndirectObject(from_dr); } - from_dr = this->qpdf.copyForeignObject(from_dr); + from_dr = qpdf.copyForeignObject(from_dr); } if (from_acroform.getKey("/DA").isString()) { from_default_da = from_acroform.getKey("/DA").getUTF8Value(); @@ -787,14 +787,14 @@ QPDFAcroFormDocumentHelper::transformAnnotations( if (!dr.isDictionary()) { dr = QPDFObjectHandle::newDictionary(); } - dr.makeResourcesIndirect(this->qpdf); + dr.makeResourcesIndirect(qpdf); if (!dr.isIndirect()) { - dr = acroform.replaceKeyAndGetNew("/DR", this->qpdf.makeIndirectObject(dr)); + dr = acroform.replaceKeyAndGetNew("/DR", qpdf.makeIndirectObject(dr)); } // Merge the other document's /DR, creating a conflict map. mergeResources checks to // make sure both objects are dictionaries. By this point, if this is foreign, from_dr // has been copied, so we use the target qpdf as the owning qpdf. - from_dr.makeResourcesIndirect(this->qpdf); + from_dr.makeResourcesIndirect(qpdf); dr.mergeResources(from_dr, &dr_map); if (from_afdh->getNeedAppearances()) { @@ -811,7 +811,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( to_copy = orig_to_copy[og]; return false; } else { - to_copy = this->qpdf.makeIndirectObject(to_copy.shallowCopy()); + to_copy = qpdf.makeIndirectObject(to_copy.shallowCopy()); orig_to_copy[og] = to_copy; return true; } @@ -872,8 +872,8 @@ QPDFAcroFormDocumentHelper::transformAnnotations( // so we'll get the right object back. // top_field and ffield_oh are known to be indirect. - top_field = this->qpdf.copyForeignObject(top_field); - ffield_oh = this->qpdf.copyForeignObject(ffield_oh); + top_field = qpdf.copyForeignObject(top_field); + ffield_oh = qpdf.copyForeignObject(ffield_oh); } else { // We don't need to add top_field to old_fields if it's foreign because the new copy // of the foreign field won't be referenced anywhere. It's just the starting point @@ -957,7 +957,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( if (!annot.isIndirect()) { annot = from_qpdf->makeIndirectObject(annot); } - annot = this->qpdf.copyForeignObject(annot); + annot = qpdf.copyForeignObject(annot); } maybe_copy_object(annot); diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index b333202..77d1e84 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -752,8 +752,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao QPDFObjectHandle::Rectangle rect = aoh.getRect(); QPDFObjectHandle::Rectangle bbox(0, 0, rect.urx - rect.llx, rect.ury - rect.lly); QPDFObjectHandle dict = QPDFObjectHandle::parse( - "<< /Resources << /ProcSet [ /PDF /Text ] >>" - " /Type /XObject /Subtype /Form >>"); + "<< /Resources << /ProcSet [ /PDF /Text ] >> /Type /XObject /Subtype /Form >>"); dict.replaceKey("/BBox", QPDFObjectHandle::newFromRectangle(bbox)); AS = QPDFObjectHandle::newStream(oh().getOwningQPDF(), "/Tx BMC\nEMC\n"); AS.replaceDict(dict); diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index f0e229d..6bd93aa 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -618,9 +618,7 @@ QPDFJob::checkConfiguration() usage("no output file may be given for this option"); } if (m->check_requires_password && m->check_is_encrypted) { - usage( - "--requires-password and --is-encrypted may not be given" - " together"); + usage("--requires-password and --is-encrypted may not be given together"); } if (m->encrypt && (!m->allow_insecure) && @@ -3142,9 +3140,7 @@ QPDFJob::writeJSON(QPDF& pdf) fp = std::make_shared("json output", fc->f); } else if ((m->json_stream_data == qpdf_sj_file) && m->json_stream_prefix.empty()) { QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout"); - usage( - "please specify --json-stream-prefix since the input file " - "name is unknown"); + usage("please specify --json-stream-prefix since the input file name is unknown"); } else { QTC::TC("qpdf", "QPDFJob write json to stdout"); m->log->saveToStandardOutput(true); diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index df791f3..36fc942 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1258,8 +1258,7 @@ QPDFObjectHandle::getUniqueResourceName( // The number of candidates we test is more than the // number of keys we're checking against. throw std::logic_error( - "unable to find unconflicting name in" - " QPDFObjectHandle::getUniqueResourceName"); + "unable to find unconflicting name in QPDFObjectHandle::getUniqueResourceName"); } // Dictionary mutators are in QPDF_Dictionary.cc diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index 1e22778..5a06935 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -718,8 +718,7 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) QPDFObjectHandle bbox = getTrimBox(false).shallowCopy(); if (!bbox.isRectangle()) { oh().warnIfPossible( - "bounding box is invalid; form" - " XObject created from page will not work"); + "bounding box is invalid; form XObject created from page will not work"); } newdict.replaceKey("/BBox", bbox); auto provider = diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index f156cab..bf7fcf6 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -166,8 +166,8 @@ Tokenizer::presentCharacter(char ch) { handleCharacter(ch); - if (this->in_token) { - this->raw_val += ch; + if (in_token) { + raw_val += ch; } } @@ -177,7 +177,7 @@ Tokenizer::handleCharacter(char ch) // In some cases, functions called below may call a second handler. This happens whenever you // have to use a character from the next token to detect the end of the current token. - switch (this->state) { + switch (state) { case st_top: inTop(ch); return; @@ -283,18 +283,18 @@ Tokenizer::inBeforeToken(char ch) { // Note: we specifically do not use ctype here. It is locale-dependent. if (isSpace(ch)) { - this->before_token = !this->include_ignorable; - this->in_token = this->include_ignorable; - if (this->include_ignorable) { - this->state = st_in_space; + before_token = !include_ignorable; + in_token = include_ignorable; + if (include_ignorable) { + state = st_in_space; } } else if (ch == '%') { - this->before_token = !this->include_ignorable; - this->in_token = this->include_ignorable; - this->state = st_in_comment; + before_token = !include_ignorable; + in_token = include_ignorable; + state = st_in_comment; } else { - this->before_token = false; - this->in_token = true; + before_token = false; + in_token = true; inTop(ch); } } @@ -304,48 +304,48 @@ Tokenizer::inTop(char ch) { switch (ch) { case '(': - this->string_depth = 1; - this->state = st_in_string; + string_depth = 1; + state = st_in_string; return; case '<': - this->state = st_lt; + state = st_lt; return; case '>': - this->state = st_gt; + state = st_gt; return; case (')'): - this->type = tt::tt_bad; + type = tt::tt_bad; QTC::TC("qpdf", "QPDFTokenizer bad )"); - this->error_message = "unexpected )"; - this->state = st_token_ready; + error_message = "unexpected )"; + state = st_token_ready; return; case '[': - this->type = tt::tt_array_open; - this->state = st_token_ready; + type = tt::tt_array_open; + state = st_token_ready; return; case ']': - this->type = tt::tt_array_close; - this->state = st_token_ready; + type = tt::tt_array_close; + state = st_token_ready; return; case '{': - this->type = tt::tt_brace_open; - this->state = st_token_ready; + type = tt::tt_brace_open; + state = st_token_ready; return; case '}': - this->type = tt::tt_brace_close; - this->state = st_token_ready; + type = tt::tt_brace_close; + state = st_token_ready; return; case '/': - this->state = st_name; - this->val += ch; + state = st_name; + val += ch; return; case '0': @@ -358,20 +358,20 @@ Tokenizer::inTop(char ch) case '7': case '8': case '9': - this->state = st_number; + state = st_number; return; case '+': case '-': - this->state = st_sign; + state = st_sign; return; case '.': - this->state = st_decimal; + state = st_decimal; return; default: - this->state = st_literal; + state = st_literal; return; } } @@ -381,10 +381,10 @@ Tokenizer::inSpace(char ch) { // We only enter this state if include_ignorable is true. if (!isSpace(ch)) { - this->type = tt::tt_space; - this->in_token = false; - this->char_to_unread = ch; - this->state = st_token_ready; + type = tt::tt_space; + in_token = false; + char_to_unread = ch; + state = st_token_ready; } } @@ -392,13 +392,13 @@ void Tokenizer::inComment(char ch) { if ((ch == '\r') || (ch == '\n')) { - if (this->include_ignorable) { - this->type = tt::tt_comment; - this->in_token = false; - this->char_to_unread = ch; - this->state = st_token_ready; + if (include_ignorable) { + type = tt::tt_comment; + in_token = false; + char_to_unread = ch; + state = st_token_ready; } else { - this->state = st_before_token; + state = st_before_token; } } } @@ -408,36 +408,36 @@ Tokenizer::inString(char ch) { switch (ch) { case '\\': - this->state = st_string_escape; + state = st_string_escape; return; case '(': - this->val += ch; - ++this->string_depth; + val += ch; + ++string_depth; return; case ')': - if (--this->string_depth == 0) { - this->type = tt::tt_string; - this->state = st_token_ready; + if (--string_depth == 0) { + type = tt::tt_string; + state = st_token_ready; return; } - this->val += ch; + val += ch; return; case '\r': // CR by itself is converted to LF - this->val += '\n'; - this->state = st_string_after_cr; + val += '\n'; + state = st_string_after_cr; return; case '\n': - this->val += ch; + val += ch; return; default: - this->val += ch; + val += ch; return; } } @@ -452,32 +452,32 @@ Tokenizer::inName(char ch) // though not on any files in the test suite as of this // writing. - this->type = this->bad ? tt::tt_bad : tt::tt_name; - this->in_token = false; - this->char_to_unread = ch; - this->state = st_token_ready; + type = bad ? tt::tt_bad : tt::tt_name; + in_token = false; + char_to_unread = ch; + state = st_token_ready; } else if (ch == '#') { - this->char_code = 0; - this->state = st_name_hex1; + char_code = 0; + state = st_name_hex1; } else { - this->val += ch; + val += ch; } } void Tokenizer::inNameHex1(char ch) { - this->hex_char = ch; + hex_char = ch; if (char hval = util::hex_decode_char(ch); hval < '\20') { - this->char_code = int(hval) << 4; - this->state = st_name_hex2; + char_code = int(hval) << 4; + state = st_name_hex2; } else { QTC::TC("qpdf", "QPDFTokenizer bad name 1"); - this->error_message = "name with stray # will not work with PDF >= 1.2"; + error_message = "name with stray # will not work with PDF >= 1.2"; // Use null to encode a bad # -- this is reversed in QPDF_Name::normalizeName. - this->val += '\0'; - this->state = st_name; + val += '\0'; + state = st_name; inName(ch); } } @@ -486,26 +486,26 @@ void Tokenizer::inNameHex2(char ch) { if (char hval = util::hex_decode_char(ch); hval < '\20') { - this->char_code |= int(hval); + char_code |= int(hval); } else { QTC::TC("qpdf", "QPDFTokenizer bad name 2"); - this->error_message = "name with stray # will not work with PDF >= 1.2"; + error_message = "name with stray # will not work with PDF >= 1.2"; // Use null to encode a bad # -- this is reversed in QPDF_Name::normalizeName. - this->val += '\0'; - this->val += this->hex_char; - this->state = st_name; + val += '\0'; + val += hex_char; + state = st_name; inName(ch); return; } - if (this->char_code == 0) { + if (char_code == 0) { QTC::TC("qpdf", "QPDFTokenizer null in name"); - this->error_message = "null character not allowed in name token"; - this->val += "#00"; - this->state = st_name; - this->bad = true; + error_message = "null character not allowed in name token"; + val += "#00"; + state = st_name; + bad = true; } else { - this->val += char(this->char_code); - this->state = st_name; + val += char(char_code); + state = st_name; } } @@ -513,11 +513,11 @@ void Tokenizer::inSign(char ch) { if (util::is_digit(ch)) { - this->state = st_number; + state = st_number; } else if (ch == '.') { - this->state = st_decimal; + state = st_decimal; } else { - this->state = st_literal; + state = st_literal; inLiteral(ch); } } @@ -526,9 +526,9 @@ void Tokenizer::inDecimal(char ch) { if (util::is_digit(ch)) { - this->state = st_real; + state = st_real; } else { - this->state = st_literal; + state = st_literal; inLiteral(ch); } } @@ -538,14 +538,14 @@ Tokenizer::inNumber(char ch) { if (util::is_digit(ch)) { } else if (ch == '.') { - this->state = st_real; + state = st_real; } else if (isDelimiter(ch)) { - this->type = tt::tt_integer; - this->state = st_token_ready; - this->in_token = false; - this->char_to_unread = ch; + type = tt::tt_integer; + state = st_token_ready; + in_token = false; + char_to_unread = ch; } else { - this->state = st_literal; + state = st_literal; } } @@ -554,18 +554,18 @@ Tokenizer::inReal(char ch) { if (util::is_digit(ch)) { } else if (isDelimiter(ch)) { - this->type = tt::tt_real; - this->state = st_token_ready; - this->in_token = false; - this->char_to_unread = ch; + type = tt::tt_real; + state = st_token_ready; + in_token = false; + char_to_unread = ch; } else { - this->state = st_literal; + state = st_literal; } } void Tokenizer::inStringEscape(char ch) { - this->state = st_in_string; + state = st_in_string; switch (ch) { case '0': case '1': @@ -575,42 +575,42 @@ Tokenizer::inStringEscape(char ch) case '5': case '6': case '7': - this->state = st_char_code; - this->char_code = 0; - this->digit_count = 0; + state = st_char_code; + char_code = 0; + digit_count = 0; inCharCode(ch); return; case 'n': - this->val += '\n'; + val += '\n'; return; case 'r': - this->val += '\r'; + val += '\r'; return; case 't': - this->val += '\t'; + val += '\t'; return; case 'b': - this->val += '\b'; + val += '\b'; return; case 'f': - this->val += '\f'; + val += '\f'; return; case '\n': return; case '\r': - this->state = st_string_after_cr; + state = st_string_after_cr; return; default: // PDF spec says backslash is ignored before anything else - this->val += ch; + val += ch; return; } } @@ -618,7 +618,7 @@ Tokenizer::inStringEscape(char ch) void Tokenizer::inStringAfterCR(char ch) { - this->state = st_in_string; + state = st_in_string; if (ch != '\n') { inString(ch); } @@ -628,12 +628,12 @@ void Tokenizer::inLt(char ch) { if (ch == '<') { - this->type = tt::tt_dict_open; - this->state = st_token_ready; + type = tt::tt_dict_open; + state = st_token_ready; return; } - this->state = st_in_hexstring; + state = st_in_hexstring; inHexstring(ch); } @@ -641,15 +641,15 @@ void Tokenizer::inGt(char ch) { if (ch == '>') { - this->type = tt::tt_dict_close; - this->state = st_token_ready; + type = tt::tt_dict_close; + state = st_token_ready; } else { - this->type = tt::tt_bad; + type = tt::tt_bad; QTC::TC("qpdf", "QPDFTokenizer bad >"); - this->error_message = "unexpected >"; - this->in_token = false; - this->char_to_unread = ch; - this->state = st_token_ready; + error_message = "unexpected >"; + in_token = false; + char_to_unread = ch; + state = st_token_ready; } } @@ -662,12 +662,12 @@ Tokenizer::inLiteral(char ch) // stream keyword. Removing it here could make the stream-reading code break on some files, // though not on any files in the test suite as of this writing. - this->in_token = false; - this->char_to_unread = ch; - this->state = st_token_ready; - this->type = (this->raw_val == "true") || (this->raw_val == "false") + in_token = false; + char_to_unread = ch; + state = st_token_ready; + type = (raw_val == "true") || (raw_val == "false") ? tt::tt_bool - : (this->raw_val == "null" ? tt::tt_null : tt::tt_word); + : (raw_val == "null" ? tt::tt_null : tt::tt_word); } } @@ -675,21 +675,21 @@ void Tokenizer::inHexstring(char ch) { if (char hval = util::hex_decode_char(ch); hval < '\20') { - this->char_code = int(hval) << 4; - this->state = st_in_hexstring_2nd; + char_code = int(hval) << 4; + state = st_in_hexstring_2nd; } else if (ch == '>') { - this->type = tt::tt_string; - this->state = st_token_ready; + type = tt::tt_string; + state = st_token_ready; } else if (isSpace(ch)) { // ignore } else { - this->type = tt::tt_bad; + type = tt::tt_bad; QTC::TC("qpdf", "QPDFTokenizer bad hexstring character"); - this->error_message = std::string("invalid character (") + ch + ") in hexstring"; - this->state = st_token_ready; + error_message = std::string("invalid character (") + ch + ") in hexstring"; + state = st_token_ready; } } @@ -697,23 +697,23 @@ void Tokenizer::inHexstring2nd(char ch) { if (char hval = util::hex_decode_char(ch); hval < '\20') { - this->val += char(this->char_code) | hval; - this->state = st_in_hexstring; + val += char(char_code) | hval; + state = st_in_hexstring; } else if (ch == '>') { // PDF spec says odd hexstrings have implicit trailing 0. - this->val += char(this->char_code); - this->type = tt::tt_string; - this->state = st_token_ready; + val += char(char_code); + type = tt::tt_string; + state = st_token_ready; } else if (isSpace(ch)) { // ignore } else { - this->type = tt::tt_bad; + type = tt::tt_bad; QTC::TC("qpdf", "QPDFTokenizer bad hexstring 2nd character"); - this->error_message = std::string("invalid character (") + ch + ") in hexstring"; - this->state = st_token_ready; + error_message = std::string("invalid character (") + ch + ") in hexstring"; + state = st_token_ready; } } @@ -722,16 +722,16 @@ Tokenizer::inCharCode(char ch) { bool handled = false; if (('0' <= ch) && (ch <= '7')) { - this->char_code = 8 * this->char_code + (int(ch) - int('0')); - if (++(this->digit_count) < 3) { + char_code = 8 * char_code + (int(ch) - int('0')); + if (++(digit_count) < 3) { return; } handled = true; } // We've accumulated \ddd or we have \d or \dd followed by other than an octal digit. The PDF // Spec says to ignore high-order overflow. - this->val += char(this->char_code % 256); - this->state = st_in_string; + val += char(char_code % 256); + state = st_in_string; if (!handled) { inString(ch); } @@ -740,11 +740,11 @@ Tokenizer::inCharCode(char ch) void Tokenizer::inInlineImage(char ch) { - if ((this->raw_val.length() + 1) == this->inline_image_bytes) { + if ((raw_val.length() + 1) == inline_image_bytes) { QTC::TC("qpdf", "QPDFTokenizer found EI by byte count"); - this->type = tt::tt_inline_image; - this->inline_image_bytes = 0; - this->state = st_token_ready; + type = tt::tt_inline_image; + inline_image_bytes = 0; + state = st_token_ready; } } @@ -757,7 +757,7 @@ QPDFTokenizer::presentEOF() void Tokenizer::presentEOF() { - switch (this->state) { + switch (state) { case st_name: case st_name_hex1: case st_name_hex2: @@ -769,20 +769,20 @@ Tokenizer::presentEOF() QTC::TC("qpdf", "QPDFTokenizer EOF reading appendable token"); // Push any delimiter to the state machine to finish off the final token. presentCharacter('\f'); - this->in_token = true; + in_token = true; break; case st_top: case st_before_token: - this->type = tt::tt_eof; + type = tt::tt_eof; break; case st_in_space: - this->type = this->include_ignorable ? tt::tt_space : tt::tt_eof; + type = include_ignorable ? tt::tt_space : tt::tt_eof; break; case st_in_comment: - this->type = this->include_ignorable ? tt::tt_comment : tt::tt_bad; + type = include_ignorable ? tt::tt_comment : tt::tt_bad; break; case st_token_ready: @@ -790,10 +790,10 @@ Tokenizer::presentEOF() default: QTC::TC("qpdf", "QPDFTokenizer EOF reading token"); - this->type = tt::tt_bad; - this->error_message = "EOF while reading token"; + type = tt::tt_bad; + error_message = "EOF while reading token"; } - this->state = st_token_ready; + state = st_token_ready; } void @@ -811,16 +811,16 @@ QPDFTokenizer::expectInlineImage(InputSource& input) void Tokenizer::expectInlineImage(InputSource& input) { - if (this->state == st_token_ready) { + if (state == st_token_ready) { reset(); - } else if (this->state != st_before_token) { + } else if (state != st_before_token) { throw std::logic_error( "QPDFTokenizer::expectInlineImage called when tokenizer is in improper state"); } findEI(input); - this->before_token = false; - this->in_token = true; - this->state = st_inline_image; + before_token = false; + in_token = true; + state = st_inline_image; } void @@ -913,15 +913,15 @@ QPDFTokenizer::getToken(Token& token, bool& unread_char, char& ch) bool Tokenizer::getToken(Token& token, bool& unread_char, char& ch) { - bool ready = (this->state == st_token_ready); - unread_char = !this->in_token && !this->before_token; - ch = this->char_to_unread; + bool ready = (state == st_token_ready); + unread_char = !in_token && !before_token; + ch = char_to_unread; if (ready) { - token = (!(this->type == tt::tt_name || this->type == tt::tt_string)) - ? Token(this->type, this->raw_val, this->raw_val, this->error_message) - : Token(this->type, this->val, this->raw_val, this->error_message); + token = (!(type == tt::tt_name || type == tt::tt_string)) + ? Token(type, raw_val, raw_val, error_message) + : Token(type, val, raw_val, error_message); - this->reset(); + reset(); } return ready; } @@ -980,46 +980,46 @@ Tokenizer::readToken(InputSource& input, std::string const& context, bool allow_ bool Tokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len) { - if (this->state != st_inline_image) { + if (state != st_inline_image) { reset(); } qpdf_offset_t offset = input.fastTell(); - while (this->state != st_token_ready) { + while (state != st_token_ready) { char ch; if (!input.fastRead(ch)) { presentEOF(); - if ((this->type == tt::tt_eof) && (!this->allow_eof)) { + if ((type == tt::tt_eof) && (!allow_eof)) { // Nothing in the qpdf library calls readToken without allowEOF anymore, so this // case is not exercised. - this->type = tt::tt_bad; - this->error_message = "unexpected EOF"; + type = tt::tt_bad; + error_message = "unexpected EOF"; offset = input.getLastOffset(); } } else { handleCharacter(ch); - if (this->before_token) { + if (before_token) { ++offset; } - if (this->in_token) { - this->raw_val += ch; + if (in_token) { + raw_val += ch; } - if (max_len && (this->raw_val.length() >= max_len) && (this->state != st_token_ready)) { + if (max_len && (raw_val.length() >= max_len) && (state != st_token_ready)) { // terminate this token now QTC::TC("qpdf", "QPDFTokenizer block long token"); - this->type = tt::tt_bad; - this->state = st_token_ready; - this->error_message = "exceeded allowable length while reading token"; + type = tt::tt_bad; + state = st_token_ready; + error_message = "exceeded allowable length while reading token"; } } } - input.fastUnread(!this->in_token && !this->before_token); + input.fastUnread(!in_token && !before_token); - if (this->type != tt::tt_eof) { + if (type != tt::tt_eof) { input.setLastOffset(offset); } - return this->error_message.empty(); + return error_message.empty(); } diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index edad06f..a981d91 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1013,8 +1013,7 @@ QPDFWriter::pushMD5Pipeline(PipelinePopper& pp) if (!m->id2.empty()) { // Can't happen in the code throw std::logic_error( - "Deterministic ID computation enabled after ID" - " generation has already occurred."); + "Deterministic ID computation enabled after ID generation has already occurred."); } qpdf_assert_debug(m->deterministic_id); qpdf_assert_debug(m->md5_pipeline == nullptr); diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 01b1c77..ac9abfa 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -167,9 +167,7 @@ QPDF::readLinearizationData() // that prevent loading. if (!isLinearized()) { - throw std::logic_error( - "called readLinearizationData for file" - " that is not linearized"); + throw std::logic_error("called readLinearizationData for file that is not linearized"); } // /L is read and stored in linp by isLinearized() @@ -468,8 +466,7 @@ QPDF::checkLinearizationInternal() if (m->file->tell() != m->first_xref_item_offset) { QTC::TC("qpdf", "QPDF err /T mismatch"); linearizationWarning( - "space before first xref item (/T) mismatch " - "(computed = " + + "space before first xref item (/T) mismatch (computed = " + std::to_string(m->first_xref_item_offset) + "; file = " + std::to_string(m->file->tell())); } @@ -694,9 +691,7 @@ QPDF::checkHPageOffset( for (size_t i = 0; i < toS(he.nshared_objects); ++i) { int idx = he.shared_identifiers.at(i); if (shared_idx_to_obj.count(idx) == 0) { - stopOnError( - "unable to get object for item in" - " shared objects hint table"); + stopOnError("unable to get object for item in shared objects hint table"); } hint_shared.insert(shared_idx_to_obj[idx]); } @@ -759,15 +754,12 @@ QPDF::checkHSharedObject(std::vector const& pages, std::mappart8.empty()) { - linearizationWarning( - "part 8 is empty but nshared_total > " - "nshared_first_page"); + linearizationWarning("part 8 is empty but nshared_total > nshared_first_page"); } else { int obj = m->part8.at(0).getObjectID(); if (obj != so.first_shared_obj) { linearizationWarning( - "first shared object number mismatch: " - "hint table = " + + "first shared object number mismatch: hint table = " + std::to_string(so.first_shared_obj) + "; computed = " + std::to_string(obj)); } @@ -846,9 +838,7 @@ QPDF::checkHOutlines() std::to_string(table_length) + "; computed = " + std::to_string(length)); } } else { - linearizationWarning( - "incorrect first object number in outline " - "hints table."); + linearizationWarning("incorrect first object number in outline hints table."); } } else { linearizationWarning("incorrect object count in outline hint table"); @@ -1131,9 +1121,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) break; case ObjUser::ou_bad: - stopOnError( - "INTERNAL ERROR: QPDF::calculateLinearizationData: " - "invalid user type"); + stopOnError("INTERNAL ERROR: QPDF::calculateLinearizationData: invalid user type"); break; } } @@ -1196,9 +1184,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) // Part 4: open document objects. We don't care about the order. if (lc_root.size() != 1) { - stopOnError( - "found other than one root while" - " calculating linearization data"); + stopOnError("found other than one root while calculating linearization data"); } m->part4.push_back(getObject(*(lc_root.begin()))); for (auto const& og: lc_open_document) { @@ -1255,8 +1241,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) QPDFObjGen page_og(pages.at(i).getObjGen()); if (!lc_other_page_private.count(page_og)) { stopOnError( - "INTERNAL ERROR: " - "QPDF::calculateLinearizationData: page object for page " + + "INTERNAL ERROR: QPDF::calculateLinearizationData: page object for page " + std::to_string(i) + " not in lc_other_page_private"); } lc_other_page_private.erase(page_og); @@ -1269,9 +1254,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) ObjUser ou(ObjUser::ou_page, toI(i)); if (m->obj_user_to_objects.count(ou) == 0) { - stopOnError( - "found unreferenced page while" - " calculating linearization data"); + stopOnError("found unreferenced page while calculating linearization data"); } for (auto const& og: m->obj_user_to_objects[ou]) { if (lc_other_page_private.count(og)) { @@ -1284,9 +1267,8 @@ QPDF::calculateLinearizationData(T const& object_stream_data) // That should have covered all part7 objects. if (!lc_other_page_private.empty()) { stopOnError( - "INTERNAL ERROR:" - " QPDF::calculateLinearizationData: lc_other_page_private is " - "not empty after generation of part7"); + "INTERNAL ERROR: QPDF::calculateLinearizationData:" + " lc_other_page_private is not empty after generation of part7"); } // Part 8: other pages' shared objects @@ -1307,9 +1289,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) std::set pages_ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")]; if (pages_ogs.empty()) { - stopOnError( - "found empty pages tree while" - " calculating linearization data"); + stopOnError("found empty pages tree while calculating linearization data"); } for (auto const& og: pages_ogs) { if (lc_other.count(og)) { @@ -1418,9 +1398,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) CHPageOffsetEntry& pe = m->c_page_offset_data.entries.at(i); ObjUser ou(ObjUser::ou_page, toI(i)); if (m->obj_user_to_objects.count(ou) == 0) { - stopOnError( - "found unreferenced page while" - " calculating linearization data"); + stopOnError("found unreferenced page while calculating linearization data"); } for (auto const& og: m->obj_user_to_objects[ou]) { if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.count(og.getObj()) > 0)) { @@ -1759,9 +1737,7 @@ QPDF::writeHSharedObject(BitWriter& w) for (size_t i = 0; i < toS(nitems); ++i) { // If signature were present, we'd have to write a 128-bit hash. if (entries.at(i).signature_present != 0) { - stopOnError( - "found unexpected signature present" - " while writing linearization data"); + stopOnError("found unexpected signature present while writing linearization data"); } } write_vector_int(w, nitems, entries, t.nbits_nobjects, &HSharedObjectEntry::nobjects_minus_one); diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc index 65916c7..19de4f4 100644 --- a/libqpdf/QPDF_optimization.cc +++ b/libqpdf/QPDF_optimization.cc @@ -168,8 +168,7 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) warn_skipped_keys); if (!key_ancestors.empty()) { throw std::logic_error( - "key_ancestors not empty after" - " pushing inherited attributes to pages"); + "key_ancestors not empty after pushing inherited attributes to pages"); } m->pushed_inherited_attributes_to_pages = true; m->ever_pushed_inherited_attributes_to_pages = true;