Commit 8768387c75ea149c07e8c95194908251f6b52793
1 parent
61804943
Add new private API InputSource read methods
Improve support for reading into std::string objects.
Showing
2 changed files
with
21 additions
and
0 deletions
include/qpdf/InputSource.hh
| @@ -76,6 +76,8 @@ class QPDF_DLL_CLASS InputSource | @@ -76,6 +76,8 @@ class QPDF_DLL_CLASS InputSource | ||
| 76 | virtual void unreadCh(char ch) = 0; | 76 | virtual void unreadCh(char ch) = 0; |
| 77 | 77 | ||
| 78 | // The following methods are for internal use by qpdf only. | 78 | // The following methods are for internal use by qpdf only. |
| 79 | + inline size_t read(std::string& str, size_t count, qpdf_offset_t at = -1); | ||
| 80 | + inline std::string read(size_t count, qpdf_offset_t at = -1); | ||
| 79 | inline qpdf_offset_t fastTell(); | 81 | inline qpdf_offset_t fastTell(); |
| 80 | inline bool fastRead(char&); | 82 | inline bool fastRead(char&); |
| 81 | inline void fastUnread(bool); | 83 | inline void fastUnread(bool); |
libqpdf/qpdf/InputSource_private.hh
| @@ -3,6 +3,25 @@ | @@ -3,6 +3,25 @@ | ||
| 3 | 3 | ||
| 4 | #include <qpdf/InputSource.hh> | 4 | #include <qpdf/InputSource.hh> |
| 5 | 5 | ||
| 6 | +inline size_t | ||
| 7 | +InputSource::read(std::string& str, size_t count, qpdf_offset_t at) | ||
| 8 | +{ | ||
| 9 | + if (at >= 0) { | ||
| 10 | + seek(at, SEEK_SET); | ||
| 11 | + } | ||
| 12 | + str.resize(count); | ||
| 13 | + str.resize(read(str.data(), count)); | ||
| 14 | + return str.size(); | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +inline std::string | ||
| 18 | +InputSource::read(size_t count, qpdf_offset_t at) | ||
| 19 | +{ | ||
| 20 | + std::string result(count, '\0'); | ||
| 21 | + (void)read(result, count, at); | ||
| 22 | + return result; | ||
| 23 | +} | ||
| 24 | + | ||
| 6 | inline void | 25 | inline void |
| 7 | InputSource::loadBuffer() | 26 | InputSource::loadBuffer() |
| 8 | { | 27 | { |