From ccfab5aecf065f42be31cb3c3d70d2960fba9c83 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Wed, 17 Dec 2025 17:07:14 -0800 Subject: [PATCH] Still working out parsing buffer stuff. --- IMFBoundary.h | 3 ++- IMFHeader.cpp | 4 +++- IMFHeader.h | 10 +++++++--- Parser.cpp | 14 ++++++++++++-- Parser.h | 32 +++++++++++++++++++++++++++++--- StreamReader.cpp | 10 ++++++++-- StreamReader.h | 7 ++++++- ZString.cpp | 5 +++++ ZString.h | 6 ++++++ 9 files changed, 78 insertions(+), 13 deletions(-) diff --git a/IMFBoundary.h b/IMFBoundary.h index 939854a..477bf0e 100644 --- a/IMFBoundary.h +++ b/IMFBoundary.h @@ -2,10 +2,11 @@ # define __IMFBoundary_h__ #include "StreamReader.h" +#include "Parser.h" namespace coreutils { - class IMFBoundary { + class IMFBoundary : public Parser { public: IMFBoundary(StreamReader &reader, ZString boundary); diff --git a/IMFHeader.cpp b/IMFHeader.cpp index 9c91155..10cb9b6 100644 --- a/IMFHeader.cpp +++ b/IMFHeader.cpp @@ -5,7 +5,9 @@ namespace coreutils { - IMFHeader::IMFHeader(int fd) { + IMFHeader::IMFHeader(int fd) {} + + virtual int parse() { char ch; int rc = ::read(fd, &ch, 1); while(ch != '\r') { diff --git a/IMFHeader.h b/IMFHeader.h index 72501b9..8e2bca2 100644 --- a/IMFHeader.h +++ b/IMFHeader.h @@ -1,18 +1,22 @@ #ifndef __IMFHeader_h__ # define __IMFHeader_h__ +# include "StreamReader.h" +# include "Parser.h" # include "IMFHeaderField.h" # include namespace coreutils { - class IMFHeader { + class IMFHeader : public Parser { public: - IMFHeader(int fd); + IMFHeader(StreamReader &reader); + + virtual int parse(); private: - std::vector headers; + std::vector headers; }; diff --git a/Parser.cpp b/Parser.cpp index d2010da..0b38d8e 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -1,4 +1,5 @@ #include "Parser.h" +#include "StreamReader.h" namespace coreutils { @@ -6,6 +7,15 @@ namespace coreutils { Parser::~Parser() {} - int Parser::parse() {} - + int Parser::doParse() { + buffer << reader.unparsed(); + reader.setParsed(); + } + + bool Parser::checkParse(Parser &parser); + + int Parser::Parse() { + + } + } diff --git a/Parser.h b/Parser.h index 3b8692c..8088cdd 100644 --- a/Parser.h +++ b/Parser.h @@ -15,16 +15,42 @@ namespace coreutils { class Parser { public: + + /// + /// + /// + Parser(StreamReader &reader, Parser *parser); + + /// + /// + /// + virtual ~Parser(); - int doParse(); <--- copy the buffer available in read to here and call parse(); - bool checkParse(Parser &parser); <--- can be called in parse to see if the parsing should branch + /// + /// doParse is the entry and re-entry point method to continue the parsing process. + /// + int doParse(); + + /// + /// Inside of parse() you can call another parser object with the checkParse method to + /// determine if the parsing should branch to the new passed parsing object. + /// + + bool checkParse(Parser &parser); <--- can be called in parse to see if the parsing should branch + + /// + /// + /// + virtual int parse(); - private: + protected: MString buffer; + + private: Parser *parser; vector chain; diff --git a/StreamReader.cpp b/StreamReader.cpp index 9455934..82c3cf0 100644 --- a/StreamReader.cpp +++ b/StreamReader.cpp @@ -2,8 +2,14 @@ namespace coreutils { - StreamReader::StreamReader(int fd) {} + StreamReader::StreamReader(int fd) fd(fd) {} StreamReader::~StreamReader() {} - + + int StreamReader::read() { + setSize(4096); + int len = ::read(fd, getData(), 4096); + + } + } diff --git a/StreamReader.h b/StreamReader.h index deab8ef..140d06b 100644 --- a/StreamReader.h +++ b/StreamReader.h @@ -1,6 +1,8 @@ #ifndef __StreamReader_h__ #define __StreamReader_h__ +#include "MString.h" +#include "Parser.h" #include #include @@ -15,10 +17,13 @@ namespace coreutils { class StreamReader { public: - StreamReader(int fd); + StreamReader(int fd, Parser *parser); virtual ~StreamReader(); + + int read(); private: + int fd; vector buffer; }; diff --git a/ZString.cpp b/ZString.cpp index bc362f2..57dd228 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -585,6 +585,11 @@ namespace coreutils { return ZString(cursor, data + length - cursor); } + int ZString::setParsed() { + cursor = data + length; + return length; + } + void ZString::reset() { cursor = data; } diff --git a/ZString.h b/ZString.h index 4ec41a8..78966db 100644 --- a/ZString.h +++ b/ZString.h @@ -413,6 +413,12 @@ namespace coreutils { /// ZString unparsed(); + + /// + /// Set the ZString cursor to the end of the ZString. + /// + + int setParsed(); /// ///