mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
Fix formatting of Int32.bf and Int64.bf
This commit is contained in:
parent
bec7dff380
commit
81168d631b
2 changed files with 50 additions and 50 deletions
|
@ -11,8 +11,8 @@ namespace System
|
||||||
case InvalidChar(int32 partialResult);
|
case InvalidChar(int32 partialResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
public const int32 MaxValue = 0x7FFFFFFF;
|
public const int32 MaxValue = 0x7FFFFFFF;
|
||||||
public const int32 MinValue = -0x80000000;
|
public const int32 MinValue = -0x80000000;
|
||||||
|
|
||||||
public static int operator<=>(Self a, Self b)
|
public static int operator<=>(Self a, Self b)
|
||||||
{
|
{
|
||||||
|
@ -48,38 +48,38 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ToString(String strBuffer)
|
public override void ToString(String strBuffer)
|
||||||
{
|
{
|
||||||
// Dumb, make better.
|
// Dumb, make better.
|
||||||
char8[] strChars = scope:: char8[16];
|
char8[] strChars = scope:: char8[16];
|
||||||
int32 char8Idx = 14;
|
int32 char8Idx = 14;
|
||||||
int32 valLeft = (int32)this;
|
int32 valLeft = (int32)this;
|
||||||
bool isNeg = true;
|
bool isNeg = true;
|
||||||
if (valLeft >= 0)
|
if (valLeft >= 0)
|
||||||
{
|
{
|
||||||
valLeft = -valLeft;
|
valLeft = -valLeft;
|
||||||
isNeg = false;
|
isNeg = false;
|
||||||
}
|
}
|
||||||
while (valLeft < 0)
|
while (valLeft < 0)
|
||||||
{
|
{
|
||||||
strChars[char8Idx] = (char8)('0' - (valLeft % 10));
|
strChars[char8Idx] = (char8)('0' - (valLeft % 10));
|
||||||
valLeft /= 10;
|
valLeft /= 10;
|
||||||
char8Idx--;
|
char8Idx--;
|
||||||
}
|
}
|
||||||
if (char8Idx == 14)
|
if (char8Idx == 14)
|
||||||
strChars[char8Idx--] = '0';
|
strChars[char8Idx--] = '0';
|
||||||
if (isNeg)
|
if (isNeg)
|
||||||
strChars[char8Idx--] = '-';
|
strChars[char8Idx--] = '-';
|
||||||
char8* char8Ptr = &strChars[char8Idx + 1];
|
char8* char8Ptr = &strChars[char8Idx + 1];
|
||||||
strBuffer.Append(char8Ptr);
|
strBuffer.Append(char8Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToString(String strBuffer, int minNumerals)
|
void ToString(String strBuffer, int minNumerals)
|
||||||
{
|
{
|
||||||
// Dumb, make better.
|
// Dumb, make better.
|
||||||
char8[] strChars = scope:: char8[16];
|
char8[] strChars = scope:: char8[16];
|
||||||
int32 char8Idx = 14;
|
int32 char8Idx = 14;
|
||||||
int32 valLeft = (int32)this;
|
int32 valLeft = (int32)this;
|
||||||
bool isNeg = true;
|
bool isNeg = true;
|
||||||
int minNumeralsLeft = minNumerals;
|
int minNumeralsLeft = minNumerals;
|
||||||
if (valLeft >= 0)
|
if (valLeft >= 0)
|
||||||
|
@ -87,19 +87,19 @@ namespace System
|
||||||
valLeft = -valLeft;
|
valLeft = -valLeft;
|
||||||
isNeg = false;
|
isNeg = false;
|
||||||
}
|
}
|
||||||
while ((valLeft < 0) || (minNumeralsLeft > 0))
|
while ((valLeft < 0) || (minNumeralsLeft > 0))
|
||||||
{
|
{
|
||||||
strChars[char8Idx] = (char8)('0' - (valLeft % 10));
|
strChars[char8Idx] = (char8)('0' - (valLeft % 10));
|
||||||
valLeft /= 10;
|
valLeft /= 10;
|
||||||
char8Idx--;
|
char8Idx--;
|
||||||
minNumeralsLeft--;
|
minNumeralsLeft--;
|
||||||
}
|
}
|
||||||
if (char8Idx == 14)
|
if (char8Idx == 14)
|
||||||
strChars[char8Idx--] = '0';
|
strChars[char8Idx--] = '0';
|
||||||
if (isNeg)
|
if (isNeg)
|
||||||
strChars[char8Idx--] = '-';
|
strChars[char8Idx--] = '-';
|
||||||
char8* char8Ptr = &strChars[char8Idx + 1];
|
char8* char8Ptr = &strChars[char8Idx + 1];
|
||||||
strBuffer.Append(char8Ptr);
|
strBuffer.Append(char8Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||||
|
@ -118,7 +118,7 @@ namespace System
|
||||||
if ((format.Length > 0) && (format[0] == '0'))
|
if ((format.Length > 0) && (format[0] == '0'))
|
||||||
{
|
{
|
||||||
if (Int32.Parse(format) case .Ok(let wantLen))
|
if (Int32.Parse(format) case .Ok(let wantLen))
|
||||||
{
|
{
|
||||||
minNumerals = wantLen;
|
minNumerals = wantLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,8 @@ namespace System
|
||||||
ToString(outString, minNumerals);
|
ToString(outString, minNumerals);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<int32, ParseError> Parse(StringView val, NumberStyles style)
|
public static Result<int32, ParseError> Parse(StringView val, NumberStyles style)
|
||||||
{
|
{
|
||||||
if (val.IsEmpty)
|
if (val.IsEmpty)
|
||||||
return .Err(.NoValue);
|
return .Err(.NoValue);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ namespace System
|
||||||
int32 result = 0;
|
int32 result = 0;
|
||||||
|
|
||||||
int32 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10;
|
int32 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10;
|
||||||
|
|
||||||
for (int32 i = 0; i < val.Length; i++)
|
for (int32 i = 0; i < val.Length; i++)
|
||||||
{
|
{
|
||||||
char8 c = val[i];
|
char8 c = val[i];
|
||||||
|
@ -181,7 +181,7 @@ namespace System
|
||||||
}
|
}
|
||||||
|
|
||||||
return isNeg ? -result : result;
|
return isNeg ? -result : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<int32, ParseError> Parse(StringView val)
|
public static Result<int32, ParseError> Parse(StringView val)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,9 +11,9 @@ namespace System
|
||||||
case InvalidChar(int64 partialResult);
|
case InvalidChar(int64 partialResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
public const int64 MaxValue = 0x7FFFFFFFFFFFFFFFL;
|
public const int64 MaxValue = 0x7FFFFFFFFFFFFFFFL;
|
||||||
//public const long MinValue = -0x8000000000000000L;
|
//public const long MinValue = -0x8000000000000000L;
|
||||||
public const int64 MinValue = -0x7FFFFFFFFFFFFFFFL; //TODO: Should be one lower!
|
public const int64 MinValue = -0x7FFFFFFFFFFFFFFFL; //TODO: Should be one lower!
|
||||||
|
|
||||||
public static int operator<=>(Int64 a, Int64 b)
|
public static int operator<=>(Int64 a, Int64 b)
|
||||||
{
|
{
|
||||||
|
@ -67,8 +67,8 @@ namespace System
|
||||||
|
|
||||||
public override void ToString(String strBuffer)
|
public override void ToString(String strBuffer)
|
||||||
{
|
{
|
||||||
// Dumb, make better.
|
// Dumb, make better.
|
||||||
char8[] strChars = scope:: char8[22];
|
char8[] strChars = scope:: char8[22];
|
||||||
int32 char8Idx = 20;
|
int32 char8Idx = 20;
|
||||||
int64 valLeft = (int64)this;
|
int64 valLeft = (int64)this;
|
||||||
bool isNeg = true;
|
bool isNeg = true;
|
||||||
|
@ -80,13 +80,13 @@ namespace System
|
||||||
}
|
}
|
||||||
while ((valLeft < 0) || (minNumeralsLeft > 0))
|
while ((valLeft < 0) || (minNumeralsLeft > 0))
|
||||||
{
|
{
|
||||||
strChars[char8Idx] = (char8)('0' - (valLeft % 10));
|
strChars[char8Idx] = (char8)('0' - (valLeft % 10));
|
||||||
valLeft /= 10;
|
valLeft /= 10;
|
||||||
char8Idx--;
|
char8Idx--;
|
||||||
minNumeralsLeft--;
|
minNumeralsLeft--;
|
||||||
}
|
}
|
||||||
if (char8Idx == 20)
|
if (char8Idx == 20)
|
||||||
strChars[char8Idx--] = '0';
|
strChars[char8Idx--] = '0';
|
||||||
if (isNeg)
|
if (isNeg)
|
||||||
strChars[char8Idx--] = '-';
|
strChars[char8Idx--] = '-';
|
||||||
char8* char8Ptr = &strChars[char8Idx + 1];
|
char8* char8Ptr = &strChars[char8Idx + 1];
|
||||||
|
@ -104,7 +104,7 @@ namespace System
|
||||||
int64 result = 0;
|
int64 result = 0;
|
||||||
|
|
||||||
int64 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10;
|
int64 radix = style.HasFlag(.AllowHexSpecifier) ? 0x10 : 10;
|
||||||
|
|
||||||
for (int32 i = 0; i < val.Length; i++)
|
for (int32 i = 0; i < val.Length; i++)
|
||||||
{
|
{
|
||||||
char8 c = val[i];
|
char8 c = val[i];
|
||||||
|
@ -143,7 +143,7 @@ namespace System
|
||||||
else
|
else
|
||||||
return .Err(.InvalidChar(result));
|
return .Err(.InvalidChar(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isNeg ? -result : result;
|
return isNeg ? -result : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue