Code refinements

This commit is contained in:
Yorick de Wid 2020-10-24 23:38:37 +02:00
parent 33b40f623c
commit e935980bad
1 changed files with 16 additions and 10 deletions

View File

@ -79,11 +79,14 @@ static Validate validator;
* @param string iban * @param string iban
* @returns {bool} * @returns {bool}
*/ */
static bool iso7064Mod97_10(std::string iBan) { static bool iso7064Mod97_10(std::string iban) {
std::rotate(iBan.begin(), iBan.begin() + 4, iBan.end()); std::rotate(iban.begin(), iban.begin() + 4, iban.end());
std::string numberstring;//will contain the letter substitutions
for (const auto& c : iBan) { /* Will contain the letter substitutions */
std::string numberstring;
numberstring.reserve(iban.size());
for (const auto& c : iban) {
if (std::isdigit(c)) { if (std::isdigit(c)) {
numberstring += c; numberstring += c;
} }
@ -92,9 +95,11 @@ static bool iso7064Mod97_10(std::string iBan) {
} }
} }
//implements a stepwise check for mod 97 in chunks of 9 at the first time /*
// , then in chunks of seven prepended by the last mod 97 operation converted * Implements a stepwise check for mod 97 in chunks of 9 at the first time
//to a string * then in chunks of seven prepended by the last mod 97 operation converted
* to a string
*/
size_t segstart = 0; size_t segstart = 0;
int step = 9; int step = 9;
std::string prepended; std::string prepended;
@ -109,8 +114,9 @@ static bool iso7064Mod97_10(std::string iBan) {
segstart = segstart + step; segstart = segstart + step;
step = 7; step = 7;
} }
number = std::stol(prepended + numberstring.substr(segstart)); number = std::stol(prepended + numberstring.substr(segstart));
return (number % 97 == 1); return number % 97 == 1;
} }
/** /**
@ -166,7 +172,7 @@ bool Validate::isValid(std::string account) {
const std::string& countryCode = account.substr(0, 2); const std::string& countryCode = account.substr(0, 2);
const std::string& shortened = account.substr(4); const std::string& shortened = account.substr(4);
const std::unique_ptr<Specification>& specFound = this->specifications[countryCode]; const std::unique_ptr<Specification>& specFound = specifications[countryCode];
if (!specFound) { if (!specFound) {
return false; return false;
} }