1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +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

@ -54,56 +54,40 @@ namespace System
public override void ToString(String strBuffer)
{
// Dumb, make better.
char8[] strChars = scope:: char8[16];
int32 char8Idx = 14;
int32 valLeft = (int32)this;
bool isNeg = false;
if (valLeft < 0)
// Dumb, make better.
char8[] strChars = scope:: char8[16];
int32 char8Idx = 14;
uint32 valLeft = (uint32)this;
while (valLeft > 0)
{
valLeft = -valLeft;
isNeg = true;
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
valLeft /= 10;
char8Idx--;
}
while (valLeft > 0)
{
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
valLeft /= 10;
char8Idx--;
}
if (char8Idx == 14)
strChars[char8Idx--] = '0';
if (isNeg)
strChars[char8Idx--] = '-';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
if (char8Idx == 14)
strChars[char8Idx--] = '0';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
}
void ToString(String strBuffer, int minNumerals)
{
// Dumb, make better.
char8[] strChars = scope:: char8[16];
int32 char8Idx = 14;
int32 valLeft = (int32)this;
bool isNeg = false;
// Dumb, make better.
char8[] strChars = scope:: char8[16];
int32 char8Idx = 14;
uint32 valLeft = (uint32)this;
int minNumeralsLeft = minNumerals;
if (valLeft < 0)
while ((valLeft > 0) || (minNumeralsLeft > 0))
{
valLeft = -valLeft;
isNeg = true;
}
while ((valLeft > 0) || (minNumeralsLeft > 0))
{
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
valLeft /= 10;
char8Idx--;
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
valLeft /= 10;
char8Idx--;
minNumeralsLeft--;
}
if (char8Idx == 14)
strChars[char8Idx--] = '0';
if (isNeg)
strChars[char8Idx--] = '-';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
}
if (char8Idx == 14)
strChars[char8Idx--] = '0';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
}
public void ToString(String outString, String format, IFormatProvider formatProvider)