Major Update:

- Update printing: Do not use '\n' if indent = 0
- Implement refilling of buffer (from fd) while parsing
  - No longer use LineMark, but keep track of char position with CharNo
  - Use Mark to reference point for shifting buffer on refill
- SkipWhiteSpace no longer inline method
  - Refill buffer if required, change Mark & CharNo on line break
- CreateBuffer(), RefillBuffer() & FreeBuffer() now public methods
- Make Loading and Saving more flexible:
  - Refactor from LoadFromFile():
    ReadFromFile(), ReadFromHandle(), ReadFromBuffer()
  - Refactor from SaveToFile() & PrintToScreen:
    WriteToFile(), WriteToScreen, WriteToHandle()
This commit is contained in:
Charl Wentzel
2017-04-02 19:44:44 +02:00
parent 8f39adb0f3
commit 2e2ba113f1
3 changed files with 268 additions and 141 deletions

View File

@@ -32,10 +32,11 @@ private:
CShiftBuffer * Buffer;
// Parsing operation
char * BufEnd;
char * BufPos;
char * LineMark;
char * Mark;
int LineNo;
int CharNo;
bool RefillBuffer;
// Printing Operation
char Spacer[100];
@@ -45,21 +46,8 @@ private:
bool Error;
char ErrorText[100];
// File Buffer operation
bool CreateBuffer( int pBufLen );
bool FillBuffer();
void FreeBuffer();
// Parsing functions
inline void SkipWhiteSpace() {
while (isspace(*BufPos)) {
if (*BufPos == '\n') {
LineMark = BufPos;
LineNo++;
}
BufPos++;
}
}
void SkipWhiteSpace();
bool ParseString( char ** Value, int &pLen );
bool ParseObject( TDataMember * Object );
bool ParseArray( TDataMember * Array );
@@ -73,10 +61,22 @@ public:
CJSONparse( CDataTree * pDataTree );
~CJSONparse();
bool PrintToScreen( const char * Path, const int Indent );
// Buffer operation
bool CreateBuffer( int pBufLen );
bool FillBuffer();
void FreeBuffer();
bool ReadFromBuffer( const char * RootPath );
bool LoadFromFile( const char * Path, const char * FilePath, int pBufLen = 500 );
bool SaveToFile( const char * Path, const char * FilePath, const int Indent = 2 );
// Input
bool ReadFromHandle( const char * RootPath, const int Handle, bool pRefillBuffer );
bool ReadFromFile( const char * RootPath, const char * Path, const char * FileName );
bool ReadFromFile( const char * RootPath, const char * FilePath );
// Output
bool WriteToHandle( const char * RootPath, const int Handle, const int Indent = 2 );
bool WriteToScreen( const char * RootPath, const int Indent = 2 );
bool WriteToFile( const char * RootPath, const char * Path, const char * FileName, const int Indent = 2 );
bool WriteToFile( const char * RootPath, const char * FilePath, const int Indent = 2 );
const char * GetError() { return ((Error)? ErrorText : "Success"); };
};