Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = Options{EastAsianWidth: false}
DefaultOptions is the default options for the display width calculation, which is EastAsianWidth: false.
Functions ¶
func Bytes ¶
Bytes calculates the display width of a []byte, by iterating over grapheme clusters in the byte slice and summing their widths.
Types ¶
type Graphemes ¶ added in v0.6.0
Graphemes is an iterator over grapheme clusters.
Iterate using the Next method, and get the width of the current grapheme using the Width method.
func BytesGraphemes ¶ added in v0.6.0
BytesGraphemes returns an iterator over grapheme clusters for the given []byte.
Iterate using the Next method, and get the width of the current grapheme using the Width method.
func StringGraphemes ¶ added in v0.6.0
StringGraphemes returns an iterator over grapheme clusters for the given string.
Iterate using the Next method, and get the width of the current grapheme using the Width method.
func (*Graphemes[T]) Next ¶ added in v0.6.0
Next advances the iterator to the next grapheme cluster.
type Options ¶
type Options struct {
EastAsianWidth bool
}
Options allows you to specify the treatment of ambiguous East Asian characters. When EastAsianWidth is false (default), ambiguous East Asian characters are treated as width 1. When EastAsianWidth is true, ambiguous East Asian characters are treated as width 2.
func (Options) Bytes ¶ added in v0.2.0
Bytes calculates the display width of a []byte, for the given options, by iterating over grapheme clusters in the slice and summing their widths.
func (Options) BytesGraphemes ¶ added in v0.6.0
BytesGraphemes returns an iterator over grapheme clusters for the given []byte, with the given options.
Iterate using the Next method, and get the width of the current grapheme using the Width method.
func (Options) Rune ¶ added in v0.2.0
Rune calculates the display width of a rune, for the given options.
You should almost certainly use String or Bytes for most purposes.
The smallest unit of display width is a grapheme cluster, not a rune. Iterating over runes to measure width is incorrect in many cases.
func (Options) String ¶ added in v0.2.0
String calculates the display width of a string, for the given options, by iterating over grapheme clusters in the string and summing their widths.
func (Options) StringGraphemes ¶ added in v0.6.0
StringGraphemes returns an iterator over grapheme clusters for the given string, with the given options.
Iterate using the Next method, and get the width of the current grapheme using the Width method.