Chromium Code Reviews| 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 |
| 11 /** | 11 /** |
| 12 * A [Converter] that splits a [String] into individual lines. | 12 * A [StreamTranformer] that splits a [String] into individual lines. |
| 13 * | 13 * |
| 14 * A line is terminated by either a CR (U+000D), a LF (U+000A), a | 14 * A line is terminated by either a CR (U+000D), a LF (U+000A), a |
| 15 * CR+LF sequence (DOS line ending), | 15 * CR+LF sequence (DOS line ending), |
| 16 * and a final non-empty line can be ended by the end of the string. | 16 * and a final non-empty line can be ended by the end of the string. |
| 17 * | 17 * |
| 18 * The returned lines do not contain the line terminators. | 18 * The returned lines do not contain the line terminators. |
| 19 */ | 19 */ |
| 20 class LineSplitter | 20 class LineSplitter implements StreamTransformer<String, String> { |
|
Lasse Reichstein Nielsen
2016/12/16 16:36:01
The analyzer kept saying that the class didn't cor
| |
| 21 extends Converter<String, List<String>>/*=Object*/ | |
| 22 implements ChunkedConverter<String, List<String>, String, String> | |
| 23 /*=StreamTransformer<String, String>*/ { | |
| 24 | 21 |
| 25 const LineSplitter(); | 22 const LineSplitter(); |
| 26 | 23 |
| 27 /// Split [lines] into individual lines. | 24 /// Split [lines] into individual lines. |
| 28 /// | 25 /// |
| 29 /// If [start] and [end] are provided, only split the contents of | 26 /// If [start] and [end] are provided, only split the contents of |
| 30 /// `lines.substring(start, end)`. The [start] and [end] values must | 27 /// `lines.substring(start, end)`. The [start] and [end] values must |
| 31 /// specify a valid sub-range of [lines] | 28 /// specify a valid sub-range of [lines] |
| 32 /// (`0 <= start <= end <= lines.length`). | 29 /// (`0 <= start <= end <= lines.length`). |
| 33 static Iterable<String> split(String lines, [int start = 0, int end]) sync* { | 30 static Iterable<String> split(String lines, [int start = 0, int end]) sync* { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 return lines; | 73 return lines; |
| 77 } | 74 } |
| 78 | 75 |
| 79 StringConversionSink startChunkedConversion(Sink<String> sink) { | 76 StringConversionSink startChunkedConversion(Sink<String> sink) { |
| 80 if (sink is! StringConversionSink) { | 77 if (sink is! StringConversionSink) { |
| 81 sink = new StringConversionSink.from(sink); | 78 sink = new StringConversionSink.from(sink); |
| 82 } | 79 } |
| 83 return new _LineSplitterSink(sink); | 80 return new _LineSplitterSink(sink); |
| 84 } | 81 } |
| 85 | 82 |
| 86 Stream/*<String>*/ bind(Stream/*<String>*/ stream) { | 83 Stream<String> bind(Stream<String> stream) { |
| 87 return new Stream<String>.eventTransformed( | 84 return new Stream<String>.eventTransformed( |
| 88 stream, | 85 stream, |
| 89 (EventSink<String> sink) => new _LineSplitterEventSink(sink)); | 86 (EventSink<String> sink) => new _LineSplitterEventSink(sink)); |
| 90 } | 87 } |
| 91 } | 88 } |
| 92 | 89 |
| 93 // TODO(floitsch): deal with utf8. | 90 // TODO(floitsch): deal with utf8. |
| 94 class _LineSplitterSink extends StringConversionSinkBase { | 91 class _LineSplitterSink extends StringConversionSinkBase { |
| 95 final StringConversionSink _sink; | 92 final StringConversionSink _sink; |
| 96 | 93 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 final EventSink<String> _eventSink; | 168 final EventSink<String> _eventSink; |
| 172 | 169 |
| 173 _LineSplitterEventSink(EventSink<String> eventSink) | 170 _LineSplitterEventSink(EventSink<String> eventSink) |
| 174 : _eventSink = eventSink, | 171 : _eventSink = eventSink, |
| 175 super(new StringConversionSink.from(eventSink)); | 172 super(new StringConversionSink.from(eventSink)); |
| 176 | 173 |
| 177 void addError(Object o, [StackTrace stackTrace]) { | 174 void addError(Object o, [StackTrace stackTrace]) { |
| 178 _eventSink.addError(o, stackTrace); | 175 _eventSink.addError(o, stackTrace); |
| 179 } | 176 } |
| 180 } | 177 } |
| OLD | NEW |