src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

iterator.go (804B)


      1 package graphemes
      2 
      3 import (
      4 	"github.com/clipperhouse/stringish"
      5 	"github.com/clipperhouse/uax29/v2/internal/iterators"
      6 )
      7 
      8 type Iterator[T stringish.Interface] struct {
      9 	*iterators.Iterator[T]
     10 }
     11 
     12 var (
     13 	splitFuncString = splitFunc[string]
     14 	splitFuncBytes  = splitFunc[[]byte]
     15 )
     16 
     17 // FromString returns an iterator for the grapheme clusters in the input string.
     18 // Iterate while Next() is true, and access the grapheme via Value().
     19 func FromString(s string) Iterator[string] {
     20 	return Iterator[string]{
     21 		iterators.New(splitFuncString, s),
     22 	}
     23 }
     24 
     25 // FromBytes returns an iterator for the grapheme clusters in the input bytes.
     26 // Iterate while Next() is true, and access the grapheme via Value().
     27 func FromBytes(b []byte) Iterator[[]byte] {
     28 	return Iterator[[]byte]{
     29 		iterators.New(splitFuncBytes, b),
     30 	}
     31 }