ktoblzcheck  1.52.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
IbanCheck Class Reference

IBAN bank information database and IBAN verification. More...

#include <iban.h>

Public Types

enum  Result {
  OK = 0, TOO_SHORT, PREFIX_NOT_FOUND, WRONG_LENGTH,
  COUNTRY_NOT_FOUND, WRONG_COUNTRY, BAD_CHECKSUM
}
 

Public Member Functions

 IbanCheck (const std::string &filename="")
 
 ~IbanCheck ()
 
Result check (const Iban &iban, const std::string &country="") const
 
Result check (const std::string &iban, const std::string &country="") const
 
Result bic_position (const std::string &iban, int &start, int &end) const
 
bool error () const
 
bool selftest ()
 

Static Public Member Functions

static const char * resultText (Result res)
 

Friends

std ::istream & operator>> (std::istream &is, Spec &spec)
 
std ::istream & operator>> (std::istream &is, Country &c)
 

Detailed Description

IBAN bank information database and IBAN verification.

Stores a mapping of IBAN-prefixes to required length of the IBAN and BIC (Bank Identification Code) position inside the IBAN, and a second mapping of the ISO 3166 2-character country code to the list of prefixes for that country (usually one, identically to the country code).

The mappings are read from a file when an instance of the class is created.

Member Enumeration Documentation

◆ Result

enum Result

Code returned by check() (and also by bic_position()).

Enumerator
OK 

IBAN is formally correct (length and checksum)

TOO_SHORT 

IBAN is too short to even check.

PREFIX_NOT_FOUND 

the 2-character IBAN prefix is unknown

WRONG_LENGTH 

IBAN has the wrong length.

COUNTRY_NOT_FOUND 

the country code to check against is unknown

WRONG_COUNTRY 

the IBAN doesn't belong to the country

BAD_CHECKSUM 

Bad IBAN checksum, i.e. the IBAN probably contains a typo.

Constructor & Destructor Documentation

◆ IbanCheck()

IbanCheck ( const std::string &  filename = "")

Constructor that initalizes the mappings from a data file at filename.

If the file name argument is empty, then the compile-time datafile will be used. On Windows, the location of the datafile will be looked up in the registry.

If the file could not be found or is not successfully read, the mappings will be empty. Use error() to check for such an error condition.

Parameters
filenameIf empty, then the compile-time file name will be used. Otherwise the relative or absolute full filename of the data file

◆ ~IbanCheck()

~IbanCheck ( )

Default destructor

Member Function Documentation

◆ bic_position()

Result bic_position ( const std::string &  iban,
int &  start,
int &  end 
) const

Returns the position of the BIC inside the IBAN. The iban should be formally correct, if not an error Result might be returned.

Parameters
iban[in] IBAN in transmission format
start[out] start of BIC (0-based index)
end[out] first position after BIC (0-based index)

◆ check() [1/2]

Result check ( const Iban iban,
const std::string &  country = "" 
) const
inline

Check the formal correctness of a given iban. This function checks if the prefix is known, if the length is correct for the prefix, if the checksum is ok and if the prefix is valid for a given country (if set).

Parameters
ibanIban instance
country2-character country code (ISO 3166)

References Iban::transmissionForm().

◆ check() [2/2]

Result check ( const std::string &  iban,
const std::string &  country = "" 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
ibanIBAN in transmission format
country2-character country code (ISO 3166)

◆ error()

bool error ( ) const
inline
Returns
false if the data file could not be opened and successfully read.

◆ resultText()

static const char* resultText ( Result  res)
static

Convert Result code into an english message string.

Note
if the value of res is an integer not inside the enum range, a special message will be returned.
Parameters
resResult code from check() or bic_position()

◆ selftest()

bool selftest ( )

uses the example data to test the check routines.

Returns
false if not successful

Friends And Related Function Documentation

◆ operator>> [1/2]

std ::istream& operator>> ( std::istream &  is,
Spec &  spec 
)
friend

◆ operator>> [2/2]

std ::istream& operator>> ( std::istream &  is,
Country &  c 
)
friend

The documentation for this class was generated from the following file: