1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-27 20:18:01 +02:00

Bugfixes for number parsing

This commit is contained in:
Ron Zuckerman 2024-01-14 17:06:43 -06:00
parent d5c336ffab
commit 8bd12814b8
No known key found for this signature in database
GPG key ID: 7EC17CB87028ABF8
11 changed files with 169 additions and 1 deletions

View file

@ -113,6 +113,7 @@ namespace System
return .Err(.NoValue);
bool isNeg = false;
bool digitsFound = false;
int64 result = 0;
int64 radix = style.HasFlag(.Hex) ? 0x10 : 10;
@ -131,6 +132,7 @@ namespace System
{
result &*= radix;
result &+= (int64)(c - '0');
digitsFound = true;
}
else if ((c >= 'a') && (c <= 'f'))
{
@ -138,6 +140,7 @@ namespace System
return .Err(.InvalidChar(result));
result &*= radix;
result &+= c - 'a' + 10;
digitsFound = true;
}
else if ((c >= 'A') && (c <= 'F'))
{
@ -145,12 +148,14 @@ namespace System
return .Err(.InvalidChar(result));
result &*= radix;
result &+= c - 'A' + 10;
digitsFound = true;
}
else if ((c == 'X') || (c == 'x'))
{
if ((!style.HasFlag(.AllowHexSpecifier)) || (i == 0) || (result != 0))
return .Err(.InvalidChar(result));
radix = 0x10;
digitsFound = false;
}
else if (c == '\'')
{
@ -167,6 +172,9 @@ namespace System
return .Err(.Overflow);
}
if (!digitsFound)
return .Err(.NoValue);
return isNeg ? -result : result;
}