1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 14:24:10 +02:00

Merge pull request #644 from thibmo/uint_string_format_fix

Fix formatting issue for UInt32, UInt16, UInt8 and UInt
This commit is contained in:
Brian Fiete 2020-10-30 13:10:57 -07:00 committed by GitHub
commit 72d48c7cfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 43 deletions

View file

@ -1735,14 +1735,14 @@ namespace System
public static void NumberToString (StringView format, uint32 value, IFormatProvider fp, String outString)
{
NumberFormatter inst = GetInstance!(fp);
inst.Init (format, value, Int32DefPrecision);
inst.Init (format, value, UInt32DefPrecision);
inst.IntegerToString(format, fp, outString);
}
public static void NumberToString (StringView format, int32 value, IFormatProvider fp, String outString)
{
NumberFormatter inst = GetInstance!(fp);
inst.Init (format, value, UInt32DefPrecision);
inst.Init (format, value, Int32DefPrecision);
inst.IntegerToString (format, fp, outString);
}

View file

@ -57,13 +57,7 @@ namespace System
// Dumb, make better.
char8[] strChars = scope:: char8[16];
int32 char8Idx = 14;
int32 valLeft = (int32)this;
bool isNeg = false;
if (valLeft < 0)
{
valLeft = -valLeft;
isNeg = true;
}
uint32 valLeft = (uint32)this;
while (valLeft > 0)
{
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
@ -72,8 +66,6 @@ namespace System
}
if (char8Idx == 14)
strChars[char8Idx--] = '0';
if (isNeg)
strChars[char8Idx--] = '-';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
}
@ -83,14 +75,8 @@ namespace System
// Dumb, make better.
char8[] strChars = scope:: char8[16];
int32 char8Idx = 14;
int32 valLeft = (int32)this;
bool isNeg = false;
uint32 valLeft = (uint32)this;
int minNumeralsLeft = minNumerals;
if (valLeft < 0)
{
valLeft = -valLeft;
isNeg = true;
}
while ((valLeft > 0) || (minNumeralsLeft > 0))
{
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
@ -100,8 +86,6 @@ namespace System
}
if (char8Idx == 14)
strChars[char8Idx--] = '0';
if (isNeg)
strChars[char8Idx--] = '-';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
}