mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Merge pull request #316 from KillaMaaki/fix/int-string-format
Hooked up NumberFormatter calls for all int type ToString methods
This commit is contained in:
commit
66039095eb
8 changed files with 48 additions and 124 deletions
|
@ -41,12 +41,14 @@ namespace System
|
|||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if ((format != null) && (format.StartsWith("X")))
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
((uint64)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (int32)this, formatProvider, outString);
|
||||
}
|
||||
((int64)this).ToString(outString, format, formatProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,27 +104,14 @@ namespace System
|
|||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
int minNumerals = -1;
|
||||
|
||||
//TOTAL HACK:
|
||||
if (format != null)
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
if (format.StartsWith("X"))
|
||||
{
|
||||
((UInt64)(uint32)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((format.Length > 0) && (format[0] == '0'))
|
||||
{
|
||||
if (Int32.Parse(format) case .Ok(let wantLen))
|
||||
{
|
||||
minNumerals = wantLen;
|
||||
}
|
||||
}
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (int32)this, formatProvider, outString);
|
||||
}
|
||||
|
||||
ToString(outString, minNumerals);
|
||||
}
|
||||
|
||||
public static Result<int32, ParseError> Parse(StringView val, NumberStyles style)
|
||||
|
|
|
@ -55,13 +55,14 @@ namespace System
|
|||
static String sHexLowerChars = "0123456789abcdef";
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if ((format != null) && (!format.IsEmpty))
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
((UInt64)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (int64)this, formatProvider, outString);
|
||||
}
|
||||
|
||||
ToString(outString);
|
||||
}
|
||||
|
||||
public override void ToString(String strBuffer)
|
||||
|
|
|
@ -41,12 +41,14 @@ namespace System
|
|||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if ((format != null) && (format.StartsWith("X")))
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
((uint64)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (int32)this, formatProvider, outString);
|
||||
}
|
||||
((int64)this).ToString(outString, format, formatProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,12 +41,14 @@ namespace System
|
|||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if ((format != null) && (format.StartsWith("X")))
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
((uint64)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (uint32)this, formatProvider, outString);
|
||||
}
|
||||
((int64)this).ToString(outString, format, formatProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,27 +97,14 @@ namespace System
|
|||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
int minNumerals = -1;
|
||||
|
||||
//TOTAL HACK:
|
||||
if (format != null)
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
if (format.StartsWith("X"))
|
||||
{
|
||||
((UInt64)(uint32)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((format.Length > 0) && (format[0] == '0'))
|
||||
{
|
||||
if (Int32.Parse(format) case .Ok(let wantLen))
|
||||
{
|
||||
minNumerals = wantLen;
|
||||
}
|
||||
}
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (uint32)this, formatProvider, outString);
|
||||
}
|
||||
|
||||
ToString(outString, minNumerals);
|
||||
}
|
||||
|
||||
public static Result<uint32, ParseError> Parse(StringView val)
|
||||
|
|
|
@ -47,73 +47,14 @@ namespace System
|
|||
static String sHexLowerChars = "0123456789abcdef";
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if (format != null)
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
if (format == "P")
|
||||
{
|
||||
String hexChars = (format == "p") ? sHexLowerChars : sHexUpperChars;
|
||||
|
||||
const int bufLen = 18;
|
||||
char8* strChars = scope:: char8[bufLen]* (?);
|
||||
int32 curLen = 0;
|
||||
uint64 valLeft = (uint64)this;
|
||||
while (valLeft > 0)
|
||||
{
|
||||
if (curLen == 8)
|
||||
strChars[bufLen - curLen++ - 1] = '\'';
|
||||
strChars[bufLen - curLen++ - 1] = hexChars[(int)(valLeft & 0xF)];
|
||||
valLeft >>= 4;
|
||||
}
|
||||
|
||||
while (curLen < 10)
|
||||
{
|
||||
if (curLen == 8)
|
||||
strChars[bufLen - curLen++ - 1] = '\'';
|
||||
strChars[bufLen - curLen++ - 1] = '0';
|
||||
}
|
||||
|
||||
char8* char8Ptr = &strChars[bufLen - curLen];
|
||||
outString.Append(char8Ptr, curLen);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (format.StartsWith("X", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
String hexChars = (format == "x") ? sHexLowerChars : sHexUpperChars;
|
||||
|
||||
const int bufLen = 18;
|
||||
char8* strChars = scope:: char8[bufLen]* (?);
|
||||
int32 curLen = 0;
|
||||
uint64 valLeft = (uint64)this;
|
||||
while (valLeft > 0)
|
||||
{
|
||||
strChars[bufLen - curLen - 1] = hexChars[(int)(valLeft & 0xF)];
|
||||
valLeft >>= 4;
|
||||
curLen++;
|
||||
}
|
||||
|
||||
int32 minChars = 1;
|
||||
if (format.Length > 0)
|
||||
{
|
||||
if (Int32.Parse(StringView(format, 1)) case .Ok(out minChars))
|
||||
minChars = Math.Max(1, minChars);
|
||||
}
|
||||
|
||||
while (curLen < minChars)
|
||||
{
|
||||
strChars[bufLen - curLen - 1] = '0';
|
||||
curLen++;
|
||||
}
|
||||
|
||||
char8* char8Ptr = &strChars[bufLen - curLen];
|
||||
outString.Append(char8Ptr, curLen);
|
||||
|
||||
return;
|
||||
}
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (uint64)this, formatProvider, outString);
|
||||
}
|
||||
|
||||
ToString(outString);
|
||||
}
|
||||
|
||||
public override void ToString(String strBuffer)
|
||||
|
|
|
@ -41,12 +41,14 @@ namespace System
|
|||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if ((format != null) && (format.StartsWith("X")))
|
||||
if(format == null || format.IsEmpty)
|
||||
{
|
||||
((uint64)this).ToString(outString, format, formatProvider);
|
||||
return;
|
||||
ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
NumberFormatter.NumberToString(format, (uint32)this, formatProvider, outString);
|
||||
}
|
||||
((int64)this).ToString(outString, format, formatProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue