convert method
Converts input
and returns the result of the conversion.
Implementation
@override
List<int> convert(String input) {
String str = input.replaceAll(" ", "");
str = str.toLowerCase();
if (str.length % 2 != 0) {
str = "0$str";
}
final Uint8List result = Uint8List(str.length ~/ 2);
for (int i = 0; i < result.length; i++) {
final int firstDigit = _alphabet.indexOf(str[i * 2]);
final int secondDigit = _alphabet.indexOf(str[i * 2 + 1]);
if (firstDigit == -1 || secondDigit == -1) {
throw FormatException("Non-hex character detected in $input");
}
result[i] = (firstDigit << 4) + secondDigit;
}
return result;
}