2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-02-05 05:18:25 +00:00

Add new private API InputSource read methods

Improve support for reading into std::string objects.
This commit is contained in:
m-holger 2024-11-02 12:10:16 +00:00
parent 2c7c121a97
commit c502abbc98
2 changed files with 21 additions and 0 deletions

View File

@ -79,6 +79,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);

View File

@ -3,6 +3,25 @@
#include <qpdf/InputSource.hh>
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()
{