Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updates SwiftRegistryProvider to r98 (July '24) #220

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 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 124 countries
# IbanNet supports 126 countries

## SWIFT registry

Expand Down Expand Up @@ -71,10 +71,11 @@ See the [SWIFT website](https://www.swift.com/standards/data-standards/iban-inte
| NI | Nicaragua | 28 | `NI45 BAPR 0000 0013 0000 0355 8124` | No | ![Supported][supported] | - |
| NL | Netherlands (The) | 18 | `NL91 ABNA 0417 1643 00` | Yes | ![Supported][supported] | - |
| NO | Norway | 15 | `NO93 8601 1117 947` | Yes | ![Supported][supported] | - |
| OM | Oman | 23 | `OM81 0180 0000 0129 9123 456` | No | ![Supported][supported] | - |
| PK | Pakistan | 24 | `PK36 SCBL 0000 0011 2345 6702` | No | ![Supported][supported] | - |
| PL | Poland | 28 | `PL61 1090 1014 0000 0712 1981 2874` | Yes | - | ![Supported][supported] |
| PS | Palestine, State of | 29 | `PS92 PALS 0000 0000 0400 1234 5670 2` | No | ![Supported][supported] | - |
| PT | Portugal | 25 | `PT50 0002 0123 1234 5678 9015 4` | Yes | ![Supported][supported] | - |
| PT | Portugal | 25 | `PT50 0002 0123 1234 5678 9015 4` | Yes | ![Supported][supported] | ![Supported][supported] |
| QA | Qatar | 29 | `QA58 DOHB 0000 1234 5678 90AB CDEF G` | No | ![Supported][supported] | - |
| RO | Romania | 24 | `RO49 AAAA 1B31 0075 9384 0000` | Yes | ![Supported][supported] | - |
| RS | Serbia | 22 | `RS35 2600 0560 1001 6113 79` | No | ![Supported][supported] | - |
Expand All @@ -95,6 +96,7 @@ See the [SWIFT website](https://www.swift.com/standards/data-standards/iban-inte
| VA | Vatican City State | 22 | `VA59 0011 2300 0012 3456 78` | Yes | ![Supported][supported] | - |
| VG | Virgin Islands | 24 | `VG96 VPVG 0000 0123 4567 8901` | No | ![Supported][supported] | - |
| XK | Kosovo | 20 | `XK05 1212 0123 4567 8906` | No | ![Supported][supported] | ![Supported][supported] |
| YE | Yemen | 30 | `YE15 CBYE 0001 0188 6123 4567 8912 34` | No | ![Supported][supported] | ![Supported][supported] |

### Finland includes:

Expand Down
10 changes: 4 additions & 6 deletions SupportedCountries.tt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Providers = { swiftProvider, wikiProvider }
};
var parser = new IbanParser(registry);
var supportedCount = registry.Count;
var supportedCount = registry.Count + registry.Sum(x => x.IncludedCountries.Count);

var comparer = new IbanCountryCodeComparer();
var filteredWikiCountries = wikiProvider.Except(swiftProvider, comparer).OrderBy(c => c.TwoLetterISORegionName);
Expand All @@ -34,15 +34,15 @@

*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 124 countries
# IbanNet supports <#= supportedCount #> countries

## SWIFT registry

See the [SWIFT website](https://www.swift.com/standards/data-standards/iban-international-bank-account-number) for more information.

<# RenderTable(swiftProvider, parser); #>

<# RenderIncludedCountries(swiftProvider, ref supportedCount); #>
<# RenderIncludedCountries(swiftProvider); #>

## Wikipedia

Expand Down Expand Up @@ -91,7 +91,7 @@ private void RenderTable(IEnumerable<IbanCountry> countries, IIbanParser parser)
}
}

private void RenderIncludedCountries(IIbanRegistryProvider provider, ref int supportedCount)
private void RenderIncludedCountries(IIbanRegistryProvider provider)
{
var overrideCountryDescription = new Dictionary<string, string>
{
Expand All @@ -102,8 +102,6 @@ private void RenderIncludedCountries(IIbanRegistryProvider provider, ref int sup
{
if (country.IncludedCountries.Count > 0)
{
supportedCount += country.IncludedCountries.Count;

WriteLine($"### {country.EnglishName} includes:");
WriteLine("");

Expand Down
38 changes: 38 additions & 0 deletions src/IbanNet.CodeGen/Swift/Patches/_8_PakistanDisappearedPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace IbanNet.CodeGen.Swift.Patches;

/// <summary>
/// Somewhere between r95 and r98, Pakistan disappeared from the txt while it is still is documented in the PDF.
/// I am starting to hate the interns at SWIFT. This patches it back in.
/// </summary>
internal sealed record _8_PakistanDisappearedPatch : SwiftCsvRecord
{
public _8_PakistanDisappearedPatch()
{
CountryCode = "PK";
EnglishName = "Pakistan";
Iban = new IbanCsvData
{
Pattern = "2!c2!n4!a16!c",
Length = 24,
ElectronicFormatExample = "PK36SCBL0000001123456702"
};
EffectiveDate = new DateTimeOffset(2012, 12, 1, 0, 0, 0, TimeSpan.Zero);
Bban = new BbanCsvData
{
Pattern = "4!a16!c",
Length = 20,
Example = "SCBL0000001123456702"
};
Bank = new BankCsvData
{
Pattern = "4!a",
Position = new Position { StartPos = 1, EndPos = 4 },
Example = "SCBL"
};
Branch = new BranchCsvData();
Sepa = new SepaCsvData { IsMember = false, OtherTerritories = [] };
OtherTerritories = [];
DomesticExample = "00260101036360";
LastUpdatedDate = new DateTimeOffset(2012, 12, 1, 0, 0, 0, TimeSpan.Zero);
}
}
14 changes: 14 additions & 0 deletions src/IbanNet.CodeGen/Swift/SwiftCsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ public SwiftCsvReader(TextReader reader)
Parser.Context.TypeConverterCache.AddConverter<Position>(new PositionConverter());
typeConverterOptions.AddOptions<Position?>(new TypeConverterOptions { NullValues = { "", "N/A" } });
}

public override IEnumerable<T> GetRecords<T>()
{
IEnumerable<T> insertRecords = [];
if (typeof(T) == typeof(SwiftCsvRecord))
{
insertRecords = typeof(SwiftCsvRecord).Assembly.GetTypes()
.Where(t => t != typeof(SwiftCsvRecord) && typeof(SwiftCsvRecord).IsAssignableFrom(t))
.Select(Activator.CreateInstance)
.Cast<T>();
}

return base.GetRecords<T>().Concat(insertRecords);
}
}
2 changes: 1 addition & 1 deletion src/IbanNet.CodeGen/Swift/SwiftCsvRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace IbanNet.CodeGen.Swift;

public sealed record SwiftCsvRecord
public record SwiftCsvRecord
{
private string _countryCode = default!;

Expand Down

Large diffs are not rendered by default.

Loading
Loading