240413.1 · 087b3e4194c1feb0856b68d0e7c425c0994829cf
Added a String method to Graphemes. Resolves #52
reading declarations
Changes to grapheme.go. All files
@@ -1,6 +1,9 @@ package uniseg -import "unicode/utf8"+import (+ "fmt"+ "unicode/utf8"+) // Graphemes implements an iterator over Unicode grapheme clusters, or // user-perceived characters. While iterating, it also provides information@@ -47,6 +50,17 @@ func NewGraphemes(str string) *Graphemes { } } +// String returns a string representation of the current grapheme cluster+// iterator. It includes the current grapheme cluster, wrapped in curly+// brackets, and the first 10 bytes of the remaining string.+func (g *Graphemes) String() string {+ remaining := g.remaining+ if len(remaining) > 10 {+ remaining = remaining[:10] + "..."+ }+ return fmt.Sprintf("{%s}%s", g.cluster, remaining)+}+ // 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.