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 
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  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 
91 private:
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 
112 class IbanCheck {
113 public:
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 
147  ~IbanCheck();
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 
194 private:
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 
230 extern "C" {
231 #else /* __cplusplus */
232  typedef struct IbanCheck IbanCheck;
233  typedef struct Iban Iban;
234  typedef int IbanCheck_Result;
235 #endif /* __cplusplus */
236 
237  /* @{ */
238 
254  IbanCheck *IbanCheck_new(const char *filename);
256  void IbanCheck_free(IbanCheck *p);
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);
295  const char *IbanCheck_resultText(IbanCheck_Result res);
299  int IbanCheck_error(const IbanCheck *p);
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 */
friend std::istream & operator>>(std::istream &is, Spec &spec)
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:229
the IBAN doesn&#39;t belong to the country
Definition: iban.h:124
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:125
int IbanCheck_error(const IbanCheck *p)
const char * Iban_transmissionForm(const Iban *iban)
bool error() const
Definition: iban.h:187
const char * IbanCheck_resultText(IbanCheck_Result res)
IBAN is too short to even check.
Definition: iban.h:120
IBAN is formally correct (length and checksum)
Definition: iban.h:119
Stores one IBAN (International Bank Account Number)
Definition: iban.h:54
IBAN has the wrong length.
Definition: iban.h:122
IBAN bank information database and IBAN verification.
Definition: iban.h:112
const std::string & printableForm()
Definition: iban.h:85
the 2-character IBAN prefix is unknown
Definition: iban.h:121
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:157
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:123
IbanCheck(const std::string &filename="")
Result
Definition: iban.h:116