mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Refactor QPDFParser::setDescriptionFromInput and rename to setDescription
Set parsed offset at the same time as setting description.
This commit is contained in:
parent
dab48544d2
commit
d03ca88275
@ -3,6 +3,7 @@
|
||||
#include <qpdf/QPDF.hh>
|
||||
#include <qpdf/QPDFObjGen.hh>
|
||||
#include <qpdf/QPDFObjectHandle.hh>
|
||||
#include <qpdf/QPDFObject_private.hh>
|
||||
#include <qpdf/QTC.hh>
|
||||
#include <qpdf/QUtil.hh>
|
||||
|
||||
@ -287,8 +288,8 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
if (!indirect_ref && !is_null) {
|
||||
// No need to set description for direct nulls - they will
|
||||
// become implicit.
|
||||
setDescriptionFromInput(object, input->getLastOffset());
|
||||
object.setParsedOffset(input->getLastOffset());
|
||||
auto os = input->getLastOffset();
|
||||
setDescription(object, os, os);
|
||||
}
|
||||
set_offset = true;
|
||||
olist.push_back(is_null ? null_oh : object);
|
||||
@ -311,13 +312,12 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
state_stack.pop_back();
|
||||
if (old_state == st_array) {
|
||||
object = QPDFObjectHandle::newArray(olist);
|
||||
setDescriptionFromInput(object, offset);
|
||||
setDescription(object, offset, offset - 1);
|
||||
// The `offset` points to the next of "[". Set the rewind
|
||||
// offset to point to the beginning of "[". This has been
|
||||
// explicitly tested with whitespace surrounding the array start
|
||||
// delimiter. getLastOffset points to the array end token and
|
||||
// therefore can't be used here.
|
||||
object.setParsedOffset(offset - 1);
|
||||
set_offset = true;
|
||||
} else if (old_state == st_dictionary) {
|
||||
// Convert list to map. Alternating elements are keys. Attempt
|
||||
@ -362,7 +362,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
"dictionary ended prematurely; "
|
||||
"using null as value for last key");
|
||||
val = QPDFObjectHandle::newNull();
|
||||
setDescriptionFromInput(val, offset);
|
||||
setDescription(val, offset);
|
||||
} else {
|
||||
val = olist.at(++i);
|
||||
}
|
||||
@ -386,13 +386,12 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
dict["/Contents"].setParsedOffset(frame.contents_offset);
|
||||
}
|
||||
object = QPDFObjectHandle::newDictionary(dict);
|
||||
setDescriptionFromInput(object, offset);
|
||||
setDescription(object, offset, offset - 2);
|
||||
// The `offset` points to the next of "<<". Set the rewind
|
||||
// offset to point to the beginning of "<<". This has been
|
||||
// explicitly tested with whitespace surrounding the dictionary
|
||||
// start delimiter. getLastOffset points to the dictionary end
|
||||
// token and therefore can't be used here.
|
||||
object.setParsedOffset(offset - 2);
|
||||
set_offset = true;
|
||||
}
|
||||
stack.pop_back();
|
||||
@ -408,20 +407,24 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
object = QPDFObjectHandle::newNull();
|
||||
}
|
||||
if (!set_offset) {
|
||||
setDescriptionFromInput(object, offset);
|
||||
object.setParsedOffset(offset);
|
||||
setDescription(object, offset, offset);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
QPDFParser::setDescriptionFromInput(
|
||||
QPDFObjectHandle oh, qpdf_offset_t offset) const
|
||||
QPDFParser::setDescription(
|
||||
QPDFObjectHandle oh,
|
||||
qpdf_offset_t descr_offset,
|
||||
qpdf_offset_t parsed_offset) const
|
||||
{
|
||||
oh.setObjectDescription(
|
||||
if (auto& obj = oh.obj) {
|
||||
obj->setDescription(
|
||||
context,
|
||||
(input->getName() + ", " + object_description + " at offset " +
|
||||
std::to_string(offset)));
|
||||
std::to_string(descr_offset)),
|
||||
parsed_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -124,8 +124,9 @@ QPDF_Stream::QPDF_Stream(
|
||||
"object for dictionary");
|
||||
}
|
||||
setDescription(
|
||||
qpdf, qpdf->getFilename() + ", stream object " + og.unparse(' '));
|
||||
this->parsed_offset = offset;
|
||||
qpdf,
|
||||
qpdf->getFilename() + ", stream object " + og.unparse(' '),
|
||||
offset);
|
||||
}
|
||||
|
||||
std::shared_ptr<QPDFObject>
|
||||
@ -282,9 +283,10 @@ QPDF_Stream::getStreamJSON(
|
||||
}
|
||||
|
||||
void
|
||||
QPDF_Stream::setDescription(QPDF* qpdf, std::string const& description)
|
||||
QPDF_Stream::setDescription(
|
||||
QPDF* qpdf, std::string const& description, qpdf_offset_t offset)
|
||||
{
|
||||
this->QPDFValue::setDescription(qpdf, description);
|
||||
this->QPDFValue::setDescription(qpdf, description, offset);
|
||||
setDictDescription();
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,10 @@ class QPDFObject
|
||||
}
|
||||
|
||||
void
|
||||
setDescription(QPDF* qpdf, std::string const& description)
|
||||
setDescription(
|
||||
QPDF* qpdf, std::string const& description, qpdf_offset_t offset = -1)
|
||||
{
|
||||
return value->setDescription(qpdf, description);
|
||||
return value->setDescription(qpdf, description, offset);
|
||||
}
|
||||
bool
|
||||
getDescription(QPDF*& qpdf, std::string& description)
|
||||
|
@ -40,9 +40,11 @@ class QPDFParser
|
||||
void warn(qpdf_offset_t offset, std::string const& msg) const;
|
||||
void warn(std::string const& msg) const;
|
||||
static void warn(QPDF*, QPDFExc const&);
|
||||
void setParsedOffset(qpdf_offset_t offset);
|
||||
void
|
||||
setDescriptionFromInput(QPDFObjectHandle oh, qpdf_offset_t offset) const;
|
||||
|
||||
void setDescription(
|
||||
QPDFObjectHandle oh,
|
||||
qpdf_offset_t descr_offset,
|
||||
qpdf_offset_t parsed_offset = -1) const;
|
||||
std::shared_ptr<InputSource> input;
|
||||
std::string const& object_description;
|
||||
QPDFTokenizer& tokenizer;
|
||||
|
@ -24,10 +24,12 @@ class QPDFValue
|
||||
virtual std::string unparse() = 0;
|
||||
virtual JSON getJSON(int json_version) = 0;
|
||||
virtual void
|
||||
setDescription(QPDF* qpdf_p, std::string const& description)
|
||||
setDescription(
|
||||
QPDF* qpdf_p, std::string const& description, qpdf_offset_t offset)
|
||||
{
|
||||
qpdf = qpdf_p;
|
||||
object_description = description;
|
||||
setParsedOffset(offset);
|
||||
}
|
||||
bool
|
||||
getDescription(QPDF*& qpdf_p, std::string& description)
|
||||
|
@ -26,7 +26,8 @@ class QPDF_Stream: public QPDFValue
|
||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual void setDescription(QPDF*, std::string const&);
|
||||
virtual void
|
||||
setDescription(QPDF*, std::string const&, qpdf_offset_t offset);
|
||||
virtual void disconnect();
|
||||
QPDFObjectHandle getDict() const;
|
||||
bool isDataModified() const;
|
||||
|
Loading…
Reference in New Issue
Block a user