dotnet / csharplang

The official repo for the design of the C# programming language
11.53k stars 1.03k forks source link

Champion "utf8 string literals" #184

Open gafter opened 7 years ago

gafter commented 7 years ago

Proposal: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/utf8-string-literals.md Old draft proposal: https://github.com/dotnet/csharplang/issues/2911

Design Review

https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-10-27.md#utf-8-string-literals https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-01-26.md#open-questions-in-utf-8-string-literals https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-06-29.md#utf-8-literal-concatenation-operator

bernd5 commented 2 years ago

This issue seems to be fixed in the spec / proposal: https://github.com/dotnet/csharplang/blob/main/proposals/utf8-string-literals.md#resolved-overload-resolution-breaks

This fix is just not implemented:

using System;
using static App;

M1("");

class App{
    public static void M1(ReadOnlySpan<char> charArray) => Console.WriteLine(charArray.Length);
    public static void M1(byte[] byteArray) => Console.WriteLine(byteArray.Length);
}
WeihanLi commented 2 years ago

I got a problem when I update the SDK, it breaks my previous code

Error message:

Error CS8652: The feature 'Utf8 String Literals' is currently in Preview and unsupported. To use Preview features, use the 'preview' language version.

Failed CI:

Sample code: https://github.com/WeihanLi/SamplesInPractice/tree/63795cd961dc64ff3b92473a09eb90a59792db19/MiniAspNetCore

orthoxerox commented 2 years ago

Will UTF-8 string literals support raw string literals?

var s2 = $"""
hello
"""u8;                // Okay and type is ReadOnlySpan<byte>
HaloFour commented 2 years ago

@orthoxerox

Regular raw strings already work on SharpLab, verbatim strings too. But it doesn't appear that interpolated strings are supported, in any flavor.

FaustVX commented 2 years ago

Will interpolated UTF8 work with Interpolated String Handler ?

333fred commented 2 years ago

As HaloFour said, there are no interpolated UTF-8 strings.

FaustVX commented 2 years ago

@333fred Ok, @HaloFour edited his response after I wrote mine 😄

HaloFour commented 2 years ago

@FaustVX

Yeah, sorry, I missed the $ in the example code in the original question. 😄