|
|
|
@ -15,6 +15,12 @@ namespace NzbDrone.Core.Parser
|
|
|
|
|
{
|
|
|
|
|
public static class StringUtil
|
|
|
|
|
{
|
|
|
|
|
private static readonly Regex WordDelimiterRegex = new Regex(@"(\s|\.|,|_|-|=|'|\|)+", RegexOptions.Compiled);
|
|
|
|
|
private static readonly Regex SpecialCharRegex = new Regex(@"(\&|\:|\\|\/)+", RegexOptions.Compiled);
|
|
|
|
|
private static readonly Regex PunctuationRegex = new Regex(@"[^\w\s]", RegexOptions.Compiled);
|
|
|
|
|
private static readonly Regex CommonWordRegex = new Regex(@"\b(a|an|the|and|or|of)\b\s?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
private static readonly Regex DuplicateSpacesRegex = new Regex(@"\s{2,}", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
public static string CleanFileName(string name, bool replace = true)
|
|
|
|
|
{
|
|
|
|
|
string result = name;
|
|
|
|
@ -248,5 +254,16 @@ namespace NzbDrone.Core.Parser
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string NormalizeTitle(this string title)
|
|
|
|
|
{
|
|
|
|
|
title = WordDelimiterRegex.Replace(title, " ");
|
|
|
|
|
title = PunctuationRegex.Replace(title, string.Empty);
|
|
|
|
|
title = CommonWordRegex.Replace(title, string.Empty);
|
|
|
|
|
title = DuplicateSpacesRegex.Replace(title, " ");
|
|
|
|
|
title = SpecialCharRegex.Replace(title, string.Empty);
|
|
|
|
|
|
|
|
|
|
return title.Trim().ToLower();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|