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

Unified Diff: sdk/lib/codec/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/codec/encoding.dart ('k') | sdk/lib/convert/byte_converter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/codec/json.dart
diff --git a/sdk/lib/codec/json.dart b/sdk/lib/codec/json.dart
new file mode 100644
index 0000000000000000000000000000000000000000..94ea12f987e9f605e21c397553389740173f4ae4
--- /dev/null
+++ b/sdk/lib/codec/json.dart
@@ -0,0 +1,35 @@
+// 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.codec;
+
+final JSON = new JsonCodec();
+
+class JsonCodec extends Codec<Object, String> {
+ const JsonCodec();
+ factory JsonCodec.withReviver(reviver(var key, var value)) =
+ _ReviverJsonCodec;
+
+ String encode(Object o) {
+ return encoder.convert(o);
+ }
+ Object decode(String str, {reviver(var key, var value)}) {
+ return new JsonDecoder(reviver).convert(str);
+ }
+
+ JsonEncoder get encoder => new JsonEncoder();
+ JsonDecoder get decoder => new JsonDecoder(null);
+}
+
+class _ReviverJsonCodec extends JsonCodec {
+ final Function _reviver;
+ _ReviverJsonCodec(this._reviver);
+
+ Object decode(String str, {reviver(var key, var value)}) {
+ reviver = reviver == null ? _reviver : reviver;
+ return new JsonDecoder(reviver).convert(str);
+ }
+
+ JsonDecoder get decoder => new JsonDecoder(_reviver);
+}
« no previous file with comments | « sdk/lib/codec/encoding.dart ('k') | sdk/lib/convert/byte_converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698