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>
|
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),
|
2008-04-29 12:55:25 +00:00
|
|
|
last_char_was_cr(false),
|
|
|
|
unread_char(false),
|
2018-01-30 02:05:15 +00:00
|
|
|
char_to_unread('\0')
|
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-02 23:21:34 +00:00
|
|
|
Pl_QPDFTokenizer::Pl_QPDFTokenizer(
|
|
|
|
char const* identifier,
|
|
|
|
QPDFObjectHandle::TokenFilter* filter)
|
|
|
|
:
|
|
|
|
Pipeline(identifier, 0),
|
|
|
|
m(new Members)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
m->filter = filter;
|
|
|
|
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
|
|
|
|
Pl_QPDFTokenizer::processChar(char ch)
|
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->tokenizer.presentCharacter(ch);
|
2008-04-29 12:55:25 +00:00
|
|
|
QPDFTokenizer::Token token;
|
2018-02-02 23:21:34 +00:00
|
|
|
if (this->m->tokenizer.getToken(
|
|
|
|
token, this->m->unread_char, this->m->char_to_unread))
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->filter->handleToken(token);
|
|
|
|
if ((token.getType() == QPDFTokenizer::tt_word) &&
|
|
|
|
(token.getValue() == "ID"))
|
2018-01-30 02:16:56 +00:00
|
|
|
{
|
2018-01-30 02:05:15 +00:00
|
|
|
QTC::TC("qpdf", "Pl_QPDFTokenizer found ID");
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->tokenizer.expectInlineImage();
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_QPDFTokenizer::checkUnread()
|
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
if (this->m->unread_char)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
processChar(this->m->char_to_unread);
|
|
|
|
if (this->m->unread_char)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2009-09-26 18:36:04 +00:00
|
|
|
throw std::logic_error(
|
|
|
|
"INTERNAL ERROR: unread_char still true after processing "
|
|
|
|
"unread character");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-20 15:20:57 +00:00
|
|
|
Pl_QPDFTokenizer::write(unsigned char* buf, size_t len)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
checkUnread();
|
2012-06-20 15:20:57 +00:00
|
|
|
for (size_t i = 0; i < len; ++i)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
processChar(buf[i]);
|
|
|
|
checkUnread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_QPDFTokenizer::finish()
|
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->tokenizer.presentEOF();
|
2018-01-30 02:05:15 +00:00
|
|
|
QPDFTokenizer::Token token;
|
2018-02-02 23:21:34 +00:00
|
|
|
if (this->m->tokenizer.getToken(
|
|
|
|
token, this->m->unread_char, this->m->char_to_unread))
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->filter->handleToken(token);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 23:21:34 +00:00
|
|
|
this->m->filter->handleEOF();
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|