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

Unified Diff: sdk/lib/codec/codec.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/_internal/libraries.dart ('k') | sdk/lib/codec/codec_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/codec/codec.dart
diff --git a/sdk/lib/codec/codec.dart b/sdk/lib/codec/codec.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d19525279b04765af2bfd80765708aec90f3923a
--- /dev/null
+++ b/sdk/lib/codec/codec.dart
@@ -0,0 +1,46 @@
+// 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.
+
+library dart.codec;
+
+import 'dart:convert';
+
+part 'encoding.dart';
+part 'json.dart';
+part 'line_splitter.dart';
+
+abstract class Codec<S, T> {
+ const Codec();
+
+ T encode(S input) => encoder.convert(input);
+ S decode(T encoded) => decoder.convert(encoded);
+
+ Converter<S, T> get encoder;
+ Converter<T, S> get decoder;
+
+ Codec<S, dynamic> fuse(Codec<T, dynamic> other) {
+ return new FusedCodec<S, T, dynamic>(this, other);
+ }
+}
+
+class FusedCodec<S, M, T> extends Codec<S, T> {
+ final Codec<S, M> first;
+ final Codec<M, T> second;
+
+ Converter get encoder => first.encoder.fuse(second.encoder);
+ Converter get decoder => second.decoder.fuse(first.decoder);
+
+ FusedCodec(Codec<S, M> first, Codec<M, T> second)
+ : this.first = first,
+ this.second = second;
+}
+
+class InvertedCodec<S, T> extends Codec<S, T> {
+ final Codec<T, S> _codec;
+
+ InvertedCodec(Codec<T, S> codec) : _codec = codec;
+
+ Converter get encoder => _codec.decoder;
+ Converter get decoder => _codec.encoder;
+}
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | sdk/lib/codec/codec_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698