-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Utf8Formatter/Utf8Parser should have UInt128 and Int128 overloads #73842
Comments
Tagging subscribers to this area: @dotnet/area-system-buffers Issue DetailsBackground and motivationAs I started looking into #73500 I realized Utf8Formatter/Utf8Parser are missing UInt128/Int128 overloads and therefore we need to unnecessarily do UTF16 <--> UTF8 conversion. cc: @tannergooding API Proposalnamespace System.Buffers.Text;
public static partial class Utf8Formatter
{
public static bool TryFormat(UInt128 value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
public static bool TryFormat(Int128 value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
}
public static partial class Utf8Parser
{
public static bool TryParse(System.ReadOnlySpan<byte> source, out UInt128 value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
public static bool TryParse(System.ReadOnlySpan<byte> source, out Int128 value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
} API Usageif (Utf8Parser.TryParse(someUtf8Span, out UInt128 value, out int bytesConsumed) && someUtf8Span.Length == bytesConsumed)
{
Console.WriteLine($"Successfully parsed UInt128 value: {value}");
}
UInt128 value = ...;
bool result = Utf8Formatter.TryFormat(value, utf8Output, out int bytesWritten);
// and similar for Int128 Alternative DesignsNo response RisksNo response
|
Looks good as proposed namespace System.Buffers.Text;
public static partial class Utf8Formatter
{
public static bool TryFormat(UInt128 value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
public static bool TryFormat(Int128 value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
}
public static partial class Utf8Parser
{
public static bool TryParse(System.ReadOnlySpan<byte> source, out UInt128 value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
public static bool TryParse(System.ReadOnlySpan<byte> source, out Int128 value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
} |
@krwq @tannergooding For Btw, why U{Int128} returns a new instance every time in properties like
|
@dotnet/area-system-buffers (does this tags work? 🤔) |
Much like with #53768 (comment), the plan is for APIs to simply implement For number types in particular, parsing where the first invalid character is treated as "end of string" rather than "invalid input" will be supported via #87171 |
Background and motivation
As I started looking into #73500 I realized Utf8Formatter/Utf8Parser are missing UInt128/Int128 overloads and therefore we need to unnecessarily do UTF16 <--> UTF8 conversion.
cc: @tannergooding
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: