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

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

Issue 959073002: Fix new line breaks on } (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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 const AsciiCodec ASCII = const AsciiCodec(); 2 const AsciiCodec ASCII = const AsciiCodec();
3 const int _ASCII_MASK = 0x7F; 3 const int _ASCII_MASK = 0x7F;
4 class AsciiCodec extends Encoding {final bool _allowInvalid; 4 class AsciiCodec extends Encoding {final bool _allowInvalid;
5 const AsciiCodec({ 5 const AsciiCodec({
6 bool allowInvalid : false} 6 bool allowInvalid : false}
7 ) : _allowInvalid = allowInvalid; 7 ) : _allowInvalid = allowInvalid;
8 String get name => "us-ascii"; 8 String get name => "us-ascii";
9 String decode(List<int> bytes, { 9 String decode(List<int> bytes, {
10 bool allowInvalid} 10 bool allowInvalid}
(...skipping 10 matching lines...) Expand all
21 AsciiDecoder get decoder => _allowInvalid ? const AsciiDecoder(allowInvalid: tr ue) : const AsciiDecoder(allowInvalid: false); 21 AsciiDecoder get decoder => _allowInvalid ? const AsciiDecoder(allowInvalid: tr ue) : const AsciiDecoder(allowInvalid: false);
22 } 22 }
23 class _UnicodeSubsetEncoder extends Converter<String, List<int>> {final int _su bsetMask; 23 class _UnicodeSubsetEncoder extends Converter<String, List<int>> {final int _su bsetMask;
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;
33 i++) {
34 var codeUnit = string.codeUnitAt(start + i); 32 var codeUnit = string.codeUnitAt(start + i);
35 if ((codeUnit & ~_subsetMask) != 0) { 33 if ((codeUnit & ~_subsetMask) != 0) {
36 throw new ArgumentError("String contains invalid characters."); 34 throw new ArgumentError("String contains invalid characters.");
37 } 35 }
38 result[i] = codeUnit; 36 result[i] = codeUnit;
39 } 37 }
40 return DDC$RT.cast(result, DDC$RT.type((List<dynamic> _) { 38 return DDC$RT.cast(result, DDC$RT.type((List<dynamic> _) {
41 } 39 }
42 ), DDC$RT.type((List<int> _) { 40 ), DDC$RT.type((List<int> _) {
43 } 41 }
(...skipping 14 matching lines...) Expand all
58 class AsciiEncoder extends _UnicodeSubsetEncoder {const AsciiEncoder() : super( _ASCII_MASK); 56 class AsciiEncoder extends _UnicodeSubsetEncoder {const AsciiEncoder() : super( _ASCII_MASK);
59 } 57 }
60 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase {final ByteCon versionSink _sink; 58 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase {final ByteCon versionSink _sink;
61 final int _subsetMask; 59 final int _subsetMask;
62 _UnicodeSubsetEncoderSink(this._subsetMask, this._sink); 60 _UnicodeSubsetEncoderSink(this._subsetMask, this._sink);
63 void close() { 61 void close() {
64 _sink.close(); 62 _sink.close();
65 } 63 }
66 void addSlice(String source, int start, int end, bool isLast) { 64 void addSlice(String source, int start, int end, bool isLast) {
67 RangeError.checkValidRange(start, end, source.length); 65 RangeError.checkValidRange(start, end, source.length);
68 for (int i = start; 66 for (int i = start; i < end; i++) {
69 i < end;
70 i++) {
71 int codeUnit = source.codeUnitAt(i); 67 int codeUnit = source.codeUnitAt(i);
72 if ((codeUnit & ~_subsetMask) != 0) { 68 if ((codeUnit & ~_subsetMask) != 0) {
73 throw new ArgumentError("Source contains invalid character with code point: $cod eUnit."); 69 throw new ArgumentError("Source contains invalid character with code point: $cod eUnit.");
74 } 70 }
75 } 71 }
76 _sink.add(source.codeUnits.sublist(start, end)); 72 _sink.add(source.codeUnits.sublist(start, end));
77 if (isLast) { 73 if (isLast) {
78 close(); 74 close();
79 } 75 }
80 } 76 }
81 } 77 }
82 abstract class _UnicodeSubsetDecoder extends Converter<List<int>, String> {fina l bool _allowInvalid; 78 abstract class _UnicodeSubsetDecoder extends Converter<List<int>, String> {fina l bool _allowInvalid;
83 final int _subsetMask; 79 final int _subsetMask;
84 const _UnicodeSubsetDecoder(this._allowInvalid, this._subsetMask); 80 const _UnicodeSubsetDecoder(this._allowInvalid, this._subsetMask);
85 String convert(List<int> bytes, [int start = 0, int end]) { 81 String convert(List<int> bytes, [int start = 0, int end]) {
86 int byteCount = bytes.length; 82 int byteCount = bytes.length;
87 RangeError.checkValidRange(start, end, byteCount); 83 RangeError.checkValidRange(start, end, byteCount);
88 if (end == null) end = byteCount; 84 if (end == null) end = byteCount;
89 int length = end - start; 85 int length = end - start;
90 for (int i = start; 86 for (int i = start; i < end; i++) {
91 i < end;
92 i++) {
93 int byte = bytes[i]; 87 int byte = bytes[i];
94 if ((byte & ~_subsetMask) != 0) { 88 if ((byte & ~_subsetMask) != 0) {
95 if (!_allowInvalid) { 89 if (!_allowInvalid) {
96 throw new FormatException("Invalid value in input: $byte"); 90 throw new FormatException("Invalid value in input: $byte");
97 } 91 }
98 return _convertInvalid(bytes, start, end); 92 return _convertInvalid(bytes, start, end);
99 } 93 }
100 } 94 }
101 return new String.fromCharCodes(bytes, start, end); 95 return new String.fromCharCodes(bytes, start, end);
102 } 96 }
103 String _convertInvalid(List<int> bytes, int start, int end) { 97 String _convertInvalid(List<int> bytes, int start, int end) {
104 StringBuffer buffer = new StringBuffer(); 98 StringBuffer buffer = new StringBuffer();
105 for (int i = start; 99 for (int i = start; i < end; i++) {
106 i < end;
107 i++) {
108 int value = bytes[i]; 100 int value = bytes[i];
109 if ((value & ~_subsetMask) != 0) value = 0xFFFD; 101 if ((value & ~_subsetMask) != 0) value = 0xFFFD;
110 buffer.writeCharCode(value); 102 buffer.writeCharCode(value);
111 } 103 }
112 return buffer.toString(); 104 return buffer.toString();
113 } 105 }
114 ByteConversionSink startChunkedConversion(Sink<String> sink); 106 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> _) { 107 Stream<String> bind(Stream<List<int>> stream) => ((__x1) => DDC$RT.cast(__x1, D DC$RT.type((DDC$async$.Stream<dynamic> _) {
116 } 108 }
117 ), DDC$RT.type((DDC$async$.Stream<String> _) { 109 ), DDC$RT.type((DDC$async$.Stream<String> _) {
(...skipping 22 matching lines...) Expand all
140 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase {ByteConver sionSink _utf8Sink; 132 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase {ByteConver sionSink _utf8Sink;
141 _ErrorHandlingAsciiDecoderSink(this._utf8Sink); 133 _ErrorHandlingAsciiDecoderSink(this._utf8Sink);
142 void close() { 134 void close() {
143 _utf8Sink.close(); 135 _utf8Sink.close();
144 } 136 }
145 void add(List<int> source) { 137 void add(List<int> source) {
146 addSlice(source, 0, source.length, false); 138 addSlice(source, 0, source.length, false);
147 } 139 }
148 void addSlice(List<int> source, int start, int end, bool isLast) { 140 void addSlice(List<int> source, int start, int end, bool isLast) {
149 RangeError.checkValidRange(start, end, source.length); 141 RangeError.checkValidRange(start, end, source.length);
150 for (int i = start; 142 for (int i = start; i < end; i++) {
151 i < end;
152 i++) {
153 if ((source[i] & ~_ASCII_MASK) != 0) { 143 if ((source[i] & ~_ASCII_MASK) != 0) {
154 if (i > start) _utf8Sink.addSlice(source, start, i, false); 144 if (i > start) _utf8Sink.addSlice(source, start, i, false);
155 _utf8Sink.add(const <int> [0xEF, 0xBF, 0xBD]); 145 _utf8Sink.add(const <int> [0xEF, 0xBF, 0xBD]);
156 start = i + 1; 146 start = i + 1;
157 } 147 }
158 } 148 }
159 if (start < end) { 149 if (start < end) {
160 _utf8Sink.addSlice(source, start, end, isLast); 150 _utf8Sink.addSlice(source, start, end, isLast);
161 } 151 }
162 else if (isLast) { 152 else if (isLast) {
163 close(); 153 close();
164 } 154 }
165 } 155 }
166 } 156 }
167 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase {Sink _sink; 157 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase {Sink _sink;
168 _SimpleAsciiDecoderSink(this._sink); 158 _SimpleAsciiDecoderSink(this._sink);
169 void close() { 159 void close() {
170 _sink.close(); 160 _sink.close();
171 } 161 }
172 void add(List<int> source) { 162 void add(List<int> source) {
173 for (int i = 0; 163 for (int i = 0; i < source.length; i++) {
174 i < source.length;
175 i++) {
176 if ((source[i] & ~_ASCII_MASK) != 0) { 164 if ((source[i] & ~_ASCII_MASK) != 0) {
177 throw new FormatException("Source contains non-ASCII bytes."); 165 throw new FormatException("Source contains non-ASCII bytes.");
178 } 166 }
179 } 167 }
180 _sink.add(new String.fromCharCodes(source)); 168 _sink.add(new String.fromCharCodes(source));
181 } 169 }
182 void addSlice(List<int> source, int start, int end, bool isLast) { 170 void addSlice(List<int> source, int start, int end, bool isLast) {
183 final int length = source.length; 171 final int length = source.length;
184 RangeError.checkValidRange(start, end, length); 172 RangeError.checkValidRange(start, end, length);
185 if (start < end) { 173 if (start < end) {
186 if (start != 0 || end != length) { 174 if (start != 0 || end != length) {
187 source = source.sublist(start, end); 175 source = source.sublist(start, end);
188 } 176 }
189 add(source); 177 add(source);
190 } 178 }
191 if (isLast) close(); 179 if (isLast) close();
192 } 180 }
193 } 181 }
OLDNEW
« no previous file with comments | « test/dart_codegen/expect/collection/set.dart ('k') | test/dart_codegen/expect/convert/html_escape.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698