| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 yield lines.substring(sliceStart, i); | 44 yield lines.substring(sliceStart, i); |
| 45 sliceStart = i + 1; | 45 sliceStart = i + 1; |
| 46 } | 46 } |
| 47 if (sliceStart < end) { | 47 if (sliceStart < end) { |
| 48 yield lines.substring(sliceStart, end); | 48 yield lines.substring(sliceStart, end); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 List<String> convert(String data) => split(data).toList(); | 52 List<String> convert(String data) { |
| 53 List<String> lines = <String>[]; |
| 54 int end = data.length; |
| 55 int sliceStart = 0; |
| 56 int char = 0; |
| 57 for (int i = 0; i < end; i++) { |
| 58 int previousChar = char; |
| 59 char = data.codeUnitAt(i); |
| 60 if (char != _CR) { |
| 61 if (char != _LF) continue; |
| 62 if (previousChar == _CR) { |
| 63 sliceStart = i + 1; |
| 64 continue; |
| 65 } |
| 66 } |
| 67 lines.add(data.substring(sliceStart, i)); |
| 68 sliceStart = i + 1; |
| 69 } |
| 70 if (sliceStart < end) { |
| 71 lines.add(data.substring(sliceStart, end)); |
| 72 } |
| 73 return lines; |
| 74 } |
| 53 | 75 |
| 54 StringConversionSink startChunkedConversion(Sink<String> sink) { | 76 StringConversionSink startChunkedConversion(Sink<String> sink) { |
| 55 if (sink is! StringConversionSink) { | 77 if (sink is! StringConversionSink) { |
| 56 sink = new StringConversionSink.from(sink); | 78 sink = new StringConversionSink.from(sink); |
| 57 } | 79 } |
| 58 return new _LineSplitterSink(sink); | 80 return new _LineSplitterSink(sink); |
| 59 } | 81 } |
| 60 | 82 |
| 61 // Override the base-class' bind, to provide a better type. | 83 // Override the base-class' bind, to provide a better type. |
| 62 Stream<String> bind(Stream<String> stream) => super.bind(stream); | 84 Stream<String> bind(Stream<String> stream) => super.bind(stream); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 _sink.add(lines.substring(sliceStart, i)); | 152 _sink.add(lines.substring(sliceStart, i)); |
| 131 sliceStart = i + 1; | 153 sliceStart = i + 1; |
| 132 } | 154 } |
| 133 if (sliceStart < end) { | 155 if (sliceStart < end) { |
| 134 _carry = lines.substring(sliceStart, end); | 156 _carry = lines.substring(sliceStart, end); |
| 135 } else { | 157 } else { |
| 136 _skipLeadingLF = (char == _CR); | 158 _skipLeadingLF = (char == _CR); |
| 137 } | 159 } |
| 138 } | 160 } |
| 139 } | 161 } |
| OLD | NEW |