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

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

Issue 963593002: Disable formatting and add new-lines to make tests faster. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 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
1 part of dart.convert; 1 part of dart.convert;
2 2 const AsciiCodec ASCII = const AsciiCodec();
3 const AsciiCodec ASCII = const AsciiCodec(); 3 const int _ASCII_MASK = 0x7F;
4 const int _ASCII_MASK = 0x7F; 4 class AsciiCodec extends Encoding {final bool _allowInvalid;
5 class AsciiCodec extends Encoding { 5 const AsciiCodec({
6 final bool _allowInvalid; 6 bool allowInvalid : false}
7 const AsciiCodec({bool allowInvalid: false}) : _allowInvalid = allowInvalid; 7 ) : _allowInvalid = allowInvalid;
8 String get name => "us-ascii"; 8 String get name => "us-ascii";
9 String decode(List<int> bytes, {bool allowInvalid}) { 9 String decode(List<int> bytes, {
10 if (allowInvalid == null) allowInvalid = _allowInvalid; 10 bool allowInvalid}
11 if (allowInvalid) { 11 ) {
12 return const AsciiDecoder(allowInvalid: true).convert(bytes); 12 if (allowInvalid == null) allowInvalid = _allowInvalid;
13 } else { 13 if (allowInvalid) {
14 return const AsciiDecoder(allowInvalid: false).convert(bytes); 14 return const AsciiDecoder(allowInvalid: true).convert(bytes);
15 }
16 else {
17 return const AsciiDecoder(allowInvalid: false).convert(bytes);
15 } 18 }
16 } 19 }
17 AsciiEncoder get encoder => const AsciiEncoder(); 20 AsciiEncoder get encoder => const AsciiEncoder();
18 AsciiDecoder get decoder => _allowInvalid 21 AsciiDecoder get decoder => _allowInvalid ? const AsciiDecoder(allowInvalid: tr ue) : const AsciiDecoder(allowInvalid: false);
19 ? const AsciiDecoder(allowInvalid: true)
20 : const AsciiDecoder(allowInvalid: false);
21 } 22 }
22 class _UnicodeSubsetEncoder extends Converter<String, List<int>> { 23 class _UnicodeSubsetEncoder extends Converter<String, List<int>> {final int _su bsetMask;
23 final int _subsetMask; 24 const _UnicodeSubsetEncoder(this._subsetMask);
24 const _UnicodeSubsetEncoder(this._subsetMask); 25 List<int> convert(String string, [int start = 0, int end]) {
25 List<int> convert(String string, [int start = 0, int end]) { 26 int stringLength = string.length;
26 int stringLength = string.length; 27 RangeError.checkValidRange(start, end, stringLength);
27 RangeError.checkValidRange(start, end, stringLength); 28 if (end == null) end = stringLength;
28 if (end == null) end = stringLength; 29 int length = end - start;
29 int length = end - start; 30 List result = new Uint8List(length);
30 List result = new Uint8List(length); 31 for (int i = 0;
31 for (int i = 0; i < length; i++) { 32 i < length;
32 var codeUnit = string.codeUnitAt(start + i); 33 i++) {
33 if ((codeUnit & ~_subsetMask) != 0) { 34 var codeUnit = string.codeUnitAt(start + i);
34 throw new ArgumentError("String contains invalid characters."); 35 if ((codeUnit & ~_subsetMask) != 0) {
35 } 36 throw new ArgumentError("String contains invalid characters.");
36 result[i] = codeUnit;
37 } 37 }
38 return DDC$RT.cast(result, DDC$RT.type((List<dynamic> _) {}), 38 result[i] = codeUnit;
39 DDC$RT.type((List<int> _) {}), "CastDynamic",
40 """line 96, column 12 of dart:convert/ascii.dart: """,
41 result is List<int>, false);
42 } 39 }
43 StringConversionSink startChunkedConversion(Sink<List<int>> sink) { 40 return DDC$RT.cast(result, DDC$RT.type((List<dynamic> _) {
44 if (sink is! ByteConversionSink) {
45 sink = new ByteConversionSink.from(sink);
46 }
47 return new _UnicodeSubsetEncoderSink(_subsetMask, sink);
48 } 41 }
49 Stream<List<int>> bind(Stream<String> stream) => ((__x0) => DDC$RT.cast(__x0, 42 ), DDC$RT.type((List<int> _) {
50 DDC$RT.type((DDC$async$.Stream<dynamic> _) {}), 43 }
51 DDC$RT.type((DDC$async$.Stream<List<int>> _) {}), "CastDynamic", 44 ), "CastDynamic", """line 96, column 12 of dart:convert/ascii.dart: """, result is List<int>, false);
52 """line 113, column 52 of dart:convert/ascii.dart: """,
53 __x0 is DDC$async$.Stream<List<int>>, false))(super.bind(stream));
54 } 45 }
55 class AsciiEncoder extends _UnicodeSubsetEncoder { 46 StringConversionSink startChunkedConversion(Sink<List<int>> sink) {
56 const AsciiEncoder() : super(_ASCII_MASK); 47 if (sink is! ByteConversionSink) {
48 sink = new ByteConversionSink.from(sink);
49 }
50 return new _UnicodeSubsetEncoderSink(_subsetMask, sink);
57 } 51 }
58 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase { 52 Stream<List<int>> bind(Stream<String> stream) => ((__x0) => DDC$RT.cast(__x0, D DC$RT.type((DDC$async$.Stream<dynamic> _) {
59 final ByteConversionSink _sink;
60 final int _subsetMask;
61 _UnicodeSubsetEncoderSink(this._subsetMask, this._sink);
62 void close() {
63 _sink.close();
64 }
65 void addSlice(String source, int start, int end, bool isLast) {
66 RangeError.checkValidRange(start, end, source.length);
67 for (int i = start; i < end; i++) {
68 int codeUnit = source.codeUnitAt(i);
69 if ((codeUnit & ~_subsetMask) != 0) {
70 throw new ArgumentError(
71 "Source contains invalid character with code point: $codeUnit.");
72 }
73 }
74 _sink.add(source.codeUnits.sublist(start, end));
75 if (isLast) {
76 close();
77 }
78 }
79 } 53 }
80 abstract class _UnicodeSubsetDecoder extends Converter<List<int>, String> { 54 ), DDC$RT.type((DDC$async$.Stream<List<int>> _) {
81 final bool _allowInvalid;
82 final int _subsetMask;
83 const _UnicodeSubsetDecoder(this._allowInvalid, this._subsetMask);
84 String convert(List<int> bytes, [int start = 0, int end]) {
85 int byteCount = bytes.length;
86 RangeError.checkValidRange(start, end, byteCount);
87 if (end == null) end = byteCount;
88 int length = end - start;
89 for (int i = start; i < end; i++) {
90 int byte = bytes[i];
91 if ((byte & ~_subsetMask) != 0) {
92 if (!_allowInvalid) {
93 throw new FormatException("Invalid value in input: $byte");
94 }
95 return _convertInvalid(bytes, start, end);
96 }
97 }
98 return new String.fromCharCodes(bytes, start, end);
99 }
100 String _convertInvalid(List<int> bytes, int start, int end) {
101 StringBuffer buffer = new StringBuffer();
102 for (int i = start; i < end; i++) {
103 int value = bytes[i];
104 if ((value & ~_subsetMask) != 0) value = 0xFFFD;
105 buffer.writeCharCode(value);
106 }
107 return buffer.toString();
108 }
109 ByteConversionSink startChunkedConversion(Sink<String> sink);
110 Stream<String> bind(Stream<List<int>> stream) => ((__x1) => DDC$RT.cast(__x1,
111 DDC$RT.type((DDC$async$.Stream<dynamic> _) {}),
112 DDC$RT.type((DDC$async$.Stream<String> _) {}), "CastDynamic",
113 """line 221, column 52 of dart:convert/ascii.dart: """,
114 __x1 is DDC$async$.Stream<String>, false))(super.bind(stream));
115 } 55 }
116 class AsciiDecoder extends _UnicodeSubsetDecoder { 56 ), "CastDynamic", """line 113, column 52 of dart:convert/ascii.dart: """, __x0 i s DDC$async$.Stream<List<int>>, false))(super.bind(stream));
117 const AsciiDecoder({bool allowInvalid: false})
118 : super(allowInvalid, _ASCII_MASK);
119 ByteConversionSink startChunkedConversion(Sink<String> sink) {
120 StringConversionSink stringSink;
121 if (sink is StringConversionSink) {
122 stringSink = sink;
123 } else {
124 stringSink = new StringConversionSink.from(sink);
125 }
126 if (_allowInvalid) {
127 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false));
128 } else {
129 return new _SimpleAsciiDecoderSink(stringSink);
130 }
131 }
132 } 57 }
133 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase { 58 class AsciiEncoder extends _UnicodeSubsetEncoder {const AsciiEncoder() : super( _ASCII_MASK);
134 ByteConversionSink _utf8Sink;
135 _ErrorHandlingAsciiDecoderSink(this._utf8Sink);
136 void close() {
137 _utf8Sink.close();
138 }
139 void add(List<int> source) {
140 addSlice(source, 0, source.length, false);
141 }
142 void addSlice(List<int> source, int start, int end, bool isLast) {
143 RangeError.checkValidRange(start, end, source.length);
144 for (int i = start; i < end; i++) {
145 if ((source[i] & ~_ASCII_MASK) != 0) {
146 if (i > start) _utf8Sink.addSlice(source, start, i, false);
147 _utf8Sink.add(const <int>[0xEF, 0xBF, 0xBD]);
148 start = i + 1;
149 }
150 }
151 if (start < end) {
152 _utf8Sink.addSlice(source, start, end, isLast);
153 } else if (isLast) {
154 close();
155 }
156 }
157 } 59 }
158 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase { 60 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase {final ByteCon versionSink _sink;
159 Sink _sink; 61 final int _subsetMask;
160 _SimpleAsciiDecoderSink(this._sink); 62 _UnicodeSubsetEncoderSink(this._subsetMask, this._sink);
161 void close() { 63 void close() {
162 _sink.close(); 64 _sink.close();
163 }
164 void add(List<int> source) {
165 for (int i = 0; i < source.length; i++) {
166 if ((source[i] & ~_ASCII_MASK) != 0) {
167 throw new FormatException("Source contains non-ASCII bytes.");
168 }
169 }
170 _sink.add(new String.fromCharCodes(source));
171 }
172 void addSlice(List<int> source, int start, int end, bool isLast) {
173 final int length = source.length;
174 RangeError.checkValidRange(start, end, length);
175 if (start < end) {
176 if (start != 0 || end != length) {
177 source = source.sublist(start, end);
178 }
179 add(source);
180 }
181 if (isLast) close();
182 }
183 } 65 }
66 void addSlice(String source, int start, int end, bool isLast) {
67 RangeError.checkValidRange(start, end, source.length);
68 for (int i = start;
69 i < end;
70 i++) {
71 int codeUnit = source.codeUnitAt(i);
72 if ((codeUnit & ~_subsetMask) != 0) {
73 throw new ArgumentError("Source contains invalid character with code point: $cod eUnit.");
74 }
75 }
76 _sink.add(source.codeUnits.sublist(start, end));
77 if (isLast) {
78 close();
79 }
80 }
81 }
82 abstract class _UnicodeSubsetDecoder extends Converter<List<int>, String> {fina l bool _allowInvalid;
83 final int _subsetMask;
84 const _UnicodeSubsetDecoder(this._allowInvalid, this._subsetMask);
85 String convert(List<int> bytes, [int start = 0, int end]) {
86 int byteCount = bytes.length;
87 RangeError.checkValidRange(start, end, byteCount);
88 if (end == null) end = byteCount;
89 int length = end - start;
90 for (int i = start;
91 i < end;
92 i++) {
93 int byte = bytes[i];
94 if ((byte & ~_subsetMask) != 0) {
95 if (!_allowInvalid) {
96 throw new FormatException("Invalid value in input: $byte");
97 }
98 return _convertInvalid(bytes, start, end);
99 }
100 }
101 return new String.fromCharCodes(bytes, start, end);
102 }
103 String _convertInvalid(List<int> bytes, int start, int end) {
104 StringBuffer buffer = new StringBuffer();
105 for (int i = start;
106 i < end;
107 i++) {
108 int value = bytes[i];
109 if ((value & ~_subsetMask) != 0) value = 0xFFFD;
110 buffer.writeCharCode(value);
111 }
112 return buffer.toString();
113 }
114 ByteConversionSink startChunkedConversion(Sink<String> sink);
115 Stream<String> bind(Stream<List<int>> stream) => ((__x1) => DDC$RT.cast(__x1, D DC$RT.type((DDC$async$.Stream<dynamic> _) {
116 }
117 ), DDC$RT.type((DDC$async$.Stream<String> _) {
118 }
119 ), "CastDynamic", """line 221, column 52 of dart:convert/ascii.dart: """, __x1 i s DDC$async$.Stream<String>, false))(super.bind(stream));
120 }
121 class AsciiDecoder extends _UnicodeSubsetDecoder {const AsciiDecoder({
122 bool allowInvalid : false}
123 ) : super(allowInvalid, _ASCII_MASK);
124 ByteConversionSink startChunkedConversion(Sink<String> sink) {
125 StringConversionSink stringSink;
126 if (sink is StringConversionSink) {
127 stringSink = sink;
128 }
129 else {
130 stringSink = new StringConversionSink.from(sink);
131 }
132 if (_allowInvalid) {
133 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false));
134 }
135 else {
136 return new _SimpleAsciiDecoderSink(stringSink);
137 }
138 }
139 }
140 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase {ByteConver sionSink _utf8Sink;
141 _ErrorHandlingAsciiDecoderSink(this._utf8Sink);
142 void close() {
143 _utf8Sink.close();
144 }
145 void add(List<int> source) {
146 addSlice(source, 0, source.length, false);
147 }
148 void addSlice(List<int> source, int start, int end, bool isLast) {
149 RangeError.checkValidRange(start, end, source.length);
150 for (int i = start;
151 i < end;
152 i++) {
153 if ((source[i] & ~_ASCII_MASK) != 0) {
154 if (i > start) _utf8Sink.addSlice(source, start, i, false);
155 _utf8Sink.add(const <int> [0xEF, 0xBF, 0xBD]);
156 start = i + 1;
157 }
158 }
159 if (start < end) {
160 _utf8Sink.addSlice(source, start, end, isLast);
161 }
162 else if (isLast) {
163 close();
164 }
165 }
166 }
167 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase {Sink _sink;
168 _SimpleAsciiDecoderSink(this._sink);
169 void close() {
170 _sink.close();
171 }
172 void add(List<int> source) {
173 for (int i = 0;
174 i < source.length;
175 i++) {
176 if ((source[i] & ~_ASCII_MASK) != 0) {
177 throw new FormatException("Source contains non-ASCII bytes.");
178 }
179 }
180 _sink.add(new String.fromCharCodes(source));
181 }
182 void addSlice(List<int> source, int start, int end, bool isLast) {
183 final int length = source.length;
184 RangeError.checkValidRange(start, end, length);
185 if (start < end) {
186 if (start != 0 || end != length) {
187 source = source.sublist(start, end);
188 }
189 add(source);
190 }
191 if (isLast) close();
192 }
193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698