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

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: Rename dump to printOn. 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..8989a0a68b8b28ff31b6a6b78b20cf9633a2828e 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.
Søren Gjesse 2012/06/25 07:46:38 DBC Shouldn this be just [object] and [output] (w
podivilov 2012/06/25 13:28:44 grep showed that it probably should. Do you know i
ahe 2012/06/25 13:30:22 Sorry, Google-internal URL: http://chromegw.corp.
+ */
+ static void printOn(Object object, StringBuffer output) {
+ return JsonStringifier.printOn(object, output);
+ }
}
//// Implementation ///////////////////////////////////////////////////////////
@@ -401,16 +408,22 @@ class JsonUnsupportedObjectType {
class JsonStringifier {
static String stringify(final object) {
- 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 printOn(final object, StringBuffer output) {
+ JsonStringifier stringifier = new JsonStringifier._internal(output);
+ stringifier._stringify(object);
+ }
+
+ JsonStringifier._internal(this._sb)
+ : _seen = [];
+
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