diff --git a/SabreTools.Filtering/Filter.cs b/SabreTools.Filtering/Filter.cs index 29fdc16c..eecf286a 100644 --- a/SabreTools.Filtering/Filter.cs +++ b/SabreTools.Filtering/Filter.cs @@ -15,36 +15,6 @@ namespace SabreTools.Filtering /// public class Filter { - #region Constants - - #region Byte (1000-based) size comparisons - - private const long KiloByte = 1000; - private readonly static long MegaByte = (long)Math.Pow(KiloByte, 2); - private readonly static long GigaByte = (long)Math.Pow(KiloByte, 3); - private readonly static long TeraByte = (long)Math.Pow(KiloByte, 4); - private readonly static long PetaByte = (long)Math.Pow(KiloByte, 5); - private readonly static long ExaByte = (long)Math.Pow(KiloByte, 6); - private readonly static long ZettaByte = (long)Math.Pow(KiloByte, 7); - private readonly static long YottaByte = (long)Math.Pow(KiloByte, 8); - - #endregion - - #region Byte (1024-based) size comparisons - - private const long KibiByte = 1024; - private readonly static long MibiByte = (long)Math.Pow(KibiByte, 2); - private readonly static long GibiByte = (long)Math.Pow(KibiByte, 3); - private readonly static long TibiByte = (long)Math.Pow(KibiByte, 4); - private readonly static long PibiByte = (long)Math.Pow(KibiByte, 5); - private readonly static long ExiByte = (long)Math.Pow(KibiByte, 6); - private readonly static long ZittiByte = (long)Math.Pow(KibiByte, 7); - private readonly static long YittiByte = (long)Math.Pow(KibiByte, 8); - - #endregion - - #endregion - #region Fields /// @@ -246,7 +216,7 @@ namespace SabreTools.Filtering operation = null; string valueString = value.TrimStart('>', '<', '='); - long? valueLong = ToSize(valueString); + long? valueLong = NumberHelper.ConvertToInt64(valueString); if (valueLong == null) return; @@ -302,65 +272,6 @@ namespace SabreTools.Filtering filterItem.PositiveSet.Add(value); } - /// - /// Get the multiplier to be used with the size given - /// - /// String with possible size with extension - /// Tuple of multiplier to use on final size and fixed size string - private static long? ToSize(string sizestring) - { - // If the string is null or empty, we return -1 - if (string.IsNullOrWhiteSpace(sizestring)) - return null; - - // Make sure the string is in lower case - sizestring = sizestring.ToLowerInvariant(); - - // Get any trailing size identifiers - long multiplier = 1; - if (sizestring.EndsWith("k") || sizestring.EndsWith("kb")) - multiplier = KiloByte; - else if (sizestring.EndsWith("ki") || sizestring.EndsWith("kib")) - multiplier = KibiByte; - else if (sizestring.EndsWith("m") || sizestring.EndsWith("mb")) - multiplier = MegaByte; - else if (sizestring.EndsWith("mi") || sizestring.EndsWith("mib")) - multiplier = MibiByte; - else if (sizestring.EndsWith("g") || sizestring.EndsWith("gb")) - multiplier = GigaByte; - else if (sizestring.EndsWith("gi") || sizestring.EndsWith("gib")) - multiplier = GibiByte; - else if (sizestring.EndsWith("t") || sizestring.EndsWith("tb")) - multiplier = TeraByte; - else if (sizestring.EndsWith("ti") || sizestring.EndsWith("tib")) - multiplier = TibiByte; - else if (sizestring.EndsWith("p") || sizestring.EndsWith("pb")) - multiplier = PetaByte; - else if (sizestring.EndsWith("pi") || sizestring.EndsWith("pib")) - multiplier = PibiByte; - else if (sizestring.EndsWith("e") || sizestring.EndsWith("eb")) - multiplier = ExaByte; - else if (sizestring.EndsWith("ei") || sizestring.EndsWith("eib")) - multiplier = ExiByte; - else if (sizestring.EndsWith("z") || sizestring.EndsWith("zb")) - multiplier = ZettaByte; - else if (sizestring.EndsWith("zi") || sizestring.EndsWith("zib")) - multiplier = ZittiByte; - else if (sizestring.EndsWith("y") || sizestring.EndsWith("yb")) - multiplier = YottaByte; - else if (sizestring.EndsWith("yi") || sizestring.EndsWith("yib")) - multiplier = YittiByte; - - // Remove any trailing identifiers - sizestring = sizestring.TrimEnd(new char[] { 'k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ' }); - - // Now try to get the size from the string - if (!Int64.TryParse(sizestring, out long size)) - return null; - else - return size * multiplier; - } - #endregion #region Running