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

Unified Diff: sdk/lib/convert/json.dart

Issue 17580014: dart:convert library. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update Created 7 years, 5 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 | « sdk/lib/convert/converter.dart ('k') | sdk/lib/convert/line_splitter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/convert/json.dart
diff --git a/sdk/lib/convert/json.dart b/sdk/lib/convert/json.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6b4d9da30539070d4abe44ac28b09ee493d11ba9
--- /dev/null
+++ b/sdk/lib/convert/json.dart
@@ -0,0 +1,59 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of dart.convert;
+
+class JsonEncoder extends Converter<Object, String> {
+ JsonEncoder();
+
+ String convert(Object o) => JSON_LIB.stringify(o);
+
+ ChunkedConversionSink<Object> startChunkedConversion(
+ ChunkedConversionSink sink) {
+ return new _JsonEncoderSink(outputInterface.adapt(sink));
+ }
+
+ ChunkedConversionInterface get outputInterface =>
+ StringConversionSink.INTERFACE;
+}
+
+class JsonDecoder extends Converter<String, Object> {
+ final _reviver;
+ JsonDecoder(this._reviver);
+
+ Object convert(String input) => JSON_LIB.parse(input, _reviver);
+
+ StringConversionSink startChunkedConversion(ChunkedConversionSink sink) {
+ return new _JsonDecoderSink(_reviver, outputInterface.adapt(sink));
+ }
+
+ ChunkedConversionInterface get inputInterface =>
+ StringConversionSink.INTERFACE;
+}
+
+class _JsonDecoderSink extends StringConversionSinkBase {
+ final _reviver;
+ ChunkedConversionSink _sink;
+ List<String> _carry = <String>[];
+
+ _JsonDecoderSink(this._reviver, this._sink);
+
+ void add(String str) => _carry.add(str);
+ void close() => _sink.addNonChunked(_convert(_carry.join()));
+
+ Object _convert(String input) {
+ return JSON_LIB.parse(input, _reviver);
+ }
+}
+
+class _JsonEncoderSink extends ChunkedConversionSink<Object> {
+ StringConversionSink _sink;
+
+ _JsonEncoderSink(this._sink);
+
+ void addNonChunked(Object o) {
+ JSON_LIB.printOn(o, _sink);
+ _sink.close();
+ }
+}
« no previous file with comments | « sdk/lib/convert/converter.dart ('k') | sdk/lib/convert/line_splitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698