mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
ParseUtil Cleanup
This commit is contained in:
@@ -20,5 +20,19 @@ namespace NzbDrone.Core.Test.ParserTests
|
||||
{
|
||||
ParseUtil.GetBytes(stringSize).Should().Be(size);
|
||||
}
|
||||
|
||||
[TestCase(" some string ", "some string")]
|
||||
public void should_normalize_multiple_spaces(string original, string newString)
|
||||
{
|
||||
ParseUtil.NormalizeMultiSpaces(original).Should().Be(newString);
|
||||
}
|
||||
|
||||
[TestCase("1", 1)]
|
||||
[TestCase("11", 11)]
|
||||
[TestCase("1000 grabs", 1000)]
|
||||
public void should_parse_int_from_string(string original, int parsedInt)
|
||||
{
|
||||
ParseUtil.CoerceInt(original).Should().Be(parsedInt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -220,7 +220,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
value = selection.TextContent;
|
||||
}
|
||||
|
||||
return ApplyFilters(ParseUtil.NormalizeSpace(value), selector.Filters, variables);
|
||||
return ApplyFilters(value.Trim(), selector.Filters, variables);
|
||||
}
|
||||
|
||||
protected string HandleJsonSelector(SelectorBlock selector, JToken parentObj, Dictionary<string, object> variables = null, bool required = true)
|
||||
@@ -271,7 +271,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
}
|
||||
}
|
||||
|
||||
return ApplyFilters(ParseUtil.NormalizeSpace(value), selector.Filters, variables);
|
||||
return ApplyFilters(value.Trim(), selector.Filters, variables);
|
||||
}
|
||||
|
||||
protected Dictionary<string, object> GetBaseTemplateVariables()
|
||||
|
@@ -121,7 +121,7 @@ namespace NzbDrone.Core.Parser
|
||||
{
|
||||
try
|
||||
{
|
||||
str = ParseUtil.NormalizeSpace(str);
|
||||
str = str.Trim();
|
||||
if (str.ToLower().Contains("now"))
|
||||
{
|
||||
return DateTime.UtcNow;
|
||||
@@ -254,7 +254,7 @@ namespace NzbDrone.Core.Parser
|
||||
// converts a date/time string to a DateTime object using a GoLang layout
|
||||
public static DateTime ParseDateTimeGoLang(string date, string layout)
|
||||
{
|
||||
date = ParseUtil.NormalizeSpace(date);
|
||||
date = date.Trim();
|
||||
var pattern = layout;
|
||||
|
||||
// year
|
||||
|
@@ -13,18 +13,16 @@ namespace NzbDrone.Core.Parser
|
||||
RegexOptions.Compiled);
|
||||
private static readonly Regex ImdbId = new Regex(@"^(?:tt)?(\d{1,8})$", RegexOptions.Compiled);
|
||||
|
||||
public static string NormalizeSpace(string s) => s.Trim();
|
||||
|
||||
public static string NormalizeMultiSpaces(string s) =>
|
||||
new Regex(@"\s+").Replace(NormalizeSpace(s), " ");
|
||||
new Regex(@"\s+").Replace(s.Trim(), " ");
|
||||
|
||||
public static string NormalizeNumber(string s)
|
||||
private static string NormalizeNumber(string s)
|
||||
{
|
||||
var valStr = new string(s.Where(c => char.IsDigit(c) || c == '.' || c == ',').ToArray());
|
||||
|
||||
valStr = (valStr.Length == 0) ? "0" : valStr.Replace(",", ".");
|
||||
|
||||
valStr = NormalizeSpace(valStr).Replace("-", "0");
|
||||
valStr = valStr.Trim().Replace("-", "0");
|
||||
|
||||
if (valStr.Count(c => c == '.') > 1)
|
||||
{
|
||||
@@ -120,7 +118,7 @@ namespace NzbDrone.Core.Parser
|
||||
return GetBytes(unit, val);
|
||||
}
|
||||
|
||||
public static long GetBytes(string unit, float value)
|
||||
private static long GetBytes(string unit, float value)
|
||||
{
|
||||
unit = unit.Replace("i", "").ToLowerInvariant();
|
||||
if (unit.Contains("kb"))
|
||||
@@ -146,12 +144,12 @@ namespace NzbDrone.Core.Parser
|
||||
return (long)value;
|
||||
}
|
||||
|
||||
public static long BytesFromTB(float tb) => BytesFromGB(tb * 1024f);
|
||||
private static long BytesFromTB(float tb) => BytesFromGB(tb * 1024f);
|
||||
|
||||
public static long BytesFromGB(float gb) => BytesFromMB(gb * 1024f);
|
||||
private static long BytesFromGB(float gb) => BytesFromMB(gb * 1024f);
|
||||
|
||||
public static long BytesFromMB(float mb) => BytesFromKB(mb * 1024f);
|
||||
private static long BytesFromMB(float mb) => BytesFromKB(mb * 1024f);
|
||||
|
||||
public static long BytesFromKB(float kb) => (long)(kb * 1024f);
|
||||
private static long BytesFromKB(float kb) => (long)(kb * 1024f);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user