Use Diacritics.NET

Last time we had to revert this due to regressions, now those regression
tests seem to succeed with a newer version of Diacritics.NET
This commit is contained in:
Bond_009 2022-12-27 16:53:58 +01:00
parent f2200c97cb
commit 6bf131b270
5 changed files with 14 additions and 23 deletions

View File

@ -444,8 +444,8 @@ namespace MediaBrowser.Providers.Manager
}
}
if ((originalPremiereDate ?? DateTime.MinValue) != (item.PremiereDate ?? DateTime.MinValue) ||
(originalProductionYear ?? -1) != (item.ProductionYear ?? -1))
if ((originalPremiereDate ?? DateTime.MinValue) != (item.PremiereDate ?? DateTime.MinValue)
|| (originalProductionYear ?? -1) != (item.ProductionYear ?? -1))
{
updateType |= ItemUpdateType.MetadataEdit;
}

View File

@ -27,6 +27,11 @@
<Compile Include="../../SharedVersion.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Diacritics" Version="3.3.14" />
</ItemGroup>
<!-- Code Analyzers-->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3">

View File

@ -20,23 +20,8 @@ namespace Jellyfin.Extensions
/// <param name="text">The string to act on.</param>
/// <returns>The string without diacritics character.</returns>
public static string RemoveDiacritics(this string text)
{
string withDiactritics = _nonConformingUnicode
.Replace(text, string.Empty)
.Normalize(NormalizationForm.FormD);
var withoutDiactritics = new StringBuilder();
foreach (char c in withDiactritics)
{
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(c);
if (uc != UnicodeCategory.NonSpacingMark)
{
withoutDiactritics.Append(c);
}
}
return withoutDiactritics.ToString().Normalize(NormalizationForm.FormC);
}
=> Diacritics.Extensions.StringExtensions.RemoveDiacritics(
_nonConformingUnicode.Replace(text, string.Empty));
/// <summary>
/// Checks whether or not the specified string has diacritics in it.
@ -44,9 +29,8 @@ namespace Jellyfin.Extensions
/// <param name="text">The string to check.</param>
/// <returns>True if the string has diacritics, false otherwise.</returns>
public static bool HasDiacritics(this string text)
{
return !string.Equals(text, text.RemoveDiacritics(), StringComparison.Ordinal);
}
=> Diacritics.Extensions.StringExtensions.HasDiacritics(text)
|| _nonConformingUnicode.IsMatch(text);
/// <summary>
/// Counts the number of occurrences of [needle] in the string.

View File

@ -23,7 +23,7 @@ namespace Jellyfin.Extensions.Tests
{
var copy = strings.Reverse().ToArray();
Array.Sort(copy, new AlphanumericComparator());
Assert.True(strings.SequenceEqual(copy));
Assert.Equal(strings, copy);
}
}
}

View File

@ -9,6 +9,7 @@ namespace Jellyfin.Extensions.Tests
[InlineData("", "")] // Identity edge-case (no diactritics)
[InlineData("Indiana Jones", "Indiana Jones")] // Identity (no diactritics)
[InlineData("a\ud800b", "ab")] // Invalid UTF-16 char stripping
[InlineData("åäö", "aao")] // Issue #7484
[InlineData("Jön", "Jon")] // Issue #7484
[InlineData("Jönssonligan", "Jonssonligan")] // Issue #7484
[InlineData("Kieślowski", "Kieslowski")] // Issue #7450
@ -25,6 +26,7 @@ namespace Jellyfin.Extensions.Tests
[InlineData("", false)] // Identity edge-case (no diactritics)
[InlineData("Indiana Jones", false)] // Identity (no diactritics)
[InlineData("a\ud800b", true)] // Invalid UTF-16 char stripping
[InlineData("åäö", true)] // Issue #7484
[InlineData("Jön", true)] // Issue #7484
[InlineData("Jönssonligan", true)] // Issue #7484
[InlineData("Kieślowski", true)] // Issue #7450