Skip to content

Commit

Permalink
feat: upgraded SWIFT registry provider to July '23 release 95, which …
Browse files Browse the repository at this point in the history
…adds Falkland Islands (FK). Upgraded Wikipedia registry provider, which adds North Macedonia (MK).

Fix the T4 templates. Wikipedia API returns some invalid XML, so we have to use a regex hack to extract the relevant part.
  • Loading branch information
skwasjer committed Jul 15, 2023
1 parent 6c54b9c commit 1405e32
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Upgraded SWIFT registry provider to July '23 release 95, which adds Falkland Islands (FK).
- Upgraded Wikipedia registry provider, which adds North Macedonia (MK).
- [#144](https://github.com/skwasjer/IbanNet/pull/144) Add Catalan localization.
- [#138](https://github.com/skwasjer/IbanNet/pull/138) Implement `IParsable<TSelf>` on Iban type.
- In `IbanParser` internals, use `ReadOnlySpan<T>`.
Expand Down
3 changes: 2 additions & 1 deletion SupportedCountries.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

*In mid 2022, an IBAN pattern for the Russian Federation (RU) was registered with SWIFT. This project has not (yet) adopted support for this pattern due to the war in Ukraine.*

# IbanNet supports 123 countries
# IbanNet supports 124 countries

## SWIFT registry

Expand Down Expand Up @@ -34,6 +34,7 @@ See the [SWIFT website](https://www.swift.com/standards/data-standards/iban-inte
| EG | Egypt | 29 | `EG38 0019 0005 0000 0000 2631 8000 2` | No | ![Supported][supported] | ![Supported][supported] |
| ES | Spain | 24 | `ES91 2100 0418 4502 0005 1332` | Yes | ![Supported][supported] | ![Supported][supported] |
| FI | Finland | 18 | `FI21 1234 5600 0007 85` | Yes | ![Supported][supported] | - |
| FK | Falkland Islands | 18 | `FK88 SC12 3456 7890 12` | No | ![Supported][supported] | - |
| FO | Faroe Islands | 18 | `FO62 6460 0001 6316 34` | No | ![Supported][supported] | - |
| FR | France | 27 | `FR14 2004 1010 0505 0001 3M02 606` | Yes | ![Supported][supported] | ![Supported][supported] |
| GB | United Kingdom | 22 | `GB29 NWBK 6016 1331 9268 19` | Yes | ![Supported][supported] | ![Supported][supported] |
Expand Down

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions src/IbanNet/Registry/Swift/SwiftRegistryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace IbanNet.Registry.Swift;
/// This IBAN registry provider contains IBAN/BBAN/SEPA information for all known IBAN countries.
/// </summary>
/// <remarks>
/// Generated from: swift_iban_registry_202304.r94.txt
/// Generated from: swift_iban_registry_202307.r95.txt
/// </remarks>
[GeneratedCode("SwiftRegistryProviderT4", "1.1-r94")]
[GeneratedCode("SwiftRegistryProviderT4", "1.1-r95")]
public class SwiftRegistryProvider : IIbanRegistryProvider
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Expand Down Expand Up @@ -878,6 +878,38 @@ private static IEnumerable<IbanCountry> Load()
LastUpdatedDate = new DateTimeOffset(2016, 8, 1, 0, 0, 0, TimeSpan.Zero)
};

// Falkland Islands
yield return new IbanCountry("FK")
{
NativeName = "Falkland Islands",
EnglishName = "Falkland Islands",
Iban = new IbanStructure(new SwiftPattern(new PatternToken[]
{
new("FK"),
new(AsciiCategory.Digit, 2, 2),
new(AsciiCategory.UppercaseLetter, 2, 2),
new(AsciiCategory.Digit, 12, 12),
}))
{
Example = "FK88SC123456789012",
EffectiveDate = new DateTimeOffset(2023, 7, 1, 0, 0, 0, TimeSpan.Zero)
},
Bban = new BbanStructure(new SwiftPattern("2!a12!n"), 4)
{
Example = "SC123456789012"
},
Bank = new BankStructure(new SwiftPattern("2!a"), 4)
{
Example = "SC"
},
Sepa = new SepaInfo
{
IsMember = false
},
DomesticAccountNumberExample = "123456789012",
LastUpdatedDate = new DateTimeOffset(2023, 7, 1, 0, 0, 0, TimeSpan.Zero)
};

// Faroe Islands
yield return new IbanCountry("FO")
{
Expand Down
3 changes: 2 additions & 1 deletion src/IbanNet/Registry/Swift/SwiftRegistryProvider.tt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="IbanNet.CodeGen.Swift" #>
<#@ import namespace="IbanNet.Registry.Patterns" #>
<#@ import namespace="IbanNet.Registry.Swift" #>
<#@ output extension=".cs" #>
using System.CodeDom.Compiler;
Expand Down Expand Up @@ -97,7 +98,7 @@ public class SwiftRegistryProvider : IIbanRegistryProvider
foreach (var token in pattern.Tokens.Skip(1))
{
#>
new(AsciiCategory.<#= token.Category #>, <#= token.MinLength #>, <#= token.MaxLength #>),
new(AsciiCategory.<#= Enum.GetName(typeof(AsciiCategory), token.Category) #>, <#= token.MinLength #>, <#= token.MaxLength #>),
<#
}
#>
Expand Down
20 changes: 10 additions & 10 deletions src/IbanNet/Registry/Wikipedia/WikipediaRegistryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace IbanNet.Registry.Wikipedia;
/// <para>
/// Generated from: https://en.wikipedia.org/wiki/International_Bank_Account_Number
/// Page ID: 15253
/// Rev ID: 1145025467
/// Rev ID: 1159613938
/// </para>
/// </remarks>
[GeneratedCode("WikiRegistryProviderT4", "1.15253-1145025467")]
[GeneratedCode("WikiRegistryProviderT4", "1.15253-1159613938")]
public class WikipediaRegistryProvider : IIbanRegistryProvider
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Expand Down Expand Up @@ -402,14 +402,6 @@ private static IEnumerable<IbanCountry> Load()
Bban = new BbanStructure(new WikipediaPattern("3n,13c"), 4)
};

yield return new IbanCountry("MK")
{
NativeName = "Северна Македонија",
EnglishName = "North Macedonia",
Iban = new IbanStructure(new IbanWikipediaPattern("MK", "3n,10c,2n")),
Bban = new BbanStructure(new WikipediaPattern("3n,10c,2n"), 4)
};

yield return new IbanCountry("MT")
{
NativeName = "Malta",
Expand Down Expand Up @@ -466,6 +458,14 @@ private static IEnumerable<IbanCountry> Load()
Bban = new BbanStructure(new WikipediaPattern("4a,10n"), 4)
};

yield return new IbanCountry("MK")
{
NativeName = "Северна Македонија",
EnglishName = "North Macedonia",
Iban = new IbanStructure(new IbanWikipediaPattern("MK", "3n,10c,2n")),
Bban = new BbanStructure(new WikipediaPattern("3n,10c,2n"), 4)
};

yield return new IbanCountry("NO")
{
NativeName = "Noreg",
Expand Down
12 changes: 10 additions & 2 deletions src/IbanNet/Registry/Wikipedia/WikipediaRegistryProvider.tt
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<#@ template hostspecific="true" language="C#" #>
<#@ assembly name="NetStandard" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Linq" #>
<#@ assembly name="System.Memory" #>
<#@ assembly name="System.Text.Json" #>
<#@ assembly name="System.Text.RegularExpressions" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Net" #>
<#@ import namespace="System.Text.Json" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Xml.XPath" #>
<#@ import namespace="System.Text.Json" #>
using System.CodeDom.Compiler;
using System.Collections;
using System.Diagnostics;
Expand All @@ -30,6 +33,11 @@ namespace IbanNet.Registry.Wikipedia;
byte[] buffer = ms.ToArray();

WikiResponse wikiResponse = JsonSerializer.Deserialize<WikiResponse>(buffer, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });

var tableRegex = new Regex("(<table[^\\>]*?>.*<\\/table>)", RegexOptions.Singleline);
var tableMatch = tableRegex.Match(wikiResponse.Parse.Text["*"]);
var tableHtml = $"<div>${tableMatch.Value}</div>";

#>
/// <summary>
/// This IBAN registry provider is derived from Wikipedia.
Expand Down Expand Up @@ -70,7 +78,7 @@ public class WikipediaRegistryProvider : IIbanRegistryProvider
// ReSharper disable CommentTypo
// ReSharper disable StringLiteralTypo
<#
using var reader = new StringReader(wikiResponse.Parse.Text["*"]);
using var reader = new StringReader(tableHtml);

var doc = XDocument.Load(reader);
var wikiSpecs = doc.XPathSelectElements("//tr")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class SwiftRegistryProviderTests : BaseRegistryProviderSpec<SwiftRegistryProvider>
{
public SwiftRegistryProviderTests() : base(84)
public SwiftRegistryProviderTests() : base(85)
{
}

Expand Down

0 comments on commit 1405e32

Please sign in to comment.