2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Pl_QPDFTokenizer.hh>
|
2011-04-30 18:20:35 +00:00
|
|
|
#include <qpdf/QTC.hh>
|
2019-01-30 19:20:56 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <qpdf/BufferInputSource.hh>
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <stdexcept>
|
2008-05-04 16:02:53 +00:00
|
|
|
#include <string.h>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2018-02-02 23:21:34 +00:00
|
|
|
Pl_QPDFTokenizer::Members::Members() :
|
|
|
|
filter(0),
|
2019-01-30 19:20:56 +00:00
|
|
|
buf("tokenizer buffer")
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-02 23:21:34 +00:00
|
|
|
Pl_QPDFTokenizer::Members::~Members()
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-16 01:45:19 +00:00
|
|
|
Pl_QPDFTokenizer::Pl_QPDFTokenizer(char const* identifier,
|
|
|
|
QPDFObjectHandle::TokenFilter* filter,
|
|
|
|
Pipeline* next) :
|
|
|
|
Pipeline(identifier, next),
|
2018-02-02 23:21:34 +00:00
|
|
|
m(new Members)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
m->filter = filter;
|
2018-02-16 01:45:19 +00:00
|
|
|
QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(
|
|
|
|
m->filter, next);
|
2018-02-02 23:21:34 +00:00
|
|
|
m->tokenizer.allowEOF();
|
|
|
|
m->tokenizer.includeIgnorable();
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 23:21:34 +00:00
|
|
|
Pl_QPDFTokenizer::~Pl_QPDFTokenizer()
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-30 19:20:56 +00:00
|
|
|
Pl_QPDFTokenizer::write(unsigned char* data, size_t len)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-01-30 19:20:56 +00:00
|
|
|
this->m->buf.write(data, len);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_QPDFTokenizer::finish()
|
|
|
|
{
|
2019-01-30 19:20:56 +00:00
|
|
|
this->m->buf.finish();
|
|
|
|
PointerHolder<InputSource> input =
|
|
|
|
new BufferInputSource("tokenizer data",
|
|
|
|
this->m->buf.getBuffer(), true);
|
|
|
|
|
|
|
|
while (true)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-01-30 19:20:56 +00:00
|
|
|
QPDFTokenizer::Token token = this->m->tokenizer.readToken(
|
|
|
|
input, "offset " + QUtil::int_to_string(input->tell()),
|
|
|
|
true);
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->filter->handleToken(token);
|
2019-01-30 19:20:56 +00:00
|
|
|
if (token.getType() == QPDFTokenizer::tt_eof)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if ((token.getType() == QPDFTokenizer::tt_word) &&
|
|
|
|
(token.getValue() == "ID"))
|
|
|
|
{
|
2019-01-31 04:24:09 +00:00
|
|
|
// Read the space after the ID.
|
|
|
|
char ch = ' ';
|
|
|
|
input->read(&ch, 1);
|
|
|
|
this->m->filter->handleToken(
|
|
|
|
QPDFTokenizer::Token(
|
|
|
|
QPDFTokenizer::tt_space, std::string(1, ch)));
|
2019-01-30 19:20:56 +00:00
|
|
|
QTC::TC("qpdf", "Pl_QPDFTokenizer found ID");
|
|
|
|
this->m->tokenizer.expectInlineImage(input);
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->filter->handleEOF();
|
2018-02-16 01:45:19 +00:00
|
|
|
QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(
|
|
|
|
m->filter, 0);
|
|
|
|
Pipeline* next = this->getNext(true);
|
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
next->finish();
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|