Commit 00b5997901cd5d292b43d95e0338415d8b9653a2

Authored by m-holger
1 parent 39bc2eb4

In QPDFParser access qpdf::Tokenizer directly

Remove remaining QPDFTokenizer private methods.
Remove QPDFTokenizer privileged access to Tokenizer.
include/qpdf/QPDFTokenizer.hh
... ... @@ -206,23 +206,6 @@ class QPDFTokenizer
206 206 private:
207 207 friend class QPDFParser;
208 208  
209   - // Read a token from an input source. Context describes the context in which the token is being
210   - // read and is used in the exception thrown if there is an error. After a token is read, the
211   - // position of the input source returned by input->tell() points to just after the token, and
212   - // the input source's "last offset" as returned by input->getLastOffset() points to the
213   - // beginning of the token. Returns false if the token is bad or if scanning produced an error
214   - // message for any reason.
215   -
216   - bool nextToken(InputSource& input, std::string const& context, size_t max_len = 0);
217   -
218   - // The following methods are only valid after nextToken has been called and until another
219   - // QPDFTokenizer method is called. They allow the results of calling nextToken to be accessed
220   - // without creating a Token, thus avoiding copying information that may not be needed.
221   - inline token_type_e getType() const noexcept;
222   - inline std::string const& getValue() const noexcept;
223   - inline std::string const& getRawValue() const noexcept;
224   - inline std::string const& getErrorMessage() const noexcept;
225   -
226 209 QPDFTokenizer(QPDFTokenizer const&) = delete;
227 210 QPDFTokenizer& operator=(QPDFTokenizer const&) = delete;
228 211  
... ...
libqpdf/QPDFTokenizer.cc
... ... @@ -936,7 +936,13 @@ Tokenizer::getToken(Token& token, bool& unread_char, char& ch)
936 936 bool
937 937 QPDFTokenizer::betweenTokens()
938 938 {
939   - return m->before_token;
  939 + return m->betweenTokens();
  940 +}
  941 +
  942 +bool
  943 +Tokenizer::betweenTokens()
  944 +{
  945 + return before_token;
940 946 }
941 947  
942 948 QPDFTokenizer::Token
... ... @@ -986,12 +992,6 @@ Tokenizer::readToken(
986 992 }
987 993  
988 994 bool
989   -QPDFTokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len)
990   -{
991   - return m->nextToken(input, context, max_len);
992   -}
993   -
994   -bool
995 995 Tokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len)
996 996 {
997 997 if (this->state != st_inline_image) {
... ...
libqpdf/qpdf/QPDFParser.hh
... ... @@ -3,6 +3,7 @@
3 3  
4 4 #include <qpdf/QPDFObjectHandle_private.hh>
5 5 #include <qpdf/QPDFObject_private.hh>
  6 +#include <qpdf/QPDFTokenizer_private.hh>
6 7  
7 8 #include <memory>
8 9 #include <string>
... ... @@ -20,7 +21,7 @@ class QPDFParser
20 21 bool parse_pdf) :
21 22 input(input),
22 23 object_description(object_description),
23   - tokenizer(tokenizer),
  24 + tokenizer(*tokenizer.m),
24 25 decrypter(decrypter),
25 26 context(context),
26 27 description(
... ... @@ -75,7 +76,7 @@ class QPDFParser
75 76 void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset);
76 77 InputSource& input;
77 78 std::string const& object_description;
78   - QPDFTokenizer& tokenizer;
  79 + qpdf::Tokenizer& tokenizer;
79 80 QPDFObjectHandle::StringDecrypter* decrypter;
80 81 QPDF* context;
81 82 std::shared_ptr<QPDFObject::Description> description;
... ...
libqpdf/qpdf/QPDFTokenizer_private.hh
... ... @@ -8,10 +8,10 @@ namespace qpdf
8 8  
9 9 class Tokenizer
10 10 {
11   - friend class ::QPDFTokenizer;
12   -
13 11 public:
14 12 Tokenizer();
  13 + Tokenizer(Tokenizer const&) = delete;
  14 + Tokenizer& operator=(Tokenizer const&) = delete;
15 15  
16 16 // Methods to support QPDFTokenizer. See QPDFTokenizer.hh for detail. Some of these are used
17 17 // by Tokenizer internally but are not accessed directly by the rest of qpdf.
... ... @@ -20,14 +20,13 @@ namespace qpdf
20 20 void includeIgnorable();
21 21 void presentCharacter(char ch);
22 22 void presentEOF();
  23 + bool betweenTokens();
23 24  
24 25 // If a token is available, return true and initialize token with the token, unread_char
25 26 // with whether or not we have to unread the last character, and if unread_char, ch with the
26 27 // character to unread.
27 28 bool getToken(QPDFTokenizer::Token& token, bool& unread_char, char& ch);
28 29  
29   - // Pull mode:
30   -
31 30 // Read a token from an input source. Context describes the context in which the token is
32 31 // being read and is used in the exception thrown if there is an error. After a token is
33 32 // read, the position of the input source returned by input->tell() points to just after the
... ... @@ -55,7 +54,6 @@ namespace qpdf
55 54  
56 55 void expectInlineImage(InputSource& input);
57 56  
58   - private:
59 57 // Read a token from an input source. Context describes the context in which the token is
60 58 // being read and is used in the exception thrown if there is an error. After a token is
61 59 // read, the position of the input source returned by input->tell() points to just after the
... ... @@ -73,9 +71,7 @@ namespace qpdf
73 71 inline std::string const& getRawValue() const;
74 72 inline std::string const& getErrorMessage() const;
75 73  
76   - Tokenizer(Tokenizer const&) = delete;
77   - Tokenizer& operator=(Tokenizer const&) = delete;
78   -
  74 + private:
79 75 bool isSpace(char);
80 76 bool isDelimiter(char);
81 77 void findEI(InputSource& input);
... ... @@ -179,25 +175,4 @@ namespace qpdf
179 175  
180 176 } // namespace qpdf
181 177  
182   -inline QPDFTokenizer::token_type_e
183   -QPDFTokenizer::getType() const noexcept
184   -{
185   - return m->type;
186   -}
187   -inline std::string const&
188   -QPDFTokenizer::getValue() const noexcept
189   -{
190   - return (m->type == tt_name || m->type == tt_string) ? m->val : m->raw_val;
191   -}
192   -inline std::string const&
193   -QPDFTokenizer::getRawValue() const noexcept
194   -{
195   - return m->raw_val;
196   -}
197   -inline std::string const&
198   -QPDFTokenizer::getErrorMessage() const noexcept
199   -{
200   - return m->error_message;
201   -}
202   -
203 178 #endif // QPDFTOKENIZER_PRIVATE_HH
... ...