update artist lists

This commit is contained in:
Luke Pulverenti 2016-11-29 14:13:01 -05:00
parent 61e195c096
commit c80ac9b823

View File

@ -2,6 +2,7 @@
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using Emby.Server.Implementations.Localization; using Emby.Server.Implementations.Localization;
namespace Emby.Server.Core.Localization namespace Emby.Server.Core.Localization
@ -10,11 +11,41 @@ namespace Emby.Server.Core.Localization
{ {
public string RemoveDiacritics(string text) public string RemoveDiacritics(string text)
{ {
return String.Concat( if (text == null)
text.Normalize(NormalizationForm.FormD) {
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != throw new ArgumentNullException("text");
UnicodeCategory.NonSpacingMark) }
).Normalize(NormalizationForm.FormC);
var chars = Normalize(text, NormalizationForm.FormD)
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark);
return Normalize(String.Concat(chars), NormalizationForm.FormC);
}
private static string Normalize(string text, NormalizationForm form, bool stripStringOnFailure = true)
{
if (stripStringOnFailure)
{
try
{
return text.Normalize(form);
}
catch (ArgumentException)
{
// will throw if input contains invalid unicode chars
// https://mnaoumov.wordpress.com/2014/06/14/stripping-invalid-characters-from-utf-16-strings/
text = StripInvalidUnicodeCharacters(text);
return Normalize(text, form, false);
}
}
return text.Normalize(form);
}
private static string StripInvalidUnicodeCharacters(string str)
{
var invalidCharactersRegex = new Regex("([\ud800-\udbff](?![\udc00-\udfff]))|((?<![\ud800-\udbff])[\udc00-\udfff])");
return invalidCharactersRegex.Replace(str, "");
} }
public string NormalizeFormKD(string text) public string NormalizeFormKD(string text)