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

Pattern matching with UTF-8 String Literals #6037

Closed
tmds opened this issue Apr 19, 2022 · 2 comments
Closed

Pattern matching with UTF-8 String Literals #6037

tmds opened this issue Apr 19, 2022 · 2 comments

Comments

@tmds
Copy link
Member

tmds commented Apr 19, 2022

C# 11 preview blog post includes UTF-8 String Literals, and Pattern matching with spans (specifically: [ReadOnly]Span<char>).

It would be interesting if both can be combined, allowing pattern matching against [ReadOnly]Span<byte>.

For example:

static HttpMethod ParseHttpMethod(ReadOnlySpan<byte> method)
{
    return method switch { 
        "GET"  => HttpMethod.Get, 
        "POST" => HttpMethod.Post, 
...
        _ => HttpVerb.Unknown };
}

This is interesting for use-cases that involve parsing UTF-8.

cc @KathleenDollard

Originally posted by @tmds in #6036

@tmds
Copy link
Member Author

tmds commented Apr 19, 2022

cc @davidfowl

@RikkiGibson
Copy link
Contributor

Moving discussion back to the discussion thread for now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants