Skip to content

[API Proposal]: Utf8Formatter/Utf8Parser should have UInt128 and Int128 overloads #73842

@krwq

Description

@krwq

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

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; }
}

API Usage

if (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 Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions