"name": "System.Buffers.Text.Tests.ParserTests.TestParserDouble",
"reason": "https://github.com/dotnet/coreclr/pull/20707"
},
+ {
+ "name": "System.Buffers.Text.Tests.FormatterTests.TestGFormatWithPrecisionNotSupported",
+ "reason": "https://github.com/dotnet/coreclr/pull/22434"
+ },
+ {
+ "name": "System.Buffers.Text.Tests.FormatterTests.TestBadFormat",
+ "reason": "https://github.com/dotnet/coreclr/pull/22434"
+ },
]
}
},
private static bool TryFormatFloatingPoint<T>(T value, Span<byte> destination, out int bytesWritten, StandardFormat format) where T : IFormattable, ISpanFormattable
{
- if (format.IsDefault)
- {
- format = 'G';
- }
+ Span<char> formatText = stackalloc char[0];
- switch (format.Symbol)
+ if (!format.IsDefault)
{
- case 'g':
- case 'G':
- if (format.Precision != StandardFormat.NoPrecision)
- throw new NotSupportedException(SR.Argument_GWithPrecisionNotSupported);
- break;
-
- case 'f':
- case 'F':
- case 'e':
- case 'E':
- break;
-
- default:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
+ formatText = stackalloc char[StandardFormat.FormatStringLength];
+ int formatTextLength = format.Format(formatText);
+ formatText = formatText.Slice(0, formatTextLength);
}
-
- Span<char> formatText = stackalloc char[StandardFormat.FormatStringLength];
- int formattedLength = format.Format(formatText);
- formatText = formatText.Slice(0, formattedLength);
// We first try to format into a stack-allocated buffer, and if it succeeds, we can avoid
// all allocation. If that fails, we fall back to allocating strings. If it proves impactful,
ReadOnlySpan<char> utf16Text = stackalloc char[0];
// Try to format into the stack buffer. If we're successful, we can avoid all allocations.
- if (value.TryFormat(stackBuffer, out formattedLength, formatText, CultureInfo.InvariantCulture))
+ if (value.TryFormat(stackBuffer, out int formattedLength, formatText, CultureInfo.InvariantCulture))
{
utf16Text = stackBuffer.Slice(0, formattedLength);
}