This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a97709
commit 9f7ce8d
Showing
6 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Xml; | ||
|
||
namespace libfintx.Sepa.Helper | ||
{ | ||
public static class SepaHelper | ||
{ | ||
public static string Escape(string str) | ||
{ | ||
// Zunächst XML-escapen | ||
var escaped = SecurityElement.Escape(str); | ||
// Dann sicherstellen, dass nur gemäß SEPA gültige Zeichen verwendet werden | ||
return ConvertToValidSepaString(escaped); | ||
} | ||
|
||
public static string ConvertToValidSepaString(string str) | ||
{ | ||
return new string(str.Select(c => ConvertToValidSepaString(c)).SelectMany(s => s).ToArray()); | ||
} | ||
|
||
/// <summary> | ||
/// Hier findet kein XML-Escaping statt, sondern es wird sichergestellt, dass nur die in SEPA gültigen Zeichen verwendet werden. | ||
/// </summary> | ||
/// <param name="c"></param> | ||
/// <returns></returns> | ||
private static string ConvertToValidSepaString(char c) | ||
{ | ||
switch (c) | ||
{ | ||
case 'Ä': return "Ae"; | ||
case 'Ö': return "Oe"; | ||
case 'Ü': return "Ue"; | ||
case 'ä': return "ae"; | ||
case 'ö': return "oe"; | ||
case 'ü': return "ue"; | ||
case 'ß': return "ss"; | ||
} | ||
|
||
if (!Regex.Match($"{c}", @"^[\sa-zA-Z0-9/?:\(\)\.,'+-]$").Success) | ||
return string.Empty; | ||
|
||
return $"{c}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters