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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/convert/converter.dart ('k') | sdk/lib/convert/line_splitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of dart.convert;
6
7 class JsonEncoder extends Converter<Object, String> {
8 JsonEncoder();
9
10 String convert(Object o) => JSON_LIB.stringify(o);
11
12 ChunkedConversionSink<Object> startChunkedConversion(
13 ChunkedConversionSink sink) {
14 return new _JsonEncoderSink(outputInterface.adapt(sink));
15 }
16
17 ChunkedConversionInterface get outputInterface =>
18 StringConversionSink.INTERFACE;
19 }
20
21 class JsonDecoder extends Converter<String, Object> {
22 final _reviver;
23 JsonDecoder(this._reviver);
24
25 Object convert(String input) => JSON_LIB.parse(input, _reviver);
26
27 StringConversionSink startChunkedConversion(ChunkedConversionSink sink) {
28 return new _JsonDecoderSink(_reviver, outputInterface.adapt(sink));
29 }
30
31 ChunkedConversionInterface get inputInterface =>
32 StringConversionSink.INTERFACE;
33 }
34
35 class _JsonDecoderSink extends StringConversionSinkBase {
36 final _reviver;
37 ChunkedConversionSink _sink;
38 List<String> _carry = <String>[];
39
40 _JsonDecoderSink(this._reviver, this._sink);
41
42 void add(String str) => _carry.add(str);
43 void close() => _sink.addNonChunked(_convert(_carry.join()));
44
45 Object _convert(String input) {
46 return JSON_LIB.parse(input, _reviver);
47 }
48 }
49
50 class _JsonEncoderSink extends ChunkedConversionSink<Object> {
51 StringConversionSink _sink;
52
53 _JsonEncoderSink(this._sink);
54
55 void addNonChunked(Object o) {
56 JSON_LIB.printOn(o, _sink);
57 _sink.close();
58 }
59 }
OLDNEW
« 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