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

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

Issue 1881553002: Revert "Steps towards making the convert library strong-mode compliant." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/latin1.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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 JsonDecoder get decoder { 155 JsonDecoder get decoder {
156 if (_reviver == null) return const JsonDecoder(); 156 if (_reviver == null) return const JsonDecoder();
157 return new JsonDecoder(_reviver); 157 return new JsonDecoder(_reviver);
158 } 158 }
159 } 159 }
160 160
161 /** 161 /**
162 * This class converts JSON objects to strings. 162 * This class converts JSON objects to strings.
163 */ 163 */
164 class JsonEncoder extends ChunkedConverter<Object, String, Object, String> { 164 class JsonEncoder extends Converter<Object, String> {
165 /** 165 /**
166 * The string used for indention. 166 * The string used for indention.
167 * 167 *
168 * When generating multi-line output, this string is inserted once at the 168 * When generating multi-line output, this string is inserted once at the
169 * beginning of each indented line for each level of indentation. 169 * beginning of each indented line for each level of indentation.
170 * 170 *
171 * If `null`, the output is encoded as a single line. 171 * If `null`, the output is encoded as a single line.
172 */ 172 */
173 final String indent; 173 final String indent;
174 174
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 } 279 }
280 280
281 /** 281 /**
282 * Encoder that encodes a single object as a UTF-8 encoded JSON string. 282 * Encoder that encodes a single object as a UTF-8 encoded JSON string.
283 * 283 *
284 * This encoder works equivalently to first converting the object to 284 * This encoder works equivalently to first converting the object to
285 * a JSON string, and then UTF-8 encoding the string, but without 285 * a JSON string, and then UTF-8 encoding the string, but without
286 * creating an intermediate string. 286 * creating an intermediate string.
287 */ 287 */
288 class JsonUtf8Encoder extends 288 class JsonUtf8Encoder extends Converter<Object, List<int>> {
289 ChunkedConverter<Object, List<int>, Object, List<int>> {
290 /** Default buffer size used by the JSON-to-UTF-8 encoder. */ 289 /** Default buffer size used by the JSON-to-UTF-8 encoder. */
291 static const int DEFAULT_BUFFER_SIZE = 256; 290 static const int DEFAULT_BUFFER_SIZE = 256;
292 /** Indentation used in pretty-print mode, `null` if not pretty. */ 291 /** Indentation used in pretty-print mode, `null` if not pretty. */
293 final List<int> _indent; 292 final List<int> _indent;
294 /** Function called with each un-encodable object encountered. */ 293 /** Function called with each un-encodable object encountered. */
295 final Function _toEncodable; 294 final Function _toEncodable;
296 /** UTF-8 buffer size. */ 295 /** UTF-8 buffer size. */
297 final int _bufferSize; 296 final int _bufferSize;
298 297
299 /** 298 /**
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (!_isDone) { 467 if (!_isDone) {
469 _isDone = true; 468 _isDone = true;
470 _sink.close(); 469 _sink.close();
471 } 470 }
472 } 471 }
473 } 472 }
474 473
475 /** 474 /**
476 * This class parses JSON strings and builds the corresponding objects. 475 * This class parses JSON strings and builds the corresponding objects.
477 */ 476 */
478 class JsonDecoder extends ChunkedConverter<String, Object, String, Object> { 477 class JsonDecoder extends Converter<String, Object> {
479 final _Reviver _reviver; 478 final _Reviver _reviver;
480 /** 479 /**
481 * Constructs a new JsonDecoder. 480 * Constructs a new JsonDecoder.
482 * 481 *
483 * The [reviver] may be `null`. 482 * The [reviver] may be `null`.
484 */ 483 */
485 const JsonDecoder([reviver(var key, var value)]) : this._reviver = reviver; 484 const JsonDecoder([reviver(var key, var value)]) : this._reviver = reviver;
486 485
487 /** 486 /**
488 * Converts the given JSON-string [input] to its corresponding object. 487 * Converts the given JSON-string [input] to its corresponding object.
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 buffer.setRange(index, end, indent); 1061 buffer.setRange(index, end, indent);
1063 index = end; 1062 index = end;
1064 } else { 1063 } else {
1065 for (int i = 0; i < indentLength; i++) { 1064 for (int i = 0; i < indentLength; i++) {
1066 writeByte(indent[i]); 1065 writeByte(indent[i]);
1067 } 1066 }
1068 } 1067 }
1069 } 1068 }
1070 } 1069 }
1071 } 1070 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/html_escape.dart ('k') | sdk/lib/convert/latin1.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698