|
|
|
@ -165,5 +165,28 @@ namespace NzbDrone.Common.Extensions
|
|
|
|
|
{
|
|
|
|
|
return source.Contains(value, StringComparer.InvariantCultureIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ToUrlSlug(this string value)
|
|
|
|
|
{
|
|
|
|
|
//First to lower case
|
|
|
|
|
value = value.ToLowerInvariant();
|
|
|
|
|
|
|
|
|
|
//Remove all accents
|
|
|
|
|
value = value.RemoveAccent();
|
|
|
|
|
|
|
|
|
|
//Replace spaces
|
|
|
|
|
value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
//Remove invalid chars
|
|
|
|
|
value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
//Trim dashes from end
|
|
|
|
|
value = value.Trim('-', '_');
|
|
|
|
|
|
|
|
|
|
//Replace double occurences of - or _
|
|
|
|
|
value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|