jellyfin-server/MediaBrowser.Controller/Library/NameExtensions.cs

42 lines
1.2 KiB
C#
Raw Normal View History

2015-04-09 21:11:57 +00:00
using MediaBrowser.Common.Extensions;
using MoreLinq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Controller.Library
{
public static class NameExtensions
{
public static bool AreEqual(string name1, string name2)
{
name1 = NormalizeForComparison(name1);
name2 = NormalizeForComparison(name2);
return string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase);
}
public static bool EqualsAny(IEnumerable<string> names, string name)
{
name = NormalizeForComparison(name);
return names.Any(i => string.Equals(NormalizeForComparison(i), name, StringComparison.OrdinalIgnoreCase));
}
private static string NormalizeForComparison(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
return string.Empty;
}
return name.RemoveDiacritics();
}
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
{
return names.DistinctBy(NormalizeForComparison, StringComparer.OrdinalIgnoreCase);
}
}
}