Skip to content

flxbe/Din91379-csharp

Repository files navigation

Din91379-csharp

GitHub license ci nuget

A C# implementation of DIN 91379:2022-08, the replacement of DIN SPEC 91379:2019-03 (also known as String.Latin+ 1.2).

  • Strict: All data types are Unicode NFC normalized and contain only characters and sequences from DIN 91379. Any string containing invalid glyphs is rejected.
  • Easy to use: The data types have a familiar string-like interface. Normalization to Unicode NFC is done automatically. The data types TypeA, TypeB and TypeC support the conversion to the canonical search form.
  • Efficient: The custom validation algorithm is up to 4x faster than using compiled regular expressions.
  • Tested: The implementation is fully tested against the complete latinchars.xml dataset as attached in DIN SPEC 91379:2019-03, extended by the newly introduced characters in DIN 91379:2022-08.

Getting Started

The library is available as a NuGet package.

dotnet add package Din91379

Instances of the provided data types can be easily generated from string values.

using Din91379;

TypeA name = TypeA.FromString("Nœl Schmidt-Strauß");
TypeB streetName = TypeB.FromString("Karl-Bröger Straße 17");

Using invalid characters will throw an error.

// Din91379.InvalidGlyphException: Found invalid glyph '1' in 'Karl-Bröger Straße 17'
TypeA.FromString("Karl-Bröger Straße 17");

The search form of a string can be derived for the data types TypeA, TypeB and TypeC.

TypeA variant1 = TypeA.FromString("Nœl Schmidt-Strauß");
TypeA variant2 = TypeA.FromString("Noël Schmidt-Strauß");

Console.WriteLine(variant1.GetSearchForm()); // Output: NOEL SCHMIDT-STRAUSS
Console.WriteLine(variant2.GetSearchForm()); // Output: NOEL SCHMIDT-STRAUSS

Compatibility with DIN SPEC 91379

DIN 91379:2022-08 added a few new characters which are not specified in DIN SPEC 91379:2019-03. The compatibility of a specific value with the replaced standard can be easily checked.

TypeA value = TypeA.FromString("Hē̍llō̍");

Console.WriteLine(value.IsDinSpec91379Compatible()); // Output: False

License

MIT License

Copyright (c) 2022 Felix Bernhardt

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A C# implementation of DIN 91379

Topics

Resources

License

Stars

Watchers

Forks

Languages