mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 11:14:23 +00:00
Fix subtle number parsing bug
This commit is contained in:
@@ -65,21 +65,23 @@ namespace SabreTools.Core.Tools
|
|||||||
// Normalize the string for easier comparison
|
// Normalize the string for easier comparison
|
||||||
numeric = numeric!.ToLowerInvariant();
|
numeric = numeric!.ToLowerInvariant();
|
||||||
|
|
||||||
// Get the multiplication modifier and trim characters
|
|
||||||
long multiplier = DetermineMultiplier(numeric);
|
|
||||||
numeric = numeric.TrimEnd(['k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ']);
|
|
||||||
|
|
||||||
// Parse the numeric string, if possible
|
// Parse the numeric string, if possible
|
||||||
long value;
|
|
||||||
if (numeric.StartsWith("0x"))
|
if (numeric.StartsWith("0x"))
|
||||||
value = Convert.ToInt64(numeric, 16);
|
{
|
||||||
else if (long.TryParse(numeric, out long longValue))
|
return Convert.ToInt64(numeric.Substring(2), 16);
|
||||||
value = longValue;
|
}
|
||||||
else
|
else
|
||||||
return null;
|
{
|
||||||
|
// Get the multiplication modifier and trim characters
|
||||||
|
long multiplier = DetermineMultiplier(numeric);
|
||||||
|
numeric = numeric.TrimEnd(['k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ']);
|
||||||
|
|
||||||
// Apply the multiplier and return
|
// Apply the multiplier and return
|
||||||
return value * multiplier;
|
if (!long.TryParse(numeric, out long longValue))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return longValue * multiplier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user