Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros

◆ FormatUInt32()

static string System.Number.FormatUInt32 ( uint value,
string format,
IFormatProvider provider )
inlinestatic

Definition at line 1975 of file Number.cs.

1976 {
1977 if (string.IsNullOrEmpty(format))
1978 {
1979 return UInt32ToDecStr(value);
1980 }
1981 return FormatUInt32Slow(value, format, provider);
1982 unsafe static string FormatUInt32Slow(uint value, string format, IFormatProvider provider)
1983 {
1984 ReadOnlySpan<char> format2 = format;
1985 int digits;
1986 char c = ParseFormatSpecifier(format2, out digits);
1987 char c2 = (char)(c & 0xFFDFu);
1988 if ((c2 == 'G') ? (digits < 1) : (c2 == 'D'))
1989 {
1990 return UInt32ToDecStr(value, digits);
1991 }
1992 if (c2 == 'X')
1993 {
1994 return Int32ToHexStr((int)value, GetHexBase(c), digits);
1995 }
1996 NumberFormatInfo instance = NumberFormatInfo.GetInstance(provider);
1997 byte* digits2 = stackalloc byte[11];
1998 NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, digits2, 11);
1999 UInt32ToNumber(value, ref number);
2000 char* pointer = stackalloc char[32];
2001 ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(pointer, 32));
2002 if (c != 0)
2003 {
2004 NumberToString(ref sb, ref number, c, digits, instance);
2005 }
2006 else
2007 {
2008 NumberToStringFormat(ref sb, ref number, format2, instance);
2009 }
2010 return sb.ToString();
2011 }
2012 }
static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
static unsafe string Int32ToHexStr(int value, char hexBase, int digits)
Definition Number.cs:2298
static unsafe void UInt32ToNumber(uint value, ref NumberBuffer number)
Definition Number.cs:2345
static char ParseFormatSpecifier(ReadOnlySpan< char > format, out int digits)
Definition Number.cs:2657
static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref NumberBuffer number, ReadOnlySpan< char > format, NumberFormatInfo info)
Definition Number.cs:2817
static char GetHexBase(char fmt)
Definition Number.cs:1877
static void NumberToString(ref ValueStringBuilder sb, ref NumberBuffer number, char format, int nMaxDigits, NumberFormatInfo info)
Definition Number.cs:2715
static unsafe string UInt32ToDecStr(uint value)
Definition Number.cs:2382

References System.format, System.Number.GetHexBase(), System.Globalization.NumberFormatInfo.GetInstance(), System.Number.Int32ToHexStr(), System.Number.NumberToString(), System.Number.NumberToStringFormat(), System.Number.ParseFormatSpecifier(), System.pointer, System.Text.ValueStringBuilder.ToString(), System.Number.UInt32ToDecStr(), System.Number.UInt32ToNumber(), and System.value.

Referenced by System.Byte.ToString(), System.UInt16.ToString(), System.UInt32.ToString(), System.Byte.ToString(), System.UInt16.ToString(), and System.UInt32.ToString().