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

Added 'A' address format specifier

This commit is contained in:
Brian Fiete 2020-06-05 07:23:46 -07:00
parent bc64ac4d78
commit 237f85b846
2 changed files with 37 additions and 7 deletions

View file

@ -1297,7 +1297,7 @@ namespace System
_defPrecision = defPrecision; _defPrecision = defPrecision;
_positive = value >= 0; _positive = value >= 0;
if (value == 0 || _specifier == 'X') { if (value == 0 || _specifier == 'X' || _specifier == 'A') {
InitHex ((uint64)value); InitHex ((uint64)value);
return; return;
} }
@ -1314,7 +1314,7 @@ namespace System
_defPrecision = defPrecision; _defPrecision = defPrecision;
_positive = true; _positive = true;
if (value == 0 || _specifier == 'X') { if (value == 0 || _specifier == 'X' || _specifier == 'A') {
InitHex (value); InitHex (value);
return; return;
} }
@ -1330,7 +1330,7 @@ namespace System
_defPrecision = Int64DefPrecision; _defPrecision = Int64DefPrecision;
_positive = value >= 0; _positive = value >= 0;
if (value == 0 || _specifier == 'X') { if (value == 0 || _specifier == 'X' || _specifier == 'A') {
InitHex ((uint64)value); InitHex ((uint64)value);
return; return;
} }
@ -1347,7 +1347,7 @@ namespace System
_defPrecision = UInt64DefPrecision; _defPrecision = UInt64DefPrecision;
_positive = true; _positive = true;
if (value == 0 || _specifier == 'X') { if (value == 0 || _specifier == 'X' || _specifier == 'A') {
InitHex ((uint64)value); InitHex ((uint64)value);
return; return;
} }
@ -1809,7 +1809,10 @@ namespace System
private void IntegerToString (StringView format, IFormatProvider fp, String outString) private void IntegerToString (StringView format, IFormatProvider fp, String outString)
{ {
NumberFormatInfo nfi = GetNumberFormatInstance (fp); NumberFormatInfo nfi = GetNumberFormatInstance (fp);
switch (_specifier) { switch (_specifier)
{
case 'A':
FormatAddress(outString);
case 'C': case 'C':
FormatCurrency (_precision, nfi, outString); FormatCurrency (_precision, nfi, outString);
case 'D': case 'D':
@ -2042,6 +2045,33 @@ namespace System
outString.Append(_cbuf, 0, _ind); outString.Append(_cbuf, 0, _ind);
} }
private void FormatAddress(String outString)
{
char8* digits = _specifierIsUpper ? &DigitUpperTable : &DigitLowerTable;
const int bufLen = 18;
char8* strChars = scope:: char8[bufLen]* (?);
int32 curLen = 0;
uint64 valLeft = _val1 | ((uint64)_val2 << 32);
while (valLeft > 0)
{
if (curLen == 8)
strChars[bufLen - curLen++ - 1] = '\'';
strChars[bufLen - curLen++ - 1] = digits[(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);
}
void FormatFixedPoint (int32 precision, NumberFormatInfo nfi, String outString) void FormatFixedPoint (int32 precision, NumberFormatInfo nfi, String outString)
{ {
var precision; var precision;

View file

@ -18,7 +18,7 @@ namespace System
public override void ToString(String strBuffer) public override void ToString(String strBuffer)
{ {
strBuffer.AppendF("0x{0:P}", (uint)(void*)mVal); strBuffer.AppendF("0x{0:A}", (uint)(void*)mVal);
} }
} }
@ -35,7 +35,7 @@ namespace System
{ {
strBuffer.Append("("); strBuffer.Append("(");
typeof(T).GetFullName(strBuffer); typeof(T).GetFullName(strBuffer);
strBuffer.AppendF("*)0x{0:P}", (uint)(void*)mVal); strBuffer.AppendF("*)0x{0:A}", (uint)(void*)mVal);
} }
} }
} }