aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/json.cpp
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2017-06-07 00:11:51 -0700
committerMike Buland <mbuland@penny-arcade.com>2017-06-07 00:11:51 -0700
commit2fc7fcd7161121ab48cda40687d7d152e03b3079 (patch)
tree2cfeff13b83605f9411798de34fffe6d0087c809 /src/unstable/json.cpp
parente98644cd777ddd4ae769da2d8bdcbc6fa8bbb30a (diff)
downloadlibbu++-2fc7fcd7161121ab48cda40687d7d152e03b3079.tar.gz
libbu++-2fc7fcd7161121ab48cda40687d7d152e03b3079.tar.bz2
libbu++-2fc7fcd7161121ab48cda40687d7d152e03b3079.tar.xz
libbu++-2fc7fcd7161121ab48cda40687d7d152e03b3079.zip
Changed interface slightly, it's easier to create json programmatically.
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' )