kreta/Kreta.BusinessLogic/Extensions/NameExtensions.cs
2024-03-13 00:33:46 +01:00

30 lines
1.1 KiB
C#

using System;
using System.Text.RegularExpressions;
using Kreta.Core;
namespace Kreta.BusinessLogic.Extensions
{
public static class NameExtensions
{
public static string CleanElotag(this string elotag)
{
var trimmed = elotag.ReplaceMultipleSpacesAndTrim();
if (string.IsNullOrWhiteSpace(trimmed))
{
return trimmed;
}
return GetStringWithoutDuplicatedDots(trimmed);
}
public static string GetNevSorrendben(string nevSorrend, string nevElotag, string vezetekNev, string keresztNev)
=> $"{nevElotag} {(string.Equals(nevSorrend, "F", StringComparison.OrdinalIgnoreCase) ? $"{vezetekNev} {keresztNev}" : $"{keresztNev} {vezetekNev}")}".ReplaceMultipleSpacesAndTrim();
private static string GetStringWithoutDuplicatedDots(string text)
=> NullableRegexReplace(text, @"\.+", ".");
private static string NullableRegexReplace(this string text, string pattern, string replacement)
=> string.IsNullOrWhiteSpace(text) ? text : Regex.Replace(text, pattern, replacement);
}
}