canEncode static method
Whether encoding
can encode the string
Implementation
static bool canEncode(Encoding? encoding, String char) {
if (encoding == null) return false;
try {
List<int> result = encoding.encode(char);
if (encoding is CodePage) {
if (result.length != char.length) {
return false;
}
} else if (!encoding.name.contains('utf')) {
if (result.contains(0xFFFD)) {
return false;
}
}
} on FormatException catch (_) {
return false;
} on ArgumentError catch (_) {
return false;
}
return true;
}