diff options
author | Jay Berkenbilt <ejb@ql.org> | 2017-08-06 14:42:01 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2017-08-11 03:30:32 +0200 |
commit | 296b679d6e3217cc112b7ed19b363b82356615ef (patch) | |
tree | 7cb9b3aa95c00da45cf1a7cf67a020c1ee54a6c9 /include | |
parent | ef8ae5449dc30782451beba64fdd0af86e1cb931 (diff) | |
download | qpdf-296b679d6e3217cc112b7ed19b363b82356615ef.tar.zst |
Implement findFirst and findLast in InputSource
Preparing to refactor some pattern searching code to use these instead
of their own memchr loops. This should simplify the code that replaces
PCRE.
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/BufferInputSource.hh | 10 | ||||
-rw-r--r-- | include/qpdf/FileInputSource.hh | 11 | ||||
-rw-r--r-- | include/qpdf/InputSource.hh | 35 | ||||
-rw-r--r-- | include/qpdf/QPDF.hh | 21 |
4 files changed, 77 insertions, 0 deletions
diff --git a/include/qpdf/BufferInputSource.hh b/include/qpdf/BufferInputSource.hh index 64ee4605..db055783 100644 --- a/include/qpdf/BufferInputSource.hh +++ b/include/qpdf/BufferInputSource.hh @@ -15,17 +15,27 @@ class BufferInputSource: public InputSource { public: + QPDF_DLL BufferInputSource(std::string const& description, Buffer* buf, bool own_memory = false); + QPDF_DLL BufferInputSource(std::string const& description, std::string const& contents); + QPDF_DLL virtual ~BufferInputSource(); + QPDF_DLL virtual qpdf_offset_t findAndSkipNextEOL(); + QPDF_DLL virtual std::string const& getName() const; + QPDF_DLL virtual qpdf_offset_t tell(); + QPDF_DLL virtual void seek(qpdf_offset_t offset, int whence); + QPDF_DLL virtual void rewind(); + QPDF_DLL virtual size_t read(char* buffer, size_t length); + QPDF_DLL virtual void unreadCh(char ch); private: diff --git a/include/qpdf/FileInputSource.hh b/include/qpdf/FileInputSource.hh index 64457365..3f0c05a9 100644 --- a/include/qpdf/FileInputSource.hh +++ b/include/qpdf/FileInputSource.hh @@ -14,16 +14,27 @@ class FileInputSource: public InputSource { public: + QPDF_DLL FileInputSource(); + QPDF_DLL void setFilename(char const* filename); + QPDF_DLL void setFile(char const* description, FILE* filep, bool close_file); + QPDF_DLL virtual ~FileInputSource(); + QPDF_DLL virtual qpdf_offset_t findAndSkipNextEOL(); + QPDF_DLL virtual std::string const& getName() const; + QPDF_DLL virtual qpdf_offset_t tell(); + QPDF_DLL virtual void seek(qpdf_offset_t offset, int whence); + QPDF_DLL virtual void rewind(); + QPDF_DLL virtual size_t read(char* buffer, size_t length); + QPDF_DLL virtual void unreadCh(char ch); private: diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh index a731918e..c20e5076 100644 --- a/include/qpdf/InputSource.hh +++ b/include/qpdf/InputSource.hh @@ -9,6 +9,7 @@ #ifndef __QPDF_INPUTSOURCE_HH__ #define __QPDF_INPUTSOURCE_HH__ +#include <qpdf/DLL.h> #include <qpdf/Types.h> #include <stdio.h> #include <string> @@ -16,18 +17,52 @@ class InputSource { public: + QPDF_DLL InputSource() : last_offset(0) { } + QPDF_DLL virtual ~InputSource() { } + class Finder + { + public: + Finder() + { + } + virtual ~Finder() + { + } + + virtual bool check() = 0; + }; + + QPDF_DLL void setLastOffset(qpdf_offset_t); + QPDF_DLL qpdf_offset_t getLastOffset() const; + QPDF_DLL std::string readLine(size_t max_line_length); + // Find first or last occurrence of a sequence of characters + // starting within the range defined by offset and len such that, + // when the input source is positioned at the beginning of that + // sequence, finder.check() returns true. If len is 0, the search + // proceeds until EOF. If a qualifying pattern these methods + // return true and leave the input source positioned wherever + // check() left it at the end of the matching pattern. + QPDF_DLL + bool findFirst(char const* start_chars, + qpdf_offset_t offset, size_t len, + Finder& finder); + QPDF_DLL + bool findLast(char const* start_chars, + qpdf_offset_t offset, size_t len, + Finder& finder); + virtual qpdf_offset_t findAndSkipNextEOL() = 0; virtual std::string const& getName() const = 0; virtual qpdf_offset_t tell() = 0; diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index f57789a0..c9d120b4 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -1006,6 +1006,27 @@ class QPDF std::string key; // if ou_trailer_key or ou_root_key }; + class PatternFinder: public InputSource::Finder + { + public: + PatternFinder(QPDF& qpdf, bool (QPDF::*checker)()) : + qpdf(qpdf), + checker(checker) + { + } + virtual ~PatternFinder() + { + } + virtual bool check() + { + return (this->qpdf.*checker)(); + } + + private: + QPDF& qpdf; + bool (QPDF::*checker)(); + }; + // methods to support linearization checking -- implemented in // QPDF_linearization.cc void readLinearizationData(); |