canDecode static method
Whether encoding
can decode the bytedata
Implementation
static bool canDecode(Encoding? encoding, List<int> char) {
if (encoding == null) return false;
try {
String result = encoding.decode(char);
if (encoding is CodePage) {
if (result.contains('\uFFFD')) {
return false;
}
} else if (!encoding.name.contains('utf')) {
// TODO(shirne): A better way to judge a invalid character
if (result.contains('\uFFFD')) {
return false;
}
}
} on FormatException catch (_) {
return false;
} on ArgumentError catch (_) {
return false;
}
return true;
}