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:
commit
72d48c7cfa
2 changed files with 27 additions and 43 deletions
|
@ -1735,14 +1735,14 @@ namespace System
|
||||||
public static void NumberToString (StringView format, uint32 value, IFormatProvider fp, String outString)
|
public static void NumberToString (StringView format, uint32 value, IFormatProvider fp, String outString)
|
||||||
{
|
{
|
||||||
NumberFormatter inst = GetInstance!(fp);
|
NumberFormatter inst = GetInstance!(fp);
|
||||||
inst.Init (format, value, Int32DefPrecision);
|
inst.Init (format, value, UInt32DefPrecision);
|
||||||
inst.IntegerToString(format, fp, outString);
|
inst.IntegerToString(format, fp, outString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NumberToString (StringView format, int32 value, IFormatProvider fp, String outString)
|
public static void NumberToString (StringView format, int32 value, IFormatProvider fp, String outString)
|
||||||
{
|
{
|
||||||
NumberFormatter inst = GetInstance!(fp);
|
NumberFormatter inst = GetInstance!(fp);
|
||||||
inst.Init (format, value, UInt32DefPrecision);
|
inst.Init (format, value, Int32DefPrecision);
|
||||||
inst.IntegerToString (format, fp, outString);
|
inst.IntegerToString (format, fp, outString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,56 +54,40 @@ 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;
|
uint32 valLeft = (uint32)this;
|
||||||
bool isNeg = false;
|
while (valLeft > 0)
|
||||||
if (valLeft < 0)
|
|
||||||
{
|
{
|
||||||
valLeft = -valLeft;
|
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
|
||||||
isNeg = true;
|
valLeft /= 10;
|
||||||
|
char8Idx--;
|
||||||
}
|
}
|
||||||
while (valLeft > 0)
|
if (char8Idx == 14)
|
||||||
{
|
strChars[char8Idx--] = '0';
|
||||||
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
|
char8* char8Ptr = &strChars[char8Idx + 1];
|
||||||
valLeft /= 10;
|
strBuffer.Append(char8Ptr);
|
||||||
char8Idx--;
|
|
||||||
}
|
|
||||||
if (char8Idx == 14)
|
|
||||||
strChars[char8Idx--] = '0';
|
|
||||||
if (isNeg)
|
|
||||||
strChars[char8Idx--] = '-';
|
|
||||||
char8* char8Ptr = &strChars[char8Idx + 1];
|
|
||||||
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;
|
uint32 valLeft = (uint32)this;
|
||||||
bool isNeg = false;
|
|
||||||
int minNumeralsLeft = minNumerals;
|
int minNumeralsLeft = minNumerals;
|
||||||
if (valLeft < 0)
|
while ((valLeft > 0) || (minNumeralsLeft > 0))
|
||||||
{
|
{
|
||||||
valLeft = -valLeft;
|
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
|
||||||
isNeg = true;
|
valLeft /= 10;
|
||||||
}
|
char8Idx--;
|
||||||
while ((valLeft > 0) || (minNumeralsLeft > 0))
|
|
||||||
{
|
|
||||||
strChars[char8Idx] = (char8)('0' + (valLeft % 10));
|
|
||||||
valLeft /= 10;
|
|
||||||
char8Idx--;
|
|
||||||
minNumeralsLeft--;
|
minNumeralsLeft--;
|
||||||
}
|
}
|
||||||
if (char8Idx == 14)
|
if (char8Idx == 14)
|
||||||
strChars[char8Idx--] = '0';
|
strChars[char8Idx--] = '0';
|
||||||
if (isNeg)
|
char8* char8Ptr = &strChars[char8Idx + 1];
|
||||||
strChars[char8Idx--] = '-';
|
strBuffer.Append(char8Ptr);
|
||||||
char8* char8Ptr = &strChars[char8Idx + 1];
|
|
||||||
strBuffer.Append(char8Ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue