grapheme

package
v0.0.0-...-d3199ed Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

A package for dealing with graphemes

Rearranged from this package.

Also this package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(g *Graphemes) []byte

Bytes returns a byte slice which corresponds to the current grapheme cluster. If the iterator is already past the end or Next() has not yet been called, nil is returned.

func ClusterCount

func ClusterCount(s string) int

ClusterCount returns the number of user-perceived characters (grapheme clusters) for the given string. To calculate this number, it iterates through the string using the Graphemes iterator.

func Indices

func Indices(g *Graphemes) (int, int)

Indices returns the interval of the current grapheme cluster as byte positions into the original string. The first returned value "from" indexes the first byte and the second returned value "to" indexes the first byte that is not included anymore, i.e. str[from:to] is the current grapheme cluster of the original string "str". If Next() has not yet been called, both values are 0. If the iterator is already past the end, both values are 1.

func Reset

func Reset(g *Graphemes)

Reset puts the iterator into its initial state such that the next call to Next() sets it to the first grapheme cluster again.

func Runes

func Runes(g *Graphemes) []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 Next() has not yet been called, nil is returned.

func String

func String(g *Graphemes) string

String returns a substring of the original string which corresponds to the current grapheme cluster. If the iterator is already past the end or Next() has not yet been called, an empty string is returned.

Types

type Graphemes

type Graphemes struct {
	// contains filtered or unexported fields
}

Graphemes implements an iterator over Unicode extended grapheme clusters, specified in the Unicode Standard Annex #29. Grapheme clusters correspond to "user-perceived characters". These characters often consist of multiple code points (e.g. the "woman kissing woman" emoji consists of 8 code points: woman + ZWJ + heavy black heart (2 code points) + ZWJ + kiss mark + ZWJ +// woman) and the rules described in Annex #29 must be applied to group those code points into clusters perceived by the user as one character.

func NewGraphemes

func NewGraphemes(s 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.

type RegexpTransformer

type RegexpTransformer struct {
	// MaxMatchSize is the maximum size of a regexp match.
	// If a match exceeds this limit, it may be omitted.
	// (Default is 64kb).
	MaxMatchSize int
	// contains filtered or unexported fields
}

RegexpTransformer replaces regexp matches in a stream See: http://golang.org/x/text/transform

func Regexp

func Regexp(re *regexp.Regexp, new []byte) *RegexpTransformer

Regexp returns a transformer that replaces all matches of re with new

func RegexpFunc

func RegexpFunc(re *regexp.Regexp, replace func([]byte) []byte) *RegexpTransformer

RegexpFunc returns a transformer that replaces all matches of re with the result of calling replace with the match. The []byte parameter passed to replace should not be modified and is not guaranteed to be valid after the function returns.

func RegexpIndexFunc

func RegexpIndexFunc(re *regexp.Regexp, replace func(src []byte, index []int) []byte) *RegexpTransformer

RegexpIndexFunc returns a transformer that replaces all matches of re with the return value of replace. The replace function recieves the underlying src buffer and indexes into that buffer. The []byte parameter passed to replace should not be modified and is not guaranteed to be valid after the function returns.

func RegexpString

func RegexpString(re *regexp.Regexp, template string) *RegexpTransformer

RegexpString returns a transformer that replaces all matches of re with template Inside template, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.

func RegexpStringFunc

func RegexpStringFunc(re *regexp.Regexp, replace func(string) string) *RegexpTransformer

RegexpStringFunc returns a transformer that replaces all matches of re with the result of calling replace with the match.

func RegexpStringSubmatchFunc

func RegexpStringSubmatchFunc(re *regexp.Regexp, replace func([]string) string) *RegexpTransformer

RegexpStringSubmatchFunc returns a transformer that replaces all matches of re with the result of calling replace with the submatch.

func RegexpSubmatchFunc

func RegexpSubmatchFunc(re *regexp.Regexp, replace func([][]byte) []byte) *RegexpTransformer

RegexpSubmatchFunc returns a transformer that replaces all matches of re with the result of calling replace with the submatch. The [][]byte parameter passed to replace should not be modified and is not guaranteed to be valid after the function returns.

func (*RegexpTransformer) Reset

func (t *RegexpTransformer) Reset()

Reset resets the state and allows a Transformer to be reused.

func (*RegexpTransformer) Transform

func (t *RegexpTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform implements golang.org/x/text/transform#Transformer

type Transformer

type Transformer struct {
	transform.NopResetter
	// contains filtered or unexported fields
}

Transformer replaces text in a stream See: http://golang.org/x/text/transform

func TBytes

func TBytes(old, new []byte) Transformer

TBytes returns a transformer that replaces all instances of old with new. Unlike bytes.Replace, empty old values don't match anything.

func TString

func TString(old, new string) Transformer

TString returns a transformer that replaces all instances of old with new. Unlike strings.Replace, empty old values don't match anything.

func (Transformer) Transform

func (t Transformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform implements golang.org/x/text/transform#Transformer

Jump to

Keyboard shortcuts

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