mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-08 17:24:06 +00:00
Refactor QPDF::isLinearized
This commit is contained in:
parent
b21973618b
commit
f92368f44f
@ -18,6 +18,8 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
template <class T, class int_type>
|
template <class T, class int_type>
|
||||||
static void
|
static void
|
||||||
load_vector_int(
|
load_vector_int(
|
||||||
@ -95,25 +97,17 @@ QPDF::isLinearized()
|
|||||||
// The PDF spec says the linearization dictionary must be completely contained within the first
|
// The PDF spec says the linearization dictionary must be completely contained within the first
|
||||||
// 1024 bytes of the file. Add a byte for a null terminator.
|
// 1024 bytes of the file. Add a byte for a null terminator.
|
||||||
auto buffer = m->file->read(1024, 0);
|
auto buffer = m->file->read(1024, 0);
|
||||||
|
|
||||||
auto buf = buffer.data();
|
|
||||||
auto tbuf_size = buffer.size();
|
|
||||||
int lindict_obj = -1;
|
int lindict_obj = -1;
|
||||||
char* p = buf;
|
size_t pos = 0;
|
||||||
while (lindict_obj == -1) {
|
while (lindict_obj == -1) {
|
||||||
// Find a digit or end of buffer
|
// Find a digit or end of buffer
|
||||||
while (((p - buf) < tbuf_size) && (!QUtil::is_digit(*p))) {
|
pos = buffer.find_first_of("0123456789"sv, pos);
|
||||||
++p;
|
if (pos == std::string::npos) {
|
||||||
}
|
return false;
|
||||||
if (p - buf == tbuf_size) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// Seek to the digit. Then skip over digits for a potential
|
// Seek to the digit. Then skip over digits for a potential
|
||||||
// next iteration.
|
// next iteration.
|
||||||
m->file->seek(p - buf, SEEK_SET);
|
m->file->seek(toO(pos), SEEK_SET);
|
||||||
while (((p - buf) < tbuf_size) && QUtil::is_digit(*p)) {
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPDFTokenizer::Token t1 = readToken(*m->file);
|
QPDFTokenizer::Token t1 = readToken(*m->file);
|
||||||
if (t1.isInteger() && readToken(*m->file).isInteger() &&
|
if (t1.isInteger() && readToken(*m->file).isInteger() &&
|
||||||
@ -121,6 +115,10 @@ QPDF::isLinearized()
|
|||||||
readToken(*m->file).getType() == QPDFTokenizer::tt_dict_open) {
|
readToken(*m->file).getType() == QPDFTokenizer::tt_dict_open) {
|
||||||
lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str()));
|
lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str()));
|
||||||
}
|
}
|
||||||
|
pos = buffer.find_first_not_of("0123456789"sv, pos);
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lindict_obj <= 0) {
|
if (lindict_obj <= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user