Created
November 5, 2025 10:13
-
-
Save hymkor/b3e1e19139f5fcc227b7d89a394466a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //go:build orgxwidth | |
| package moji | |
| import ( | |
| "unicode" | |
| "golang.org/x/text/width" | |
| ) | |
| func newRuneWidth(ambiguousIsWide bool) func(rune) int { | |
| var aw int | |
| if ambiguousIsWide { | |
| aw = 2 | |
| } else { | |
| aw = 1 | |
| } | |
| return func(r rune) int { | |
| if !unicode.IsPrint(r) { | |
| return 0 | |
| } | |
| switch width.LookupRune(r).Kind() { | |
| case width.Neutral, width.EastAsianNarrow, width.EastAsianHalfwidth: | |
| return 1 | |
| case width.EastAsianWide, width.EastAsianFullwidth: | |
| return 2 | |
| case width.EastAsianAmbiguous: | |
| return aw | |
| default: | |
| return 0 | |
| } | |
| } | |
| } | |
| var runeWidth = newRuneWidth(AmbiguousIsWide) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment