2013-11-07 01:48:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Organizer
|
|
|
|
|
{
|
|
|
|
|
public class FilenameBuilderTokenEqualityComparer : IEqualityComparer<String>
|
|
|
|
|
{
|
2013-11-14 02:02:27 +00:00
|
|
|
|
public static readonly FilenameBuilderTokenEqualityComparer Instance = new FilenameBuilderTokenEqualityComparer();
|
|
|
|
|
|
2013-11-07 01:48:51 +00:00
|
|
|
|
private static readonly Regex SimpleTokenRegex = new Regex(@"\s|_|\W", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
2013-11-14 02:02:27 +00:00
|
|
|
|
private FilenameBuilderTokenEqualityComparer()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 01:48:51 +00:00
|
|
|
|
public bool Equals(String s1, String s2)
|
|
|
|
|
{
|
|
|
|
|
return SimplifyToken(s1).Equals(SimplifyToken(s2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetHashCode(String str)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
return SimpleTokenRegex.Replace(token, String.Empty).ToLower();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|