Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Unified Diff: lib/json/json.dart

Issue 10632002: Implement JSON serialization to stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/json/json.dart
diff --git a/lib/json/json.dart b/lib/json/json.dart
index 738a38e75a4fb5202b9e2c798a4293d4f37f0e5c..253df66bf065f28585b769fc164d593157bc7eb6 100644
--- a/lib/json/json.dart
+++ b/lib/json/json.dart
@@ -32,6 +32,13 @@ class JSON {
static String stringify(Object object) {
return JsonStringifier.stringify(object);
}
+
+ /**
+ * Serializes [:object:] into [:output:] stream.
+ */
+ static void dump(Object object, StringBuffer output) {
Anton Muhin 2012/06/21 11:02:19 maybe make StringBuffer an optional argument of st
podivilov 2012/06/21 11:44:17 I think these are just different functions, no nee
Anton Muhin 2012/06/21 11:50:00 Okay, than maybe rename it to printOn---there is a
podivilov 2012/06/21 12:03:58 Done.
+ return JsonStringifier.dump(object, output);
+ }
}
//// Implementation ///////////////////////////////////////////////////////////
@@ -401,16 +408,22 @@ class JsonUnsupportedObjectType {
class JsonStringifier {
static String stringify(final object) {
Anton Muhin 2012/06/21 11:02:19 maybe we should drop this method altogether and mo
podivilov 2012/06/21 11:44:17 It might be a good idea, but I prefer to keep this
- JsonStringifier stringifier = new JsonStringifier._internal();
+ StringBuffer output = new StringBuffer();
+ JsonStringifier stringifier = new JsonStringifier._internal(output);
stringifier._stringify(object);
- return stringifier._result;
+ return output.toString();
}
- JsonStringifier._internal()
- : _sb = new StringBuffer(), _seen = new List<Object>() {}
+ static void dump(final object, StringBuffer output) {
+ JsonStringifier stringifier = new JsonStringifier._internal(output);
+ stringifier._stringify(object);
+ }
+
+ JsonStringifier._internal(this._sb)
+ : _seen = new List<Object>() {}
Anton Muhin 2012/06/21 11:02:19 nit: please, use _seen = []
podivilov 2012/06/21 11:44:17 Done.
+
StringBuffer _sb;
List<Object> _seen; // TODO: that should be identity set.
- String get _result() { return _sb.toString(); }
static String _numberToString(num x) {
// TODO: need some more investigation what to do with precision
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698