aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/InputSource.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-07-21 11:37:14 +0200
committerJay Berkenbilt <ejb@ql.org>2012-07-21 15:06:06 +0200
commit15eaed5c52c85dd97ce5bc829817c5535c527207 (patch)
tree9114c410414102d7de50184fb4866f8e881a33cc /libqpdf/InputSource.cc
parent8657c6f00489b5c26fc0c00f2fc91c5682acbe95 (diff)
downloadqpdf-15eaed5c52c85dd97ce5bc829817c5535c527207.tar.zst
Refactor: pull *InputSource out of QPDF
InputSource, FileInputSource, and BufferInputSource are now top-level classes instead of privately nested inside QPDF.
Diffstat (limited to 'libqpdf/InputSource.cc')
-rw-r--r--libqpdf/InputSource.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/libqpdf/InputSource.cc b/libqpdf/InputSource.cc
new file mode 100644
index 00000000..79c889bf
--- /dev/null
+++ b/libqpdf/InputSource.cc
@@ -0,0 +1,41 @@
+#include <qpdf/InputSource.hh>
+#include <string.h>
+#include <qpdf/PointerHolder.hh>
+
+void
+InputSource::setLastOffset(qpdf_offset_t offset)
+{
+ this->last_offset = offset;
+}
+
+qpdf_offset_t
+InputSource::getLastOffset() const
+{
+ return this->last_offset;
+}
+
+std::string
+InputSource::readLine(size_t max_line_length)
+{
+ // Return at most max_line_length characters from the next line.
+ // Lines are terminated by one or more \r or \n characters.
+ // Consume the trailing newline characters but don't return them.
+ // After this is called, the file will be positioned after a line
+ // terminator or at the end of the file, and last_offset will
+ // point to position the file had when this method was called.
+
+ qpdf_offset_t offset = this->tell();
+ char* buf = new char[max_line_length + 1];
+ PointerHolder<char> bp(true, buf);
+ memset(buf, '\0', max_line_length + 1);
+ this->read(buf, max_line_length);
+ this->seek(offset, SEEK_SET);
+ qpdf_offset_t eol = this->findAndSkipNextEOL();
+ this->last_offset = offset;
+ size_t line_length = eol - offset;
+ if (line_length < max_line_length)
+ {
+ buf[line_length] = '\0';
+ }
+ return std::string(buf);
+}