ktoblzcheck  1.52.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 
54 class Iban
55 {
56 public:
57 
59  Iban();
60 
62  Iban(const Iban &iban);
63 
74  Iban(const std::string &iban, bool normalize = true);
75 
77  ~Iban();
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 
94 private:
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 {
117 public:
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 
150  ~IbanCheck();
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 
202 private:
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 
242 extern "C" {
243 #else /* __cplusplus */
244 typedef struct IbanCheck IbanCheck;
245 typedef struct Iban Iban;
246 typedef int IbanCheck_Result;
247 #endif /* __cplusplus */
248 
249 /* @{ */
250 
266 IbanCheck *IbanCheck_new(const char *filename);
268 void IbanCheck_free(IbanCheck *p);
274 IbanCheck_Result IbanCheck_check_str(const IbanCheck *p, const char *iban, const char *country);
284 IbanCheck_Result IbanCheck_check_iban(const IbanCheck *p, const Iban *iban, const char *country);
293 IbanCheck_Result IbanCheck_bic_position(const IbanCheck *p, const char *iban, int *start, int *end);
301 const char *IbanCheck_resultText(IbanCheck_Result res);
305 int IbanCheck_error(const IbanCheck *p);
310 /* @} */
311 
313 /* @{ */
315 Iban *Iban_new(const char *iban, int normalize);
317 void Iban_free(Iban *p);
319 const char *Iban_transmissionForm(const Iban *iban);
321 const char *Iban_printableForm(Iban *iban);
322 /* @} */
323 #ifdef __cplusplus
324 }
325 #endif /* __cplusplus */
326 
327 #endif /* IBAN_H */
int IbanCheck_selftest(IbanCheck *p)
const std::string & transmissionForm() const
Definition: iban.h:80
Result bic_position(const std::string &iban, int &start, int &end) const
const char * Iban_printableForm(Iban *iban)
IbanCheck::Result IbanCheck_Result
Definition: iban.h:241
the IBAN doesn&#39;t belong to the country
Definition: iban.h:128
IbanCheck_Result IbanCheck_check_iban(const IbanCheck *p, const Iban *iban, const char *country)
Iban * Iban_new(const char *iban, int normalize)
IbanCheck * IbanCheck_new(const char *filename)
Bad IBAN checksum, i.e. the IBAN probably contains a typo.
Definition: iban.h:129
int IbanCheck_error(const IbanCheck *p)
const char * Iban_transmissionForm(const Iban *iban)
bool error() const
Definition: iban.h:192
const char * IbanCheck_resultText(IbanCheck_Result res)
IBAN is too short to even check.
Definition: iban.h:124
IBAN is formally correct (length and checksum)
Definition: iban.h:123
Stores one IBAN (International Bank Account Number)
Definition: iban.h:54
IBAN has the wrong length.
Definition: iban.h:126
IBAN bank information database and IBAN verification.
Definition: iban.h:115
friend std ::istream & operator>>(std::istream &is, Spec &spec)
const std::string & printableForm()
Definition: iban.h:86
the 2-character IBAN prefix is unknown
Definition: iban.h:125
void Iban_free(Iban *p)
void IbanCheck_free(IbanCheck *p)
IbanCheck_Result IbanCheck_bic_position(const IbanCheck *p, const char *iban, int *start, int *end)
Result check(const Iban &iban, const std::string &country="") const
Definition: iban.h:160
IbanCheck_Result IbanCheck_check_str(const IbanCheck *p, const char *iban, const char *country)
bool selftest()
static const char * resultText(Result res)
the country code to check against is unknown
Definition: iban.h:127
IbanCheck(const std::string &filename="")
Result
Definition: iban.h:120