2016-12-23 21:45:24 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-11-07 01:48:51 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Organizer
|
|
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
|
public class FileNameBuilderTokenEqualityComparer : IEqualityComparer<string>
|
2013-11-07 01:48:51 +00:00
|
|
|
|
{
|
2014-07-28 21:14:34 +00:00
|
|
|
|
public static readonly FileNameBuilderTokenEqualityComparer Instance = new FileNameBuilderTokenEqualityComparer();
|
2013-11-14 02:02:27 +00:00
|
|
|
|
|
2013-11-07 01:48:51 +00:00
|
|
|
|
private static readonly Regex SimpleTokenRegex = new Regex(@"\s|_|\W", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
2014-07-28 21:14:34 +00:00
|
|
|
|
private FileNameBuilderTokenEqualityComparer()
|
2013-11-14 02:02:27 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
|
public bool Equals(string s1, string s2)
|
2013-11-07 01:48:51 +00:00
|
|
|
|
{
|
|
|
|
|
return SimplifyToken(s1).Equals(SimplifyToken(s2));
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
|
public int GetHashCode(string str)
|
2013-11-07 01:48:51 +00:00
|
|
|
|
{
|
|
|
|
|
return SimplifyToken(str).GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-14 02:02:27 +00:00
|
|
|
|
private static string SimplifyToken(string token)
|
2013-11-07 01:48:51 +00:00
|
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
|
return SimpleTokenRegex.Replace(token, string.Empty).ToLower();
|
2013-11-07 01:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|