Fix subtle number parsing bug

This commit is contained in:
Matt Nadareski
2025-05-13 12:32:15 -04:00
parent 6fc301f49f
commit e82bbdc879

View File

@@ -65,21 +65,23 @@ namespace SabreTools.Core.Tools
// Normalize the string for easier comparison
numeric = numeric!.ToLowerInvariant();
// Parse the numeric string, if possible
if (numeric.StartsWith("0x"))
{
return Convert.ToInt64(numeric.Substring(2), 16);
}
else
{
// 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
long value;
if (numeric.StartsWith("0x"))
value = Convert.ToInt64(numeric, 16);
else if (long.TryParse(numeric, out long longValue))
value = longValue;
else
// Apply the multiplier and return
if (!long.TryParse(numeric, out long longValue))
return null;
// Apply the multiplier and return
return value * multiplier;
return longValue * multiplier;
}
}
/// <summary>