Documentation
¶
Index ¶
Constants ¶
const ShiftWidth = 4
The number of bits to shift the boundary information returned by [Step] to obtain the monospace width of the grapheme cluster.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graphemes ¶
type Graphemes struct {
// contains filtered or unexported fields
}
Graphemes implements an iterator over Unicode grapheme clusters, or user-perceived characters. While iterating, it also provides information about word boundaries, sentence boundaries, line breaks, and monospace character widths.
After constructing the class via NewGraphemes for a given string "str", Graphemes.Next is called for every grapheme cluster in a loop until it returns false. Inside the loop, information about the grapheme cluster as well as boundary information and character width is available via the various methods (see examples below).
Using this class to iterate over a string is convenient but it is much slower than using this package's [Step] or [StepString] functions or any of the other specialized functions starting with "First".
func NewGraphemes ¶
NewGraphemes returns a new grapheme cluster iterator.
func (*Graphemes) Next ¶
Next advances the iterator by one grapheme cluster and returns false if no clusters are left. This function must be called before the first cluster is accessed.
func (*Graphemes) Runes ¶
Runes returns a slice of runes (code points) which corresponds to the current grapheme cluster. If the iterator is already past the end or Graphemes.Next has not yet been called, nil is returned.