Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: test/dart_codegen/expect/convert/line_splitter.dart

Issue 1148283010: Remove dart backend (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 part of dart.convert;
2 class LineSplitter extends Converter<String, List<String>> {const LineSplitter( );
3 List<String> convert(String data) {
4 var lines = new List<String>();
5 _LineSplitterSink._addSlice(data, 0, data.length, true, lines.add);
6 return lines;
7 }
8 StringConversionSink startChunkedConversion(Sink<dynamic> sink) {
9 if (sink is! StringConversionSink) {
10 sink = new StringConversionSink.from(DEVC$RT.cast(sink, DEVC$RT.type((Sink<d ynamic> _) {
11 }
12 ), DEVC$RT.type((Sink<String> _) {
13 }
14 ), "CompositeCast", """line 24, column 44 of dart:convert/line_splitter.dart : """, sink is Sink<String>, false));
15 }
16 return new _LineSplitterSink(DEVC$RT.cast(sink, DEVC$RT.type((Sink<dynamic> _ ) {
17 }
18 ), StringConversionSink, "ImplicitCast", """line 26, column 34 of dart:convert /line_splitter.dart: """, sink is StringConversionSink, true));
19 }
20 }
21 class _LineSplitterSink extends StringConversionSinkBase {static const int _LF = 10;
22 static const int _CR = 13;
23 final StringConversionSink _sink;
24 String _carry;
25 _LineSplitterSink(this._sink);
26 void addSlice(String chunk, int start, int end, bool isLast) {
27 if (_carry != null) {
28 chunk = _carry + chunk.substring(start, end);
29 start = 0;
30 end = chunk.length;
31 _carry = null;
32 }
33 _carry = _addSlice(chunk, start, end, isLast, _sink.add);
34 if (isLast) _sink.close();
35 }
36 void close() {
37 addSlice('', 0, 0, true);
38 }
39 static String _addSlice(String chunk, int start, int end, bool isLast, void add er(String val)) {
40 int pos = start;
41 while (pos < end) {
42 int skip = 0;
43 int char = chunk.codeUnitAt(pos);
44 if (char == _LF) {
45 skip = 1;
46 }
47 else if (char == _CR) {
48 skip = 1;
49 if (pos + 1 < end) {
50 if (chunk.codeUnitAt(pos + 1) == _LF) {
51 skip = 2;
52 }
53 }
54 else if (!isLast) {
55 return chunk.substring(start, end);
56 }
57 }
58 if (skip > 0) {
59 adder(chunk.substring(start, pos));
60 start = pos = pos + skip;
61 }
62 else {
63 pos++;
64 }
65 }
66 if (pos != start) {
67 var carry = chunk.substring(start, pos);
68 if (isLast) {
69 adder(carry);
70 }
71 else {
72 return carry;
73 }
74 }
75 return null;
76 }
77 }
OLDNEW
« no previous file with comments | « test/dart_codegen/expect/convert/latin1.dart ('k') | test/dart_codegen/expect/convert/string_conversion.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698