mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Implemented users update button in frontend
This commit is contained in:
44
src/Helpers/UsersHelper.cs
Normal file
44
src/Helpers/UsersHelper.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
namespace Berufsschule_HAM.Helpers;
|
||||
|
||||
public static partial class UsersHelper
|
||||
{
|
||||
public static string CreateUsername(string givenName, string surname)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(givenName) || string.IsNullOrWhiteSpace(surname))
|
||||
throw new ArgumentException("Given name and surname must not be empty.");
|
||||
|
||||
string combined = (surname + givenName).ToLowerInvariant();
|
||||
|
||||
// Normalize to decompose accents (e.g., é -> e + ́)
|
||||
string normalized = combined.Normalize(NormalizationForm.FormD);
|
||||
|
||||
// Remove diacritics
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in normalized)
|
||||
{
|
||||
var category = CharUnicodeInfo.GetUnicodeCategory(c);
|
||||
if (category != UnicodeCategory.NonSpacingMark)
|
||||
sb.Append(c);
|
||||
}
|
||||
|
||||
string cleaned = sb.ToString();
|
||||
|
||||
// Replace German ligatures etc.
|
||||
cleaned = cleaned
|
||||
.Replace("ß", "ss")
|
||||
.Replace("æ", "ae")
|
||||
.Replace("œ", "oe")
|
||||
.Replace("ø", "o");
|
||||
|
||||
// Remove everything not a-z
|
||||
cleaned = AtoZ().Replace(cleaned, "");
|
||||
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
[GeneratedRegex("[^a-z]")]
|
||||
private static partial Regex AtoZ();
|
||||
}
|
||||
Reference in New Issue
Block a user