Intermediate commit

This commit is contained in:
pcjones
2024-02-12 21:04:18 +01:00
parent 0071b0c080
commit 4ca89f8bdd
14 changed files with 624 additions and 135 deletions

View File

@@ -1,9 +1,10 @@
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
namespace UmlautAdaptarr.Utilities
{
public static class Extensions
public static partial class Extensions
{
public static string GetQuery(this HttpContext context, string key)
{
@@ -46,11 +47,18 @@ namespace UmlautAdaptarr.Utilities
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
// TODO possibly replace GetCleanTitle with RemoveSpecialCharacters
public static string GetCleanTitle(this string text)
{
return text.Replace("(", "").Replace(")", "").Replace("?","").Replace(":", "").Replace("'", "");
}
public static string RemoveSpecialCharacters(this string text)
{
return SpecialCharactersRegex().Replace(text, "");
}
public static string ReplaceGermanUmlautsWithLatinEquivalents(this string text)
{
return text
@@ -75,11 +83,22 @@ namespace UmlautAdaptarr.Utilities
.Replace("ß", "ss");
}
public static bool HasGermanUmlauts(this string text)
public static string RemoveExtraWhitespaces(this string text)
{
return MultipleWhitespaceRegex().Replace(text, " ");
}
public static bool HasUmlauts(this string text)
{
if (text == null) return false;
var umlauts = new[] { 'ö', 'ä', 'ü', 'Ä', 'Ü', 'Ö', 'ß' };
return umlauts.Any(text.Contains);
}
[GeneratedRegex("[^a-zA-Z0-9 ]+", RegexOptions.Compiled)]
private static partial Regex SpecialCharactersRegex();
[GeneratedRegex(@"\s+")]
private static partial Regex MultipleWhitespaceRegex();
}
}