uniseg

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: AGPL-3.0, MIT, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewGraphemes(str string) *Graphemes

NewGraphemes returns a new grapheme cluster iterator.

func (*Graphemes) Next

func (g *Graphemes) Next() bool

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

func (g *Graphemes) Runes() []rune

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL