From 520cf363b3559353c48fc502336f03bfa5ab1b8e Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Wed, 22 Mar 2023 15:53:56 +0100 Subject: [PATCH] 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 --- packages/flutter_tools/lib/src/convert.dart | 26 ++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/convert.dart b/packages/flutter_tools/lib/src/convert.dart index 836f5820e9..a17b910831 100644 --- a/packages/flutter_tools/lib/src/convert.dart +++ b/packages/flutter_tools/lib/src/convert.dart @@ -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, String> { + const Utf8Decoder({this.reportErrors = true}); + + static const cnv.Utf8Decoder _systemDecoder = + cnv.Utf8Decoder(allowMalformed: true); final bool reportErrors; @override - String convert(List 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 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 sink) => + _systemDecoder.startChunkedConversion(sink); + + @override + Stream bind(Stream> stream) => _systemDecoder.bind(stream); + + @override + Converter, T> fuse(Converter other) => + _systemDecoder.fuse(other); }