mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-10 23:20:58 +00:00
cb769c62e5
This comment expands all tabs using an 8-character tab-width. You should ignore this commit when using git blame or use git blame -w. In the early days, I used to use tabs where possible for indentation, since emacs did this automatically. In recent years, I have switched to only using spaces, which means qpdf source code has been a mixture of spaces and tabs. I have avoided cleaning this up because of not wanting gratuitous whitespaces change to cloud the output of git blame, but I changed my mind after discussing with users who view qpdf source code in editors/IDEs that have other tab widths by default and in light of the fact that I am planning to start applying automatic code formatting soon.
82 lines
2.1 KiB
C++
82 lines
2.1 KiB
C++
#include <qpdf/Pl_QPDFTokenizer.hh>
|
|
|
|
#include <qpdf/QTC.hh>
|
|
#include <qpdf/QUtil.hh>
|
|
#include <qpdf/BufferInputSource.hh>
|
|
#include <stdexcept>
|
|
#include <string.h>
|
|
|
|
Pl_QPDFTokenizer::Members::Members() :
|
|
filter(0),
|
|
buf("tokenizer buffer")
|
|
{
|
|
}
|
|
|
|
Pl_QPDFTokenizer::Members::~Members()
|
|
{
|
|
}
|
|
|
|
Pl_QPDFTokenizer::Pl_QPDFTokenizer(char const* identifier,
|
|
QPDFObjectHandle::TokenFilter* filter,
|
|
Pipeline* next) :
|
|
Pipeline(identifier, next),
|
|
m(new Members)
|
|
{
|
|
m->filter = filter;
|
|
QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(
|
|
m->filter, next);
|
|
m->tokenizer.allowEOF();
|
|
m->tokenizer.includeIgnorable();
|
|
}
|
|
|
|
Pl_QPDFTokenizer::~Pl_QPDFTokenizer()
|
|
{
|
|
}
|
|
|
|
void
|
|
Pl_QPDFTokenizer::write(unsigned char* data, size_t len)
|
|
{
|
|
this->m->buf.write(data, len);
|
|
}
|
|
|
|
void
|
|
Pl_QPDFTokenizer::finish()
|
|
{
|
|
this->m->buf.finish();
|
|
auto input = PointerHolder<InputSource>(
|
|
new BufferInputSource("tokenizer data",
|
|
this->m->buf.getBuffer(), true));
|
|
|
|
while (true)
|
|
{
|
|
QPDFTokenizer::Token token = this->m->tokenizer.readToken(
|
|
input, "offset " + QUtil::int_to_string(input->tell()),
|
|
true);
|
|
this->m->filter->handleToken(token);
|
|
if (token.getType() == QPDFTokenizer::tt_eof)
|
|
{
|
|
break;
|
|
}
|
|
else if ((token.getType() == QPDFTokenizer::tt_word) &&
|
|
(token.getValue() == "ID"))
|
|
{
|
|
// 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)));
|
|
QTC::TC("qpdf", "Pl_QPDFTokenizer found ID");
|
|
this->m->tokenizer.expectInlineImage(input);
|
|
}
|
|
}
|
|
this->m->filter->handleEOF();
|
|
QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(
|
|
m->filter, 0);
|
|
Pipeline* next = this->getNext(true);
|
|
if (next)
|
|
{
|
|
next->finish();
|
|
}
|
|
}
|