summaryrefslogtreecommitdiff
path: root/src/unstable/json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unstable/json.cpp')
-rw-r--r--src/unstable/json.cpp53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/unstable/json.cpp b/src/unstable/json.cpp
index 0b47da4..f5a1696 100644
--- a/src/unstable/json.cpp
+++ b/src/unstable/json.cpp
@@ -9,15 +9,52 @@
9#define next( txt ) readChar( c, sInput, "Unexpected end of stream while reading " txt "." ) 9#define next( txt ) readChar( c, sInput, "Unexpected end of stream while reading " txt "." )
10 10
11Bu::Json::Json() : 11Bu::Json::Json() :
12 eType( Invalid ) 12 eType( Null )
13{ 13{
14} 14}
15 15
16Bu::Json::Json( const Bu::String &sJson ) : 16Bu::Json::Json( const Bu::String &sValue ) :
17 eType( Invalid ) 17 eType( String ),
18 uDat( sValue )
19{
20}
21
22Bu::Json::Json( double dValue ) :
23 eType( Number ),
24 uDat( dValue )
25{
26}
27
28Bu::Json::Json( bool bValue ) :
29 eType( Boolean ),
30 uDat( bValue )
18{ 31{
19 Bu::StaticMemBuf mIn( sJson.getStr(), sJson.getSize() ); 32}
20 parse( mIn ); 33
34Bu::Json::Json( Type eType ) :
35 eType( eType )
36{
37 switch( eType )
38 {
39 case Object:
40 uDat.pObject = new JsonHash();
41 break;
42
43 case Array:
44 uDat.pArray = new JsonList();
45 break;
46
47 case String:
48 uDat.pString = new Bu::String();
49 break;
50
51 case Number:
52 case Boolean:
53 case Null:
54 case Invalid:
55 uDat.pObject = NULL;
56 break;
57 }
21} 58}
22 59
23Bu::Json::Json( Bu::Stream &sInput ) : 60Bu::Json::Json( Bu::Stream &sInput ) :
@@ -132,6 +169,12 @@ void Bu::Json::parse( Bu::Stream &sInput )
132 parse( c, sInput ); 169 parse( c, sInput );
133} 170}
134 171
172void Bu::Json::parse( const Bu::String &sInput )
173{
174 Bu::StaticMemBuf mb( sInput.getStr(), sInput.getSize() );
175 parse( mb );
176}
177
135void Bu::Json::parse( char &c, Bu::Stream &sInput ) 178void Bu::Json::parse( char &c, Bu::Stream &sInput )
136{ 179{
137 while( c == ' ' || c == '\t' || c == '\r' || c == '\n' ) 180 while( c == ' ' || c == '\t' || c == '\r' || c == '\n' )