text icon indicating copy to clipboard operation
text copied to clipboard

x/text: Preserve modifiers in AppendReverse() and ReverseString()

Open elliotwutingfeng opened this issue 2 years ago • 1 comments

Issue

Current implementation of AppendReverse() and ReverseString() does not check for modifier runes, which causes modifiers to be applied to wrong characters after string is reversed.

Proposed change

AppendReverse() and ReverseString() to check for modifier runes. Unicode Character Categories M and Sk are considered as modifiers in this proposed change.

Questions

  • Is it safe to assume that categories M and Sk contain only modifiers?
  • Are there any unicode modifiers not covered by categories M and Sk?

Unresolved

  • Current proposed change does not handle grapheme clusters that use zero-width joiners sandwiched between non-modifier runes like 🏳️‍🌈 and ണ്‍. More information on grapheme clusters: https://unicode.org/reports/tr29
  • A third-party package that handles grapheme clusters: https://github.com/rivo/uniseg (It also has a ReverseString() function)

Fixes https://github.com/golang/go/issues/50633

elliotwutingfeng avatar Jun 23 '23 19:06 elliotwutingfeng

This PR (HEAD: 58b4a27fea58d0ccf553b1cc864b67e903b68e4b) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/text/+/505775 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off) See the Wiki page for more info

gopherbot avatar Jun 23 '23 19:06 gopherbot