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

Side by Side Diff: sdk/lib/convert/json.dart

Issue 2767943002: Revert "Fix some strong mode issues in the core libraries." (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « sdk/lib/convert/html_escape.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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * Error thrown by JSON serialization if an object cannot be serialized. 8 * Error thrown by JSON serialization if an object cannot be serialized.
9 * 9 *
10 * The [unsupportedObject] field holds that object that failed to be serialized. 10 * The [unsupportedObject] field holds that object that failed to be serialized.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 JsonDecoder get decoder { 150 JsonDecoder get decoder {
151 if (_reviver == null) return const JsonDecoder(); 151 if (_reviver == null) return const JsonDecoder();
152 return new JsonDecoder(_reviver); 152 return new JsonDecoder(_reviver);
153 } 153 }
154 } 154 }
155 155
156 /** 156 /**
157 * This class converts JSON objects to strings. 157 * This class converts JSON objects to strings.
158 */ 158 */
159 class JsonEncoder extends Converter<Object, String> { 159 class JsonEncoder extends Converter<Object, String>
160 implements ChunkedConverter<Object, String, Object, String> {
160 /** 161 /**
161 * The string used for indention. 162 * The string used for indention.
162 * 163 *
163 * When generating multi-line output, this string is inserted once at the 164 * When generating multi-line output, this string is inserted once at the
164 * beginning of each indented line for each level of indentation. 165 * beginning of each indented line for each level of indentation.
165 * 166 *
166 * If `null`, the output is encoded as a single line. 167 * If `null`, the output is encoded as a single line.
167 */ 168 */
168 final String indent; 169 final String indent;
169 170
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 276 }
276 } 277 }
277 278
278 /** 279 /**
279 * Encoder that encodes a single object as a UTF-8 encoded JSON string. 280 * Encoder that encodes a single object as a UTF-8 encoded JSON string.
280 * 281 *
281 * This encoder works equivalently to first converting the object to 282 * This encoder works equivalently to first converting the object to
282 * a JSON string, and then UTF-8 encoding the string, but without 283 * a JSON string, and then UTF-8 encoding the string, but without
283 * creating an intermediate string. 284 * creating an intermediate string.
284 */ 285 */
285 class JsonUtf8Encoder extends Converter<Object, List<int>> { 286 class JsonUtf8Encoder extends Converter<Object, List<int>>
287 implements ChunkedConverter<Object, List<int>, Object, List<int>> {
286 /** Default buffer size used by the JSON-to-UTF-8 encoder. */ 288 /** Default buffer size used by the JSON-to-UTF-8 encoder. */
287 static const int DEFAULT_BUFFER_SIZE = 256; 289 static const int DEFAULT_BUFFER_SIZE = 256;
288 /** Indentation used in pretty-print mode, `null` if not pretty. */ 290 /** Indentation used in pretty-print mode, `null` if not pretty. */
289 final List<int> _indent; 291 final List<int> _indent;
290 /** Function called with each un-encodable object encountered. */ 292 /** Function called with each un-encodable object encountered. */
291 final _ToEncodable _toEncodable; 293 final _ToEncodable _toEncodable;
292 /** UTF-8 buffer size. */ 294 /** UTF-8 buffer size. */
293 final int _bufferSize; 295 final int _bufferSize;
294 296
295 /** 297 /**
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 if (!_isDone) { 461 if (!_isDone) {
460 _isDone = true; 462 _isDone = true;
461 _sink.close(); 463 _sink.close();
462 } 464 }
463 } 465 }
464 } 466 }
465 467
466 /** 468 /**
467 * This class parses JSON strings and builds the corresponding objects. 469 * This class parses JSON strings and builds the corresponding objects.
468 */ 470 */
469 class JsonDecoder extends Converter<String, Object> { 471 class JsonDecoder extends Converter<String, Object>
472 implements ChunkedConverter<String, Object, String, Object> {
470 final _Reviver _reviver; 473 final _Reviver _reviver;
471 /** 474 /**
472 * Constructs a new JsonDecoder. 475 * Constructs a new JsonDecoder.
473 * 476 *
474 * The [reviver] may be `null`. 477 * The [reviver] may be `null`.
475 */ 478 */
476 const JsonDecoder([reviver(var key, var value)]) : this._reviver = reviver; 479 const JsonDecoder([reviver(var key, var value)]) : this._reviver = reviver;
477 480
478 /** 481 /**
479 * Converts the given JSON-string [input] to its corresponding object. 482 * Converts the given JSON-string [input] to its corresponding object.
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 buffer.setRange(index, end, indent); 1052 buffer.setRange(index, end, indent);
1050 index = end; 1053 index = end;
1051 } else { 1054 } else {
1052 for (int i = 0; i < indentLength; i++) { 1055 for (int i = 0; i < indentLength; i++) {
1053 writeByte(indent[i]); 1056 writeByte(indent[i]);
1054 } 1057 }
1055 } 1058 }
1056 } 1059 }
1057 } 1060 }
1058 } 1061 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/html_escape.dart ('k') | sdk/lib/convert/line_splitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698