From 00b5997901cd5d292b43d95e0338415d8b9653a2 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 1 Mar 2025 18:19:13 +0000 Subject: [PATCH] In QPDFParser access qpdf::Tokenizer directly --- include/qpdf/QPDFTokenizer.hh | 17 ----------------- libqpdf/QPDFTokenizer.cc | 14 +++++++------- libqpdf/qpdf/QPDFParser.hh | 5 +++-- libqpdf/qpdf/QPDFTokenizer_private.hh | 33 ++++----------------------------- 4 files changed, 14 insertions(+), 55 deletions(-) diff --git a/include/qpdf/QPDFTokenizer.hh b/include/qpdf/QPDFTokenizer.hh index 2da4763..b84e214 100644 --- a/include/qpdf/QPDFTokenizer.hh +++ b/include/qpdf/QPDFTokenizer.hh @@ -206,23 +206,6 @@ class QPDFTokenizer private: friend class QPDFParser; - // Read a token from an input source. Context describes the context in which the token is being - // read and is used in the exception thrown if there is an error. After a token is read, the - // position of the input source returned by input->tell() points to just after the token, and - // the input source's "last offset" as returned by input->getLastOffset() points to the - // beginning of the token. Returns false if the token is bad or if scanning produced an error - // message for any reason. - - bool nextToken(InputSource& input, std::string const& context, size_t max_len = 0); - - // The following methods are only valid after nextToken has been called and until another - // QPDFTokenizer method is called. They allow the results of calling nextToken to be accessed - // without creating a Token, thus avoiding copying information that may not be needed. - inline token_type_e getType() const noexcept; - inline std::string const& getValue() const noexcept; - inline std::string const& getRawValue() const noexcept; - inline std::string const& getErrorMessage() const noexcept; - QPDFTokenizer(QPDFTokenizer const&) = delete; QPDFTokenizer& operator=(QPDFTokenizer const&) = delete; diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index 1a12251..bcab379 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -936,7 +936,13 @@ Tokenizer::getToken(Token& token, bool& unread_char, char& ch) bool QPDFTokenizer::betweenTokens() { - return m->before_token; + return m->betweenTokens(); +} + +bool +Tokenizer::betweenTokens() +{ + return before_token; } QPDFTokenizer::Token @@ -986,12 +992,6 @@ Tokenizer::readToken( } bool -QPDFTokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len) -{ - return m->nextToken(input, context, max_len); -} - -bool Tokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len) { if (this->state != st_inline_image) { diff --git a/libqpdf/qpdf/QPDFParser.hh b/libqpdf/qpdf/QPDFParser.hh index 545a7c9..6033f30 100644 --- a/libqpdf/qpdf/QPDFParser.hh +++ b/libqpdf/qpdf/QPDFParser.hh @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -20,7 +21,7 @@ class QPDFParser bool parse_pdf) : input(input), object_description(object_description), - tokenizer(tokenizer), + tokenizer(*tokenizer.m), decrypter(decrypter), context(context), description( @@ -75,7 +76,7 @@ class QPDFParser void setDescription(std::shared_ptr& obj, qpdf_offset_t parsed_offset); InputSource& input; std::string const& object_description; - QPDFTokenizer& tokenizer; + qpdf::Tokenizer& tokenizer; QPDFObjectHandle::StringDecrypter* decrypter; QPDF* context; std::shared_ptr description; diff --git a/libqpdf/qpdf/QPDFTokenizer_private.hh b/libqpdf/qpdf/QPDFTokenizer_private.hh index 046a881..f109cbb 100644 --- a/libqpdf/qpdf/QPDFTokenizer_private.hh +++ b/libqpdf/qpdf/QPDFTokenizer_private.hh @@ -8,10 +8,10 @@ namespace qpdf class Tokenizer { - friend class ::QPDFTokenizer; - public: Tokenizer(); + Tokenizer(Tokenizer const&) = delete; + Tokenizer& operator=(Tokenizer const&) = delete; // Methods to support QPDFTokenizer. See QPDFTokenizer.hh for detail. Some of these are used // by Tokenizer internally but are not accessed directly by the rest of qpdf. @@ -20,14 +20,13 @@ namespace qpdf void includeIgnorable(); void presentCharacter(char ch); void presentEOF(); + bool betweenTokens(); // If a token is available, return true and initialize token with the token, unread_char // with whether or not we have to unread the last character, and if unread_char, ch with the // character to unread. bool getToken(QPDFTokenizer::Token& token, bool& unread_char, char& ch); - // Pull mode: - // Read a token from an input source. Context describes the context in which the token is // being read and is used in the exception thrown if there is an error. After a token is // read, the position of the input source returned by input->tell() points to just after the @@ -55,7 +54,6 @@ namespace qpdf void expectInlineImage(InputSource& input); - private: // Read a token from an input source. Context describes the context in which the token is // being read and is used in the exception thrown if there is an error. After a token is // read, the position of the input source returned by input->tell() points to just after the @@ -73,9 +71,7 @@ namespace qpdf inline std::string const& getRawValue() const; inline std::string const& getErrorMessage() const; - Tokenizer(Tokenizer const&) = delete; - Tokenizer& operator=(Tokenizer const&) = delete; - + private: bool isSpace(char); bool isDelimiter(char); void findEI(InputSource& input); @@ -179,25 +175,4 @@ namespace qpdf } // namespace qpdf -inline QPDFTokenizer::token_type_e -QPDFTokenizer::getType() const noexcept -{ - return m->type; -} -inline std::string const& -QPDFTokenizer::getValue() const noexcept -{ - return (m->type == tt_name || m->type == tt_string) ? m->val : m->raw_val; -} -inline std::string const& -QPDFTokenizer::getRawValue() const noexcept -{ - return m->raw_val; -} -inline std::string const& -QPDFTokenizer::getErrorMessage() const noexcept -{ - return m->error_message; -} - #endif // QPDFTOKENIZER_PRIVATE_HH -- libgit2 0.21.4