Remove unnecessary logic
This commit is contained in:
parent
8601bb11c3
commit
316d44be81
|
@ -0,0 +1,2 @@
|
||||||
|
*.o
|
||||||
|
iban.so
|
51
iban.cc
51
iban.cc
|
@ -104,30 +104,29 @@ std::regex parseStructure(std::string structure) {
|
||||||
return std::regex(regex.c_str());
|
return std::regex(regex.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Validate::setSelectedSpecification(std::string countryCode) {
|
|
||||||
this->selectedSpec = this->specifications[countryCode];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Validate::isValid(std::string arg) {
|
bool Validate::isValid(std::string arg) {
|
||||||
Specification* spec = new Specification("", 0, "", arg);
|
Specification* spec = new Specification(arg);
|
||||||
if (!this->selectedSpec) {
|
|
||||||
std::transform(spec->example.begin(), spec->example.end(), spec->example.begin(), toupper);
|
/* Convert uppercase */
|
||||||
spec->countryCode = spec->example.substr(0, 2);
|
std::transform(spec->example.begin(), spec->example.end(),
|
||||||
spec->length = spec->example.length();
|
spec->example.begin(), toupper);
|
||||||
setSelectedSpecification(spec->countryCode);
|
|
||||||
}
|
/* Match on country */
|
||||||
if (!(this->selectedSpec == nullptr)) {
|
spec->countryCode = spec->example.substr(0, 2);
|
||||||
std::string shortened = spec->example.substr(4, spec->example.length());
|
spec->length = spec->example.length();
|
||||||
bool result = this->selectedSpec->length == spec->length
|
Specification* specFound = this->specifications[spec->countryCode];
|
||||||
&& this->selectedSpec->countryCode.compare(spec->countryCode) == 0
|
if (!specFound)
|
||||||
&& std::regex_match(shortened, parseStructure(this->selectedSpec->structure))
|
|
||||||
&& iso7064Mod97_10(spec->example);
|
|
||||||
delete spec;
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
delete spec;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
/* Test accountnumber */
|
||||||
|
std::string shortened = spec->example.substr(4, spec->example.length());
|
||||||
|
bool result = specFound->length == spec->length
|
||||||
|
&& specFound->countryCode.compare(spec->countryCode) == 0
|
||||||
|
&& std::regex_match(shortened, parseStructure(specFound->structure))
|
||||||
|
&& iso7064Mod97_10(spec->example);
|
||||||
|
|
||||||
|
delete spec;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Validate::~Validate() {
|
Validate::~Validate() {
|
||||||
|
@ -399,13 +398,7 @@ bool account_validate(text *iban) {
|
||||||
Validate val;
|
Validate val;
|
||||||
ciban = text_to_cstring(iban);
|
ciban = text_to_cstring(iban);
|
||||||
|
|
||||||
elog(DEBUG1, "Evaluating '%s'", ciban);
|
return val.isValid(std::string(ciban));
|
||||||
|
|
||||||
bool r = val.isValid(std::string(ciban));
|
|
||||||
|
|
||||||
elog(DEBUG1, "Result %d", r);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Specification {
|
class Specification {
|
||||||
public:
|
public:
|
||||||
Specification(std::string countryCode, int length, std::string structure, std::string example) :
|
Specification(std::string countryCode, int length, std::string structure, std::string example) :
|
||||||
countryCode(countryCode),
|
countryCode(countryCode),
|
||||||
length(length),
|
length(length),
|
||||||
structure(structure),
|
structure(structure),
|
||||||
example(example)
|
example(example) {
|
||||||
{};
|
};
|
||||||
|
Specification(std::string example) : example(example) {};
|
||||||
std::string countryCode;
|
std::string countryCode;
|
||||||
int length;
|
int length;
|
||||||
std::string structure;
|
std::string structure;
|
||||||
|
|
|
@ -9,8 +9,6 @@ class Validate {
|
||||||
~Validate();
|
~Validate();
|
||||||
bool isValid(std::string arg);
|
bool isValid(std::string arg);
|
||||||
void addSpecification(Specification* specPtr);
|
void addSpecification(Specification* specPtr);
|
||||||
void setSelectedSpecification(std::string countryCode);
|
|
||||||
|
|
||||||
std::map<std::string, Specification*> specifications;
|
std::map<std::string, Specification*> specifications;
|
||||||
Specification* selectedSpec;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue