mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Fixed: (Cardigann) Number normalize to ignore non-digits
This commit is contained in:
@@ -20,17 +20,19 @@ namespace NzbDrone.Core.Parser
|
|||||||
|
|
||||||
public static string NormalizeNumber(string s)
|
public static string NormalizeNumber(string s)
|
||||||
{
|
{
|
||||||
s = (s.Length == 0) ? "0" : s.Replace(",", ".");
|
var valStr = new string(s.Where(c => char.IsDigit(c) || c == '.' || c == ',').ToArray());
|
||||||
|
|
||||||
s = NormalizeSpace(s).Replace("-", "0");
|
valStr = (valStr.Length == 0) ? "0" : valStr.Replace(",", ".");
|
||||||
|
|
||||||
if (s.Count(c => c == '.') > 1)
|
valStr = NormalizeSpace(valStr).Replace("-", "0");
|
||||||
|
|
||||||
|
if (valStr.Count(c => c == '.') > 1)
|
||||||
{
|
{
|
||||||
var lastOcc = s.LastIndexOf('.');
|
var lastOcc = valStr.LastIndexOf('.');
|
||||||
s = s.Substring(0, lastOcc).Replace(".", string.Empty) + s.Substring(lastOcc);
|
valStr = valStr.Substring(0, lastOcc).Replace(".", string.Empty) + valStr.Substring(lastOcc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return valStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RemoveInvalidXmlChars(string text) => string.IsNullOrEmpty(text) ? "" : InvalidXmlChars.Replace(text, "");
|
public static string RemoveInvalidXmlChars(string text) => string.IsNullOrEmpty(text) ? "" : InvalidXmlChars.Replace(text, "");
|
||||||
@@ -113,9 +115,8 @@ namespace NzbDrone.Core.Parser
|
|||||||
|
|
||||||
public static long GetBytes(string str)
|
public static long GetBytes(string str)
|
||||||
{
|
{
|
||||||
var valStr = new string(str.Where(c => char.IsDigit(c) || c == '.' || c == ',').ToArray());
|
|
||||||
var unit = new string(str.Where(char.IsLetter).ToArray());
|
var unit = new string(str.Where(char.IsLetter).ToArray());
|
||||||
var val = CoerceFloat(valStr);
|
var val = CoerceFloat(str);
|
||||||
return GetBytes(unit, val);
|
return GetBytes(unit, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user