Use Diacritical.Net library for NameFirstCharacter token

(cherry picked from commit 59ea524e0ce85333779f430b867e93aae366289f)

Closes #4230
pull/4273/head
Stevie Robinson 7 months ago committed by Bogdan
parent 2e91a61ccf
commit 8df5a5011b

@ -42,6 +42,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
[TestCase("¡Mucha Lucha!", "M", "¡Mucha Lucha!")]
[TestCase(".hack", "H", "hack")]
[TestCase("Ütopya", "U", "Ütopya")]
[TestCase("Æon Flux", "A", "Æon Flux")]
public void should_get_expected_folder_name_back(string title, string parent, string child)
{
_artist.Name = title;

@ -4,6 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Diacritical.Net" Version="1.0.4" />
<PackageReference Include="System.Text.Json" Version="6.0.8" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />

@ -4,6 +4,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Diacritical;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Disk;
@ -268,13 +269,13 @@ namespace NzbDrone.Core.Organizer
{
if (char.IsLetterOrDigit(title[0]))
{
return title.Substring(0, 1).ToUpper().RemoveAccent();
return title.Substring(0, 1).ToUpper().RemoveDiacritics()[0].ToString();
}
// Try the second character if the first was non alphanumeric
if (char.IsLetterOrDigit(title[1]))
{
return title.Substring(1, 1).ToUpper().RemoveAccent();
return title.Substring(1, 1).ToUpper().RemoveDiacritics()[0].ToString();
}
// Default to "_" if no alphanumeric character can be found in the first 2 positions

Loading…
Cancel
Save