Commit eeb6162f7620fba49bb141ccd2c715cd829c8e24
1 parent
6f1041af
Add optional parameter separator to QPDFObjGen::unparse
Also, revert inlining of unparse and operator << from commit 4c6640c in order to avoid exposing QUtil.
Showing
12 changed files
with
58 additions
and
70 deletions
include/qpdf/QPDFObjGen.hh
| ... | ... | @@ -23,7 +23,6 @@ |
| 23 | 23 | #define QPDFOBJGEN_HH |
| 24 | 24 | |
| 25 | 25 | #include <qpdf/DLL.h> |
| 26 | -#include <qpdf/QUtil.hh> | |
| 27 | 26 | #include <iostream> |
| 28 | 27 | |
| 29 | 28 | // This class represents an object ID and generation pair. It is |
| ... | ... | @@ -69,18 +68,9 @@ class QPDFObjGen |
| 69 | 68 | return gen; |
| 70 | 69 | } |
| 71 | 70 | QPDF_DLL |
| 72 | - std::string | |
| 73 | - unparse() const | |
| 74 | - { | |
| 75 | - return QUtil::int_to_string(obj) + "," + QUtil::int_to_string(gen); | |
| 76 | - } | |
| 71 | + std::string unparse(char separator = ',') const; | |
| 77 | 72 | QPDF_DLL |
| 78 | - friend std::ostream& | |
| 79 | - operator<<(std::ostream& os, const QPDFObjGen& og) | |
| 80 | - { | |
| 81 | - os << og.obj << "," << og.gen; | |
| 82 | - return os; | |
| 83 | - } | |
| 73 | + friend std::ostream& operator<<(std::ostream& os, const QPDFObjGen& og); | |
| 84 | 74 | |
| 85 | 75 | private: |
| 86 | 76 | // This class does not use the Members pattern to avoid a memory | ... | ... |
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -1584,7 +1584,6 @@ class QPDFObjectHandle |
| 1584 | 1584 | bool stop_at_streams); |
| 1585 | 1585 | void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only); |
| 1586 | 1586 | void releaseResolved(); |
| 1587 | - std::string getObjGenAsStr() const; | |
| 1588 | 1587 | static void setObjectDescriptionFromInput( |
| 1589 | 1588 | QPDFObjectHandle, |
| 1590 | 1589 | QPDF*, | ... | ... |
libqpdf/CMakeLists.txt
libqpdf/QPDF.cc
| ... | ... | @@ -1493,9 +1493,8 @@ QPDF::setLastObjectDescription( |
| 1493 | 1493 | } |
| 1494 | 1494 | } |
| 1495 | 1495 | if (objid > 0) { |
| 1496 | - this->m->last_object_description += "object " + | |
| 1497 | - QUtil::int_to_string(objid) + " " + | |
| 1498 | - QUtil::int_to_string(generation); | |
| 1496 | + this->m->last_object_description += | |
| 1497 | + "object " + QPDFObjGen(objid, generation).unparse(' '); | |
| 1499 | 1498 | } |
| 1500 | 1499 | } |
| 1501 | 1500 | |
| ... | ... | @@ -1862,8 +1861,8 @@ QPDF::readObjectAtOffset( |
| 1862 | 1861 | this->m->file->getName(), |
| 1863 | 1862 | this->m->last_object_description, |
| 1864 | 1863 | offset, |
| 1865 | - (std::string("expected ") + QUtil::int_to_string(exp_objid) + | |
| 1866 | - " " + QUtil::int_to_string(exp_generation) + " obj")); | |
| 1864 | + (std::string("expected ") + | |
| 1865 | + QPDFObjGen(exp_objid, exp_generation).unparse(' ') + " obj")); | |
| 1867 | 1866 | if (try_recovery) { |
| 1868 | 1867 | // Will be retried below |
| 1869 | 1868 | throw e; |
| ... | ... | @@ -1898,8 +1897,8 @@ QPDF::readObjectAtOffset( |
| 1898 | 1897 | "", |
| 1899 | 1898 | 0, |
| 1900 | 1899 | std::string( |
| 1901 | - "object " + QUtil::int_to_string(exp_objid) + " " + | |
| 1902 | - QUtil::int_to_string(exp_generation) + | |
| 1900 | + "object " + | |
| 1901 | + QPDFObjGen(exp_objid, exp_generation).unparse(' ') + | |
| 1903 | 1902 | " not found in file after regenerating" |
| 1904 | 1903 | " cross reference table")); |
| 1905 | 1904 | return QPDFObjectHandle::newNull(); |
| ... | ... | @@ -2002,8 +2001,7 @@ QPDF::resolve(int objid, int generation) |
| 2002 | 2001 | qpdf_e_damaged_pdf, |
| 2003 | 2002 | "", |
| 2004 | 2003 | this->m->file->getLastOffset(), |
| 2005 | - ("loop detected resolving object " + QUtil::int_to_string(objid) + | |
| 2006 | - " " + QUtil::int_to_string(generation))); | |
| 2004 | + ("loop detected resolving object " + og.unparse(' '))); | |
| 2007 | 2005 | return QPDF_Null::create(); |
| 2008 | 2006 | } |
| 2009 | 2007 | ResolveRecorder rr(this, og); |
| ... | ... | @@ -2039,8 +2037,7 @@ QPDF::resolve(int objid, int generation) |
| 2039 | 2037 | this->m->file->getName(), |
| 2040 | 2038 | "", |
| 2041 | 2039 | 0, |
| 2042 | - ("object " + QUtil::int_to_string(objid) + "/" + | |
| 2043 | - QUtil::int_to_string(generation) + | |
| 2040 | + ("object " + og.unparse('/') + | |
| 2044 | 2041 | " has unexpected xref entry type")); |
| 2045 | 2042 | } |
| 2046 | 2043 | } catch (QPDFExc& e) { |
| ... | ... | @@ -2050,8 +2047,7 @@ QPDF::resolve(int objid, int generation) |
| 2050 | 2047 | qpdf_e_damaged_pdf, |
| 2051 | 2048 | "", |
| 2052 | 2049 | 0, |
| 2053 | - ("object " + QUtil::int_to_string(objid) + "/" + | |
| 2054 | - QUtil::int_to_string(generation) + | |
| 2050 | + ("object " + og.unparse('/') + | |
| 2055 | 2051 | ": error reading object: " + e.what())); |
| 2056 | 2052 | } |
| 2057 | 2053 | } |
| ... | ... | @@ -2065,10 +2061,7 @@ QPDF::resolve(int objid, int generation) |
| 2065 | 2061 | |
| 2066 | 2062 | std::shared_ptr<QPDFObject> result(this->m->obj_cache[og].object); |
| 2067 | 2063 | if (!result->hasDescription()) { |
| 2068 | - result->setDescription( | |
| 2069 | - this, | |
| 2070 | - ("object " + QUtil::int_to_string(objid) + " " + | |
| 2071 | - QUtil::int_to_string(generation))); | |
| 2064 | + result->setDescription(this, ("object " + og.unparse(' '))); | |
| 2072 | 2065 | } |
| 2073 | 2066 | return result; |
| 2074 | 2067 | } |
| ... | ... | @@ -2809,8 +2802,8 @@ QPDF::pipeStreamData( |
| 2809 | 2802 | "", |
| 2810 | 2803 | file->getLastOffset(), |
| 2811 | 2804 | ("error decoding stream data for object " + |
| 2812 | - QUtil::int_to_string(objid) + " " + | |
| 2813 | - QUtil::int_to_string(generation) + ": " + e.what()))); | |
| 2805 | + QPDFObjGen(objid, generation).unparse(' ') + ": " + | |
| 2806 | + e.what()))); | |
| 2814 | 2807 | if (will_retry) { |
| 2815 | 2808 | qpdf_for_warning.warn( |
| 2816 | 2809 | // line-break | ... | ... |
libqpdf/QPDFAcroFormDocumentHelper.cc
| ... | ... | @@ -991,8 +991,8 @@ QPDFAcroFormDocumentHelper::transformAnnotations( |
| 991 | 991 | } else { |
| 992 | 992 | parent.warnIfPossible( |
| 993 | 993 | "while traversing field " + |
| 994 | - obj.getObjGen().unparse() + ", found parent (" + | |
| 995 | - parent_og.unparse() + | |
| 994 | + obj.getObjGen().unparse(',') + ", found parent (" + | |
| 995 | + parent_og.unparse(',') + | |
| 996 | 996 | ") that had not been seen, indicating likely" |
| 997 | 997 | " invalid field structure"); |
| 998 | 998 | } | ... | ... |
libqpdf/QPDFJob.cc
| ... | ... | @@ -947,7 +947,7 @@ QPDFJob::doShowObj(QPDF& pdf) |
| 947 | 947 | } |
| 948 | 948 | if (error) { |
| 949 | 949 | throw std::runtime_error( |
| 950 | - "unable to get object " + obj.getObjGen().unparse()); | |
| 950 | + "unable to get object " + obj.getObjGen().unparse(',')); | |
| 951 | 951 | } |
| 952 | 952 | } |
| 953 | 953 | |
| ... | ... | @@ -995,7 +995,8 @@ QPDFJob::doListAttachments(QPDF& pdf) |
| 995 | 995 | auto efoh = i.second; |
| 996 | 996 | *this->m->log->getInfo() |
| 997 | 997 | << key << " -> " |
| 998 | - << efoh->getEmbeddedFileStream().getObjGen().unparse() << "\n"; | |
| 998 | + << efoh->getEmbeddedFileStream().getObjGen().unparse(',') | |
| 999 | + << "\n"; | |
| 999 | 1000 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 1000 | 1001 | auto desc = efoh->getDescription(); |
| 1001 | 1002 | if (!desc.empty()) { |
| ... | ... | @@ -1010,7 +1011,7 @@ QPDFJob::doListAttachments(QPDF& pdf) |
| 1010 | 1011 | for (auto i2: efoh->getEmbeddedFileStreams().ditems()) { |
| 1011 | 1012 | auto efs = QPDFEFStreamObjectHelper(i2.second); |
| 1012 | 1013 | v << " " << i2.first << " -> " |
| 1013 | - << efs.getObjectHandle().getObjGen().unparse() << "\n"; | |
| 1014 | + << efs.getObjectHandle().getObjGen().unparse(',') << "\n"; | |
| 1014 | 1015 | v << " creation date: " << efs.getCreationDate() |
| 1015 | 1016 | << "\n" |
| 1016 | 1017 | << " modification date: " << efs.getModDate() << "\n" | ... | ... |
libqpdf/QPDFObjGen.cc
0 โ 100644
| 1 | +#include <qpdf/QPDFObjGen.hh> | |
| 2 | + | |
| 3 | +#include <qpdf/QUtil.hh> | |
| 4 | + | |
| 5 | +std::ostream& | |
| 6 | +operator<<(std::ostream& os, const QPDFObjGen& og) | |
| 7 | +{ | |
| 8 | + os << og.obj << "," << og.gen; | |
| 9 | + return os; | |
| 10 | +} | |
| 11 | + | |
| 12 | +std::string | |
| 13 | +QPDFObjGen::unparse(char separator) const | |
| 14 | +{ | |
| 15 | + return QUtil::int_to_string(this->obj) + separator + | |
| 16 | + QUtil::int_to_string(this->gen); | |
| 17 | +} | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -103,9 +103,8 @@ void |
| 103 | 103 | CoalesceProvider::provideStreamData(int, int, Pipeline* p) |
| 104 | 104 | { |
| 105 | 105 | QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); |
| 106 | - std::string description = "page object " + | |
| 107 | - QUtil::int_to_string(containing_page.getObjectID()) + " " + | |
| 108 | - QUtil::int_to_string(containing_page.getGeneration()); | |
| 106 | + std::string description = | |
| 107 | + "page object " + containing_page.getObjGen().unparse(' '); | |
| 109 | 108 | std::string all_description; |
| 110 | 109 | old_contents.pipeContentStreams(p, description, all_description); |
| 111 | 110 | } |
| ... | ... | @@ -1485,13 +1484,6 @@ QPDFObjectHandle::getObjGen() const |
| 1485 | 1484 | return QPDFObjGen(this->objid, this->generation); |
| 1486 | 1485 | } |
| 1487 | 1486 | |
| 1488 | -std::string | |
| 1489 | -QPDFObjectHandle::getObjGenAsStr() const | |
| 1490 | -{ | |
| 1491 | - return QUtil::int_to_string(this->objid) + " " + | |
| 1492 | - QUtil::int_to_string(this->generation); | |
| 1493 | -} | |
| 1494 | - | |
| 1495 | 1487 | int |
| 1496 | 1488 | QPDFObjectHandle::getObjectID() const |
| 1497 | 1489 | { |
| ... | ... | @@ -1556,7 +1548,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( |
| 1556 | 1548 | } else { |
| 1557 | 1549 | all_description += ","; |
| 1558 | 1550 | } |
| 1559 | - all_description += " stream " + item.getObjGenAsStr(); | |
| 1551 | + all_description += " stream " + item.getObjGen().unparse(' '); | |
| 1560 | 1552 | } |
| 1561 | 1553 | |
| 1562 | 1554 | return result; |
| ... | ... | @@ -1565,7 +1557,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( |
| 1565 | 1557 | std::vector<QPDFObjectHandle> |
| 1566 | 1558 | QPDFObjectHandle::getPageContents() |
| 1567 | 1559 | { |
| 1568 | - std::string description = "page object " + getObjGenAsStr(); | |
| 1560 | + std::string description = "page object " + getObjGen().unparse(' '); | |
| 1569 | 1561 | std::string all_description; |
| 1570 | 1562 | return this->getKey("/Contents") |
| 1571 | 1563 | .arrayOrStreamToStreamArray(description, all_description); |
| ... | ... | @@ -1674,7 +1666,7 @@ QPDFObjectHandle::unparse() |
| 1674 | 1666 | { |
| 1675 | 1667 | std::string result; |
| 1676 | 1668 | if (this->isIndirect()) { |
| 1677 | - result = getObjGenAsStr() + " R"; | |
| 1669 | + result = getObjGen().unparse(' ') + " R"; | |
| 1678 | 1670 | } else { |
| 1679 | 1671 | result = unparseResolved(); |
| 1680 | 1672 | } |
| ... | ... | @@ -1789,7 +1781,7 @@ QPDFObjectHandle::parse( |
| 1789 | 1781 | void |
| 1790 | 1782 | QPDFObjectHandle::pipePageContents(Pipeline* p) |
| 1791 | 1783 | { |
| 1792 | - std::string description = "page object " + getObjGenAsStr(); | |
| 1784 | + std::string description = "page object " + getObjGen().unparse(' '); | |
| 1793 | 1785 | std::string all_description; |
| 1794 | 1786 | this->getKey("/Contents") |
| 1795 | 1787 | .pipeContentStreams(p, description, all_description); |
| ... | ... | @@ -1813,7 +1805,7 @@ QPDFObjectHandle::pipeContentStreams( |
| 1813 | 1805 | throw QPDFExc( |
| 1814 | 1806 | qpdf_e_damaged_pdf, |
| 1815 | 1807 | "content stream", |
| 1816 | - "content stream object " + stream.getObjGenAsStr(), | |
| 1808 | + "content stream object " + stream.getObjGen().unparse(' '), | |
| 1817 | 1809 | 0, |
| 1818 | 1810 | "errors while decoding content stream"); |
| 1819 | 1811 | } |
| ... | ... | @@ -1829,7 +1821,7 @@ QPDFObjectHandle::pipeContentStreams( |
| 1829 | 1821 | void |
| 1830 | 1822 | QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks) |
| 1831 | 1823 | { |
| 1832 | - std::string description = "page object " + getObjGenAsStr(); | |
| 1824 | + std::string description = "page object " + getObjGen().unparse(' '); | |
| 1833 | 1825 | this->getKey("/Contents") |
| 1834 | 1826 | .parseContentStream_internal(description, callbacks); |
| 1835 | 1827 | } |
| ... | ... | @@ -1837,14 +1829,15 @@ QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks) |
| 1837 | 1829 | void |
| 1838 | 1830 | QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks) |
| 1839 | 1831 | { |
| 1840 | - std::string description = "object " + getObjGenAsStr(); | |
| 1832 | + std::string description = "object " + getObjGen().unparse(' '); | |
| 1841 | 1833 | this->parseContentStream_internal(description, callbacks); |
| 1842 | 1834 | } |
| 1843 | 1835 | |
| 1844 | 1836 | void |
| 1845 | 1837 | QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next) |
| 1846 | 1838 | { |
| 1847 | - auto description = "token filter for page object " + getObjGenAsStr(); | |
| 1839 | + auto description = | |
| 1840 | + "token filter for page object " + getObjGen().unparse(' '); | |
| 1848 | 1841 | Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next); |
| 1849 | 1842 | this->pipePageContents(&token_pipeline); |
| 1850 | 1843 | } |
| ... | ... | @@ -1852,7 +1845,7 @@ QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next) |
| 1852 | 1845 | void |
| 1853 | 1846 | QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next) |
| 1854 | 1847 | { |
| 1855 | - auto description = "token filter for object " + getObjGenAsStr(); | |
| 1848 | + auto description = "token filter for object " + getObjGen().unparse(' '); | |
| 1856 | 1849 | Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next); |
| 1857 | 1850 | this->pipeStreamData(&token_pipeline, 0, qpdf_dl_specialized); |
| 1858 | 1851 | } | ... | ... |
libqpdf/QPDFPageObjectHelper.cc
| ... | ... | @@ -33,9 +33,8 @@ void |
| 33 | 33 | ContentProvider::provideStreamData(int, int, Pipeline* p) |
| 34 | 34 | { |
| 35 | 35 | Pl_Concatenate concat("concatenate", p); |
| 36 | - std::string description = "contents from page object " + | |
| 37 | - QUtil::int_to_string(from_page.getObjectID()) + " " + | |
| 38 | - QUtil::int_to_string(from_page.getGeneration()); | |
| 36 | + std::string description = | |
| 37 | + "contents from page object " + from_page.getObjGen().unparse(' '); | |
| 39 | 38 | std::string all_description; |
| 40 | 39 | from_page.getKey("/Contents") |
| 41 | 40 | .pipeContentStreams(&concat, description, all_description); | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -1990,9 +1990,8 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) |
| 1990 | 1990 | if (object_stream_index == -1) { |
| 1991 | 1991 | if (this->m->qdf_mode && (!this->m->suppress_original_object_ids)) { |
| 1992 | 1992 | writeString( |
| 1993 | - "%% Original object ID: " + | |
| 1994 | - QUtil::int_to_string(object.getObjectID()) + " " + | |
| 1995 | - QUtil::int_to_string(object.getGeneration()) + "\n"); | |
| 1993 | + "%% Original object ID: " + object.getObjGen().unparse(' ') + | |
| 1994 | + "\n"); | |
| 1996 | 1995 | } |
| 1997 | 1996 | openObject(new_id); |
| 1998 | 1997 | setDataKey(new_id); | ... | ... |
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -130,8 +130,7 @@ QPDF_Stream::QPDF_Stream( |
| 130 | 130 | setDescription( |
| 131 | 131 | this->qpdf, |
| 132 | 132 | this->qpdf->getFilename() + ", stream object " + |
| 133 | - QUtil::int_to_string(this->objid) + " " + | |
| 134 | - QUtil::int_to_string(this->generation)); | |
| 133 | + QPDFObjGen(objid, generation).unparse(' ')); | |
| 135 | 134 | } |
| 136 | 135 | |
| 137 | 136 | std::shared_ptr<QPDFObject> |
| ... | ... | @@ -196,8 +195,7 @@ std::string |
| 196 | 195 | QPDF_Stream::unparse() |
| 197 | 196 | { |
| 198 | 197 | // Unparse stream objects as indirect references |
| 199 | - return QUtil::int_to_string(this->objid) + " " + | |
| 200 | - QUtil::int_to_string(this->generation) + " R"; | |
| 198 | + return QPDFObjGen(objid, generation).unparse(' ') + " R"; | |
| 201 | 199 | } |
| 202 | 200 | |
| 203 | 201 | JSON |
| ... | ... | @@ -643,8 +641,7 @@ QPDF_Stream::pipeStreamData( |
| 643 | 641 | // part of a library user, not by invalid input data. |
| 644 | 642 | throw std::runtime_error( |
| 645 | 643 | "stream data provider for " + |
| 646 | - QUtil::int_to_string(this->objid) + " " + | |
| 647 | - QUtil::int_to_string(this->generation) + " provided " + | |
| 644 | + QPDFObjGen(objid, generation).unparse(' ') + " provided " + | |
| 648 | 645 | QUtil::int_to_string(actual_length) + |
| 649 | 646 | " bytes instead of expected " + |
| 650 | 647 | QUtil::int_to_string(desired_length) + " bytes"); | ... | ... |
libqpdf/QPDF_encryption.cc
| ... | ... | @@ -1176,8 +1176,7 @@ QPDF::decryptString(std::string& str, int objid, int generation) |
| 1176 | 1176 | this->m->last_object_description, |
| 1177 | 1177 | this->m->file->getLastOffset(), |
| 1178 | 1178 | "error decrypting string for object " + |
| 1179 | - QUtil::int_to_string(objid) + " " + | |
| 1180 | - QUtil::int_to_string(generation) + ": " + e.what()); | |
| 1179 | + QPDFObjGen(objid, generation).unparse() + ": " + e.what()); | |
| 1181 | 1180 | } |
| 1182 | 1181 | } |
| 1183 | 1182 | ... | ... |