package uniseg// runeWidth returns the monospace width for the given rune. The provided// grapheme property is a value mapped by the [graphemeCodePoints] table.//// Every rune has a width of 1, except for runes with the following properties// (evaluated in this order)://// - Control, CR, LF, Extend, ZWJ: Width of 0// - \u2e3a, TWO-EM DASH: Width of 3// - \u2e3b, THREE-EM DASH: Width of 4// - East-Asian width Fullwidth and Wide: Width of 2 (Ambiguous and Neutral// have a width of 1)// - Regional Indicator: Width of 2// - Extended Pictographic: Width of 2, unless Emoji Presentation is "No".func runeWidth( rune, int) int {switch {caseprControl, prCR, prLF, prExtend, prZWJ:return0caseprRegionalIndicator:return2caseprExtendedPictographic:ifproperty(emojiPresentation, ) == prEmojiPresentation {return2 }return1 }switch {case0x2e3a:return3case0x2e3b:return4 }switchproperty(eastAsianWidth, ) {caseprW, prF:return2 }return1}// StringWidth returns the monospace width for the given string, that is, the// number of same-size cells to be occupied by the string.func ( string) ( int) { := -1forlen() > 0 {varint _, , , = FirstGraphemeClusterInString(, ) += }return}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.