nationalFR function
Implementation
String nationalFR(String bban, BbanStructure structure) {
final Map<String, String> replaceChars = {
"[AJ]": "1",
"[BKS]": "2",
"[CLT]": "3",
"[DMU]": "4",
"[ENV]": "5",
"[FOW]": "6",
"[GPX]": "7",
"[HQY]": "8",
"[IRZ]": "9",
};
String combined = "${[
PartType.BANK_CODE,
PartType.BRANCH_CODE,
PartType.ACCOUNT_NUMBER
].map((p) => structure.extractValue(bban, p)).join("")}00";
for (var element in replaceChars.entries) {
combined = combined.replaceAll(RegExp(element.key), element.value);
}
// Number is bigger than max integer, take the mod%97 by hand
final List<String> listCombined = combined.split("");
int reducedTotal = 0;
for (int i = 0; i < listCombined.length; ++i) {
reducedTotal = (reducedTotal * 10 + int.parse(listCombined[i])) % 97;
}
final int expected = 97 - reducedTotal;
return expected.toString().padLeft(2, "0");
}