Skip to content

proposal: unicode/utf8: provide generic versions of all functions  #56948

Open
@dsnet

Description

@dsnet

I'm trying to a write a generic function that operates on either string | []byte. However, I'm unable to do so since the implementation of that function needs to depend on either utf8.DecodeRune or utf8.DecodeRuneInString, but I'm unable to express that as a simple expression without using a type switch.

I propose we add generic versions of:

func DecodeRune[Bytes []byte | string](p Bytes) (r rune, size int)
func DecodeLastRune[Bytes []byte | string](p Bytes) (r rune, size int)
func FullRune[Bytes []byte | string](p Bytes) bool
func RuneCount[Bytes []byte | string](p Bytes) int
func Valid[Bytes []byte | string](p Bytes) bool

It is unclear what the name should be since the simpler names are already taken by the non-generic variants.
Perhaps, we should have a v2 variant of utf8 that operates on either type.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Hold

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions