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