| OLD | NEW |
| 1 part of dart.convert; | 1 part of dart.convert; |
| 2 | 2 const Latin1Codec LATIN1 = const Latin1Codec(); |
| 3 const Latin1Codec LATIN1 = const Latin1Codec(); | 3 const int _LATIN1_MASK = 0xFF; |
| 4 const int _LATIN1_MASK = 0xFF; | 4 class Latin1Codec extends Encoding {final bool _allowInvalid; |
| 5 class Latin1Codec extends Encoding { | 5 const Latin1Codec({ |
| 6 final bool _allowInvalid; | 6 bool allowInvalid : false} |
| 7 const Latin1Codec({bool allowInvalid: false}) : _allowInvalid = allowInvalid; | 7 ) : _allowInvalid = allowInvalid; |
| 8 String get name => "iso-8859-1"; | 8 String get name => "iso-8859-1"; |
| 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 Latin1Decoder(allowInvalid: true).convert(bytes); | 12 if (allowInvalid == null) allowInvalid = _allowInvalid; |
| 13 } else { | 13 if (allowInvalid) { |
| 14 return const Latin1Decoder(allowInvalid: false).convert(bytes); | 14 return const Latin1Decoder(allowInvalid: true).convert(bytes); |
| 15 } |
| 16 else { |
| 17 return const Latin1Decoder(allowInvalid: false).convert(bytes); |
| 15 } | 18 } |
| 16 } | 19 } |
| 17 Converter<String, List<int>> get encoder => const Latin1Encoder(); | 20 Converter<String, List<int>> get encoder => const Latin1Encoder(); |
| 18 Converter<List<int>, String> get decoder => _allowInvalid | 21 Converter<List<int>, String> get decoder => _allowInvalid ? const Latin1Decoder
(allowInvalid: true) : const Latin1Decoder(allowInvalid: false); |
| 19 ? const Latin1Decoder(allowInvalid: true) | |
| 20 : const Latin1Decoder(allowInvalid: false); | |
| 21 } | 22 } |
| 22 class Latin1Encoder extends _UnicodeSubsetEncoder { | 23 class Latin1Encoder extends _UnicodeSubsetEncoder {const Latin1Encoder() : supe
r(_LATIN1_MASK); |
| 23 const Latin1Encoder() : super(_LATIN1_MASK); | |
| 24 } | 24 } |
| 25 class Latin1Decoder extends _UnicodeSubsetDecoder { | 25 class Latin1Decoder extends _UnicodeSubsetDecoder {const Latin1Decoder({ |
| 26 const Latin1Decoder({bool allowInvalid: false}) | 26 bool allowInvalid : false} |
| 27 : super(allowInvalid, _LATIN1_MASK); | 27 ) : super(allowInvalid, _LATIN1_MASK); |
| 28 ByteConversionSink startChunkedConversion(Sink<String> sink) { | 28 ByteConversionSink startChunkedConversion(Sink<String> sink) { |
| 29 StringConversionSink stringSink; | 29 StringConversionSink stringSink; |
| 30 if (sink is StringConversionSink) { | 30 if (sink is StringConversionSink) { |
| 31 stringSink = sink; | 31 stringSink = sink; |
| 32 } else { | |
| 33 stringSink = new StringConversionSink.from(sink); | |
| 34 } | |
| 35 if (!_allowInvalid) return new _Latin1DecoderSink(stringSink); | |
| 36 return new _Latin1AllowInvalidDecoderSink(stringSink); | |
| 37 } | |
| 38 } | 32 } |
| 39 class _Latin1DecoderSink extends ByteConversionSinkBase { | 33 else { |
| 40 StringConversionSink _sink; | 34 stringSink = new StringConversionSink.from(sink); |
| 41 _Latin1DecoderSink(this._sink); | |
| 42 void close() { | |
| 43 _sink.close(); | |
| 44 } | |
| 45 void add(List<int> source) { | |
| 46 addSlice(source, 0, source.length, false); | |
| 47 } | |
| 48 void _addSliceToSink(List<int> source, int start, int end, bool isLast) { | |
| 49 _sink.add(new String.fromCharCodes(source, start, end)); | |
| 50 if (isLast) close(); | |
| 51 } | |
| 52 void addSlice(List<int> source, int start, int end, bool isLast) { | |
| 53 RangeError.checkValidRange(start, end, source.length); | |
| 54 for (int i = start; i < end; i++) { | |
| 55 int char = source[i]; | |
| 56 if (char > _LATIN1_MASK || char < 0) { | |
| 57 throw new FormatException("Source contains non-Latin-1 characters."); | |
| 58 } | |
| 59 } | |
| 60 if (start < end) { | |
| 61 _addSliceToSink(source, start, end, isLast); | |
| 62 } | |
| 63 if (isLast) { | |
| 64 close(); | |
| 65 } | |
| 66 } | |
| 67 } | 35 } |
| 68 class _Latin1AllowInvalidDecoderSink extends _Latin1DecoderSink { | 36 if (!_allowInvalid) return new _Latin1DecoderSink(stringSink); |
| 69 _Latin1AllowInvalidDecoderSink(StringConversionSink sink) : super(sink); | 37 return new _Latin1AllowInvalidDecoderSink(stringSink); |
| 70 void addSlice(List<int> source, int start, int end, bool isLast) { | |
| 71 RangeError.checkValidRange(start, end, source.length); | |
| 72 for (int i = start; i < end; i++) { | |
| 73 int char = source[i]; | |
| 74 if (char > _LATIN1_MASK || char < 0) { | |
| 75 if (i > start) _addSliceToSink(source, start, i, false); | |
| 76 _addSliceToSink(((__x26) => DDC$RT.cast(__x26, | |
| 77 DDC$RT.type((List<dynamic> _) {}), DDC$RT.type((List<int> _) {}), | |
| 78 "CastLiteral", | |
| 79 """line 161, column 25 of dart:convert/latin1.dart: """, | |
| 80 __x26 is List<int>, false))(const [0xFFFD]), 0, 1, false); | |
| 81 start = i + 1; | |
| 82 } | |
| 83 } | |
| 84 if (start < end) { | |
| 85 _addSliceToSink(source, start, end, isLast); | |
| 86 } | |
| 87 if (isLast) { | |
| 88 close(); | |
| 89 } | |
| 90 } | |
| 91 } | 38 } |
| 39 } |
| 40 class _Latin1DecoderSink extends ByteConversionSinkBase {StringConversionSink _
sink; |
| 41 _Latin1DecoderSink(this._sink); |
| 42 void close() { |
| 43 _sink.close(); |
| 44 } |
| 45 void add(List<int> source) { |
| 46 addSlice(source, 0, source.length, false); |
| 47 } |
| 48 void _addSliceToSink(List<int> source, int start, int end, bool isLast) { |
| 49 _sink.add(new String.fromCharCodes(source, start, end)); |
| 50 if (isLast) close(); |
| 51 } |
| 52 void addSlice(List<int> source, int start, int end, bool isLast) { |
| 53 RangeError.checkValidRange(start, end, source.length); |
| 54 for (int i = start; |
| 55 i < end; |
| 56 i++) { |
| 57 int char = source[i]; |
| 58 if (char > _LATIN1_MASK || char < 0) { |
| 59 throw new FormatException("Source contains non-Latin-1 characters."); |
| 60 } |
| 61 } |
| 62 if (start < end) { |
| 63 _addSliceToSink(source, start, end, isLast); |
| 64 } |
| 65 if (isLast) { |
| 66 close(); |
| 67 } |
| 68 } |
| 69 } |
| 70 class _Latin1AllowInvalidDecoderSink extends _Latin1DecoderSink {_Latin1AllowIn
validDecoderSink(StringConversionSink sink) : super(sink); |
| 71 void addSlice(List<int> source, int start, int end, bool isLast) { |
| 72 RangeError.checkValidRange(start, end, source.length); |
| 73 for (int i = start; |
| 74 i < end; |
| 75 i++) { |
| 76 int char = source[i]; |
| 77 if (char > _LATIN1_MASK || char < 0) { |
| 78 if (i > start) _addSliceToSink(source, start, i, false); |
| 79 _addSliceToSink(((__x26) => DDC$RT.cast(__x26, DDC$RT.type((List<dynamic> _) { |
| 80 } |
| 81 ), DDC$RT.type((List<int> _) { |
| 82 } |
| 83 ), "CastLiteral", """line 161, column 25 of dart:convert/latin1.dart: """, __x26
is List<int>, false))(const [0xFFFD]), 0, 1, false); |
| 84 start = i + 1; |
| 85 } |
| 86 } |
| 87 if (start < end) { |
| 88 _addSliceToSink(source, start, end, isLast); |
| 89 } |
| 90 if (isLast) { |
| 91 close(); |
| 92 } |
| 93 } |
| 94 } |
| OLD | NEW |