Make custom Utf8Decoder replacement not extend platform class. (#123211)
* Make custom `Utf8Decoder` replacement not extend platform class. The Dart 3.0 class modifiers will make `Utf8Decoder`, and other pure implementation classes, be `final`. This replacement class does not need to extend the original class, just like the `Utf8Codec` in the same file doesn't extend the `Ut8Codec` from the platform libraries. Instead it can just forward to a single `const` instance of the original class. * Forgot one constant * Fix merge conflict. --------- Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
d81e915780
commit
520cf363b3
@@ -44,15 +44,18 @@ class Utf8Codec extends Encoding {
|
||||
|
||||
const Encoding utf8 = Utf8Codec();
|
||||
|
||||
class Utf8Decoder extends cnv.Utf8Decoder {
|
||||
const Utf8Decoder({this.reportErrors = true}) : super(allowMalformed: true);
|
||||
class Utf8Decoder extends Converter<List<int>, String> {
|
||||
const Utf8Decoder({this.reportErrors = true});
|
||||
|
||||
static const cnv.Utf8Decoder _systemDecoder =
|
||||
cnv.Utf8Decoder(allowMalformed: true);
|
||||
|
||||
final bool reportErrors;
|
||||
|
||||
@override
|
||||
String convert(List<int> codeUnits, [ int start = 0, int? end ]) {
|
||||
final String result = super.convert(codeUnits, start, end);
|
||||
// Finding a unicode replacement character indicates that the input
|
||||
String convert(List<int> input, [int start = 0, int? end]) {
|
||||
final String result = _systemDecoder.convert(input, start, end);
|
||||
// Finding a Unicode replacement character indicates that the input
|
||||
// was malformed.
|
||||
if (reportErrors && result.contains('\u{FFFD}')) {
|
||||
throwToolExit(
|
||||
@@ -60,8 +63,19 @@ class Utf8Decoder extends cnv.Utf8Decoder {
|
||||
'The Flutter team would greatly appreciate if you could file a bug explaining '
|
||||
'exactly what you were doing when this happened:\n'
|
||||
'https://github.com/flutter/flutter/issues/new/choose\n'
|
||||
'The source bytes were:\n$codeUnits\n\n');
|
||||
'The source bytes were:\n$input\n\n');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
ByteConversionSink startChunkedConversion(Sink<String> sink) =>
|
||||
_systemDecoder.startChunkedConversion(sink);
|
||||
|
||||
@override
|
||||
Stream<String> bind(Stream<List<int>> stream) => _systemDecoder.bind(stream);
|
||||
|
||||
@override
|
||||
Converter<List<int>, T> fuse<T>(Converter<String, T> other) =>
|
||||
_systemDecoder.fuse(other);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user