| OLD | NEW |
| 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 * If `this` was initialized with a reviver, then the parsing operation | 488 * If `this` was initialized with a reviver, then the parsing operation |
| 489 * invokes the reviver on every object or list property that has been parsed. | 489 * invokes the reviver on every object or list property that has been parsed. |
| 490 * The arguments are the property name ([String]) or list index ([int]), and | 490 * The arguments are the property name ([String]) or list index ([int]), and |
| 491 * the value is the parsed value. The return value of the reviver is used as | 491 * the value is the parsed value. The return value of the reviver is used as |
| 492 * the value of that property instead the parsed value. | 492 * the value of that property instead the parsed value. |
| 493 * | 493 * |
| 494 * Throws [FormatException] if the input is not valid JSON text. | 494 * Throws [FormatException] if the input is not valid JSON text. |
| 495 */ | 495 */ |
| 496 dynamic convert(String input) => _parseJson(input, _reviver); | 496 dynamic convert(String input) => _parseJson(input, _reviver); |
| 497 | 497 |
| 498 @patch | 498 /** |
| 499 * Starts a conversion from a chunked JSON string to its corresponding |
| 500 * object. |
| 501 * |
| 502 * The output [sink] receives exactly one decoded element through `add`. |
| 503 */ |
| 499 StringConversionSink startChunkedConversion(Sink<Object> sink) { | 504 StringConversionSink startChunkedConversion(Sink<Object> sink) { |
| 500 return new _JsonDecoderSink(_reviver, sink); | 505 return new _JsonDecoderSink(_reviver, sink); |
| 501 } | 506 } |
| 502 | 507 |
| 503 // Override the base-classes bind, to provide a better type. | 508 // Override the base-classes bind, to provide a better type. |
| 504 Stream<Object> bind(Stream<String> stream) => super.bind(stream); | 509 Stream<Object> bind(Stream<String> stream) => super.bind(stream); |
| 505 } | 510 } |
| 506 | 511 |
| 507 // Internal optimized JSON parsing implementation. | 512 // Internal optimized JSON parsing implementation. |
| 508 /** | |
| 509 * Parses [json] and builds the corresponding parsed JSON value. | |
| 510 * | |
| 511 * Parsed JSON values Nare of the types [num], [String], [bool], [Null], | |
| 512 * [List]s of parsed JSON values or [Map]s from [String] to parsed | |
| 513 * JSON values. | |
| 514 * | |
| 515 * The optional [reviver] function, if provided, is called once for each object | |
| 516 * or list property parsed. The arguments are the property name ([String]) or | |
| 517 * list index ([int]), and the value is the parsed value. The return value of | |
| 518 * the reviver will be used as the value of that property instead of the parsed | |
| 519 * value. The top level value is passed to the reviver with the empty string as | |
| 520 * a key. | |
| 521 * | |
| 522 * Throws [FormatException] if the input is not valid JSON text. | |
| 523 */ | |
| 524 @patch | |
| 525 _parseJson(String source, reviver(key, value)) { | 513 _parseJson(String source, reviver(key, value)) { |
| 526 if (source is! String) throw new ArgumentError(source); | 514 if (source is! String) throw new ArgumentError(source); |
| 527 | 515 |
| 528 var parsed; | 516 var parsed; |
| 529 try { | 517 try { |
| 530 parsed = JS('=Object|JSExtendableArray|Null|bool|num|String', | 518 parsed = JS('=Object|JSExtendableArray|Null|bool|num|String', |
| 531 'JSON.parse(#)', | 519 'JSON.parse(#)', |
| 532 source); | 520 source); |
| 533 } catch (e) { | 521 } catch (e) { |
| 534 throw new FormatException(JS('String', 'String(#)', e)); | 522 throw new FormatException(JS('String', 'String(#)', e)); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 buffer.setRange(index, end, indent); | 1048 buffer.setRange(index, end, indent); |
| 1061 index = end; | 1049 index = end; |
| 1062 } else { | 1050 } else { |
| 1063 for (int i = 0; i < indentLength; i++) { | 1051 for (int i = 0; i < indentLength; i++) { |
| 1064 writeByte(indent[i]); | 1052 writeByte(indent[i]); |
| 1065 } | 1053 } |
| 1066 } | 1054 } |
| 1067 } | 1055 } |
| 1068 } | 1056 } |
| 1069 } | 1057 } |
| OLD | NEW |