Cysharp/ZString

Support C# 10 string interpolation

NN--- opened this issue · 5 comments

NN--- commented

Together with InterpolatedStringHandler this should be even faster than before.

https://devblogs.microsoft.com/dotnet/string-interpolation-in-c-10-and-net-6/

Yes, I'm interested.

It will be a little better, but not ideal, so I want to pend it.
If the proposed UTF8-String-Literals supports InterpolatedStringHandler, we can create an ideal API.
dotnet/csharplang#5355

// concept design.
[InterpolatedStringHandler]
public ref struct Utf8InterpolatedStringHandler
{
    IBufferWriter<byte> bufferWriter;

    public Utf8InterpolatedStringHandler(int literalLength, int formattedCount, IBufferWriter<byte> bufferWriter)
    {
        this.bufferWriter = bufferWriter;
    }

    public void AppendLiteral(ReadOnlySpan<byte> s)
    {
        s.CopyTo(bufferWriter.GetSpan(s.Length));
        bufferWriter.Advance(s.Length);
    }

    public void AppendFormatted<T>(T value)
    {
        var size = Unsafe.SizeOf<T>();
        Utf8Formatter.TryFormat(value, bufferWriter.GetSpan(size), out var written);
        bufferWriter.Advance(written);
    }
}

I'll make a suggestion when the utf8-string-literals discussion is started.
https://github.com/dotnet/csharplang/blob/main/proposals/utf8-string-literals.md

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

Finally UTF8 type is not introduced in C#.
It seems that only ReadOnlySpan<byte> is available.