aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2019-06-12 17:12:15 -0700
committerMike Buland <mbuland@penny-arcade.com>2019-06-12 17:12:15 -0700
commit889cf794108dc1a8c4d2c50fc864846799f512e1 (patch)
tree0bcaaa64c9289cc48f55f9f1daa7f64ca5c8c45a
parentca3f5b64d656a86ea411572737be7facd067fd62 (diff)
downloadlibbu++-889cf794108dc1a8c4d2c50fc864846799f512e1.tar.gz
libbu++-889cf794108dc1a8c4d2c50fc864846799f512e1.tar.bz2
libbu++-889cf794108dc1a8c4d2c50fc864846799f512e1.tar.xz
libbu++-889cf794108dc1a8c4d2c50fc864846799f512e1.zip
Json objects can be formatted directly.
-rw-r--r--src/tests/json.cpp6
-rw-r--r--src/unstable/json.cpp6
-rw-r--r--src/unstable/json.h5
3 files changed, 16 insertions, 1 deletions
diff --git a/src/tests/json.cpp b/src/tests/json.cpp
index 6490d8d..6ec92f0 100644
--- a/src/tests/json.cpp
+++ b/src/tests/json.cpp
@@ -7,6 +7,12 @@ int main( int argc, char *argv[] )
7{ 7{
8 Bu::Json j( "\x01" "ACTION" "\x01" ); 8 Bu::Json j( "\x01" "ACTION" "\x01" );
9 Bu::println( j.toString() ); 9 Bu::println( j.toString() );
10
11 Bu::Json ob( Bu::Json::Object );
12 ob.insert("hello", 47.0 );
13 const Bu::Json &obRef = ob;
14 Bu::println("%1").arg( obRef["hello"] );
15
10 return 0; 16 return 0;
11} 17}
12 18
diff --git a/src/unstable/json.cpp b/src/unstable/json.cpp
index 8c766dd..7e6387b 100644
--- a/src/unstable/json.cpp
+++ b/src/unstable/json.cpp
@@ -832,3 +832,9 @@ void Bu::Json::writeStr( const Bu::UtfString &sStr, Bu::Stream &sOutput ) const
832 sOutput.write("\"", 1 ); 832 sOutput.write("\"", 1 );
833} 833}
834 834
835Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Json &j )
836{
837 f.write( j.toString() );
838 return f;
839}
840
diff --git a/src/unstable/json.h b/src/unstable/json.h
index 2ea62a2..100a3d1 100644
--- a/src/unstable/json.h
+++ b/src/unstable/json.h
@@ -10,6 +10,7 @@
10namespace Bu 10namespace Bu
11{ 11{
12 class Stream; 12 class Stream;
13 class Formatter;
13 typedef Bu::List<Bu::UtfString> UtfStringList; 14 typedef Bu::List<Bu::UtfString> UtfStringList;
14 15
15 class Json 16 class Json
@@ -123,6 +124,8 @@ namespace Bu
123 bool bBoolean; 124 bool bBoolean;
124 } uDat; 125 } uDat;
125 }; 126 };
126}; 127
128 Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::Json &j );
129}
127 130
128#endif 131#endif