Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ FormatInt64()

static string System.Number.FormatInt64 ( long value,
string format,
IFormatProvider provider )
inlinestatic

Definition at line 2052 of file Number.cs.

2053 {
2054 if (string.IsNullOrEmpty(format))
2055 {
2056 if (value < 0)
2057 {
2058 return NegativeInt64ToDecStr(value, -1, NumberFormatInfo.GetInstance(provider).NegativeSign);
2059 }
2060 return UInt64ToDecStr((ulong)value, -1);
2061 }
2062 return FormatInt64Slow(value, format, provider);
2063 unsafe static string FormatInt64Slow(long value, string format, IFormatProvider provider)
2064 {
2065 ReadOnlySpan<char> format2 = format;
2066 int digits;
2067 char c = ParseFormatSpecifier(format2, out digits);
2068 char c2 = (char)(c & 0xFFDFu);
2069 if ((c2 == 'G') ? (digits < 1) : (c2 == 'D'))
2070 {
2071 if (value < 0)
2072 {
2073 return NegativeInt64ToDecStr(value, digits, NumberFormatInfo.GetInstance(provider).NegativeSign);
2074 }
2075 return UInt64ToDecStr((ulong)value, digits);
2076 }
2077 if (c2 == 'X')
2078 {
2079 return Int64ToHexStr(value, GetHexBase(c), digits);
2080 }
2081 NumberFormatInfo instance = NumberFormatInfo.GetInstance(provider);
2082 byte* digits2 = stackalloc byte[20];
2083 NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, digits2, 20);
2084 Int64ToNumber(value, ref number);
2085 char* pointer = stackalloc char[32];
2086 ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(pointer, 32));
2087 if (c != 0)
2088 {
2089 NumberToString(ref sb, ref number, c, digits, instance);
2090 }
2091 else
2092 {
2093 NumberToStringFormat(ref sb, ref number, format2, instance);
2094 }
2095 return sb.ToString();
2096 }
2097 }
static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
static unsafe string UInt64ToDecStr(ulong value, int digits)
Definition Number.cs:2606
static unsafe string NegativeInt64ToDecStr(long input, int digits, string sNegative)
Definition Number.cs:2484
static unsafe void Int64ToNumber(long input, ref NumberBuffer number)
Definition Number.cs:2450
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 unsafe string Int64ToHexStr(long value, char hexBase, int digits)
Definition Number.cs:2541
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

References System.format, System.Number.GetHexBase(), System.Globalization.NumberFormatInfo.GetInstance(), System.Number.Int64ToHexStr(), System.Number.Int64ToNumber(), System.Number.NegativeInt64ToDecStr(), System.Number.NumberToString(), System.Number.NumberToStringFormat(), System.Number.ParseFormatSpecifier(), System.pointer, System.Text.ValueStringBuilder.ToString(), System.Number.UInt64ToDecStr(), and System.value.

Referenced by System.Int64.ToString(), System.Int64.ToString(), and System.Int64.ToString().