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 // Character constants. | 7 // Character constants. |
8 const int _LF = 10; | 8 const int _LF = 10; |
9 const int _CR = 13; | 9 const int _CR = 13; |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 List<String> convert(String data) => split(data).toList(); | 52 List<String> convert(String data) => split(data).toList(); |
53 | 53 |
54 StringConversionSink startChunkedConversion(Sink<String> sink) { | 54 StringConversionSink startChunkedConversion(Sink<String> sink) { |
55 if (sink is! StringConversionSink) { | 55 if (sink is! StringConversionSink) { |
56 sink = new StringConversionSink.from(sink); | 56 sink = new StringConversionSink.from(sink); |
57 } | 57 } |
58 return new _LineSplitterSink(sink); | 58 return new _LineSplitterSink(sink); |
59 } | 59 } |
60 | 60 |
| 61 // Override the base-class' bind, to provide a better type. |
61 Stream<String> bind(Stream<String> stream) => super.bind(stream); | 62 Stream<String> bind(Stream<String> stream) => super.bind(stream); |
62 } | 63 } |
63 | 64 |
64 // TODO(floitsch): deal with utf8. | 65 // TODO(floitsch): deal with utf8. |
65 class _LineSplitterSink extends StringConversionSinkBase { | 66 class _LineSplitterSink extends StringConversionSinkBase { |
66 final StringConversionSink _sink; | 67 final StringConversionSink _sink; |
67 | 68 |
68 /// The carry-over from the previous chunk. | 69 /// The carry-over from the previous chunk. |
69 /// | 70 /// |
70 /// If the previous slice ended in a line without a line terminator, | 71 /// If the previous slice ended in a line without a line terminator, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 _sink.add(lines.substring(sliceStart, i)); | 130 _sink.add(lines.substring(sliceStart, i)); |
130 sliceStart = i + 1; | 131 sliceStart = i + 1; |
131 } | 132 } |
132 if (sliceStart < end) { | 133 if (sliceStart < end) { |
133 _carry = lines.substring(sliceStart, end); | 134 _carry = lines.substring(sliceStart, end); |
134 } else { | 135 } else { |
135 _skipLeadingLF = (char == _CR); | 136 _skipLeadingLF = (char == _CR); |
136 } | 137 } |
137 } | 138 } |
138 } | 139 } |
OLD | NEW |