Skip to content

Commit

Permalink
Merge pull request #20 from ThomasdenH/develop
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
ThomasdenH authored Dec 21, 2018
2 parents c3a8df9 + d66d553 commit 715fa25
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rust:
# check it compiles on the latest stable compiler
- stable
# Test for the minimum required version
- 1.20.0
- 1.31.0

matrix:
allow_failures:
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[package]
name = "iban_validate"
# Note: When updating, also update in lib.rs and README.md
version = "1.0.3"
version = "2.0.0"
authors = ["Thomas den Hollander <[email protected]>"]
description = "A small crate to verify IBAN account numbers."
repository = "https://github.com/ThomasdenH/iban_check"
license = "MIT/Apache-2.0"
readme = "README.md"
keywords = ["iban", "iban-validator"]
categories = ["parsing"]
edition = "2018"

[badges]
appveyor = { repository = "ThomasdenH/iban-validate" }
Expand All @@ -23,8 +24,9 @@ name = "iban"
path = "src/lib.rs"

[dependencies]
regex = "1.0.0"
lazy_static = "1.0.0"
regex = "1.1.0"
lazy_static = "1.2.0"

[dev-dependencies]
expectest = "0.10.0"
expectest = "0.11.0"
proptest = "0.8.7"
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Coverage Status](https://coveralls.io/repos/github/ThomasdenH/iban_validate/badge.svg?branch=master)](https://coveralls.io/github/ThomasdenH/iban_validate?branch=master)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/ThomasdenH/iban_validate.svg)](http://isitmaintained.com/project/ThomasdenH/iban_validate "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/ThomasdenH/iban_validate.svg)](http://isitmaintained.com/project/ThomasdenH/iban_validate "Percentage of issues still open")
[![Rust](https://img.shields.io/badge/rust-1.20%2B-blue.svg?maxAge=3600)](https://github.com/ThomasdenH/iban_validate)
[![Rust](https://img.shields.io/badge/rust-1.31%2B-blue.svg?maxAge=3600)](https://github.com/ThomasdenH/iban_validate)

This is a small crate that is able to validate an IBAN account number.

Expand All @@ -14,7 +14,7 @@ The crate can be found on [crates.io](https://crates.io/crates/iban_validate). T
dependency:

[dependencies]
iban_validate = "1.0.3"
iban_validate = "2.0.0"

## Functionality
This crate provides an easy way to validate an IBAN (International Bank Account Number). To do so, you can use the
Expand Down Expand Up @@ -45,6 +45,9 @@ The full documentation is available at [docs.rs](https://docs.rs/iban_validate/)
## Contributing
If you experience issues with this crate or want to help, please look [here](contributing.md).

## Stability
This crate has the goal of being usable on the latest stable version of Rust. Its minimum version is documented and tested against, although no extra effort is taken to support earlier versions. The minimum version of Rust can be increased, although this corresponds to a new major release. The crate does not use unsafe itself, although dependencies might. Breaking changes are not avoided in new major versions, although these will always be well-documented and the process of upgrading made clear.

## License

Licensed under either of
Expand All @@ -60,4 +63,4 @@ at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
dual licensed as above, without any additional terms or conditions.
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ environment:
target: x86_64-pc-windows-gnu
- channel: nightly
target: i686-pc-windows-gnu
- channel: 1.20.0
- channel: 1.31.0
target: x86_64-pc-windows-msvc
- channel: 1.20.0
- channel: 1.31.0
target: i686-pc-windows-msvc
- channel: 1.20.0
- channel: 1.31.0
target: x86_64-pc-windows-gnu
- channel: 1.20.0
- channel: 1.31.0
target: i686-pc-windows-gnu

matrix:
Expand Down
187 changes: 94 additions & 93 deletions src/countries.rs
Original file line number Diff line number Diff line change
@@ -1,106 +1,107 @@
//! This module contains the code for the validation of the countries in the Swift IBAN registry. It
//! checks if the country code is recognized and then tries to match the regular expression.
extern crate regex;

use lazy_static::lazy_static;
use regex;
use regex::{RegexSet, RegexSetBuilder};

static COUNTRY_FORMATS: [(&'static str, &'static str); 75] =
[
("AD", r"^\d{8}[A-Z\d]{12}$"),
("AE", r"^\d{19}$"),
("AL", r"^\d{8}[A-Z\d]{16}$"),
("AT", r"^\d{16}$"),
("AZ", r"^[A-Z]{4}[A-Z\d]{20}$"),
("BA", r"^\d{16}$"),
("BE", r"^\d{12}$"),
("BG", r"^[A-Z]{4}\d{6}[A-Z\d]{8}$"),
("BH", r"^[A-Z]{4}[A-Z\d]{14}$"),
("BR", r"^\d{23}[A-Z]{1}[A-Z\d]{1}$"),
("BY", r"^[A-Z\d]{4}\d{4}[A-Z\d]{16}$"),
("CH", r"^\d{5}[A-Z\d]{12}$"),
("CR", r"^\d{18}$"),
("CY", r"^\d{8}[A-Z\d]{16}$"),
("CZ", r"^\d{20}$"),
("DE", r"^\d{18}$"),
("DK", r"^\d{14}$"),
("DO", r"^[A-Z\d]{4}\d{20}$"),
("EE", r"^\d{16}$"),
("ES", r"^\d{20}$"),
("FI", r"^\d{14}$"),
("FO", r"^\d{14}$"),
("FR", r"^\d{10}[A-Z\d]{11}\d{2}$"),
("GB", r"^[A-Z]{4}\d{14}$"),
("GE", r"^[A-Z]{2}\d{16}$"),
("GI", r"^[A-Z]{4}[A-Z\d]{15}$"),
("GL", r"^\d{14}$"),
("GR", r"^\d{7}[A-Z\d]{16}$"),
("GT", r"^[A-Z\d]{24}$"),
("HR", r"^\d{17}$"),
("HU", r"^\d{24}$"),
("IE", r"^[A-Z]{4}\d{14}$"),
("IL", r"^\d{19}$"),
("IQ", r"^[A-Z]{4}\d{15}$"),
("IS", r"^\d{22}$"),
("IT", r"^[A-Z]{1}\d{10}[A-Z\d]{12}$"),
("JO", r"^[A-Z]{4}\d{4}[A-Z\d]{18}$"),
("KW", r"^[A-Z]{4}[A-Z\d]{22}$"),
("KZ", r"^\d{3}[A-Z\d]{13}$"),
("LB", r"^\d{4}[A-Z\d]{20}$"),
("LC", r"^[A-Z]{4}[A-Z\d]{24}$"),
("LI", r"^\d{5}[A-Z\d]{12}$"),
("LT", r"^\d{16}$"),
("LU", r"^\d{3}[A-Z\d]{13}$"),
("LV", r"^[A-Z]{4}[A-Z\d]{13}$"),
("MC", r"^\d{10}[A-Z\d]{11}\d{2}$"),
("MD", r"^[A-Z\d]{20}$"),
("ME", r"^\d{18}$"),
("MK", r"^\d{3}[A-Z\d]{10}\d{2}$"),
("MR", r"^\d{23}$"),
("MT", r"^[A-Z]{4}\d{5}[A-Z\d]{18}$"),
("MU", r"^[A-Z]{4}\d{19}[A-Z]{3}$"),
("NL", r"^[A-Z]{4}\d{10}$"),
("NO", r"^\d{11}$"),
("PK", r"^[A-Z]{4}[A-Z\d]{16}$"),
("PL", r"^\d{24}$"),
("PS", r"^[A-Z]{4}[A-Z\d]{21}$"),
("PT", r"^\d{21}$"),
("QA", r"^[A-Z]{4}[A-Z\d]{21}$"),
("RO", r"^[A-z]{4}[A-Z\d]{16}$"),
("RS", r"^\d{18}$"),
("SA", r"^\d{2}[A-Z\d]{18}$"),
("SC", r"^[A-Z]{4}\d{20}[A-Z]{3}$"),
("SE", r"^\d{20}$"),
("SI", r"^\d{15}$"),
("SK", r"^\d{20}$"),
("SM", r"^[A-Z]{1}\d{10}[A-Z\d]{12}$"),
("ST", r"^\d{21}$"),
("SV", r"^[A-Z]{4}\d{20}$"),
("TL", r"^\d{19}$"),
("TN", r"^\d{20}$"),
("TR", r"^\d{6}[A-Z\d]{16}$"),
("UA", r"^\d{6}[A-Z\d]{19}$"),
("VG", r"^[A-Z]{4}\d{16}$"),
("XK", r"^\d{16}$"),
];
static COUNTRY_FORMATS: [(&'static str, &'static str); 75] = [
("AD", r"^\d{8}[A-Z\d]{12}$"),
("AE", r"^\d{19}$"),
("AL", r"^\d{8}[A-Z\d]{16}$"),
("AT", r"^\d{16}$"),
("AZ", r"^[A-Z]{4}[A-Z\d]{20}$"),
("BA", r"^\d{16}$"),
("BE", r"^\d{12}$"),
("BG", r"^[A-Z]{4}\d{6}[A-Z\d]{8}$"),
("BH", r"^[A-Z]{4}[A-Z\d]{14}$"),
("BR", r"^\d{23}[A-Z]{1}[A-Z\d]{1}$"),
("BY", r"^[A-Z\d]{4}\d{4}[A-Z\d]{16}$"),
("CH", r"^\d{5}[A-Z\d]{12}$"),
("CR", r"^\d{18}$"),
("CY", r"^\d{8}[A-Z\d]{16}$"),
("CZ", r"^\d{20}$"),
("DE", r"^\d{18}$"),
("DK", r"^\d{14}$"),
("DO", r"^[A-Z\d]{4}\d{20}$"),
("EE", r"^\d{16}$"),
("ES", r"^\d{20}$"),
("FI", r"^\d{14}$"),
("FO", r"^\d{14}$"),
("FR", r"^\d{10}[A-Z\d]{11}\d{2}$"),
("GB", r"^[A-Z]{4}\d{14}$"),
("GE", r"^[A-Z]{2}\d{16}$"),
("GI", r"^[A-Z]{4}[A-Z\d]{15}$"),
("GL", r"^\d{14}$"),
("GR", r"^\d{7}[A-Z\d]{16}$"),
("GT", r"^[A-Z\d]{24}$"),
("HR", r"^\d{17}$"),
("HU", r"^\d{24}$"),
("IE", r"^[A-Z]{4}\d{14}$"),
("IL", r"^\d{19}$"),
("IQ", r"^[A-Z]{4}\d{15}$"),
("IS", r"^\d{22}$"),
("IT", r"^[A-Z]{1}\d{10}[A-Z\d]{12}$"),
("JO", r"^[A-Z]{4}\d{4}[A-Z\d]{18}$"),
("KW", r"^[A-Z]{4}[A-Z\d]{22}$"),
("KZ", r"^\d{3}[A-Z\d]{13}$"),
("LB", r"^\d{4}[A-Z\d]{20}$"),
("LC", r"^[A-Z]{4}[A-Z\d]{24}$"),
("LI", r"^\d{5}[A-Z\d]{12}$"),
("LT", r"^\d{16}$"),
("LU", r"^\d{3}[A-Z\d]{13}$"),
("LV", r"^[A-Z]{4}[A-Z\d]{13}$"),
("MC", r"^\d{10}[A-Z\d]{11}\d{2}$"),
("MD", r"^[A-Z\d]{20}$"),
("ME", r"^\d{18}$"),
("MK", r"^\d{3}[A-Z\d]{10}\d{2}$"),
("MR", r"^\d{23}$"),
("MT", r"^[A-Z]{4}\d{5}[A-Z\d]{18}$"),
("MU", r"^[A-Z]{4}\d{19}[A-Z]{3}$"),
("NL", r"^[A-Z]{4}\d{10}$"),
("NO", r"^\d{11}$"),
("PK", r"^[A-Z]{4}[A-Z\d]{16}$"),
("PL", r"^\d{24}$"),
("PS", r"^[A-Z]{4}[A-Z\d]{21}$"),
("PT", r"^\d{21}$"),
("QA", r"^[A-Z]{4}[A-Z\d]{21}$"),
("RO", r"^[A-z]{4}[A-Z\d]{16}$"),
("RS", r"^\d{18}$"),
("SA", r"^\d{2}[A-Z\d]{18}$"),
("SC", r"^[A-Z]{4}\d{20}[A-Z]{3}$"),
("SE", r"^\d{20}$"),
("SI", r"^\d{15}$"),
("SK", r"^\d{20}$"),
("SM", r"^[A-Z]{1}\d{10}[A-Z\d]{12}$"),
("ST", r"^\d{21}$"),
("SV", r"^[A-Z]{4}\d{20}$"),
("TL", r"^\d{19}$"),
("TN", r"^\d{20}$"),
("TR", r"^\d{6}[A-Z\d]{16}$"),
("UA", r"^\d{6}[A-Z\d]{19}$"),
("VG", r"^[A-Z]{4}\d{16}$"),
("XK", r"^\d{16}$"),
];

lazy_static! {
pub static ref RE_COUNTRY_CODE: RegexSet = RegexSetBuilder::new(
COUNTRY_FORMATS.iter().map(|&(re, _)| re)
)
.build()
.expect("Could not compile regular expression for country codes. \
Please file an issue at https://github.com/ThomasdenH/iban_validate.");
pub static ref RE_COUNTRY_CODE: RegexSet =
RegexSetBuilder::new(COUNTRY_FORMATS.iter().map(|&(re, _)| re))
.build()
.expect(
"Could not compile regular expression for country codes. \
Please file an issue at https://github.com/ThomasdenH/iban_validate."
);
}

lazy_static! {
pub static ref RE_ADDRESS_REMAINDER: RegexSet = RegexSetBuilder::new(
COUNTRY_FORMATS.iter().map(|&(_, re)| re)
)
.size_limit(16_000_000)
.build()
.expect("Could not compile regular expression for IBAN addresses. \
Please file an issue at https://github.com/ThomasdenH/iban_validate.");
pub static ref RE_ADDRESS_REMAINDER: RegexSet =
RegexSetBuilder::new(COUNTRY_FORMATS.iter().map(|&(_, re)| re))
.size_limit(16_000_000)
.build()
.expect(
"Could not compile regular expression for IBAN addresses. \
Please file an issue at https://github.com/ThomasdenH/iban_validate."
);
}

/// A variant of this enum is returned by the method [`validate_bban()`].
Expand Down
Loading

0 comments on commit 715fa25

Please sign in to comment.