ktoblzcheck 1.57.0
iban.h
Go to the documentation of this file.
1
30#ifndef IBAN_H
31#define IBAN_H
32
39#ifdef __cplusplus
40
41#include <iostream>
42#include <fstream>
43#include <sstream>
44#include <vector>
45#include <map>
46#include <ctype.h>
47
54class Iban
55{
56public:
57
60
62 Iban(const Iban &iban);
63
74 Iban(const std::string &iban, bool normalize = true);
75
78
80 const std::string &transmissionForm() const
81 {
82 return m_transmission;
83 }
84
86 const std::string &printableForm()
87 {
88 if (m_printable.empty()) {
89 m_printable = createPrintable();
90 }
91 return m_printable;
92 }
93
94private:
95 std::string m_transmission;
96 std::string m_printable;
97
99 static std::string createTransmission(const std::string &iban_str);
101 std::string createPrintable() const;
102};
103
116{
117public:
118
120 enum Result {
121 // do not change anything here without changing
122 // the initialisation of m_ResultText!
123 OK = 0,
130 };
131
147 IbanCheck(const std::string &filename = "");
148
151
160 Result check(const Iban &iban, const std::string &country = "") const
161 {
162 return check(iban.transmissionForm(), country);
163 }
164
169 Result check(const std::string &iban, const std::string &country = "") const;
170
178 Result bic_position(const std::string &iban, int &start, int &end) const;
179
187 static const char *resultText(Result res);
188
192 bool error() const
193 {
194 return m_IbanSpec.size() == 0;
195 }
196
200 bool selftest();
201
202private:
203
204 static const char *m_ResultText[];
205
206 typedef std::vector<std::string> svector;
207
208 struct Spec {
209 std::string prefix;
210 unsigned int length;
211 unsigned int bic_start, bic_end;
212 std::string example;
213 };
214
215 typedef std::map<std::string, Spec *> specmap;
216
217 struct Country {
218 std::string country;
219 svector prefixes;
220 };
221
222 typedef std::map<std::string, Country *> countrymap;
223
224 friend std ::istream &operator>>(std::istream &is, Spec &spec);
225 friend std ::istream &operator>>(std::istream &is, Country &c);
226
227 bool readSpecTable(std::istream &fin, const std::string &stopcomment);
228 bool readCountryTable(std::istream &fin);
229 static int to_number(char c)
230 {
231 return c - 'A' + 10;
232 }
233
234 static std::string iban2number(const std::string &iban);
235 static int modulo97(const std::string &number);
236
237 specmap m_IbanSpec;
238 countrymap m_CountryMap;
239};
240
242extern "C" {
243#else /* __cplusplus */
244typedef struct IbanCheck IbanCheck;
245typedef struct Iban Iban;
246typedef int IbanCheck_Result;
247#endif /* __cplusplus */
249/* @{ */
250
266IbanCheck *IbanCheck_new(const char *filename);
274IbanCheck_Result IbanCheck_check_str(const IbanCheck *p, const char *iban, const char *country);
284IbanCheck_Result IbanCheck_check_iban(const IbanCheck *p, const Iban *iban, const char *country);
293IbanCheck_Result IbanCheck_bic_position(const IbanCheck *p, const char *iban, int *start, int *end);
310/* @} */
311
313/* @{ */
315Iban *Iban_new(const char *iban, int normalize);
319const char *Iban_transmissionForm(const Iban *iban);
321const char *Iban_printableForm(Iban *iban);
322/* @} */
323#ifdef __cplusplus
324}
325#endif /* __cplusplus */
326
327#endif /* IBAN_H */
IBAN bank information database and IBAN verification.
Definition iban.h:116
Result
Definition iban.h:120
@ PREFIX_NOT_FOUND
the 2-character IBAN prefix is unknown
Definition iban.h:125
@ OK
IBAN is formally correct (length and checksum)
Definition iban.h:123
@ BAD_CHECKSUM
Bad IBAN checksum, i.e. the IBAN probably contains a typo.
Definition iban.h:129
@ TOO_SHORT
IBAN is too short to even check.
Definition iban.h:124
@ WRONG_COUNTRY
the IBAN doesn't belong to the country
Definition iban.h:128
@ WRONG_LENGTH
IBAN has the wrong length.
Definition iban.h:126
@ COUNTRY_NOT_FOUND
the country code to check against is unknown
Definition iban.h:127
IbanCheck(const std::string &filename="")
Result check(const Iban &iban, const std::string &country="") const
Definition iban.h:160
static const char * resultText(Result res)
Result check(const std::string &iban, const std::string &country="") const
friend std::istream & operator>>(std::istream &is, Country &c)
friend std::istream & operator>>(std::istream &is, Spec &spec)
bool selftest()
bool error() const
Definition iban.h:192
Result bic_position(const std::string &iban, int &start, int &end) const
Stores one IBAN (International Bank Account Number)
Definition iban.h:55
Iban(const std::string &iban, bool normalize=true)
const std::string & printableForm()
Definition iban.h:86
const std::string & transmissionForm() const
Definition iban.h:80
Iban(const Iban &iban)
const char * Iban_printableForm(Iban *iban)
const char * IbanCheck_resultText(IbanCheck_Result res)
IbanCheck_Result IbanCheck_bic_position(const IbanCheck *p, const char *iban, int *start, int *end)
IbanCheck::Result IbanCheck_Result
Definition iban.h:241
int IbanCheck_selftest(IbanCheck *p)
void IbanCheck_free(IbanCheck *p)
const char * Iban_transmissionForm(const Iban *iban)
IbanCheck * IbanCheck_new(const char *filename)
int IbanCheck_error(const IbanCheck *p)
IbanCheck_Result IbanCheck_check_iban(const IbanCheck *p, const Iban *iban, const char *country)
IbanCheck_Result IbanCheck_check_str(const IbanCheck *p, const char *iban, const char *country)
Iban * Iban_new(const char *iban, int normalize)
void Iban_free(Iban *p)