mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-07 06:08:26 +00:00
In QPDFParser constructor change input parameter to InputSource&
This commit is contained in:
parent
258343fcc9
commit
5d25aac6c7
@ -1465,7 +1465,7 @@ QPDF::readTrailer()
|
||||
qpdf_offset_t offset = m->file->tell();
|
||||
bool empty = false;
|
||||
auto object =
|
||||
QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false);
|
||||
QPDFParser(*m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false);
|
||||
if (empty) {
|
||||
// Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
|
||||
// actual PDF files and Adobe Reader appears to ignore them.
|
||||
@ -1488,7 +1488,7 @@ QPDF::readObject(std::string const& description, QPDFObjGen og)
|
||||
StringDecrypter decrypter{this, og};
|
||||
StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr;
|
||||
auto object =
|
||||
QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true)
|
||||
QPDFParser(*m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true)
|
||||
.parse(empty, false);
|
||||
if (empty) {
|
||||
// Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
|
||||
@ -1608,7 +1608,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj)
|
||||
m->last_object_description += " 0";
|
||||
|
||||
bool empty = false;
|
||||
auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this, true)
|
||||
auto object = QPDFParser(*input, m->last_object_description, m->tokenizer, nullptr, this, true)
|
||||
.parse(empty, false);
|
||||
if (empty) {
|
||||
// Nothing in the PDF spec appears to allow empty objects, but they have been encountered in
|
||||
|
@ -2164,7 +2164,7 @@ QPDFObjectHandle::parseContentStream_data(
|
||||
qpdf_offset_t offset = input->getLastOffset();
|
||||
input->seek(offset, SEEK_SET);
|
||||
auto obj =
|
||||
QPDFParser(input, "content", tokenizer, nullptr, context, false).parse(empty, true);
|
||||
QPDFParser(*input, "content", tokenizer, nullptr, context, false).parse(empty, true);
|
||||
if (!obj.isInitialized()) {
|
||||
// EOF
|
||||
break;
|
||||
@ -2223,7 +2223,7 @@ QPDFObjectHandle::parse(
|
||||
StringDecrypter* decrypter,
|
||||
QPDF* context)
|
||||
{
|
||||
return QPDFParser(input, object_description, tokenizer, decrypter, context, false)
|
||||
return QPDFParser(*input, object_description, tokenizer, decrypter, context, false)
|
||||
.parse(empty, false);
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
|
||||
QPDF::ParseGuard pg(context);
|
||||
empty = false;
|
||||
start = input->tell();
|
||||
start = input.tell();
|
||||
|
||||
if (!tokenizer.nextToken(*input, object_description)) {
|
||||
if (!tokenizer.nextToken(input, object_description)) {
|
||||
warn(tokenizer.getErrorMessage());
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
|
||||
} else if (value == "endobj") {
|
||||
// We just saw endobj without having read anything. Treat this as a null and do
|
||||
// not move the input source's offset.
|
||||
input->seek(input->getLastOffset(), SEEK_SET);
|
||||
input.seek(input.getLastOffset(), SEEK_SET);
|
||||
empty = true;
|
||||
return {QPDF_Null::create()};
|
||||
} else {
|
||||
@ -138,7 +138,7 @@ QPDFParser::parseRemainder(bool content_stream)
|
||||
bool b_contents = false;
|
||||
|
||||
while (true) {
|
||||
if (!tokenizer.nextToken(*input, object_description)) {
|
||||
if (!tokenizer.nextToken(input, object_description)) {
|
||||
warn(tokenizer.getErrorMessage());
|
||||
}
|
||||
++good_count; // optimistically
|
||||
@ -151,7 +151,7 @@ QPDFParser::parseRemainder(bool content_stream)
|
||||
// Process the oldest buffered integer.
|
||||
addInt(int_count);
|
||||
}
|
||||
last_offset_buffer[int_count % 2] = input->getLastOffset();
|
||||
last_offset_buffer[int_count % 2] = input.getLastOffset();
|
||||
int_buffer[int_count % 2] = QUtil::string_to_ll(tokenizer.getValue().c_str());
|
||||
continue;
|
||||
|
||||
@ -309,7 +309,7 @@ QPDFParser::parseRemainder(bool content_stream)
|
||||
case QPDFTokenizer::tt_integer:
|
||||
if (!content_stream) {
|
||||
// Buffer token in case it is part of an indirect reference.
|
||||
last_offset_buffer[1] = input->getLastOffset();
|
||||
last_offset_buffer[1] = input.getLastOffset();
|
||||
int_buffer[1] = QUtil::string_to_ll(tokenizer.getValue().c_str());
|
||||
int_count = 1;
|
||||
} else {
|
||||
@ -351,7 +351,7 @@ QPDFParser::parseRemainder(bool content_stream)
|
||||
if (decrypter) {
|
||||
if (b_contents) {
|
||||
frame->contents_string = val;
|
||||
frame->contents_offset = input->getLastOffset();
|
||||
frame->contents_offset = input.getLastOffset();
|
||||
b_contents = false;
|
||||
}
|
||||
std::string s{val};
|
||||
@ -419,7 +419,7 @@ void
|
||||
QPDFParser::addScalar(Args&&... args)
|
||||
{
|
||||
auto obj = T::create(args...);
|
||||
obj->setDescription(context, description, input->getLastOffset());
|
||||
obj->setDescription(context, description, input.getLastOffset());
|
||||
add(std::move(obj));
|
||||
}
|
||||
|
||||
@ -506,11 +506,11 @@ QPDFParser::warnDuplicateKey()
|
||||
void
|
||||
QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const
|
||||
{
|
||||
warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg));
|
||||
warn(QPDFExc(qpdf_e_damaged_pdf, input.getName(), object_description, offset, msg));
|
||||
}
|
||||
|
||||
void
|
||||
QPDFParser::warn(std::string const& msg) const
|
||||
{
|
||||
warn(input->getLastOffset(), msg);
|
||||
warn(input.getLastOffset(), msg);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class QPDFParser
|
||||
public:
|
||||
QPDFParser() = delete;
|
||||
QPDFParser(
|
||||
std::shared_ptr<InputSource> input,
|
||||
InputSource& input,
|
||||
std::string const& object_description,
|
||||
QPDFTokenizer& tokenizer,
|
||||
QPDFObjectHandle::StringDecrypter* decrypter,
|
||||
@ -24,7 +24,7 @@ class QPDFParser
|
||||
decrypter(decrypter),
|
||||
context(context),
|
||||
description(std::make_shared<QPDFValue::Description>(
|
||||
std::string(input->getName() + ", " + object_description + " at offset $PO"))),
|
||||
std::string(input.getName() + ", " + object_description + " at offset $PO"))),
|
||||
parse_pdf(parse_pdf)
|
||||
{
|
||||
}
|
||||
@ -39,9 +39,9 @@ class QPDFParser
|
||||
|
||||
struct StackFrame
|
||||
{
|
||||
StackFrame(std::shared_ptr<InputSource> const& input, parser_state_e state) :
|
||||
StackFrame(InputSource& input, parser_state_e state) :
|
||||
state(state),
|
||||
offset(input->tell())
|
||||
offset(input.tell())
|
||||
{
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ class QPDFParser
|
||||
// NB the offset includes any leading whitespace.
|
||||
QPDFObjectHandle withDescription(Args&&... args);
|
||||
void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset);
|
||||
std::shared_ptr<InputSource> input;
|
||||
InputSource& input;
|
||||
std::string const& object_description;
|
||||
QPDFTokenizer& tokenizer;
|
||||
QPDFObjectHandle::StringDecrypter* decrypter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user