mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +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)
|
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);
|
ToString(outString);
|
||||||
return;
|
}
|
||||||
|
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)
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||||
{
|
{
|
||||||
int minNumerals = -1;
|
if(format == null || format.IsEmpty)
|
||||||
|
|
||||||
//TOTAL HACK:
|
|
||||||
if (format != null)
|
|
||||||
{
|
{
|
||||||
if (format.StartsWith("X"))
|
ToString(outString);
|
||||||
{
|
}
|
||||||
((UInt64)(uint32)this).ToString(outString, format, formatProvider);
|
else
|
||||||
return;
|
{
|
||||||
}
|
NumberFormatter.NumberToString(format, (int32)this, formatProvider, outString);
|
||||||
|
|
||||||
if ((format.Length > 0) && (format[0] == '0'))
|
|
||||||
{
|
|
||||||
if (Int32.Parse(format) case .Ok(let wantLen))
|
|
||||||
{
|
|
||||||
minNumerals = wantLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ToString(outString, minNumerals);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<int32, ParseError> Parse(StringView val, NumberStyles style)
|
public static Result<int32, ParseError> Parse(StringView val, NumberStyles style)
|
||||||
|
|
|
@ -55,13 +55,14 @@ namespace System
|
||||||
static String sHexLowerChars = "0123456789abcdef";
|
static String sHexLowerChars = "0123456789abcdef";
|
||||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
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);
|
ToString(outString);
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NumberFormatter.NumberToString(format, (int64)this, formatProvider, outString);
|
||||||
}
|
}
|
||||||
|
|
||||||
ToString(outString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ToString(String strBuffer)
|
public override void ToString(String strBuffer)
|
||||||
|
|
|
@ -41,12 +41,14 @@ namespace System
|
||||||
|
|
||||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
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);
|
ToString(outString);
|
||||||
return;
|
}
|
||||||
|
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)
|
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);
|
ToString(outString);
|
||||||
return;
|
}
|
||||||
|
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)
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||||
{
|
{
|
||||||
int minNumerals = -1;
|
if(format == null || format.IsEmpty)
|
||||||
|
|
||||||
//TOTAL HACK:
|
|
||||||
if (format != null)
|
|
||||||
{
|
{
|
||||||
if (format.StartsWith("X"))
|
ToString(outString);
|
||||||
{
|
}
|
||||||
((UInt64)(uint32)this).ToString(outString, format, formatProvider);
|
else
|
||||||
return;
|
{
|
||||||
}
|
NumberFormatter.NumberToString(format, (uint32)this, formatProvider, outString);
|
||||||
|
|
||||||
if ((format.Length > 0) && (format[0] == '0'))
|
|
||||||
{
|
|
||||||
if (Int32.Parse(format) case .Ok(let wantLen))
|
|
||||||
{
|
|
||||||
minNumerals = wantLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ToString(outString, minNumerals);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<uint32, ParseError> Parse(StringView val)
|
public static Result<uint32, ParseError> Parse(StringView val)
|
||||||
|
|
|
@ -47,73 +47,14 @@ namespace System
|
||||||
static String sHexLowerChars = "0123456789abcdef";
|
static String sHexLowerChars = "0123456789abcdef";
|
||||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||||
{
|
{
|
||||||
if (format != null)
|
if(format == null || format.IsEmpty)
|
||||||
{
|
{
|
||||||
if (format == "P")
|
ToString(outString);
|
||||||
{
|
}
|
||||||
String hexChars = (format == "p") ? sHexLowerChars : sHexUpperChars;
|
else
|
||||||
|
{
|
||||||
const int bufLen = 18;
|
NumberFormatter.NumberToString(format, (uint64)this, formatProvider, outString);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ToString(String strBuffer)
|
public override void ToString(String strBuffer)
|
||||||
|
|
|
@ -41,12 +41,14 @@ namespace System
|
||||||
|
|
||||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
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);
|
ToString(outString);
|
||||||
return;
|
}
|
||||||
|
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