Important Update: (incomplete)

- Implemented JSON type NULL
- Implement dynamic buffer
- Split parsing int separate re-usable methods
- Implement basic parsing of an object
- Add GetError() method
- Add SkipWhiteSpace as inline method
- Make parsing variable private attributes
- Improve checking when getting parameters
This commit is contained in:
Charl Wentzel
2017-03-15 04:29:01 +02:00
parent 9b180c77f5
commit 508cf0fb0d
2 changed files with 404 additions and 166 deletions

View File

@@ -14,10 +14,12 @@
// Standard C/C++ Libraries
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
//---------------------------------------------------------------------------
typedef enum { jtNone = 0, jtBool = 1, jtInt = 2, jtFloat = 3, jtString = 4, jtArray = 5, jtObject = 6 } EJSONtype;
typedef enum { jtNull = 0, jtBool = 1, jtInt = 2, jtFloat = 3, jtString = 4, jtArray = 5, jtObject = 6 } EJSONtype;
//---------------------------------------------------------------------------
@@ -41,6 +43,40 @@ class CConfigCore
private:
TConfigParam * FirstParam;
// File operation
FILE * InputFile;
char * Buffer;
int BufLen;
// Parsing operation
char * BufEnd;
char * BufPos;
char * LineMark;
int LineNo;
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 ParseObject( TConfigParam * Object );
bool ParseString( char ** Value, int * pLen = NULL, EJSONtype * pType = NULL );
bool ParsePrimitive( char ** Value, int * pLen = NULL, EJSONtype * pType = NULL );
// Find Param
inline TConfigParam * GetParam( const char * Name ) {
TConfigParam * Param = FirstParam;
@@ -74,10 +110,11 @@ public:
CConfigCore();
~CConfigCore();
bool SetParamStr( const char * Name, const char * Value = NULL, const int Len = -1 );
bool SetParamStr( const char * Name, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values
bool SetParamInt( const char * Name, const long Value );
bool SetParamFloat( const char * Name, const double Value );
bool SetParamBool( const char * Name, const bool Value );
bool SetParamNull( const char * Name );
const EJSONtype GetParamType( const char * Name );
@@ -90,8 +127,10 @@ public:
bool DeleteParam( const char * Name );
bool DeleteAll();
bool LoadFile( const char * FilePath );
bool LoadFile( const char * FilePath, int pBufLen = 500 );
bool SaveFile( const char * FilePath, const int ValueTab = 20 );
const char * GetError() { return ((Error)? ErrorText : "Success"); };
};
#endif /* REDACORE_CONFIGCORE_H_ */