From 0243468d44c3296cba6acb12a657e36e72fc6684 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 16 Dec 2025 16:51:44 -0800 Subject: [PATCH] Continued work on Parser. --- IMFBoundary.cpp | 23 +++++++++++++++++++++-- IMFBoundary.h | 2 ++ Parser.cpp | 8 +++++--- Parser.h | 13 ++++++++++--- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/IMFBoundary.cpp b/IMFBoundary.cpp index 7ededd1..4c42f1f 100644 --- a/IMFBoundary.cpp +++ b/IMFBoundary.cpp @@ -5,7 +5,26 @@ namespace coreutils { IMFBoundary(StreamReader &reader, ZString boundary) : boundary(boundary) { - if(reader.unparsed().getLength() + } - + + int IMFBoundary::parse() { + switch(state) { + case PREFIX: + if(buffer.remaining() > 3) + if(reader.nextIf("\r\n--")) + state = BOUNDARY; + case BOUNDARY: + while(buffer.getTokenInclude("")); + if(buffer.eod()) + return 2; + else if(buffer.remaining() > 1) + if(buffer.ifNext("--")) + state = LAST_BOUNDARY; + case LAST_BOUNDARY: + return 0; + } + + } + } \ No newline at end of file diff --git a/IMFBoundary.h b/IMFBoundary.h index 217f3cb..939854a 100644 --- a/IMFBoundary.h +++ b/IMFBoundary.h @@ -9,6 +9,8 @@ namespace coreutils { public: IMFBoundary(StreamReader &reader, ZString boundary); + + virtual int parse(); private: ZString boundary; diff --git a/Parser.cpp b/Parser.cpp index 9455934..d2010da 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -1,9 +1,11 @@ -#include "StreamReader.h" +#include "Parser.h" namespace coreutils { - StreamReader::StreamReader(int fd) {} + Parser::Parser(StreamReader &reader) : parser(parser) {} - StreamReader::~StreamReader() {} + Parser::~Parser() {} + + int Parser::parse() {} } diff --git a/Parser.h b/Parser.h index 630dfb6..3b8692c 100644 --- a/Parser.h +++ b/Parser.h @@ -15,11 +15,18 @@ namespace coreutils { class Parser { public: - Parser(int fd); - virtual ~Parser(); + 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 + + virtual int parse(); private: - vector buffer; + MString buffer; + Parser *parser; + vector chain; };