Documentation ¶
Index ¶
- func Bytes(g *Graphemes) []byte
- func ClusterCount(s string) int
- func Indices(g *Graphemes) (int, int)
- func Reset(g *Graphemes)
- func Runes(g *Graphemes) []rune
- func String(g *Graphemes) string
- type Graphemes
- type RegexpTransformer
- func Regexp(re *regexp.Regexp, new []byte) *RegexpTransformer
- func RegexpFunc(re *regexp.Regexp, replace func([]byte) []byte) *RegexpTransformer
- func RegexpIndexFunc(re *regexp.Regexp, replace func(src []byte, index []int) []byte) *RegexpTransformer
- func RegexpString(re *regexp.Regexp, template string) *RegexpTransformer
- func RegexpStringFunc(re *regexp.Regexp, replace func(string) string) *RegexpTransformer
- func RegexpStringSubmatchFunc(re *regexp.Regexp, replace func([]string) string) *RegexpTransformer
- func RegexpSubmatchFunc(re *regexp.Regexp, replace func([][]byte) []byte) *RegexpTransformer
- type Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes ¶
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 ¶
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 ¶
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.
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 ¶
NewGraphemes returns a new grapheme cluster iterator.
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.
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.