summaryrefslogtreecommitdiff
path: root/src/unstable/json.h
blob: 47009cbe7fafb79b32348bd25b289ad7fe4f40c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef BU_JSON_H
#define BU_JSON_H

#include "bu/hash.h"
#include "bu/list.h"
#include "bu/string.h"

namespace Bu
{
    class Stream;

    class Json
    {
    public:
        enum Type
        {
            Invalid,
            Object,
            Array,
            String,
            Number,
            Boolean,
            Null
        };

    public:
        Json();
        Json( const Bu::String &sJson );
        Json( Bu::Stream &sInput );
        virtual ~Json();

        void parse( Bu::Stream &sInput );
        void reset();

    private:
        void parseString( char &c, Bu::Stream &sInput, Bu::String &sOut );
        void parseString( char &c, Bu::Stream &sInput );
        void parseObject( char &c, Bu::Stream &sInput );
        void parseArray( char &c, Bu::Stream &sInput );
        void parseNumber( char &c, Bu::Stream &sInput );
        void parseLiteral( char &c, Bu::Stream &sInput );
        bool readChar( char &c, Bu::Stream &sInput );
        void readChar( char &c, Bu::Stream &sInput, const char *sSection );
        bool isWs( char c );

    private:
        typedef Bu::Hash<Bu::String, Json *> JsonHash;
        typedef Bu::List<Json *> JsonList;

        Type eType;
        union DatUnion
        {
            DatUnion() : pObject( NULL ) { }
            JsonHash *pObject;
            JsonList *pArray;
            Bu::String *pString;
            double dNumber;
            bool bBoolean;
        } uDat;
    };
};

#endif