Open aymanbagabas opened 3 months ago
Related Issues and Documentation
[Package utf8 > func RuneCount ¶
](https://go.dev/pkg/unicode/utf8/?m=old#RuneCount) <!-- score=0.85166 -->
[Package utf8 > func RuneLen ¶
](https://go.dev/pkg/unicode/utf8/?m=old#RuneLen) <!-- score=0.84605 -->
[Package utf8 > func RuneStart ¶
](https://go.dev/pkg/unicode/utf8/?m=old#RuneStart) <!-- score=0.84119 -->
[Package utf8 > func DecodeLastRune ¶
](https://go.dev/pkg/unicode/utf8/?m=old#DecodeLastRune) <!-- score=0.82540 -->
[Package utf8 > func DecodeRune ¶
](https://go.dev/pkg/unicode/utf8/?m=old#DecodeRune) <!-- score=0.82336 -->
[Package utf8 > func RuneCountInString ¶
](https://go.dev/pkg/unicode/utf8/?m=old#RuneCountInString) <!-- score=0.82101 -->
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
This is a reasonable function, but it is rarely needed except by clients that are doing something unusually sophisticated, and it's a trivial consequence of the four constants that appear in the compact pictorial summary of UTF-8 found in any document on the subject--especially if you simplify each else if cond1 && cond2
to else if cond2
. (Each first condition is trivially true as a consequence of the control flow.)
Proposal Details
I find myself in need of such a method to determine how many bytes in a UTF-8 string when iterating over bytes. Following RFC 3629, we can implement something like
utf8.RuneStartLen(b byte) int
.Zig and Rust have these implemented to provide this functionality. Go could have something like this to do the same.