Still working out parsing buffer stuff.

This commit is contained in:
Brad Arant 2025-12-17 17:07:14 -08:00
parent 0243468d44
commit ccfab5aecf
9 changed files with 78 additions and 13 deletions

View File

@ -2,10 +2,11 @@
# define __IMFBoundary_h__ # define __IMFBoundary_h__
#include "StreamReader.h" #include "StreamReader.h"
#include "Parser.h"
namespace coreutils { namespace coreutils {
class IMFBoundary { class IMFBoundary : public Parser {
public: public:
IMFBoundary(StreamReader &reader, ZString boundary); IMFBoundary(StreamReader &reader, ZString boundary);

View File

@ -5,7 +5,9 @@
namespace coreutils { namespace coreutils {
IMFHeader::IMFHeader(int fd) { IMFHeader::IMFHeader(int fd) {}
virtual int parse() {
char ch; char ch;
int rc = ::read(fd, &ch, 1); int rc = ::read(fd, &ch, 1);
while(ch != '\r') { while(ch != '\r') {

View File

@ -1,18 +1,22 @@
#ifndef __IMFHeader_h__ #ifndef __IMFHeader_h__
# define __IMFHeader_h__ # define __IMFHeader_h__
# include "StreamReader.h"
# include "Parser.h"
# include "IMFHeaderField.h" # include "IMFHeaderField.h"
# include <vector> # include <vector>
namespace coreutils { namespace coreutils {
class IMFHeader { class IMFHeader : public Parser {
public: public:
IMFHeader(int fd); IMFHeader(StreamReader &reader);
virtual int parse();
private: private:
std::vector<IMFHeaderField*> headers; std::vector<IMFHeaderField *> headers;
}; };

View File

@ -1,4 +1,5 @@
#include "Parser.h" #include "Parser.h"
#include "StreamReader.h"
namespace coreutils { namespace coreutils {
@ -6,6 +7,15 @@ namespace coreutils {
Parser::~Parser() {} Parser::~Parser() {}
int Parser::parse() {} int Parser::doParse() {
buffer << reader.unparsed();
reader.setParsed();
}
bool Parser::checkParse(Parser &parser);
int Parser::Parse() {
}
} }

View File

@ -15,16 +15,42 @@ namespace coreutils {
class Parser { class Parser {
public: public:
///
///
///
Parser(StreamReader &reader, Parser *parser); Parser(StreamReader &reader, Parser *parser);
///
///
///
virtual ~Parser(); virtual ~Parser();
int doParse(); <--- copy the buffer available in read to here and call parse(); ///
/// 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 bool checkParse(Parser &parser); <--- can be called in parse to see if the parsing should branch
///
///
///
virtual int parse(); virtual int parse();
private: protected:
MString buffer; MString buffer;
private:
Parser *parser; Parser *parser;
vector<Parser *> chain; vector<Parser *> chain;

View File

@ -2,8 +2,14 @@
namespace coreutils { namespace coreutils {
StreamReader::StreamReader(int fd) {} StreamReader::StreamReader(int fd) fd(fd) {}
StreamReader::~StreamReader() {} StreamReader::~StreamReader() {}
int StreamReader::read() {
setSize(4096);
int len = ::read(fd, getData(), 4096);
}
} }

View File

@ -1,6 +1,8 @@
#ifndef __StreamReader_h__ #ifndef __StreamReader_h__
#define __StreamReader_h__ #define __StreamReader_h__
#include "MString.h"
#include "Parser.h"
#include <fstream> #include <fstream>
#include <vector> #include <vector>
@ -15,10 +17,13 @@ namespace coreutils {
class StreamReader { class StreamReader {
public: public:
StreamReader(int fd); StreamReader(int fd, Parser *parser);
virtual ~StreamReader(); virtual ~StreamReader();
int read();
private: private:
int fd;
vector<MString> buffer; vector<MString> buffer;
}; };

View File

@ -585,6 +585,11 @@ namespace coreutils {
return ZString(cursor, data + length - cursor); return ZString(cursor, data + length - cursor);
} }
int ZString::setParsed() {
cursor = data + length;
return length;
}
void ZString::reset() { void ZString::reset() {
cursor = data; cursor = data;
} }

View File

@ -414,6 +414,12 @@ namespace coreutils {
ZString unparsed(); ZString unparsed();
///
/// Set the ZString cursor to the end of the ZString.
///
int setParsed();
/// ///
/// ///
/// ///