diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2019-03-11 11:25:32 -0700 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2019-03-11 11:25:32 -0700 |
commit | 33d08f7b68ee57824c135c927bf86ca5fa3444cb (patch) | |
tree | 00e6b2a0f9113e1682d4b2ba5533f530f6797b3d /src/unstable | |
parent | 252225fa9b2dd3dbc0a3c87bc65ce1f821706e7e (diff) | |
download | libbu++-33d08f7b68ee57824c135c927bf86ca5fa3444cb.tar.gz libbu++-33d08f7b68ee57824c135c927bf86ca5fa3444cb.tar.bz2 libbu++-33d08f7b68ee57824c135c927bf86ca5fa3444cb.tar.xz libbu++-33d08f7b68ee57824c135c927bf86ca5fa3444cb.zip |
Json parsing fix + new API for copying.
Diffstat (limited to 'src/unstable')
-rw-r--r-- | src/unstable/json.cpp | 57 | ||||
-rw-r--r-- | src/unstable/json.h | 4 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/unstable/json.cpp b/src/unstable/json.cpp index 06df9b1..d7e84d9 100644 --- a/src/unstable/json.cpp +++ b/src/unstable/json.cpp | |||
@@ -81,6 +81,12 @@ Bu::Json::Json( char &c, Bu::Stream &sInput ) : | |||
81 | parse( c, sInput ); | 81 | parse( c, sInput ); |
82 | } | 82 | } |
83 | 83 | ||
84 | Bu::Json::Json( const Json &rSrc ) : | ||
85 | eType( Invalid ) | ||
86 | { | ||
87 | (*this) = rSrc; | ||
88 | } | ||
89 | |||
84 | Bu::Json::~Json() | 90 | Bu::Json::~Json() |
85 | { | 91 | { |
86 | reset(); | 92 | reset(); |
@@ -194,6 +200,10 @@ void Bu::Json::insert( const Bu::String &sKey, Bu::Json *pObj ) | |||
194 | { | 200 | { |
195 | uDat.pObject->insert( sKey, pObj ); | 201 | uDat.pObject->insert( sKey, pObj ); |
196 | } | 202 | } |
203 | void Bu::Json::insert( const Bu::String &sKey, const Bu::Json &rObj ) | ||
204 | { | ||
205 | uDat.pObject->insert( sKey, new Bu::Json( rObj ) ); | ||
206 | } | ||
197 | 207 | ||
198 | void Bu::Json::insert( const Bu::String &sKey, const Bu::String &sValue ) | 208 | void Bu::Json::insert( const Bu::String &sKey, const Bu::String &sValue ) |
199 | { | 209 | { |
@@ -352,6 +362,7 @@ void Bu::Json::reset() | |||
352 | break; | 362 | break; |
353 | } | 363 | } |
354 | uDat.pObject = NULL; | 364 | uDat.pObject = NULL; |
365 | eType = Invalid; | ||
355 | } | 366 | } |
356 | 367 | ||
357 | void Bu::Json::write( Bu::Stream &sOutput ) const | 368 | void Bu::Json::write( Bu::Stream &sOutput ) const |
@@ -457,6 +468,51 @@ Bu::String Bu::Json::toStringStable() const | |||
457 | return mb.getString(); | 468 | return mb.getString(); |
458 | } | 469 | } |
459 | 470 | ||
471 | Bu::Json &Bu::Json::operator=( const Bu::Json &rSrc ) | ||
472 | { | ||
473 | reset(); | ||
474 | |||
475 | eType = rSrc.eType; | ||
476 | switch( eType ) | ||
477 | { | ||
478 | case Invalid: | ||
479 | case Null: | ||
480 | break; | ||
481 | |||
482 | case String: | ||
483 | uDat.pString = new Bu::String( *rSrc.uDat.pString ); | ||
484 | break; | ||
485 | |||
486 | case Number: | ||
487 | uDat.dNumber = rSrc.uDat.dNumber; | ||
488 | break; | ||
489 | |||
490 | case Boolean: | ||
491 | uDat.bBoolean = rSrc.uDat.bBoolean; | ||
492 | break; | ||
493 | |||
494 | case Object: | ||
495 | uDat.pObject = new JsonHash(); | ||
496 | for( JsonHash::const_iterator i = rSrc.uDat.pObject->begin(); | ||
497 | i; ++i ) | ||
498 | { | ||
499 | uDat.pObject->insert( i.getKey(), new Json( *i.getValue() ) ); | ||
500 | } | ||
501 | break; | ||
502 | |||
503 | case Array: | ||
504 | uDat.pArray = new JsonList(); | ||
505 | for( JsonList::const_iterator i = rSrc.uDat.pArray->begin(); | ||
506 | i; ++i ) | ||
507 | { | ||
508 | uDat.pArray->append( new Json( *(*i) ) ); | ||
509 | } | ||
510 | break; | ||
511 | } | ||
512 | |||
513 | return *this; | ||
514 | } | ||
515 | |||
460 | void Bu::Json::parseString( char &c, Bu::Stream &sInput, Bu::String &sOut ) | 516 | void Bu::Json::parseString( char &c, Bu::Stream &sInput, Bu::String &sOut ) |
461 | { | 517 | { |
462 | skipWs( c, sInput ); | 518 | skipWs( c, sInput ); |
@@ -535,6 +591,7 @@ void Bu::Json::parseObject( char &c, Bu::Stream &sInput ) | |||
535 | uDat.pObject = new JsonHash(); | 591 | uDat.pObject = new JsonHash(); |
536 | 592 | ||
537 | next( "object" ); | 593 | next( "object" ); |
594 | skipWs( c, sInput ); | ||
538 | 595 | ||
539 | // Check to see if it's an empty object. | 596 | // Check to see if it's an empty object. |
540 | if( c == '}' ) | 597 | if( c == '}' ) |
diff --git a/src/unstable/json.h b/src/unstable/json.h index 336f1fd..4c85dd9 100644 --- a/src/unstable/json.h +++ b/src/unstable/json.h | |||
@@ -41,6 +41,7 @@ namespace Bu | |||
41 | Json( bool bValue ); | 41 | Json( bool bValue ); |
42 | Json( Type eType ); | 42 | Json( Type eType ); |
43 | Json( Bu::Stream &sInput ); | 43 | Json( Bu::Stream &sInput ); |
44 | Json( const Json &rSrc ); | ||
44 | virtual ~Json(); | 45 | virtual ~Json(); |
45 | 46 | ||
46 | Type getType() const; | 47 | Type getType() const; |
@@ -59,6 +60,7 @@ namespace Bu | |||
59 | 60 | ||
60 | bool has( const Bu::String &sKey ) const; | 61 | bool has( const Bu::String &sKey ) const; |
61 | void insert( const Bu::String &sKey, Bu::Json *pObj ); | 62 | void insert( const Bu::String &sKey, Bu::Json *pObj ); |
63 | void insert( const Bu::String &sKey, const Bu::Json &rObj ); | ||
62 | void insert( const Bu::String &sKey, const Bu::String &sValue ); | 64 | void insert( const Bu::String &sKey, const Bu::String &sValue ); |
63 | void insert( const Bu::String &sKey, const char *sValue ); | 65 | void insert( const Bu::String &sKey, const char *sValue ); |
64 | void insert( const Bu::String &sKey, double dValue ); | 66 | void insert( const Bu::String &sKey, double dValue ); |
@@ -82,6 +84,8 @@ namespace Bu | |||
82 | Bu::String toString() const; | 84 | Bu::String toString() const; |
83 | Bu::String toStringStable() const; | 85 | Bu::String toStringStable() const; |
84 | 86 | ||
87 | Bu::Json &operator=( const Bu::Json &rSrc ); | ||
88 | |||
85 | private: | 89 | private: |
86 | void parse( char &c, Bu::Stream &sInput ); | 90 | void parse( char &c, Bu::Stream &sInput ); |
87 | void parseString( char &c, Bu::Stream &sInput, Bu::String &sOut ); | 91 | void parseString( char &c, Bu::Stream &sInput, Bu::String &sOut ); |