Skip to content
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

Add MemoryExtensions.TryWriteUtf8 #83761

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/libraries/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ public static void Sort<TKey, TValue, TComparer>(this System.Span<TKey> keys, Sy
public static bool TryWrite<TArg0, TArg1, TArg2>(this System.Span<char> destination, System.IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, TArg0 arg0, TArg1 arg1, TArg2 arg2) { throw null; }
public static bool TryWrite(this Span<char> destination, System.IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, params object?[] args) { throw null; }
public static bool TryWrite(this Span<char> destination, System.IFormatProvider? provider, System.Text.CompositeFormat format, out int charsWritten, System.ReadOnlySpan<object?> args) { throw null; }
public static bool TryWriteUtf8(this System.Span<byte> destination, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute("destination")] ref System.MemoryExtensions.TryWriteUtf8InterpolatedStringHandler handler, out int bytesWritten) { throw null; }
public static bool TryWriteUtf8(this System.Span<byte> destination, IFormatProvider? provider, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute("destination", "provider")] ref System.MemoryExtensions.TryWriteUtf8InterpolatedStringHandler handler, out int bytesWritten) { throw null; }
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute]
public ref struct TryWriteInterpolatedStringHandler
Expand All @@ -401,6 +403,27 @@ public ref struct TryWriteInterpolatedStringHandler
public bool AppendFormatted(string? value) { throw null; }
public bool AppendFormatted(string? value, int alignment = 0, string? format = null) { throw null; }
}
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute]
public ref struct TryWriteUtf8InterpolatedStringHandler
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public TryWriteUtf8InterpolatedStringHandler(int literalLength, int formattedCount, System.Span<byte> destination, out bool shouldAppend) { throw null; }
public TryWriteUtf8InterpolatedStringHandler(int literalLength, int formattedCount, System.Span<byte> destination, IFormatProvider? provider, out bool shouldAppend) { throw null; }
public bool AppendLiteral(string value) { throw null; }
public bool AppendFormatted(scoped System.ReadOnlySpan<char> value) { throw null; }
public bool AppendFormatted(scoped System.ReadOnlySpan<char> value, int alignment = 0, string? format = null) { throw null; }
public bool AppendFormatted(scoped System.ReadOnlySpan<byte> utf8Value) { throw null; }
public bool AppendFormatted(scoped System.ReadOnlySpan<byte> utf8Value, int alignment = 0, string? format = null) { throw null; }
public bool AppendFormatted<T>(T value) { throw null; }
public bool AppendFormatted<T>(T value, string? format) { throw null; }
public bool AppendFormatted<T>(T value, int alignment) { throw null; }
public bool AppendFormatted<T>(T value, int alignment, string? format) { throw null; }
public bool AppendFormatted(object? value, int alignment = 0, string? format = null) { throw null; }
public bool AppendFormatted(string? value) { throw null; }
public bool AppendFormatted(string? value, int alignment = 0, string? format = null) { throw null; }
}
}
}
namespace System.Buffers
Expand Down
20 changes: 10 additions & 10 deletions src/libraries/System.Memory/tests/Span/TryWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ private static void AssertModeMatchesType<T>(T tss) where T : IHasToStringState
Assert.Equal(expected, tss.ToStringState.ToStringMode);
}

private sealed class SpanFormattableStringWrapper : IFormattable, ISpanFormattable, IHasToStringState
internal sealed class SpanFormattableStringWrapper : IFormattable, ISpanFormattable, IHasToStringState
{
private readonly string _value;
public ToStringState ToStringState { get; } = new ToStringState();
Expand Down Expand Up @@ -576,7 +576,7 @@ public override string ToString()
}
}

private struct SpanFormattableInt32Wrapper : IFormattable, ISpanFormattable, IHasToStringState
internal struct SpanFormattableInt32Wrapper : IFormattable, ISpanFormattable, IHasToStringState
{
private readonly int _value;
public ToStringState ToStringState { get; }
Expand Down Expand Up @@ -613,7 +613,7 @@ public override string ToString()
}
}

private sealed class FormattableStringWrapper : IFormattable, IHasToStringState
internal sealed class FormattableStringWrapper : IFormattable, IHasToStringState
{
private readonly string _value;
public ToStringState ToStringState { get; } = new ToStringState();
Expand All @@ -637,7 +637,7 @@ public override string ToString()
}
}

private struct FormattableInt32Wrapper : IFormattable, IHasToStringState
internal struct FormattableInt32Wrapper : IFormattable, IHasToStringState
{
private readonly int _value;
public ToStringState ToStringState { get; }
Expand Down Expand Up @@ -665,27 +665,27 @@ public override string ToString()
}
}

private sealed class ToStringState
internal sealed class ToStringState
{
public string LastFormat { get; set; }
public IFormatProvider LastProvider { get; set; }
public ToStringMode ToStringMode { get; set; }
}

private interface IHasToStringState
internal interface IHasToStringState
{
ToStringState ToStringState { get; }
}

private enum ToStringMode
internal enum ToStringMode
{
ObjectToString,
IFormattableToString,
ISpanFormattableTryFormat,
ICustomFormatterFormat,
}

private sealed class StringWrapper
internal sealed class StringWrapper
{
private readonly string _value;

Expand All @@ -694,7 +694,7 @@ private sealed class StringWrapper
public override string ToString() => _value;
}

private sealed class ConcatFormatter : IFormatProvider, ICustomFormatter
internal sealed class ConcatFormatter : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType) => formatType == typeof(ICustomFormatter) ? this : null;

Expand All @@ -714,7 +714,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
}
}

private sealed class ConstFormatter : IFormatProvider, ICustomFormatter
internal sealed class ConstFormatter : IFormatProvider, ICustomFormatter
{
private readonly string _value;

Expand Down
Loading