From b252e70cb6c1637d1e50f1cf5cbccb5726ba06f0 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 4 Oct 2022 20:50:36 +0100 Subject: Add new methods QPDFTokenizer::getType, getValue, getRawValue and getErrorMessage --- include/qpdf/QPDFTokenizer.hh | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/include/qpdf/QPDFTokenizer.hh b/include/qpdf/QPDFTokenizer.hh index ec9e66c7..b9642fc3 100644 --- a/include/qpdf/QPDFTokenizer.hh +++ b/include/qpdf/QPDFTokenizer.hh @@ -219,7 +219,15 @@ class QPDFTokenizer bool nextToken( InputSource& input, std::string const& context, size_t max_len = 0); - private: + // 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; @@ -301,4 +309,26 @@ class QPDFTokenizer int digit_count; }; +inline QPDFTokenizer::token_type_e +QPDFTokenizer::getType() const noexcept +{ + return this->type; +} +inline std::string const& +QPDFTokenizer::getValue() const noexcept +{ + return (this->type == tt_name || this->type == tt_string) ? this->val + : this->raw_val; +} +inline std::string const& +QPDFTokenizer::getRawValue() const noexcept +{ + return this->raw_val; +} +inline std::string const& +QPDFTokenizer::getErrorMessage() const noexcept +{ + return this->error_message; +} + #endif // QPDFTOKENIZER_HH -- cgit v1.2.3-54-g00ecf