Unverified Commit 520cf363 authored by Lasse R.H. Nielsen's avatar Lasse R.H. Nielsen Committed by GitHub

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: 's avatarZachary Anderson <zanderso@users.noreply.github.com>
parent d81e9157
...@@ -44,15 +44,18 @@ class Utf8Codec extends Encoding { ...@@ -44,15 +44,18 @@ class Utf8Codec extends Encoding {
const Encoding utf8 = Utf8Codec(); const Encoding utf8 = Utf8Codec();
class Utf8Decoder extends cnv.Utf8Decoder { class Utf8Decoder extends Converter<List<int>, String> {
const Utf8Decoder({this.reportErrors = true}) : super(allowMalformed: true); const Utf8Decoder({this.reportErrors = true});
static const cnv.Utf8Decoder _systemDecoder =
cnv.Utf8Decoder(allowMalformed: true);
final bool reportErrors; final bool reportErrors;
@override @override
String convert(List<int> codeUnits, [ int start = 0, int? end ]) { String convert(List<int> input, [int start = 0, int? end]) {
final String result = super.convert(codeUnits, start, end); final String result = _systemDecoder.convert(input, start, end);
// Finding a unicode replacement character indicates that the input // Finding a Unicode replacement character indicates that the input
// was malformed. // was malformed.
if (reportErrors && result.contains('\u{FFFD}')) { if (reportErrors && result.contains('\u{FFFD}')) {
throwToolExit( throwToolExit(
...@@ -60,8 +63,19 @@ class Utf8Decoder extends cnv.Utf8Decoder { ...@@ -60,8 +63,19 @@ class Utf8Decoder extends cnv.Utf8Decoder {
'The Flutter team would greatly appreciate if you could file a bug explaining ' 'The Flutter team would greatly appreciate if you could file a bug explaining '
'exactly what you were doing when this happened:\n' 'exactly what you were doing when this happened:\n'
'https://github.com/flutter/flutter/issues/new/choose\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; 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);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment