Files
redAcore/JSONparseCore.h
Charl Wentzel 8f39adb0f3 Important update:
- Buffer:
  - fix undefined value: zero terminate buffer when loading from FD
- DataTree:
  - fix memory leak: destroy temporary search path
  - improve delete(): delete all children for member if no path given
  - bug fix: initiate object with 0 length (not -1)
- JSONparse:
  - Remove level parameter
  - Add path to load/save/print methods (print only portion of tree)
  - fix memory leak: destroy temporary object name
2017-03-29 21:27:28 +02:00

85 lines
1.9 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 * BufEnd;
char * BufPos;
char * LineMark;
int LineNo;
// Printing Operation
char Spacer[100];
int SpacerLen;
// Error
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++;
}
}
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();
bool PrintToScreen( const char * Path, const int Indent );
bool LoadFromFile( const char * Path, const char * FilePath, int pBufLen = 500 );
bool SaveToFile( const char * Path, const char * FilePath, const int Indent = 2 );
const char * GetError() { return ((Error)? ErrorText : "Success"); };
};
#endif /* REDACORE_JSONPARSECORE_H_ */