Codebase list golang-github-rivo-uniseg / 2e71928
Import Upstream version 0.2.0 Thorsten Alteholz 3 years ago
1 changed file(s) with 16 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
00 package uniseg
1
2 import "unicode/utf8"
13
24 // The states of the grapheme cluster parser.
35 const (
117119
118120 // NewGraphemes returns a new grapheme cluster iterator.
119121 func NewGraphemes(s string) *Graphemes {
120 g := &Graphemes{}
121 for index, codePoint := range s {
122 g.codePoints = append(g.codePoints, codePoint)
123 g.indices = append(g.indices, index)
124 }
125 g.indices = append(g.indices, len(s))
122 l := utf8.RuneCountInString(s)
123 codePoints := make([]rune, l)
124 indices := make([]int, l+1)
125 i := 0
126 for pos, r := range s {
127 codePoints[i] = r
128 indices[i] = pos
129 i++
130 }
131 indices[l] = len(s)
132 g := &Graphemes{
133 codePoints: codePoints,
134 indices: indices,
135 }
126136 g.Next() // Parse ahead.
127137 return g
128138 }