aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Extensions/StringExtensions.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2026-05-04 21:26:26 +0200
committerShadowghost <Ghost_of_Stone@web.de>2026-05-04 21:26:26 +0200
commit57c0fcd674c659c658369f0aebfd5d9d6787a9d4 (patch)
tree7aff23d6f54e913a6a34cb5a2568a07298582444 /src/Jellyfin.Extensions/StringExtensions.cs
parent68ab58589444091925c15ad20d36f935b7bc2e21 (diff)
parentec04313317bed62728b059108cd232e9744f6354 (diff)
Merge remote-tracking branch 'upstream/master' into epg-fixes
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;
+ }
}
}