- 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()
85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
/*
|
|
* JSONparseCore.h
|
|
*
|
|
* Created on: 5 Mar 2017
|
|
* Author: wentzelc
|
|
*/
|
|
|
|
#ifndef REDACORE_JSONPARSECORE_H_
|
|
#define REDACORE_JSONPARSECORE_H_
|
|
|
|
// redA Libraries
|
|
#include <BufferCore.h>
|
|
#include <DataTreeCore.h>
|
|
|
|
// Standard C/C++ Libraries
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <stdio.h>
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
class CJSONparse
|
|
{
|
|
private:
|
|
CDataTree * DataTree;
|
|
|
|
// File operation
|
|
int InputHandle;
|
|
int OutputHandle;
|
|
|
|
CShiftBuffer * Buffer;
|
|
|
|
// Parsing operation
|
|
char * BufPos;
|
|
char * Mark;
|
|
int LineNo;
|
|
int CharNo;
|
|
bool RefillBuffer;
|
|
|
|
// Printing Operation
|
|
char Spacer[100];
|
|
int SpacerLen;
|
|
|
|
// Error
|
|
bool Error;
|
|
char ErrorText[100];
|
|
|
|
// Parsing functions
|
|
void SkipWhiteSpace();
|
|
bool ParseString( char ** Value, int &pLen );
|
|
bool ParseObject( TDataMember * Object );
|
|
bool ParseArray( TDataMember * Array );
|
|
bool ParseString( TDataMember * Member );
|
|
bool ParsePrimitive( TDataMember * Member );
|
|
|
|
bool PrintObject( TDataMember * Object, const int Indent );
|
|
bool PrintArray( TDataMember * Object, const int Indent );
|
|
|
|
public:
|
|
CJSONparse( CDataTree * pDataTree );
|
|
~CJSONparse();
|
|
|
|
// Buffer operation
|
|
bool CreateBuffer( int pBufLen );
|
|
bool FillBuffer();
|
|
void FreeBuffer();
|
|
bool ReadFromBuffer( const char * RootPath );
|
|
|
|
// 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"); };
|
|
};
|
|
|
|
#endif /* REDACORE_JSONPARSECORE_H_ */
|