From 8768387c75ea149c07e8c95194908251f6b52793 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 2 Nov 2024 12:10:16 +0000 Subject: [PATCH] Add new private API InputSource read methods --- include/qpdf/InputSource.hh | 2 ++ libqpdf/qpdf/InputSource_private.hh | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh index 1cd0920..889ce69 100644 --- a/include/qpdf/InputSource.hh +++ b/include/qpdf/InputSource.hh @@ -76,6 +76,8 @@ class QPDF_DLL_CLASS InputSource virtual void unreadCh(char ch) = 0; // The following methods are for internal use by qpdf only. + inline size_t read(std::string& str, size_t count, qpdf_offset_t at = -1); + inline std::string read(size_t count, qpdf_offset_t at = -1); inline qpdf_offset_t fastTell(); inline bool fastRead(char&); inline void fastUnread(bool); diff --git a/libqpdf/qpdf/InputSource_private.hh b/libqpdf/qpdf/InputSource_private.hh index a81efe4..6194615 100644 --- a/libqpdf/qpdf/InputSource_private.hh +++ b/libqpdf/qpdf/InputSource_private.hh @@ -3,6 +3,25 @@ #include +inline size_t +InputSource::read(std::string& str, size_t count, qpdf_offset_t at) +{ + if (at >= 0) { + seek(at, SEEK_SET); + } + str.resize(count); + str.resize(read(str.data(), count)); + return str.size(); +} + +inline std::string +InputSource::read(size_t count, qpdf_offset_t at) +{ + std::string result(count, '\0'); + (void)read(result, count, at); + return result; +} + inline void InputSource::loadBuffer() { -- libgit2 0.21.4