diff options
author | Mike Buland <eichlan@xagasoft.com> | 2019-05-13 19:47:19 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2019-05-13 19:47:19 -0700 |
commit | d605d6c3c04c1e26121f9b1c5c1d2dbcc5f7bc37 (patch) | |
tree | 0cd21d420fc67ae757ec2475610c4624fd714363 /src/unstable/json.h | |
parent | 62753c815b5ec34ebfae37a3c89187a01cc17160 (diff) | |
download | libbu++-d605d6c3c04c1e26121f9b1c5c1d2dbcc5f7bc37.tar.gz libbu++-d605d6c3c04c1e26121f9b1c5c1d2dbcc5f7bc37.tar.bz2 libbu++-d605d6c3c04c1e26121f9b1c5c1d2dbcc5f7bc37.tar.xz libbu++-d605d6c3c04c1e26121f9b1c5c1d2dbcc5f7bc37.zip |
UtfString & Json overhaul.
UtfString supports a load of new stuff, and Json uses UtfString
exclusively now.
Diffstat (limited to 'src/unstable/json.h')
-rw-r--r-- | src/unstable/json.h | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/src/unstable/json.h b/src/unstable/json.h index 4c85dd9..2ea62a2 100644 --- a/src/unstable/json.h +++ b/src/unstable/json.h | |||
@@ -10,12 +10,13 @@ | |||
10 | namespace Bu | 10 | namespace Bu |
11 | { | 11 | { |
12 | class Stream; | 12 | class Stream; |
13 | typedef Bu::List<Bu::UtfString> UtfStringList; | ||
13 | 14 | ||
14 | class Json | 15 | class Json |
15 | { | 16 | { |
16 | private: | 17 | private: |
17 | Json( char &c, Bu::Stream &sInput ); | 18 | Json( Bu::UtfChar &c, Bu::Stream &sInput ); |
18 | typedef Bu::Hash<Bu::String, Json *> JsonHash; | 19 | typedef Bu::Hash<Bu::UtfString, Json *> JsonHash; |
19 | typedef Bu::Array<Json *> JsonList; | 20 | typedef Bu::Array<Json *> JsonList; |
20 | 21 | ||
21 | public: | 22 | public: |
@@ -45,33 +46,33 @@ namespace Bu | |||
45 | virtual ~Json(); | 46 | virtual ~Json(); |
46 | 47 | ||
47 | Type getType() const; | 48 | Type getType() const; |
48 | Bu::String getString() const; | 49 | Bu::UtfString getString() const; |
49 | double getNumber() const; | 50 | double getNumber() const; |
50 | bool getBoolean() const; | 51 | bool getBoolean() const; |
51 | bool isNull() const; | 52 | bool isNull() const; |
52 | Json &operator[]( const Bu::String &sKey ) const; | 53 | Json &operator[]( const Bu::UtfString &sKey ) const; |
53 | Json &operator[]( int iIndex ) const; | 54 | Json &operator[]( int iIndex ) const; |
54 | int getSize() const; | 55 | int getSize() const; |
55 | Bu::StringList getKeys() const; | 56 | Bu::UtfStringList getKeys() const; |
56 | iterator begin(); | 57 | iterator begin(); |
57 | const_iterator begin() const; | 58 | const_iterator begin() const; |
58 | iterator end(); | 59 | iterator end(); |
59 | const_iterator end() const; | 60 | const_iterator end() const; |
60 | 61 | ||
61 | bool has( const Bu::String &sKey ) const; | 62 | bool has( const Bu::String &sKey ) const; |
62 | void insert( const Bu::String &sKey, Bu::Json *pObj ); | 63 | Json &insert( const Bu::String &sKey, Bu::Json *pObj ); |
63 | void insert( const Bu::String &sKey, const Bu::Json &rObj ); | 64 | Json &insert( const Bu::String &sKey, const Bu::Json &rObj ); |
64 | void insert( const Bu::String &sKey, const Bu::String &sValue ); | 65 | Json &insert( const Bu::String &sKey, const Bu::String &sValue ); |
65 | void insert( const Bu::String &sKey, const char *sValue ); | 66 | Json &insert( const Bu::String &sKey, const char *sValue ); |
66 | void insert( const Bu::String &sKey, double dValue ); | 67 | Json &insert( const Bu::String &sKey, double dValue ); |
67 | void insert( const Bu::String &sKey, bool bValue ); | 68 | Json &insert( const Bu::String &sKey, bool bValue ); |
68 | Json &insertObject( const Bu::String &sKey ); | 69 | Json &insertObject( const Bu::String &sKey ); |
69 | Json &insertArray( const Bu::String &sKey ); | 70 | Json &insertArray( const Bu::String &sKey ); |
70 | void append( Bu::Json *pObj ); | 71 | Json &append( Bu::Json *pObj ); |
71 | void append( const Bu::String &sValue ); | 72 | Json &append( const Bu::String &sValue ); |
72 | void append( const char *sValue ); | 73 | Json &append( const char *sValue ); |
73 | void append( double dValue ); | 74 | Json &append( double dValue ); |
74 | void append( bool bValue ); | 75 | Json &append( bool bValue ); |
75 | Json &appendObject(); | 76 | Json &appendObject(); |
76 | Json &appendArray(); | 77 | Json &appendArray(); |
77 | 78 | ||
@@ -87,18 +88,20 @@ namespace Bu | |||
87 | Bu::Json &operator=( const Bu::Json &rSrc ); | 88 | Bu::Json &operator=( const Bu::Json &rSrc ); |
88 | 89 | ||
89 | private: | 90 | private: |
90 | void parse( char &c, Bu::Stream &sInput ); | 91 | void parse( Bu::UtfChar &c, Bu::Stream &sInput ); |
91 | void parseString( char &c, Bu::Stream &sInput, Bu::String &sOut ); | 92 | void parseString( Bu::UtfChar &c, Bu::Stream &sInput, |
92 | void parseString( char &c, Bu::Stream &sInput ); | 93 | Bu::UtfString &sOut ); |
93 | void parseObject( char &c, Bu::Stream &sInput ); | 94 | void parseString( Bu::UtfChar &c, Bu::Stream &sInput ); |
94 | void parseArray( char &c, Bu::Stream &sInput ); | 95 | void parseObject( Bu::UtfChar &c, Bu::Stream &sInput ); |
95 | void parseNumber( char &c, Bu::Stream &sInput ); | 96 | void parseArray( Bu::UtfChar &c, Bu::Stream &sInput ); |
96 | void parseLiteral( char &c, Bu::Stream &sInput ); | 97 | void parseNumber( Bu::UtfChar &c, Bu::Stream &sInput ); |
97 | bool readChar( char &c, Bu::Stream &sInput ); | 98 | void parseLiteral( Bu::UtfChar &c, Bu::Stream &sInput ); |
98 | void readChar( char &c, Bu::Stream &sInput, const char *sSection ); | 99 | bool readChar( Bu::UtfChar &c, Bu::Stream &sInput ); |
99 | bool isWs( char c ); | 100 | void readChar( Bu::UtfChar &c, Bu::Stream &sInput, |
100 | void skipWs( char &c, Bu::Stream &sInput ); | 101 | const char *sSection ); |
101 | void writeStr( const Bu::String &sStr, Bu::Stream &sOutput ) const; | 102 | bool isWs( Bu::UtfChar c ); |
103 | void skipWs( Bu::UtfChar &c, Bu::Stream &sInput ); | ||
104 | void writeStr( const Bu::UtfString &sStr, Bu::Stream &sOutput ) const; | ||
102 | 105 | ||
103 | private: | 106 | private: |
104 | Type eType; | 107 | Type eType; |
@@ -106,14 +109,16 @@ namespace Bu | |||
106 | { | 109 | { |
107 | DatUnion() : pObject( NULL ) { } | 110 | DatUnion() : pObject( NULL ) { } |
108 | DatUnion( const Bu::String &sValue ) : | 111 | DatUnion( const Bu::String &sValue ) : |
109 | pString( new Bu::String( sValue ) ) { } | 112 | pString( new Bu::UtfString( sValue ) ) { } |
113 | DatUnion( const Bu::UtfString &sValue ) : | ||
114 | pString( new Bu::UtfString( sValue ) ) { } | ||
110 | DatUnion( const char *sValue ) : | 115 | DatUnion( const char *sValue ) : |
111 | pString( new Bu::String( sValue ) ) { } | 116 | pString( new Bu::UtfString( sValue ) ) { } |
112 | DatUnion( double dValue ) : dNumber( dValue ) { } | 117 | DatUnion( double dValue ) : dNumber( dValue ) { } |
113 | DatUnion( bool bValue ) : bBoolean( bValue ) { } | 118 | DatUnion( bool bValue ) : bBoolean( bValue ) { } |
114 | JsonHash *pObject; | 119 | JsonHash *pObject; |
115 | JsonList *pArray; | 120 | JsonList *pArray; |
116 | Bu::String *pString; | 121 | Bu::UtfString *pString; |
117 | double dNumber; | 122 | double dNumber; |
118 | bool bBoolean; | 123 | bool bBoolean; |
119 | } uDat; | 124 | } uDat; |