mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-22 22:14:44 -04:00
5428d9d53f
- Added specific rejection code for 32 random characters to ignore all md5 and mixed-case hashes. - Added NZBGeek hash format. - Removed -RP from Release Group. - Added test and fix for reversed title. Currently matching it based on a couple of patterns.
69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace NzbDrone.Common
|
|
{
|
|
public static class StringExtensions
|
|
{
|
|
public static string NullSafe(this string target)
|
|
{
|
|
return ((object)target).NullSafe().ToString();
|
|
}
|
|
|
|
public static object NullSafe(this object target)
|
|
{
|
|
if (target != null) return target;
|
|
return "[NULL]";
|
|
}
|
|
|
|
public static string FirstCharToUpper(this string input)
|
|
{
|
|
return input.First().ToString().ToUpper() + String.Join("", input.Skip(1));
|
|
}
|
|
|
|
public static string Inject(this string format, params object[] formattingArgs)
|
|
{
|
|
return string.Format(format, formattingArgs);
|
|
}
|
|
|
|
private static readonly Regex CollapseSpace = new Regex(@"\s+", RegexOptions.Compiled);
|
|
|
|
public static string RemoveAccent(this string text)
|
|
{
|
|
var normalizedString = text.Normalize(NormalizationForm.FormD);
|
|
var stringBuilder = new StringBuilder();
|
|
|
|
foreach (var c in normalizedString)
|
|
{
|
|
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
|
|
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
|
|
{
|
|
stringBuilder.Append(c);
|
|
}
|
|
}
|
|
|
|
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
|
|
}
|
|
|
|
public static string TrimEnd(this string text, string postfix)
|
|
{
|
|
if (text.EndsWith(postfix))
|
|
text = text.Substring(0, text.Length - postfix.Length);
|
|
|
|
return text;
|
|
}
|
|
|
|
public static string CleanSpaces(this string text)
|
|
{
|
|
return CollapseSpace.Replace(text, " ").Trim();
|
|
}
|
|
|
|
public static bool IsNullOrWhiteSpace(this string text)
|
|
{
|
|
return String.IsNullOrWhiteSpace(text);
|
|
}
|
|
}
|
|
} |