mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-26 11:38:02 +02:00
Bugfixes for number parsing
This commit is contained in:
parent
d5c336ffab
commit
8bd12814b8
11 changed files with 169 additions and 1 deletions
|
@ -83,6 +83,7 @@ namespace System
|
|||
return .Err(.NoValue);
|
||||
|
||||
bool isNeg = false;
|
||||
bool digitsFound = false;
|
||||
int8 result = 0;
|
||||
|
||||
int8 radix = style.HasFlag(.Hex) ? 0x10 : 10;
|
||||
|
@ -101,6 +102,7 @@ namespace System
|
|||
{
|
||||
result &*= radix;
|
||||
result &+= (int8)(c - '0');
|
||||
digitsFound = true;
|
||||
}
|
||||
else if ((c >= 'a') && (c <= 'f'))
|
||||
{
|
||||
|
@ -108,6 +110,7 @@ namespace System
|
|||
return .Err(.InvalidChar(result));
|
||||
result &*= radix;
|
||||
result &+= (int8)(c - 'a' + 10);
|
||||
digitsFound = true;
|
||||
}
|
||||
else if ((c >= 'A') && (c <= 'F'))
|
||||
{
|
||||
|
@ -115,12 +118,14 @@ namespace System
|
|||
return .Err(.InvalidChar(result));
|
||||
result &*= radix;
|
||||
result &+= (int8)(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 == '\'')
|
||||
{
|
||||
|
@ -137,6 +142,9 @@ namespace System
|
|||
return .Err(.Overflow);
|
||||
}
|
||||
|
||||
if (!digitsFound)
|
||||
return .Err(.NoValue);
|
||||
|
||||
return isNeg ? -result : result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue