| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import "dart:_internal" show POWERS_OF_TEN; | 5 import "dart:_internal" show POWERS_OF_TEN; |
| 6 | 6 |
| 7 // JSON conversion. | 7 // JSON conversion. |
| 8 | 8 |
| 9 patch _parseJson(String json, reviver(var key, var value)) { | 9 @patch _parseJson(String json, reviver(var key, var value)) { |
| 10 _BuildJsonListener listener; | 10 _BuildJsonListener listener; |
| 11 if (reviver == null) { | 11 if (reviver == null) { |
| 12 listener = new _BuildJsonListener(); | 12 listener = new _BuildJsonListener(); |
| 13 } else { | 13 } else { |
| 14 listener = new _ReviverJsonListener(reviver); | 14 listener = new _ReviverJsonListener(reviver); |
| 15 } | 15 } |
| 16 var parser = new _JsonStringParser(listener); | 16 var parser = new _JsonStringParser(listener); |
| 17 parser.chunk = json; | 17 parser.chunk = json; |
| 18 parser.chunkEnd = json.length; | 18 parser.chunkEnd = json.length; |
| 19 parser.parse(0); | 19 parser.parse(0); |
| 20 parser.close(); | 20 parser.close(); |
| 21 return listener.result; | 21 return listener.result; |
| 22 } | 22 } |
| 23 | 23 |
| 24 patch class Utf8Decoder { | 24 @patch class Utf8Decoder { |
| 25 /* patch */ | 25 /* @patch */ |
| 26 Converter<List<int>, dynamic/*=T*/> fuse/*<T>*/( | 26 Converter<List<int>, dynamic/*=T*/> fuse/*<T>*/( |
| 27 Converter<String, dynamic/*=T*/> next) { | 27 Converter<String, dynamic/*=T*/> next) { |
| 28 if (next is JsonDecoder) { | 28 if (next is JsonDecoder) { |
| 29 return new _JsonUtf8Decoder(next._reviver, this._allowMalformed) | 29 return new _JsonUtf8Decoder(next._reviver, this._allowMalformed) |
| 30 as dynamic/*=Converter<List<int>, T>*/; | 30 as dynamic/*=Converter<List<int>, T>*/; |
| 31 } | 31 } |
| 32 // TODO(lrn): Recognize a fused decoder where the next step is JsonDecoder. | 32 // TODO(lrn): Recognize a fused decoder where the next step is JsonDecoder. |
| 33 return super.fuse/*<T>*/(next); | 33 return super.fuse/*<T>*/(next); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Allow intercepting of UTF-8 decoding when built-in lists are passed. | 36 // Allow intercepting of UTF-8 decoding when built-in lists are passed. |
| 37 /* patch */ | 37 /* @patch */ |
| 38 static String _convertIntercepted( | 38 static String _convertIntercepted( |
| 39 bool allowMalformed, List<int> codeUnits, int start, int end) { | 39 bool allowMalformed, List<int> codeUnits, int start, int end) { |
| 40 return null; // This call was not intercepted. | 40 return null; // This call was not intercepted. |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 class _JsonUtf8Decoder extends Converter<List<int>, Object> { | 44 class _JsonUtf8Decoder extends Converter<List<int>, Object> { |
| 45 final _Reviver _reviver; | 45 final _Reviver _reviver; |
| 46 final bool _allowMalformed; | 46 final bool _allowMalformed; |
| 47 | 47 |
| (...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 for (int i = 0; i < length; i++) { | 1369 for (int i = 0; i < length; i++) { |
| 1370 target[offset + i] = chunk.codeUnitAt(start + i); | 1370 target[offset + i] = chunk.codeUnitAt(start + i); |
| 1371 } | 1371 } |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 double parseDouble(int start, int end) { | 1374 double parseDouble(int start, int end) { |
| 1375 return _parseDouble(chunk, start, end); | 1375 return _parseDouble(chunk, start, end); |
| 1376 } | 1376 } |
| 1377 } | 1377 } |
| 1378 | 1378 |
| 1379 patch class JsonDecoder { | 1379 @patch class JsonDecoder { |
| 1380 /* patch */ StringConversionSink startChunkedConversion(Sink<Object> sink) { | 1380 /* @patch */ StringConversionSink startChunkedConversion(Sink<Object> sink) { |
| 1381 return new _JsonStringDecoderSink(this._reviver, sink); | 1381 return new _JsonStringDecoderSink(this._reviver, sink); |
| 1382 } | 1382 } |
| 1383 } | 1383 } |
| 1384 | 1384 |
| 1385 /** | 1385 /** |
| 1386 * Implements the chunked conversion from a JSON string to its corresponding | 1386 * Implements the chunked conversion from a JSON string to its corresponding |
| 1387 * object. | 1387 * object. |
| 1388 * | 1388 * |
| 1389 * The sink only creates one object, but its input can be chunked. | 1389 * The sink only creates one object, but its input can be chunked. |
| 1390 */ | 1390 */ |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 _parser.parse(start); | 1767 _parser.parse(start); |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 void close() { | 1770 void close() { |
| 1771 _parser.close(); | 1771 _parser.close(); |
| 1772 var decoded = _parser.result; | 1772 var decoded = _parser.result; |
| 1773 _sink.add(decoded); | 1773 _sink.add(decoded); |
| 1774 _sink.close(); | 1774 _sink.close(); |
| 1775 } | 1775 } |
| 1776 } | 1776 } |
| OLD | NEW |