mirror of
https://github.com/gigablast/open-source-search-engine.git
synced 2024-10-04 20:27:43 +03:00
c5ae5ca4b5
using the "objects" array in the json.
90 lines
1.7 KiB
C++
90 lines
1.7 KiB
C++
#ifndef JSON_H
|
|
#define JSON_H
|
|
|
|
#define JT_NULL 2
|
|
#define JT_NUMBER 3
|
|
#define JT_STRING 4
|
|
#define JT_ARRAY 5
|
|
#define JT_OBJECT 6
|
|
|
|
//#define JT_IsReference 256
|
|
|
|
#include "gb-include.h"
|
|
#include "Unicode.h"
|
|
#include "SafeBuf.h"
|
|
|
|
#define MAXJSONPARENTS 64
|
|
|
|
class JsonItem {
|
|
|
|
public:
|
|
// scan the linked list
|
|
class JsonItem *m_next,*m_prev;
|
|
class JsonItem *m_parent;//child;
|
|
|
|
// the JT_* values above
|
|
int m_type;
|
|
|
|
// . the NAME of the item
|
|
// . points into the ORIGINAL json string
|
|
char *m_name;
|
|
long m_nameLen;
|
|
|
|
// for JT_NUMBER
|
|
long m_valueLong;
|
|
// for JT_NUMBER
|
|
double m_valueDouble;
|
|
|
|
// for JT_String
|
|
long m_valueLen;
|
|
|
|
// for JT_String
|
|
long getValueLen() { return m_valueLen; };
|
|
|
|
// for arrays (JT_ARRAY), hack the char ptr into m_valueLong
|
|
char *getArrayStart() { return (char *)m_valueLong; }
|
|
long getArrayLen () { return m_valueLen; };
|
|
|
|
// for JT_String
|
|
char *getValue () {
|
|
// if value is another json object, then return NULL
|
|
// must be string
|
|
if ( m_type != JT_STRING ) return NULL;
|
|
// otherwie return the string which is stored decoded
|
|
// after this object in the same buffer
|
|
return (char *)this + sizeof(JsonItem);
|
|
};
|
|
|
|
// convert nubers and bools to strings for this one
|
|
char *getValueAsString ( long *valueLen ) ;
|
|
|
|
// like acme.product.offerPrice if "acme:{product:{offerprice:1.23}}"
|
|
bool getCompoundName ( SafeBuf &nameBuf ) ;
|
|
|
|
bool isInArray ( );
|
|
};
|
|
|
|
|
|
class Json {
|
|
public:
|
|
|
|
void test();
|
|
|
|
JsonItem *parseJsonStringIntoJsonItems ( char *json , long niceness );
|
|
|
|
JsonItem *getFirstItem ( ) ;
|
|
|
|
JsonItem *getItem ( char *name );
|
|
|
|
JsonItem *addNewItem ();
|
|
|
|
Json() { m_stackPtr = 0; m_prev = NULL; };
|
|
|
|
SafeBuf m_sb;
|
|
JsonItem *m_stack[MAXJSONPARENTS];
|
|
long m_stackPtr;
|
|
class JsonItem *m_prev;
|
|
};
|
|
|
|
#endif
|