ktoblzcheck 1.50.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 return m_transmission;
82 }
83
85 const std::string& printableForm() {
86 if (m_printable.empty())
87 m_printable = createPrintable();
88 return m_printable;
89 }
90
91private:
92 std::string m_transmission;
93 std::string m_printable;
94
96 static std::string createTransmission(const std::string& iban_str);
98 std::string createPrintable() const;
99};
100
113public:
114
116 enum Result {
117 // do not change anything here without changing
118 // the initialisation of m_ResultText!
119 OK = 0,
126 };
127
128
144 IbanCheck(const std::string& filename = "");
145
148
157 Result check(const Iban& iban, const std::string& country = "") const {
158 return check(iban.transmissionForm(), country); }
159
164 Result check(const std::string& iban, const std::string& country = "") const;
165
173 Result bic_position(const std::string& iban, int& start, int& end) const;
174
182 static const char *resultText(Result res);
183
187 bool error() const { return m_IbanSpec.size() == 0; }
188
192 bool selftest();
193
194private:
195
196 static const char *m_ResultText[];
197
198 typedef std::vector<std::string> svector;
199
200 struct Spec {
201 std::string prefix;
202 unsigned int length;
203 unsigned int bic_start, bic_end;
204 std::string example;
205 };
206
207 typedef std::map<std::string,Spec*> specmap;
208
209 struct Country {
210 std::string country;
211 svector prefixes;
212 };
213
214 typedef std::map<std::string, Country*> countrymap;
215
216 friend std::istream& operator>>(std::istream &is, Spec &spec);
217 friend std::istream& operator>>(std::istream &is, Country &c);
218
219 bool readSpecTable(std::istream &fin, const std::string& stopcomment);
220 bool readCountryTable(std::istream &fin);
221 static int to_number(char c) { return c - 'A' + 10; }
222 static std::string iban2number(const std::string& iban);
223 static int modulo97(const std::string& number);
224
225 specmap m_IbanSpec;
226 countrymap m_CountryMap;
227};
228
230extern "C" {
231#else /* __cplusplus */
232 typedef struct IbanCheck IbanCheck;
233 typedef struct Iban Iban;
234 typedef int IbanCheck_Result;
235#endif /* __cplusplus */
237 /* @{ */
238
254 IbanCheck *IbanCheck_new(const char *filename);
263 const char *iban,
264 const char *country);
275 const Iban *iban,
276 const char *country);
286 const char *iban,
287 int *start, int *end);
304 /* @} */
305
307 /* @{ */
309 Iban *Iban_new(const char* iban, int normalize);
311 void Iban_free(Iban *p);
313 const char *Iban_transmissionForm(const Iban *iban);
315 const char *Iban_printableForm(Iban *iban);
316 /* @} */
317#ifdef __cplusplus
318}
319#endif /* __cplusplus */
320
321#endif /* IBAN_H */
IBAN bank information database and IBAN verification.
Definition: iban.h:112
Result
Definition: iban.h:116
@ PREFIX_NOT_FOUND
the 2-character IBAN prefix is unknown
Definition: iban.h:121
@ OK
IBAN is formally correct (length and checksum)
Definition: iban.h:119
@ BAD_CHECKSUM
Bad IBAN checksum, i.e. the IBAN probably contains a typo.
Definition: iban.h:125
@ TOO_SHORT
IBAN is too short to even check.
Definition: iban.h:120
@ WRONG_COUNTRY
the IBAN doesn't belong to the country
Definition: iban.h:124
@ WRONG_LENGTH
IBAN has the wrong length.
Definition: iban.h:122
@ COUNTRY_NOT_FOUND
the country code to check against is unknown
Definition: iban.h:123
IbanCheck(const std::string &filename="")
Result check(const Iban &iban, const std::string &country="") const
Definition: iban.h:157
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:187
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:85
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:229
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)