aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Extensions/StringExtensions.cs
diff options
context:
space:
mode:
authorKGT1 <kilian.gamn@gmx.de>2026-05-03 22:35:57 +0200
committerGitHub <noreply@github.com>2026-05-03 22:35:57 +0200
commit4464b2e2ed9d8cc3f4c520ee76dfedac3557cf0d (patch)
tree4fdf6dc5fff74c21b3b2cd74c1d3d5fd695b0638 /src/Jellyfin.Extensions/StringExtensions.cs
parent950c6525d1ab456115c4ee80b8fed86c5a81eaf5 (diff)
parent622947e37425f3620432995cde5d4a0809d91694 (diff)
Merge branch 'jellyfin:master' into removeGenericConfigurationEndpoint
Diffstat (limited to 'src/Jellyfin.Extensions/StringExtensions.cs')
-rw-r--r--src/Jellyfin.Extensions/StringExtensions.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs
index c7e8319f59..906efbcbcc 100644
--- a/src/Jellyfin.Extensions/StringExtensions.cs
+++ b/src/Jellyfin.Extensions/StringExtensions.cs
@@ -148,5 +148,30 @@ namespace Jellyfin.Extensions
{
return string.IsNullOrEmpty(text) ? text : text.AsSpan().LeftPart('\0').ToString();
}
+
+ /// <summary>
+ /// Normalizes a string for comparison by removing diacritics, converting to lowercase,
+ /// replacing punctuation/special characters with spaces, and collapsing whitespace.
+ /// </summary>
+ /// <param name="value">The string to normalize.</param>
+ /// <returns>The normalized string, or the original if null/whitespace.</returns>
+ public static string GetCleanValue(this string value)
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ return value;
+ }
+
+ // Remove diacritics and convert to lowercase
+ var cleaned = value.RemoveDiacritics().ToLowerInvariant();
+
+ // Replace all punctuation and special characters with spaces
+ cleaned = Regex.Replace(cleaned, @"[^\p{L}\p{N}\s]", " ");
+
+ // Collapse multiple spaces into single space and trim
+ cleaned = Regex.Replace(cleaned, @"\s+", " ").Trim();
+
+ return cleaned;
+ }
}
}